meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

peerhood:service-database [2011/09/02 12:05] (current)
Line 1: Line 1:
 +====== Service Database ======
 +
 +===== Service database entries =====
 +
 +There is only one instance of a daemon in each machine. This daemon holds the information concerning local clients (list<​ClientData*>​ iClients) as well as local services (list<​Cservice*>​ iServiceList). Whenever daemon receives PH_INSERT_SERVICE pdu it adds a new service to the list of local services. This happens with the ''​HandleInsertService(fd,​ pid)''​ command. Whenever daemon receives PH_REMOVE_SERVICE pdu it removes one service from the list. This happens with ''​HandleRemoveService(fd)''​ command. In both insertion and removal the deamon communicates with the library through the local daemon socket to get the necessary informantion for the operation.
 +
 +Service database is a storage where the daemon stores the registered local services.
 +
 +At the moment the following details are stored as the service is registered:
 +<​code>​
 +int iPid - process id where the service is located
 +unsigned short iPort - port of the service (unique number)
 +std::string iAttributes - attributes of the service (should this be parameters)
 +std::string iName - name of the service
 +</​code>​
 +
 +===== Service creation methods =====
 +Service can be created by the following methods of the CService class:
 +<​code>​
 +CService(CService&​ Original) - copy constructor
 +CService(char* data) - from received data (usually from applications)
 +CService(char* data, int Pid) 
 +CService(char* data, string key) - according to the proto (BT-base, WLANbase, local, etc.)
 +CService(char* name, string attributes, int pid, unsigned short port) - if all parameters known
 +</​code>​
 +
 +==== Future ideas ====
 +A field of service description could be added here. Later this could be a pointer to XML, etc. whatever service description.
 +
 +===== Use of service database =====
 +Initially the service database is empty. As the [[daemon]] is initialized no services are in this database. Applications or service environments e.g. FAME may register their own services into the daemon and after this these services can be seen from outside as well as from inside. We have examples of [[server]] that registeres services to the database and [[client]] that can be used for looking and using the services. ​
 +
 +==== Registering services ====
 +Service registration starts with the application like [[client]] or [[server]] registering their services with the following two commands defined in the [[MPeerHood interface]]:​ ''​peerhood->​RegisterService(name,​ attributes)''​ and ''​peerhood->​RegisterService(name,​ attributes, port)''​. The difference between these two is that the funtion with ''​port''​ parameter tries to reserve the port given. ​
 +
 +These RegisterService commands mainly check that there'​s connection to the daemon(''​iConnected''​) and that the callback (''​iCallback''​) is there. After this the port need to be got/​verifies. This is done by sending '''​PH_GET_FREE_PORT'''​ pdu with the port to the [[Daemon]] (two seperate writes). Daemon checks if the given port, if any, is free and ALWAYS returns a port for the library. This means that if the port was given but not available, then a new port is selected. This happens also if no port was given. After having a suitable port the service is created by using [service creation methods]. This service is then sent to the daemon and pushed into the process'​s own list ''​iServiceList''​. This list is for the local services within the process.
 +
 +=== Example ===
 +In server:
 +<​code>​
 +peerhood->​RegisterService(string("​number"​),​ string("​Number crunching"​))
 +peerhood->​RegisterService(string("​alphabet"​),​ string("​Alphabet crunching"​),​ string("​444444"​))
 +</​code>​
 +
 +These commands register two separate services. The first one does not specify the port number so it receives a free port, but the second one gets the port it requests if available.
 +
 +==== Unregistering services ====
 +Unregistering the services happen by using the [[MPeerhood interface]] methods: peerhood->​UnregisterService(string service) or UnregisterService(string service, string port). There is a minor difference between these two methods that may in some cases be disasterous. If the '''​Port'''​ is given ONLY the service in that port will be Unregistered. But if the port is incorrect or not given, then ALL services with the given name are Unregistered.
 +
 +=== Example ===
 +In server:
 +<​code>​
 +peerhood->​UnregisterService(string("​number"​))
 +peerhood->​UnregisterService(string("​alphabet"​),​ string("​444444"​))
 +</​code>​
 +
 +These two commands are examples of using those two different UnregisterService() methods. The first one would unregister all services named number and the last one only one service if found from the port given.