EchoLib  1.3.3
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
EchoLink::Dispatcher Class Reference

A class for handling incoming connections and dispatch active connections. More...

#include <EchoLinkDispatcher.h>

Inheritance diagram for EchoLink::Dispatcher:

Public Member Functions

 ~Dispatcher (void)
 Destructor. More...
 

Static Public Member Functions

static void setPortBase (int base)
 Set the port base for the two UDP ports. More...
 
static void setBindAddr (const Async::IpAddress &ip)
 Set the bind address for the two UDP ports. More...
 
static Dispatcherinstance (void)
 Get the Singleton instance. More...
 
static void deleteInstance (void)
 Delete the singleton object if it exists. More...
 

Public Attributes

sigc::signal< void, const Async::IpAddress &, const std::string &, const std::string &, const std::string & > incomingConnection
 A signal that is emitted when someone is trying to connect. More...
 

Friends

class Qso
 

Detailed Description

A class for handling incoming connections and dispatch active connections.

Author
Tobias Blomberg
Date
2003-03-30

This is a class that listens to incoming packets on the two EchoLink UDP-ports. The incoming packets are dispatched to the associated connection object (EchoLink::Qso), if it exists. If the connection does not exist, a signal will be emitted to indicate that an incoming connection is on its way. The Qso objects will register themselfs automatically with the Dispatcher upon creation.

This class is a Singleton object. That is, there can be only one object. The constructor is private so the only way to create a Dispatcher object is to use the static method Dispatcher::instance. It will create a new object if it does not exist and return the object if it exists. On error, a NULL pointer will be returned.

Start your application by creating a Dispatcher object. It will then start to listen to the EchoLink ports for incoming connections. Also, be sure to check the returned pointer. If it is NULL, something went wrong. If it is not checked, you will have trouble later when creating Qso objects. So, a typical start in your application would be something like the code below.

#include <iostream>
#include <cstdlib>
#include <AsyncCppApplication.h>
using namespace std;
using namespace Async;
using namespace EchoLink;
class MyClass : public sigc::trackable
{
public:
MyClass(void)
{
{
cerr << "Could not create EchoLink listener (Dispatcher) object\n";
exit(1);
}
Dispatcher::instance()->incomingConnection.connect(mem_fun(*this,
&MyClass::onIncomingConnection));
}
private:
void onIncomingConnection(const IpAddress& ip, const string& callsign,
const string& name, const string& priv)
{
cerr << "Incoming connection from " << ip << ": " << callsign
<< " (" << name << ")\n";
// Find out the station data by using the Directory class
// Create a new Qso object to accept the connection
}
};
int main(int argc, char **argv)
{
CppApplication app; // or QtApplication
MyClass my_class;
app.exec();
}

Definition at line 144 of file EchoLinkDispatcher.h.

Constructor & Destructor Documentation

EchoLink::Dispatcher::~Dispatcher ( void  )

Destructor.

Member Function Documentation

static void EchoLink::Dispatcher::deleteInstance ( void  )
static

Delete the singleton object if it exists.

static Dispatcher* EchoLink::Dispatcher::instance ( void  )
static

Get the Singleton instance.

Returns
Returns a dispatcher object. If the object does not already exist, a new object will be created. If the object can not be created, a NULL pointer is returned.

This function should be used to get access to the Singleton dispatcher object. Every time access to the dispatcher object is required, this function should be used to get the pointer. It is illegal to store it in a variable at program startup and then use that variable. It is possible that the dispatcher is deleted at some point in a program. The stored pointer would then be invalid. It is ok to use a local temporary variable to make access more convenient if no calls are made to other functions that access the dispatcher.

static void EchoLink::Dispatcher::setBindAddr ( const Async::IpAddress &  ip)
static

Set the bind address for the two UDP ports.

Parameters
ipThe IP address to use

This static function set the IP-address/interface to bind to for the two UDP communications ports. This may be necessary if the computer is fitted with more than one network interface and only one should be used for EchoLink. This function may only be called when a dispatcher object does not exist. Typically, call this function before calling the Dispatcher::instance function for the first time. If this function is not called at all, the dispatcher will bind to all available interfaces.

static void EchoLink::Dispatcher::setPortBase ( int  base)
static

Set the port base for the two UDP ports.

Parameters
baseThe port base to use

This static function set the port base to use for the two UDP communications ports. This function may only be called when a dispatcher object does not exist. Typically, call this function before calling the Dispatcher::instance function for the first time. If this function is not called at all, the default ports will be used.

Friends And Related Function Documentation

friend class Qso
friend

Definition at line 215 of file EchoLinkDispatcher.h.

Member Data Documentation

sigc::signal<void, const Async::IpAddress&, const std::string&, const std::string&, const std::string&> EchoLink::Dispatcher::incomingConnection

A signal that is emitted when someone is trying to connect.

Parameters
callsignThe callsign of the connecting station
nameThe name of the connecting station
privA private string for passing connection parameters

This signal is emitted when a remote station tries to connect. It will be emitted every time a connect datagram is received.

Definition at line 210 of file EchoLinkDispatcher.h.


The documentation for this class was generated from the following file: