Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

balser.h

00001 /*
00002    Cabal - balser.h
00003    Short description
00004 
00005    $Id: balser.h,v 1.2 2004/03/29 14:17:29 jonnymind Exp $
00006 ---------------------------------------------
00007    Begin      : lun mar 29 2004 03:22
00008    Author     : Giancarlo Niccolai <gc@niccolai.ws>, (C) 2004
00009 
00010    Last modified because:
00011 
00012 */
00013 
00014 /**************************************************************************
00015 *   This program is free software; you can redistribute it and/or modify  *
00016 *   it under the terms of the GNU Library General Public License as       *
00017 *   published by the Free Software Foundation; either version 2.1 of the  *
00018 *   License, or (at your option) any later version.                       *
00019 ***************************************************************************/
00020 
00021 #ifndef _BALSER_H
00022 #define _BALSER_H
00023 
00024 #include <cabal.h>
00025 
00026 #define DEFAULT_PORT       2051
00027 #define CHANNEL_BANDWIDTH  8096
00028 #define LINE_BANDWITH      2048
00029 #define START_CONNECT      0xf3f0f1f2
00030 #define END_CONNECT        0xf9f8f7f1
00031 #define CLIENT_REP_SIZE    16
00032 
00033 using namespace std;
00034 using namespace Cabal;
00035 
00036 
00037 /**********************************************************************
00038 * This is our protocol definition.
00039 * May be much more complex than this.
00040 ***********************************************************************/
00041 
00042 typedef struct tag_packet {
00043    unsigned long userId;
00044    unsigned long id;
00045    unsigned long timestamp; // in milliseconds since midnight.
00046    char data[512 - (3 * sizeof( unsigned long ))];
00047 } PACKET;
00048 
00049 #define REQ_TYPE_ACK      1
00050 #define REQ_TYPE_RESEND   2
00051 
00052 typedef struct tag_clireq 
00053 {
00054    unsigned char type;
00055    unsigned long value;
00056 }CLI_REQ;
00057 
00058 /**********************************************************************
00059 * Theese are our clients; in real apps, we'll have a client object
00060 * encapsulating the lines, and some other kind of mapping.
00061 ***********************************************************************/
00062 
00063 class Client 
00064 {
00065 public:
00066    MSECS m_lastHail;
00067    Line *m_comLine;
00068    unsigned long m_userId;
00069    unsigned long m_rtt;
00070    unsigned long m_packetId;
00071    
00072    
00073    Client( unsigned long id, Line *line ) { 
00074       m_userId = id;
00075       m_comLine = line; 
00076       m_lastHail = Net::timeOfDay();
00077       m_rtt = 0xFFFF;
00078    }
00079    
00080    ~Client() { delete m_comLine; }
00081 };
00082 
00083 typedef map<unsigned long, Client *> ClientHash;
00084 
00085 /**********************************************************************
00086 * Transmissions are meant to send random data to our clients.
00087 ***********************************************************************/
00088 
00089 class DflTransmit: public Transmission
00090 {
00091    unsigned long m_packetId;
00092    unsigned long m_size;
00093       
00094    Address m_dest;
00095    Priority m_prio;
00096    unsigned long m_userId;
00097    std::list<unsigned long> m_resend;
00098    
00099 public:
00100    DflTransmit( unsigned long userId, unsigned long length, const Address &dest, Priority prio ) 
00101    {
00102       m_dest = dest;
00103       m_prio = prio;
00104       m_size = length;
00105       m_packetId = 0;
00106       // notice: in a real application we may receive a pointer to the client object (which
00107       // contains a line with a connection using this transmission. Or we may overload the
00108       // connection; as connections-transmissions are 1:1, a transmission may be specialized
00109       // in receiving a special connections subclass.
00110       m_userId = userId;
00111    }
00112    
00113    virtual void init( Connection *con ) {}
00114    virtual bool transmit( Connection *con );
00115    virtual void terminate( Connection *con ) { }
00116    
00117    void resend( unsigned long id ) {
00118       m_resend.push_back( id );
00119    }
00120 };
00121 
00122 
00123 /**********************************************************************
00124 * The reception has the duty to detect new clients incoming, and to 
00125 * fulfil existing clients request.
00126 *
00127 * This server has only one socket, and then, only one reception.
00128 ***********************************************************************/
00129 class DflReception: public Reception
00130 {
00131 
00132 public:
00133    DflReception() {
00134    }
00135 
00136    virtual void init( Socket *skt ) {}
00137    virtual bool receive( Socket *skt );
00138    virtual void terminate( Socket *skt ) {}
00139    
00140 };
00141 
00142 #endif
00143 
00144 /* end of balser.h */

Generated on Sat Apr 10 17:41:48 2004 for Cabal by doxygen 1.3.5