Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/naming service tests #713

Merged
merged 7 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
if-no-files-found: error

- name: Push image
if: github.ref == 'refs/heads/${{ env.DEFAULT_BRANCH }}'
if: ${{ github.ref == format('refs/heads/{0}', env.DEFAULT_BRANCH) }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
docker push "${{ needs.strings.outputs.docker-image-tag }}"
3 changes: 2 additions & 1 deletion nel/include/nel/net/callback_net_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <queue>
#endif

#include <functional>
#include <vector>


Expand All @@ -43,7 +44,7 @@ class CCallbackNetBase;
* msgin contains parameters of the message
* from is the SockId of the connection, for a client, from is always the same value
*/
typedef void (*TMsgCallback) (CMessage &msgin, TSockId from, CCallbackNetBase &netbase);
typedef std::function<void(CMessage &msgin, TSockId from, CCallbackNetBase &netbase)> TMsgCallback;


/// Callback items. See CMsgSocket::update() for an explanation on how the callbacks are called.
Expand Down
2 changes: 1 addition & 1 deletion nel/src/net/callback_net_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void CCallbackNetBase::processOneMessage ()
}
else
{
LNETL3_DEBUG ("LNETL3NB_CB: Calling callback (%s)%s", msgin.getName().c_str(), (cb==_DefaultCallback)?" DEFAULT_CB":"");
LNETL3_DEBUG ("LNETL3NB_CB: Calling callback (%s)", msgin.getName().c_str());

if (_PreDispatchCallback != NULL)
{
Expand Down
22 changes: 0 additions & 22 deletions nelns/naming_service/nelns/naming_service/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,28 +420,6 @@ void cbResendRegisteration(CMessage &msgin, TSockId from, CCallbackNetBase &netb
doRegister(name, addr, sid, from, netbase, true);
}

/**
* Callback for service registration.
*
* Message expected : RG
* - Name of service to register (string)
* - Address of service (CInetAddress)
*
* Message emitted : RG
* - Allocated service identifier (TServiceId) or 0 if failed
*/
void cbRegister(CMessage &msgin, TSockId from, CCallbackNetBase &netbase)
{
string name;
vector<CInetAddress> addr;
TServiceId sid;
msgin.serial(name);
msgin.serialCont(addr);
msgin.serial(sid);

doRegister(name, addr, sid, from, netbase);
}

/**
* Callback for service unregistration.
*
Expand Down
12 changes: 0 additions & 12 deletions nelns/naming_service/nelns/naming_service/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ void cbACKUnregistration(NLNET::CMessage &msgin, NLNET::TSockId from, NLNET::CCa
*/
void cbResendRegisteration(NLNET::CMessage &msgin, NLNET::TSockId from, NLNET::CCallbackNetBase &netbase);

/**
* Callback for service registration.
*
* Message expected : RG
* - Name of service to register (string)
* - Address of service (CInetAddress)
*
* Message emitted : RG
* - Allocated service identifier (TServiceId) or 0 if failed
*/
void cbRegister(NLNET::CMessage &msgin, NLNET::TSockId from, NLNET::CCallbackNetBase &netbase);

/**
* Callback for service unregistration.
*
Expand Down
35 changes: 22 additions & 13 deletions nelns/naming_service/nelns/naming_service/naming_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,15 @@ using std::vector;
using NLMISC::CConfigFile;
using NLMISC::Exception;
using NLMISC::toString;
using NLNET::CCallbackNetBase;
using NLNET::CCallbackServer;
using NLNET::CInetAddress;
using NLNET::CMessage;
using NLNET::CUnifiedNetwork;
using NLNET::TCallbackItem;
using NLNET::TServiceId;
using NLNET::TSockId;

//
// Callback array
//

TCallbackItem CallbackArray[] = {
{ "RG", cbRegister },
{ "RRG", cbResendRegisteration },
{ "QP", cbQueryPort },
{ "UNI", cbUnregisterSId },
{ "ACK_UNI", cbACKUnregistration },
// { "RS", cbRegisteredServices },
};

/**
* Init
*/
Expand Down Expand Up @@ -105,6 +94,14 @@ void CNamingService::init()
nsport = var->asInt();
}

TCallbackItem CallbackArray[] = {
{ "RG", [=](auto &msgin, auto from, auto &netbase) { cbRegister(msgin, from); } },
{ "RRG", cbResendRegisteration },
{ "QP", cbQueryPort },
{ "UNI", cbUnregisterSId },
{ "ACK_UNI", cbACKUnregistration },
// { "RS", cbRegisteredServices },
};
CallbackServer = new CCallbackServer;
CallbackServer->init(nsport);
CallbackServer->addCallbackArray(CallbackArray, sizeof(CallbackArray) / sizeof(CallbackArray[0]));
Expand All @@ -130,3 +127,15 @@ void CNamingService::release()
delete CallbackServer;
CallbackServer = NULL;
}

void CNamingService::cbRegister(CMessage &msgin, TSockId from)
{
string name;
vector<CInetAddress> addr;
TServiceId sid;
msgin.serial(name);
msgin.serialCont(addr);
msgin.serial(sid);

doRegister(name, addr, sid, from, *CallbackServer);
}
14 changes: 14 additions & 0 deletions nelns/naming_service/nelns/naming_service/naming_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define NELNS_NAMING_SERVICE_SERVICE_NAMING_SERVICE_H

#include <nel/net/buf_net_base.h>
#include <nel/net/callback_net_base.h>
#include <nel/net/message.h>
#include <nel/net/service.h>

#include <nelns/naming_service/service_instance_manager.h>
Expand All @@ -26,6 +28,18 @@ class CNamingService : public NLNET::IService
void release();

private:
/**
* Callback for service registration.
*
* Message expected : RG
* - Name of service to register (string)
* - Address of service (CInetAddress)
*
* Message emitted : RG
* - Allocated service identifier (TServiceId) or 0 if failed
*/
void cbRegister(NLNET::CMessage &msgin, NLNET::TSockId from);

/// Service instance manager singleton
CServiceInstanceManager _ServiceInstances;
};
Expand Down
19 changes: 13 additions & 6 deletions nelns/naming_service/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
add_test_executable(do_allocate_port_test
add_test_executable(nelns_do_allocate_port_test
do_allocate_port.test.cpp
)
target_link_libraries(do_allocate_port_test
target_link_libraries(nelns_do_allocate_port_test
nelns::ns
)


add_test_executable(naming_service_test
add_test_executable(nelns_naming_service_test
naming_service.test.cpp
)
target_link_libraries(naming_service_test
target_link_libraries(nelns_naming_service_test
nelns::ns
)


add_test_executable(service_instance_manager_test
add_test_executable(nelns_service_instance_manager_test
service_instance_manager.test.cpp
)
target_link_libraries(service_instance_manager_test
target_link_libraries(nelns_service_instance_manager_test
nelns::ns
)

add_test_executable(nelns_naming_service_it
naming_service.it.cpp
)
target_link_libraries(nelns_naming_service_it
nelns::ns
)
Loading
Loading