# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

service.h File Reference

Base class for all network services. More...

#include "nel/misc/types_nl.h"
#include "nel/misc/config_file.h"
#include "nel/misc/entity_id.h"
#include "nel/net/unified_network.h"
#include <string>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  NLMISC
namespace  NLNET

Defines

#define NLNET_SERVICE_MAIN(__ServiceClassName, __ServiceShortName, __ServiceLongName, __ServicePort, __ServiceCallbackArray, __ConfigDir, __LogDir)
 The goal of this macro is to simplify the service creation, it creates the main body function. More...


Detailed Description

Base class for all network services.

Id:
service.h,v 1.59 2002/11/08 13:28:40 lecroart Exp

Definition in file service.h.


Define Documentation

#define NLNET_SERVICE_MAIN __ServiceClassName,
__ServiceShortName,
__ServiceLongName,
__ServicePort,
__ServiceCallbackArray,
__ConfigDir,
__LogDir   
 

Value:

\
int main(int argc, const char **argv) \
{ \
        __ServiceClassName *scn = new __ServiceClassName; \
        scn->setArgs (argc, argv); \
        scn->setCallbackArray (__ServiceCallbackArray, sizeof(__ServiceCallbackArray)/sizeof(__ServiceCallbackArray[0])); \
        sint retval = scn->main (__ServiceShortName, __ServiceLongName, __ServicePort, __ConfigDir, __LogDir); \
        delete scn; \
        return retval; \
}
The goal of this macro is to simplify the service creation, it creates the main body function.

If you don't want to give a callback array, just put EmptyCallbackArray in the last argument

Example:

        // Create the Test Service class
        class CTestService : public IService
        {
        public:
                void init () { nlinfo("init()"); }
                bool update () { nlinfo ("update();"); return true; }
                void release () { nlinfo("release()"); }
        };
        // Create the main() function that create a test service instance and execute it.
        // "TS" is the short service name and "test_service" is the long one.
        // The name of the config file is based on the long name!
        // EmptyCallbackArray means that you don't provide right now the callback
        // the last 2 path are where is the config file is (directory) and where to log info (directory)
        NLNET_SERVICE_MAIN(CTestService, "TS", "test_service", 0, EmptyCallbackArray, "", "");
 *

If you want the port to not be auto-assigned by the naming service, set the port to a number different than 0.

Args used by service are always in lower case:

-C followed by the directory where we can find the config file -L followed by the directory where we have to log -N followed by the alias name (used by the admin system) -P followed by the listen port -A followed by the path where to execute the service (it uses chdir()) -I to start the service iconified

Definition at line 119 of file service.h.