Dragonfly  4.4
A text-based game engine
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
df::NetworkManager Class Reference
Inheritance diagram for df::NetworkManager:
Inheritance graph
[legend]
Collaboration diagram for df::NetworkManager:
Collaboration graph
[legend]

Public Member Functions

int startUp ()
 
void shutDown ()
 
bool isValid (std::string event_type) const
 
int setServer (bool server=true, std::string port=DRAGONFLY_PORT)
 
bool isServer () const
 
int accept ()
 
int connect (std::string host, std::string port=DRAGONFLY_PORT)
 
void setMaxSockets (int new_max_sock)
 
int getMaxSockets () const
 
int getNumSockets () const
 
int send (const void *buffer, int bytes, int sock_index=0)
 
int receive (void *buffer, int nbytes, bool leave, int sock_index=0)
 
int close (int sock_index=0)
 
int closeAll ()
 
int genDataEvents (int sock_index=0) const
 
bool isConnected (int sock_index=0) const
 
int isData (int sock_index=0) const
 
int isAnyData () const
 
int getSocket (int sock_index=0) const
 
- Public Member Functions inherited from df::Manager
std::string getType () const
 
bool isStarted () const
 
int onEvent (const Event *p_event) const
 
int registerInterest (Object *p_o, std::string event_type)
 
int unregisterInterest (Object *p_o, std::string event_type)
 

Static Public Member Functions

static NetworkManagergetInstance ()
 

Private Member Functions

 NetworkManager (NetworkManager const &)
 
void operator= (NetworkManager const &)
 

Private Attributes

int m_unconnected_sock
 
std::vector< int > m_sock
 
int m_max_sock
 

Additional Inherited Members

- Protected Member Functions inherited from df::Manager
void setType (std::string new_type)
 

Member Function Documentation

int df::NetworkManager::accept ( )

Accept network connection.

If successful, generate EventNetwork (accept). Return sock index if new connection (note, 0 for first). Return -1 if no new connection, but no error. Return -2 if errror.

int df::NetworkManager::close ( int  sock_index = 0)

Close network connection on indicated socket.

Return 0 if success, else -1.

int df::NetworkManager::closeAll ( )

Close all network connections.

Return 0 if success, else negative number.

int df::NetworkManager::connect ( std::string  host,
std::string  port = DRAGONFLY_PORT 
)

Make network connection to host at port.

If successful, generate EventNetwork (connect). Return return socket index if success, -1 if error.

int df::NetworkManager::genDataEvents ( int  sock_index = 0) const

If complete network message on indicated socket, (first int is message size, in bytes) generate EventNetwork (data).

Return 1 if generated event, 0 if no message, -1 if error.

static NetworkManager& df::NetworkManager::getInstance ( )
static

Get the one and only instance of the NetworkManager.

int df::NetworkManager::getMaxSockets ( ) const

Get maximum number of connected sockets.

int df::NetworkManager::getNumSockets ( ) const

Get number of connected sockets.

int df::NetworkManager::getSocket ( int  sock_index = 0) const

Return system socket from socket index, -1 if error.

int df::NetworkManager::isAnyData ( ) const

Check if data on any connected socket.

Return index of first socket with data. Return -1 if no socket has data.

bool df::NetworkManager::isConnected ( int  sock_index = 0) const

Return true if socket is connected, else false.

int df::NetworkManager::isData ( int  sock_index = 0) const

Check if network data on indicated socket.

Return amount of data (0 if no data), -1 if not connected or error.

bool df::NetworkManager::isServer ( ) const

Return true if successufully setup as server, else false.

bool df::NetworkManager::isValid ( std::string  event_type) const
virtual

Accept only network events.

Returns false for other engine events.

Reimplemented from df::Manager.

int df::NetworkManager::receive ( void *  buffer,
int  nbytes,
bool  leave,
int  sock_index = 0 
)

Receive from connected network socket (no more than nbytes).

If leave is true, don't remove data from socket (peek). Return number of bytes received, -1 if error.

int df::NetworkManager::send ( const void *  buffer,
int  bytes,
int  sock_index = 0 
)

Send bytes from buffer to connected network socket.

Return 0 if success, -1 if error.

void df::NetworkManager::setMaxSockets ( int  new_max_sock)

Set maximum number of connected sockets.

int df::NetworkManager::setServer ( bool  server = true,
std::string  port = DRAGONFLY_PORT 
)

Setup NetworkManager as server (if false, reset to client).

Return 0 if ok, else -1.

void df::NetworkManager::shutDown ( )
virtual

Shut down NetworkManager.

Reimplemented from df::Manager.

int df::NetworkManager::startUp ( )
virtual

Start up NetworkManager.

Reimplemented from df::Manager.