"Fossies" - the Fresh Open Source Software Archive

Member "erltools/com/connect/connect.h" (28 May 2004, 11565 Bytes) of package /linux/misc/old/erltools-4.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "connect.h" see the Fossies "Dox" file reference documentation.

    1 ///////////////////////////////////////////////////////////////////////////////////
    2 // connect.h : manage a connection
    3 ///////////////////////////////////////////////////////////////////////////////////
    4 #ifndef CONNECT_FILE
    5 #define CONNECT_FILE 1
    6 #if 0
    7 #include "/usr/local/include/sockinet.h"
    8 #else 
    9 #include "erlsock.h"
   10 #endif
   11 #include "token.h"
   12 
   13 // #include <String.h>
   14 #include "../asn/decasn.h"
   15 #include "../asnext/asnext.h"
   16 #include "coding.h"
   17 #include "inetutil.h"
   18 #include "metaconnect.h"
   19 #ifdef MOST_RECENT_STL
   20 #include <list>
   21 #else
   22 #include <list.h>
   23 #endif
   24 
   25 class Connection : public MetaConnection {
   26     
   27     public :
   28     
   29         // constructor 
   30         Connection ()
   31             : pvName(""),  pvChannel(""),  pvSendEvent(0),  pvSendEventChunk(0),  pvSendEventChunkEnd(0),  pvGetEvent(0),  pvGetEventBlocked(0)
   32                 ,  pvWaitingResponse(false),  pvIsOpened(false)
   33         {}
   34         
   35         // destructor
   36         ~Connection ()
   37         {
   38             if ( pvIsOpened ) 
   39                 CloseChannels();
   40         }
   41         
   42         // Open : opening of a connection under a name
   43         // parameters :
   44         //             name : name of the connection
   45         //             locAddr : local ip address
   46         //             _iIpAddr : IP address where to connect
   47         //             port : port where to connect
   48         //             maxTry : number max of try on dispatcher
   49         // return : the object
   50         virtual MetaConnection  &Open (const EString &name, char *locAddr = "127.0.0.1", char *_iIpAddr = (char *)0, int port = dispatcherPort
   51             , int maxTry = -1) ;
   52         
   53         // OpenChannel : opening a channel in a connection
   54         // parameters :
   55         //             channel : name of the channel
   56         //             outputPco : declare as an only ouput channel
   57         // return : the object
   58         virtual MetaConnection  &OpenChannel (EString channel, bool ouputPco = false) ;
   59         
   60         // CloseChannel : closing a channel in a connection
   61         // parameters :
   62         //             channel : name of the channel
   63         // return : the object
   64         virtual MetaConnection  &CloseChannel (EString channel) ;
   65         
   66         // CloseChannels : closing channels in a connection
   67         virtual void            CloseChannels () ;
   68         
   69         // SendRaw : send a raw content 
   70         // parameters :
   71         //               message : message to be send
   72         virtual void SendRaw ( PTREE message )
   73         {
   74             pvInetUtil.InetWrite(message, false, true);
   75         }
   76         
   77         // Send : send a content on a channel
   78         // parameters :
   79         //               channel : the channel where to send
   80         //               content : the content to send
   81         //               coarse : tell to send as a coarse string
   82         virtual void    Send (const EString &channel, PTREE content, bool coarse = false) ;
   83         
   84         // SendString : send a string content on a channel 
   85         // parameters :
   86         //               channel : the channel where to send
   87         //               messageString : message string to be send
   88         virtual void    SendString (const EString &channel, const EString &messageString) ;
   89         
   90         // Rearm : rearm connection to receive an event
   91         virtual void    Rearm () ; // Receive : receive a content 
   92         
   93         // Receive : receive a message
   94         // parameters :
   95         //               blocked : tell if wait for message
   96         // return : received tree
   97         virtual PTREE   Receive (bool blocked = false) ;
   98         
   99         // ReceiveContent : receive sthing on a channel
  100         // parameters :
  101         //               blocked : tell if wait for message
  102         // return : the received content
  103         virtual PTREE   ReceiveContent (bool blocked = false) ;
  104         
  105         // Syntax : set syntax for connection
  106         // parameters :
  107         // 
  108         //              channel : channel where to put syntax
  109         //              fileSyntax : file where to read syntax
  110         // return : the whole object
  111         virtual MetaConnection &Syntax ( EString channel, EString fileSyntax )
  112         {
  113             pvInetUtil.Syntax(channel, fileSyntax);
  114             return *this ;
  115         }
  116         
  117         // Syntax : set syntax for connection, default syntax
  118         // parameters :
  119         // 
  120         //              fileSyntax : file where to read syntax
  121         // return : the whole object
  122         virtual MetaConnection &Syntax ( EString fileSyntax )
  123         {
  124             pvInetUtil.Syntax(fileSyntax);
  125             return *this ;
  126         }
  127         
  128         // Decomp : get decompiler on a given channel
  129         // parameters :
  130         //              channel : the channel where to get the asn decompiler
  131         // return : the decompiler
  132         virtual DecompAsn *Decomp ( const EString &channel )
  133         {
  134             return pvInetUtil.Decomp(channel);
  135         }
  136         
  137         // FullInterpret : interpret a string coded as hexa string with user grammar
  138         // parameters :
  139         //              message : the string to be interpreted
  140         //              channel : channel of interpretation (if some)
  141         // return : the decoded tree
  142         virtual PTREE FullInterpret ( char *message, EString channel = " " )
  143         {
  144             return pvInetUtil.FullInterpret(message, channel);
  145         }
  146         
  147         // FullEncode : full encoding of a tree
  148         // parameters :
  149         //              tree : the tree to be encoded
  150         //              channel : channel of interpretation (if some)
  151         // return : the encoding
  152         virtual EString FullEncode ( PTREE tree, EString channel = " " )
  153         {
  154             Coding  *coding = pvInetUtil.FullEncode(tree, channel);
  155             EString resString = *((EString *)(*coding));
  156             
  157             free(coding);
  158             return resString ;
  159         }
  160         
  161         // TimeVal : TimeVal modifier
  162         // parameters :
  163         //               timeVal : new value for timeval
  164         virtual void TimeVal ( struct timeval &tval )
  165         {
  166             
  167             // set timeval struct 
  168             pvInetUtil.TimeVal(tval);
  169         }
  170         
  171         // Connected : accessor
  172         virtual bool Connected () const
  173         {
  174             return pvConnected ;
  175         }
  176         
  177         // Connected : connected modifier
  178         // parameters :
  179         //              connected : the new connected value
  180         // return : the whole object
  181         virtual MetaConnection &Connected ( bool connected )
  182         {
  183             pvConnected = connected ;
  184             return *this ;
  185         }
  186         
  187         // Empty : tell if they are messages allready read
  188         // return : true if no message
  189         virtual bool Empty ()
  190         {
  191             return pvInetUtil.Empty();
  192         }
  193         
  194         // FastEncode : tell if fast encode
  195         //              channel : channel to look for
  196         virtual bool FastEncode ( const EString &channel )
  197         {
  198             return pvInetUtil.FastEncode(channel);
  199         }
  200         
  201         // FastEncode : set fast encode
  202         // parameters :
  203         //              channel : channel to look for
  204         //              fastSpeed : tell if fast encode
  205         virtual void FastEncode ( const EString &channel, bool fastSpeed )
  206         {
  207             pvInetUtil.FastEncode(channel, fastSpeed);
  208         }
  209         
  210         // GetAMessage : get different type of messages
  211         // parameters :
  212         //               typeMessage : type of message
  213         //               string1 : first parameter string in message
  214         //               string2 : second parameter string in message
  215         //               string3 : third parameter string in message
  216         // return : the message
  217         virtual PTREE   GetAMessage (TypeMessage typeMessage, char *string1, char *string2 = (char *)0, char *string3 = (char *)0) ;
  218         
  219         // OutputSock : output socket 
  220         // return : the output socket
  221         virtual SOCKET OutputSock ()
  222         {
  223             return pvInetUtil.OutputSock();
  224         }
  225         
  226         // InputSock : input socket 
  227         // return : the input sockets
  228         virtual std::vector<SOCKET> InputSock ()
  229         {
  230             return pvInetUtil.InputSock();
  231         }
  232         
  233         // add input socket
  234         // parameters :
  235         //              newSock : the new socket
  236         virtual void AddInputSock ( SOCKET newSock )
  237         {
  238             pvInetUtil.AddInputSock(newSock);
  239         }
  240         
  241         // add input socket
  242         // parameters :
  243         //              newSock : the new socket
  244         virtual void RemoveInputSock ( SOCKET newSock )
  245         {
  246             pvInetUtil.RemoveInputSock(newSock);
  247         }
  248         
  249         // SizeMin : set size min of pdu
  250         // parameters :
  251         //               sizeMin : the size min
  252         // return : the whole object
  253         virtual MetaConnection &SizeMin ( unsigned int sizeMin )
  254         {
  255             
  256             // set value
  257             pvInetUtil.SizeMin(sizeMin);
  258             
  259             // return object
  260             return *this ;
  261         }
  262     
  263     private :
  264     
  265         EString     pvName ;                     // name of communication
  266         EString     pvChannel ;                  // channel where there are some
  267         
  268         //  pdu waiting
  269         InetUtil    pvInetUtil ;                 // for writing and reading
  270         bool        pvConnected ;                // tell if connected
  271         PTREE       pvSendEvent ;                // ptree sending event
  272         PTREE       pvSendEventName ;            // ptree sending event
  273         PTREE       pvSendEventPco ;             // ptree sending event
  274         PTREE       pvSendEventContent ;         // ptree sending event
  275         PTREE       pvSendEventChunk ;           // idem
  276         PTREE       pvSendEventChunkName ;       // ptree sending event
  277         PTREE       pvSendEventChunkPco ;        // ptree sending event
  278         PTREE       pvSendEventChunkContent ;    // ptree sending event
  279         PTREE       pvSendEventChunkEnd ;        // idem
  280         PTREE       pvSendEventChunkEndName ;    // ptree sending event
  281         PTREE       pvSendEventChunkEndPco ;     // ptree sending event
  282         PTREE       pvSendEventChunkEndContent ; // ptree sending event
  283         PTREE       pvGetEvent ;                 // idem
  284         PTREE       pvGetEventName ;             // idem
  285         PTREE       pvGetEventBlocked ;          // idem
  286         PTREE       pvGetEventBlockedName ;      // idem
  287         bool        pvWaitingResponse ;          // we send a blocked asking
  288         bool        pvIsOpened ;                 // tell if connection is opened
  289         EString     pvIp ;                       // ip address
  290         EString     pvAddress ;                  // local port
  291 };
  292 
  293 class AsnEncoder : public PTREE {
  294     
  295     public :
  296     
  297         // constructor
  298         AsnEncoder ()
  299             : PTREE()
  300         {}
  301         
  302         // destructor
  303         ~AsnEncoder () {}
  304         
  305         // EncodeClass : encoding of a class
  306         // parameters :
  307         //              tree : the tree to be encoded
  308         //              string : recipient string
  309         virtual void    EncodeClass (const PTREE &tree, EString &string) ;
  310         
  311         // DecodeClass : Decode a class 
  312         // parameters :
  313         //              string : string to be decoded
  314         // return : the tree
  315         virtual PTREE   DecodeClass (char *&string) ;
  316 };
  317 #endif