NDCore Class Reference

Core NetDog object. More...

List of all members.

Public Types

typedef uint8_t SocketType

Public Member Functions

 NDCore ()
 Constructor.
 ~NDCore ()
 Destructor.
NDSocketAddresscreateSocketAddress (void)
 Allocates a new NDSocketAddress object Due to ND's internal memory management, you need to use this function to create an NDSocketAddress, however you should use the "delete" operator to clean it up.
NDResult createChannel (SocketType stype, NDChannelID channel_id=0, NDChannel **chan_ptr=NULL, uint16_t ip_port=0)
 Creates a new UDP or TCP communications channel.
NDChannelgetChannelByID (NDChannelID id)
 Finds NDChannel by its Channel ID.
NDTimeValue getCoreTime (void)
 Gets miliseconds since initialization of ND.
NDResult registerScheduledHandler (NDScheduledHandler *shan, NDTimeValue period)
 Schedules a user-specified function to be called on a regular basis.
NDResult cancelScheduledHandler (void)
 Cancels the user-specified scheduled function.
NDResult registerConnHandler (NDConnHandler *ch)
 Installs a handler for conn-related events (conn create/timeout/close/reconnect/delete callbacks).
void mainLoop (NDTimeValue timeout=-1)
 Executes the main loop of NetDog.

Static Public Attributes

static const SocketType TCP = 0x01
static const SocketType UDP = 0x02

Detailed Description

Core NetDog object. This is the "root" of the object hierarchy, and is used to create channels, perform network processing via mainLoop(), etc.


Constructor & Destructor Documentation

NDCore::NDCore (  ) 

Creating an instance of the core initializes NetDog and gives you access to NetDog functions, e.g. allows you to create channels, which in turn allow you to create conns, etc.

Returns:
new NDCore object

Member Function Documentation

NDResult NDCore::cancelScheduledHandler ( void   ) 
Returns:
NDRES_OK if the scheduled function was cancelled successfully
NDResult NDCore::createChannel ( NDCore::SocketType  stype,
NDChannelID  channel_id = 0,
NDChannel **  chan_ptr = NULL,
uint16_t  ip_port = 0 
)
Parameters:
stype Determines if this is a UDP or TCP channel, acceptable values are NDCore::UDP or NDCore::TCP
channel_id A network-wide unique integer identifier for the channel. This is user specified, and the meaning is user defined.
chan_ptr Location of the channel pointer that will contain the new NDChannel object. No pointer is passed back if chan_ptr=NULL.
ip_port The UDP port number to accept incomming packets on, uses an OS assigned port number if udp_port=0
Returns:
NDRES_OK on success
Example:
        NDCore *core = ... //already initialized

        NDChannel *chan = NULL;
        if(core->createChannelUDP(100, &chan, 0) != NDRES_OK){
            // Bail Out
            exit(1);
        }
        // Do stuff with our working channel!
    
NDSocketAddress * NDCore::createSocketAddress ( void   ) 
Returns:
A new NDSocketAddress object
NDChannel * NDCore::getChannelByID ( NDChannelID  id  ) 
Parameters:
[in] id the channel ID.
Returns:
Pointer to the NDChannel object, or NULL if not found.
NDTimeValue NDCore::getCoreTime ( void   ) 
Returns:
time in miliseconds
void NDCore::mainLoop ( NDTimeValue  timeout = -1  ) 

Executes the main loop of NetDog. This must be called frequently (e.g. at least every 10ms) or network performance may decline, potentially dropping connections. This loop processing all incoming network data, such as events, RPCs, object updates, etc.

Parameters:
timeout maximum time in milliseconds to allow this function to run before exiting (e.g. to maintain a certain graphical framerate, etc.)
NDResult NDCore::registerConnHandler ( NDConnHandler ch  ) 
Parameters:
ch An instance of a class implementing the NDConnHandler interface
Returns:
NDRES_OK if the handler was install successfully
NDResult NDCore::registerScheduledHandler ( NDScheduledHandler shan,
NDTimeValue  period 
)
Parameters:
shan An instance of a class which implements the NDScheduledHandler interface
period The interval at which to call the scheduled function, in milliseconds
Returns:
NDRES_OK if the scheduled function was installed successfully

Generated on Wed Jul 21 18:14:48 2010 for nd2 by  doxygen 1.6.1