class CDaemon

PeerHood's Daemon class. This daemon is constantly running on the background and gathering information about nearby devices.

Inheritance:


Public Methods

[more]CDaemon* GetInstance()
Returns the currently running CDaemon instance.
[more]bool MakeDaemon()
Creates a daemon process.
[more]bool IsUnique()
Checks if another daemon is already running.
[more]void SignalHandler(int aSignum)
Handler for the signals TERM and INT.
[more]bool CreateLocalSocket()
Creates a local socket that is used between the daemon and PeerHood objects.
[more]void Run()
Main loop of the PeerHood Daemon. Listens for incoming requests and handles those.
[more]int LoadPlugins()
Loads all plugins.
[more]void StartPlugins()
Starts all loaded plugins.
[more]void Shutdown()
[more]void HandleGetDeviceList(const int aFd)
Handles the PH_GET_DEVICELIST request.
[more]void HandleGetLocalServiceList(const int aFd)
Handles the PH_GET_LOCAL_SERVICELIST request.
[more]void HandleInsertService(const int aFd, int aPid)
Handles the PH_INSERT_SERVICE request.
[more]void HandleRemoveService(const int aFd)
Handles the PH_REMOVE_SERVICE request.
[more]void HandleGetFreePort(const int aFd)
Handles the PH_GET_FREE_PORT request.
[more]bool Write(const int aFd, void* aBuffer, int aLength)
Writes data to the given file descriptor.
[more]bool SendDeviceInfo(MAbstractConnection* aConnection)
Sends device information
[more]bool SendServiceList(MAbstractConnection* aConnection)
Sends all local services to the given connection.
[more]bool SendPrototypes(MAbstractConnection* aConnection)
Sends all local services to the given connection.
[more]bool SendNeighborList(MAbstractConnection* aConnection)
Sends all devices in local database to the given connection.
[more]bool LoadParameter(string& aParameter)
Loads a parameter from the configuration file.
[more]void RemoveListeners()
Removes all listeners (disconnects and deletes) @docRemove event listeners @doc
[more]void RegisterListener(MAbstractListener* aListener)
Register a listener with daemon Register system state register
[more]void SetState(bool aActive)
Change daemon activity state Change activity of daemon
[more]void TriggerShutdown()
Set daemon to shut down state Trigger daemon shutdown


Inherited from MAbstractStateConverter:

Public Methods

ovirtual void SetAdapter(const std::string& aInterface, int aId)


Documentation

This class forms the base part of the PeerHood Daemon that monitors device's neighborhood all the time. The actual monitoring is carried out by several different plugins, one for each networking technology. Information gathered by the plugins is stored in this daemon and delivered to PeerHood objects when requested. The communication between the daemon and PeerHood objects is done via a local socket.

oCDaemon* GetInstance()
Returns the currently running instance of the CDaemon class. If no instances are created then an assertion will take place.

Returns:
pointer to the currently running CDaemon instance

obool MakeDaemon()
Changes the currently running program into a daemon process. This is done by forking twice and closing all open file descriptors. The pid of the daemon process is written to the /var/run/phd.pid file and checked upon every instantiation so that multiple instances of the program are not started. All standard file descriptors (STDIN, STDOUT and STDERR) are redirected to /dev/null.

Returns:
boolean telling whether the operation was successfull or not

obool IsUnique()
Checks if another daemon is already running. This is done by sending the signal 0 to the process whose pid is read from /var/run/phd.pid. If the result of kill is either success or EPERM then the other process exists.

Returns:
boolean telling if another daemon is already running

ovoid SignalHandler(int aSignum)
Handles the signals TERM and INT so that the daemon is shut down in a controlled manner. These actions include stopping all running plugins and closing the local / remote sockets.

Parameters:
aSignum - The number of the signal to be handled.
Returns:
none

obool CreateLocalSocket()
Creates a local (PF_UNIX) streaming socket (SOCK_STREAM) that is used as a communication channel between the daemon and PeerHood objects. The created socket is set to the listening state and possibly existing socket is simply removed without any further checking.

Returns:
boolean indicating the success of the socket creation

ovoid Run()
Main loop of the PeerHood Daemon. This function listens the local communications socket and handles the incoming requests. The only way to exit this function is via TERM, INT and KILL signals (or because of a bug of course...).

Returns:
none

oint LoadPlugins()
Loads all plugins from the directory pointed by the environment variable PH_PLUGIN_DIR. If the environment variable is not set then the operation will fail and no plugins are loaded. Note that this function doesn't start the plugins, it just loads them. The maximum length of the plugin's path is 1024 chars.

Returns:
the number of loaded plugins or -1 in the case of an error

