class CPeerHoodImpl

Implementation of the MPeerHood interface.

Inheritance:


Public Methods

[more]MPeerHood* GetInstance(CBasicCallback* aCallback)
Getter of the <code>CPeerHoodImpl</code> singleton.
[more] CPeerHoodImpl(CBasicCallback* aCallback)
Constructor.
[more] ~CPeerHoodImpl()
Destructor.
[more]bool Init(int aArgc, char** aArgv)
Initializes the PeerHood library.
[more]void LoadPlugins()
Loads all available plugins.
[more]TDeviceList* GetDeviceListL()
Returns a list of all detected devices.
[more]TDeviceList* GetDeviceListL(const string* aServiceName)
Returns a list of devices hosting the given service.
[more]TServiceList* GetLocalServiceListL()
Returns a list of local services.
[more]MAbstractConnection* Connect(TDeviceIterator& aDevice, const string aServiceName)
Creates connection to a service.
[more]MAbstractConnection* Connect(MAbstractDevice& aDevice, const string& aServiceName)
Creates connection to a service.
[more]MAbstractConnection* Connect(TServiceIterator& aService)
Creates connection to a service.
[more]MAbstractConnection* Connect(CService& aService)
Creates connection to a service.
[more]MAbstractConnection* Connect(const string& aPrototype, const string& aAddress, const int aPort, const int aPid, const string& aServiceName, const string& aDeviceName, int aChecksum)
Creates connection to a service.
[more]bool Write(const void* aBuffer, int aLength)
Sends data to the PeerHood daemon.
[more]bool Read(void* aBuffer, int aLength)
Reads data from the PeerHood daemon.
[more]unsigned short RegisterService(const string& aName, const string& aAttributes, const string& aPort)
Registers a service with predefined port
[more]unsigned short RegisterService(const string& aName, const string& aAttributes)
Registers a service.
[more]bool UnregisterService(const string& aService)
Unregisters a method of the given name. Notice that this destroys ALL services of the given name
[more]bool UnregisterService(const string& aService, const string& aPort)
Unregisters a service.
[more]void SetPreferedPlugin(const char* aPluginName)
Sets the prefered plugin.
[more]bool LoadParameter(string& aParameter)
Loads a parameter from the configuration file.
[more]bool LoadParameter(char* aName, int* aParameter)
Loads an integral parameter from the configuration file.
[more]bool MonitorDevice(TDeviceIterator& aDevice)
Monitors a remote device.
[more]bool UnmonitorDevice(TDeviceIterator& aDevice)
Ceases device monitoring.
[more]bool SignalMonitorDevice(TDeviceIterator& aDevice)
Monitors a remote device.
[more]bool SignalUnmonitorDevice()
Ceases device monitoring.
[more]void* ThreadStarter(void* aArguments)
Starts the monitoring thread.
[more]void* SignalThreadStarter(void* aArguments)
Starts the signal monitoring thread.
[more]void* RoamingThreadStarter(void* aArguments)
Starts the roaming thread.
[more]bool StopRoamingThread()
Stops the roaming thread.
[more]bool StartRoamingThread()
Creates a new thread for Roaming Thread
[more]void PingerThread()
Monitor thread's function.
[more]void MonitorThread()
Signal monitor thread's function.
[more]void RoamingThread()
Roaming Thread Implementation
[more]void Lock()
Sets library's internal lock.
[more]void Unlock()
Unsets the internal lock.
[more]const char* CreatePidfilePath()
Create a path for pid file


Inherited from MPeerHood:


Documentation

Implementation of the MPeerHood interface. This class separates the definition of the PeerHood interface from its implementation. Application developers should not use this class directly. Instead, they should use the MPeerHood interface.

oMPeerHood* GetInstance(CBasicCallback* aCallback)
Getter of the <code>CPeerHoodImpl</code> singleton. This getter ensures that only one instance of the class is created at any given time.

Parameters:
aCallback - Callback interface that is used to receive notifications about different PeerHood events.
Returns:
pointer to the currently active instance of the class

o CPeerHoodImpl(CBasicCallback* aCallback)
Default constructor of the class. This constructor is protected and can be called only via the <code>GetInstance</code> method.

Parameters:
aCallback - Callback interface that is used to receive notifications about different PeerHood events. This method gets also iPid which is used for identifying devices with user-specified device name.
Returns:
none

o ~CPeerHoodImpl()
Destructor. During the destruction process the local socket is closed, registered services are removed and all active pingers are stopped and deleted.

Returns:
none

