Implementation of the MPeerHood interface.
Inheritance:
Public Methods
-
MPeerHood* GetInstance(CBasicCallback* aCallback)
- Getter of the <code>CPeerHoodImpl</code> singleton.
-
CPeerHoodImpl(CBasicCallback* aCallback)
- Constructor.
-
~CPeerHoodImpl()
- Destructor.
-
bool Init(int aArgc, char** aArgv)
- Initializes the PeerHood library.
-
void LoadPlugins()
- Loads all available plugins.
-
TDeviceList* GetDeviceListL()
- Returns a list of all detected devices.
-
TDeviceList* GetDeviceListL(const string* aServiceName)
- Returns a list of devices hosting the given service.
-
TServiceList* GetLocalServiceListL()
- Returns a list of local services.
-
MAbstractConnection* Connect(TDeviceIterator& aDevice, const string aServiceName)
- Creates connection to a service.
-
MAbstractConnection* Connect(MAbstractDevice& aDevice, const string& aServiceName)
- Creates connection to a service.
-
MAbstractConnection* Connect(TServiceIterator& aService)
- Creates connection to a service.
-
MAbstractConnection* Connect(CService& aService)
- Creates connection to a service.
-
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.
-
bool Write(const void* aBuffer, int aLength)
- Sends data to the PeerHood daemon.
-
bool Read(void* aBuffer, int aLength)
- Reads data from the PeerHood daemon.
-
unsigned short RegisterService(const string& aName, const string& aAttributes, const string& aPort)
- Registers a service with predefined port
-
unsigned short RegisterService(const string& aName, const string& aAttributes)
- Registers a service.
-
bool UnregisterService(const string& aService)
- Unregisters a method of the given name. Notice that this destroys ALL services of the given name
-
bool UnregisterService(const string& aService, const string& aPort)
- Unregisters a service.
-
void SetPreferedPlugin(const char* aPluginName)
- Sets the prefered plugin.
-
bool LoadParameter(string& aParameter)
- Loads a parameter from the configuration file.
-
bool LoadParameter(char* aName, int* aParameter)
- Loads an integral parameter from the configuration file.
-
bool MonitorDevice(TDeviceIterator& aDevice)
- Monitors a remote device.
-
bool UnmonitorDevice(TDeviceIterator& aDevice)
- Ceases device monitoring.
-
bool SignalMonitorDevice(TDeviceIterator& aDevice)
- Monitors a remote device.
-
bool SignalUnmonitorDevice()
- Ceases device monitoring.
-
void* ThreadStarter(void* aArguments)
- Starts the monitoring thread.
-
void* SignalThreadStarter(void* aArguments)
- Starts the signal monitoring thread.
-
void* RoamingThreadStarter(void* aArguments)
- Starts the roaming thread.
-
bool StopRoamingThread()
- Stops the roaming thread.
-
bool StartRoamingThread()
- Creates a new thread for Roaming Thread
-
void PingerThread()
- Monitor thread's function.
-
void MonitorThread()
- Signal monitor thread's function.
-
void RoamingThread()
- Roaming Thread Implementation
-
void Lock()
- Sets library's internal lock.
-
void Unlock()
- Unsets the internal lock.
-
const char* CreatePidfilePath()
- Create a path for pid file
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.
MPeerHood* 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
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
~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
bool 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
void 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
TDeviceList* GetDeviceListL()
-
Returns a list containing all detected devices. It's caller's
responsibility to free the returned list.
- Returns:
- list containing all detected devices
TDeviceList* 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
TServiceList* 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
MAbstractConnection* 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
MAbstractConnection* 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
MAbstractConnection* 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
MAbstractConnection* 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
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. 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
bool 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
bool 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
unsigned 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
unsigned 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
bool 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
bool 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
void 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
bool 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
bool 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
bool 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
bool UnmonitorDevice(TDeviceIterator& aDevice)
-
Ceases device monitoring.
- Parameters:
- aDevice - Target device.
- Returns:
- true if the device was under monitoring, otherwise false
bool SignalMonitorDevice(TDeviceIterator& aDevice)
-
Monitors a remote device.
- Parameters:
- aDevice - Iterator pointing to the target device.
- Returns:
- true if the monitoring could be started
bool SignalUnmonitorDevice()
-
Ceases device monitoring.
- Parameters:
- aDevice - Target device.
- Returns:
- true if the device was under monitoring, otherwise false
void* 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
void* 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
void* 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
bool StopRoamingThread()
-
Stops the roaming thread.
- Parameters:
- aArguments - Pointer to the currently running instance of the class.
- Returns:
- boolean for errors
bool StartRoamingThread()
-
- Parameters:
- Creates - a new thread for Roaming Thread
- Returns:
- true if the thread could be created
void 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
void MonitorThread()
-
Function that the dedicated monitoring thread is running on.
Method notifies callback PH_WEAK_LINK if link level goes down
- Returns:
- none
void 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
void 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
void 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
const 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++.