ovoid StartPlugins()
Starts all successfully loaded plugins. Currently it is not possible to start only some certains plugins.

Returns:
none

ovoid Shutdown()

ovoid HandleGetDeviceList(const int aFd)
Handles the PH_GET_DEVICELIST request. First, the list of all devices is fecthed from the DeviceStorage database. Then it is inserted into pdus and finally the whole list is sent to the given file descriptor.

Parameters:
aFd - The file descriptor where the response should be sent to.
Returns:
none

ovoid HandleGetLocalServiceList(const int aFd)
Handles the PH_GET_LOCAL_SERVICELIST request. Each locally registered service is marshalled into octet data and sent to the given unix scoket.

Parameters:
aFd - The file descriptor where the response should be sent to.
Returns:
none

ovoid HandleInsertService(const int aFd, int aPid)
Handles the PH_INSERT_SERVICE request. The corresponding pdu is read and a new CService object created using the read marshalled information. Unmarshalling is done by the CService's constructor.

Parameters:
aFd - The file descriptor where the marshalled data should be read.
Returns:
none

ovoid HandleRemoveService(const int aFd)
Handles the PH_REMOVE_SERVICE request. The service corresponding to the read name is removed from the list of available local services. Note that an application can remove only the services it has inserted! (removing other services is prevented on the library side).

Parameters:
aFd - The file descriptor where the name should be read from.
Returns:
none

ovoid HandleGetFreePort(const int aFd)
Handles the PH_GET_FREE_PORT request. This function looks if the given port is free. If not or if the port is not given, this function looks for the next available port.

Parameters:
aFd - The file descriptor where the response should be sent to.
Returns:
none

obool Write(const int aFd, void* aBuffer, int aLength)
Writes data to the given file descriptor. The file descriptor is assumed to be open. The fd will not be closed even in the case of an error.

Parameters:
aFd - The file desriptor where the data should be written.
aBuffer - The data to be written.
aLength - The length of the data buffer.
Returns:
true if the data was written succesfully

obool SendDeviceInfo(MAbstractConnection* aConnection)
Parameters:
aConnection - The connection that should be used when sending the service list. This parameter cannot be NULL.
Returns:
true if the services were sent succesfully

obool SendServiceList(MAbstractConnection* aConnection)
Sends all local services to the given connection. This method should be called when a plugin gets the service list request from another PeerHood device. The connection must be opened before calling this function. Note that the connection object will be destroyed before this function returns.

Parameters:
aConnection - The connection that should be used when sending the service list. This parameter cannot be NULL.
Returns:
true if the services were sent succesfully

obool SendPrototypes(MAbstractConnection* aConnection)
Sends all local services to the given connection. This method should be called when a plugin gets the service list request from another PeerHood device. The connection must be opened before calling this function. Note that the connection object will be destroyed before this function returns.

Parameters:
aConnection - The connection that should be used when sending the service list. This parameter cannot be NULL.
Returns:
true if the services were sent succesfully

obool SendNeighborList(MAbstractConnection* aConnection)
Sends all devices in local database to the given connection. This method should be called when a plugin gets the neighborhood device list request from another PeerHood device. The connection must be opened before calling this function. Note that the connection object will be destroyed before this function returns.

Parameters:
aConnection - The connection that should be used when sending the service list. This parameter cannot be NULL.
Returns:
true if the neighborhood devices were sent succesfully

obool LoadParameter(string& aParameter)
Loads a parameter from the configuration file. If the requested parameter is found then the argument <code>aParameter</code> is replaced with parameter's value.

Parameters:
aParameter - Parameter's name.
Returns:
true if the requested parameter was found

ovoid RemoveListeners()

ovoid RegisterListener(MAbstractListener* aListener)
Add (register) new system state listener for daemon. New listeners are added to the end of iListenerList.

Register a new listener into daemon.

Parameters:
aListener - New listener to be registered
aListener - The actual listener to be registered

ovoid SetState(bool aActive)
Change the activity state of the daemon from passive to active and vice versa. Changing daemon state from active to passive makes the daemon to stop all plugins and when back in active state daemon restarts all plugins.

Change the state of the daemon from active to passive. Currently used by listeners -> into interface for listeners to use?

Parameters:
aActive - New activity state (true = active, false = passive)
aActive - New state (true - active, false - passive)

ovoid TriggerShutdown()
Set daemon to be shut down nicely. Multiple calls of this function do not mess up the shutdown process, when already shutting down new shutdown calls are just ignored - no need to change state e.g. when sending kill signal. Set daemon into shutdown state. Currently used by listeners -> into interface for listeners to use?


This class has no child classes.
See Also:
MAbstractPlugin
CPeerHood

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.