obool Init(int aArgc, char** aArgv)
Initialized the PeerHood library. The initialization process includes connection establishment to the PeerHood daemon. If the daemon cannot be contacted then initialization has failed.

Parameters:
aArgc - The number of arguments.
aArgv - An array containing all parameters. Currently the only recognized parameter is <code>'-DEBUG='</code> that sets the logging output.
Returns:
true if the PeerHood daemon could be contacted

ovoid LoadPlugins()
Loads all available plugins from the directory pointed by the PH_PLUGIN_DIR environment variable. If the variable is not set then no plugins will be loaded. All plugins have a filename *peerhood.so.

Returns:
none

oTDeviceList* GetDeviceListL()
Returns a list containing all detected devices. It's caller's responsibility to free the returned list.

Returns:
list containing all detected devices

oTDeviceList* GetDeviceListL(const string* aServiceName)
Returns a list of devices hosting the given service. The returned list is reserved by this function and the caller should take care of its deletion.

Parameters:
aServiceName - The service to look for.
Returns:
list containing all detected devices that host the given service

oTServiceList* GetLocalServiceListL()
Returns a list of local services. The list contains all the services that are registered to the local device.

Returns:
list containing all locally registered devices

oMAbstractConnection* Connect(TDeviceIterator& aDevice, const string aServiceName)
Creates connection to a service. Caller must free and, if necessary, close the returned connection object.

Parameters:
aDevice - The remote device to connect to.
aServiceName - The destination service.
Returns:
connection object that is connected to a remote device or NULL if the connection establishmnent failed

oMAbstractConnection* Connect(MAbstractDevice& aDevice, const string& aServiceName)
Creates connection to a service. Caller must free and, if necessary, close the returned connection object.

Parameters:
aDevice - The remote device to connect to.
aServiceName - The destination service.
Returns:
connection object that is connected to a remote device or NULL if the connection establishmnent failed

oMAbstractConnection* Connect(TServiceIterator& aService)
Creates connection to a service. Caller must free and, if necessary, close the returned connection object.

Parameters:
aService - The destination service.
Returns:
connection object that is connected to a remote device or NULL if the connection establishmnent failed

oMAbstractConnection* Connect(CService& aService)
Creates connection to a service. Caller must free and, if necessary, close the returned connection object. Functionality is exactly the same as in CPeerHoodImpl::Connect(TServiceIterator& aService) but with direct reference to CService-object. This was implemented that the library could be used via C-wrapper functions.

Parameters:
aService - The destination service.
Returns:
connection object that is connected to a remote device or NULL if the connection establishmnent failed

oMAbstractConnection* Connect(const string& aPrototype, const string& aAddress, const int aPort, const int aPid, const string& aServiceName, const string& aDeviceName, int aChecksum)
Creates connection to a service. Caller must free and, if necessary, close the returned connection object. This method provides a virtul "handle" for the application. This virtual connection is then mapped to some specific technology. If roaming -option is enabled a RoamingThread is created. This thread provides Seamless Connectivity for application.

Parameters:
aPrototype - Targets prototype
aAddress - Target service's address.
aPort - Target service's port (or equivalent).
aServiceName - The destination service.
aDevice - Targets device name
aChecksum - Targets checksum number
Returns:
connection object that is connected to a service or NULL if the connection establishmnent failed

obool Write(const void* aBuffer, int aLength)
Sends data to the PeerHood daemon.

Parameters:
aBuffer - Buffer containg the data to be sent.
aLength - Source data's length.
Returns:
true if all data was sent without errors

obool Read(void* aBuffer, int aLength)
Reads data from the PeerHood daemon. The destination buffer must be large enough to hold the requested data.

Parameters:
aBuffer - Destination buffer.
aLength - The amount of bytes to be read.
Returns:
true if the requested number of bytes could be read

ounsigned short RegisterService(const string& aName, const string& aAttributes, const string& aPort)
Registers a service to the PeerHood library and the daemon with predefined port. This kind of service could be e.g. a one that is contacted with the direct data connection mode.

Parameters:
aName - Service's name.
aAttributes - Service's attributes.
aPort - Service's port
Returns:
port number

ounsigned short RegisterService(const string& aName, const string& aAttributes)
Registers a service to the PeerHood library and the daemon. This kind of service could be e.g. a one that is contacted with the direct data connection mode.

Parameters:
aName - Service's name.
aAttributes - Service's attributes.
Returns:
port number, if the service was registered succesfully - 0 otherwise

obool UnregisterService(const string& aService)
Unregisters a method. The requested service is removed from the PeerHood library and the daemon. Note that the actual service object is not deleted - it's the application's responsibility to take care of that.

Parameters:
aService - Service's name.
Returns:
true if the service was succesfully unregistered

obool UnregisterService(const string& aService, const string& aPort)
Unregisters a method. The requested service is removed from the PeerHood library and the daemon. Note that the actual service object is not deleted - it's the application's responsibility to take care of that.

Parameters:
aService - Service's name.
Returns:
true if the service was succesfully unregistered

ovoid SetPreferedPlugin(const char* aPluginName)
Sets the prefered networking plugin. This function can be used to override the setting 'PreferedPlugin' from the configuration file. Changes will take effect only from the moment of call, i.e. running services are not affected.

Parameters:
aPluginName - New default plugin's name.
Returns:
none

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

obool LoadParameter(char* aName, int* aParameter)
Loads an integral parameter from the configuration file. If the given paramter is found then the argument <code>aParameter</code> is replaced with the parameter's value.

Parameters:
aName - Parameter's name.
aParameter - Will contain asked parameter's value on return. This argument cannot be NULL.
Returns:
true if the requested parameter could be loaded

obool MonitorDevice(TDeviceIterator& aDevice)
Monitors a remote device. If a change (connection loss, return to range etc.) happens then the registered callback interface is notified.

Parameters:
aDevice - Iterator pointing to the target device.
Returns:
true if the monitoring could be started

obool UnmonitorDevice(TDeviceIterator& aDevice)
Ceases device monitoring.

Parameters:
aDevice - Target device.
Returns:
true if the device was under monitoring, otherwise false

obool SignalMonitorDevice(TDeviceIterator& aDevice)
Monitors a remote device.

Parameters:
aDevice - Iterator pointing to the target device.
Returns:
true if the monitoring could be started

obool SignalUnmonitorDevice()
Ceases device monitoring.

Parameters:
aDevice - Target device.
Returns:
true if the device was under monitoring, otherwise false

ovoid* ThreadStarter(void* aArguments)
Starts the monitoring thread. This is function is used because the <code>pthreads</code> library doesn't allow to start a member function as a thread.

Parameters:
aArguments - Pointer to the currently running instance of the class.
Returns:
always NULL

ovoid* SignalThreadStarter(void* aArguments)
Starts the signal monitoring thread. This is function is used because the <code>pthreads</code> library doesn't allow to start a member function as a thread.

Parameters:
aArguments - Pointer to the currently running instance of the class.
Returns:
always NULL

ovoid* RoamingThreadStarter(void* aArguments)
Starts the roaming thread. This is function is used because the <code>pthreads</code> library doesn't allow to start a member function as a thread.

Parameters:
aArguments - Pointer to the currently running instance of the class.
Returns:
always NULL

obool StopRoamingThread()
Stops the roaming thread.

Parameters:
aArguments - Pointer to the currently running instance of the class.
Returns:
boolean for errors

obool StartRoamingThread()
Parameters:
Creates - a new thread for Roaming Thread
Returns:
true if the thread could be created

ovoid PingerThread()
Function that the dedicated monitoring thread is running on. Devices under monitoring are checked one at a time so that the interval one device is checked is approximately the value 'MonitoringInterval' from the configuration file. If a device is lost or found again then the registered callback interface is notified.

Returns:
none

ovoid MonitorThread()
Function that the dedicated monitoring thread is running on. Method notifies callback PH_WEAK_LINK if link level goes down

Returns:
none

ovoid RoamingThread()
Roaming Thread Implementation. This thread monitores current connections and tries to replace weak connections using alternative networking technology. iThreadList is used by RoamingThread and VirtualConnection class for to contain all the estblished connections. If these two threads try to change or read this list at the sametime problems arise. PeerHoodImpl class uses iCopying boolean member variable which is used for "locking" the iThreadList. RoamingThread first locks the iThreadList (virtualconnection can't change it) and then makes a local copy of it and releases the "lock". More specific description in Thesis.

Returns:
none

ovoid Lock()
Sets library's internal lock. This lock is used to prevent multiple threads from accessing the same monitoring data at the same time.

Returns:
none

ovoid Unlock()
Unsets library's internal locking mutex. This lock is used to prevent multiple threads to access the same monitoring data at the same time.

Returns:
none

oconst char* CreatePidfilePath()
Create a path for pid file


This class has no child classes.
Friends:
class CVirtualConnection
See Also:
MPeerHood

Alphabetic index HTML hierarchy of classes or Java



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