(file) Return to protocol.h CVS log (file) (dir) Up to [OMI] / omi / protocol

Diff for /omi/protocol/protocol.h between version 1.3 and 1.4

version 1.3, 2015/04/20 18:10:13 version 1.4, 2015/04/20 18:19:56
Line 28 
Line 28 
 #include "config.h" #include "config.h"
 #include <string.h> #include <string.h>
 #include <common.h> #include <common.h>
 #include <base/messages.h>  #include <base/Strand.h>
 #include <sock/selector.h> #include <sock/selector.h>
   #include <pal/thread.h>
   #include <protocol/header.h>
  
 BEGIN_EXTERNC BEGIN_EXTERNC
  
 typedef struct _Protocol Protocol;  #define PROTOCOLSOCKET_STRANDAUX_POSTMSG        0
   #define PROTOCOLSOCKET_STRANDAUX_READYTOFINISH  1
   #define PROTOCOLSOCKET_STRANDAUX_CONNECTEVENT   2
  
 /*  typedef enum _Protocol_AuthState
     Callback for processing new message.  {
     Parameters:      /* authentication failed (intentionaly takes value '0')*/
     protocol - pointer to a protocol object that received a message      PRT_AUTH_FAILED,
     message - message; consumer ahs to call 'AddRef' to keep message around  
         longer than callback's lifetime      /* listener (server) waits for connect request */
     data - user-provided callback data      PRT_AUTH_WAIT_CONNECTION_REQUEST,
     Return:  
         normally callbacks should return TRUE (means keep connection open);      /* listener (server) waits for second connect request with random data from file */
         returning FALSE means close connection      PRT_AUTH_WAIT_CONNECTION_REQUEST_WITH_FILE_DATA,
 */  
 typedef MI_Boolean (*ProtocolCallback)(      /* connector (client) waits for server's response */
     Protocol* protocol,      PRT_AUTH_WAIT_CONNECTION_RESPONSE,
     Message* message,  
     void* data);      /* authentication completed */
       PRT_AUTH_OK
 typedef enum _ProtocolEvent  }
 {  Protocol_AuthState;
     PROTOCOLEVENT_CONNECT,  
     PROTOCOLEVENT_CONNECT_FAILED,  typedef enum _Protocol_Type
     PROTOCOLEVENT_DISCONNECT  {
 }      PRT_TYPE_LISTENER,
 ProtocolEvent;      PRT_TYPE_CONNECTOR,
       PRT_TYPE_FROM_SOCKET
 typedef void (*ProtocolEventCallback)(  }
     Protocol* protocol,  Protocol_Type;
     ProtocolEvent event,  
     void* data);  /* Keeps data for file-based authentication */
   typedef struct _Protocol_AuthData
 MI_Result Protocol_New_Listener(  {
     Protocol** self,      char    path[PAL_MAX_PATH_SIZE];
     Selector* selector, /*optional, maybe NULL*/      char    authRandom[AUTH_RANDOM_DATA_SIZE];
     const char* locator,  }
     ProtocolCallback callback,  Protocol_AuthData;
     void* callbackData);  
   typedef struct _ProtocolBase
   {
       MI_Uint32           magic;                  //TODO: Evaluate if this is still needed after implementing multiplexer
       Selector*           selector;
       Selector            internal_selector;
       MI_Boolean          internal_selector_used;
       Addr                addr;
       OpenCallback        callback;               // Callback for new Interaction (when the connection is opened on listener/agent)
       void*               callbackData;
       Protocol_Type       type;
       /* Indicates whether instance has to be upacked or stored as byte array */
       MI_Boolean          skipInstanceUnpack;
   }
   ProtocolBase;
   
   typedef struct _ProtocolSocket
   {
       /* based member*/
       Handler             base;
   
       Strand              strand;
   
       /* currently sending message */
       Message*            message;
       size_t              sentCurrentBlockBytes;
       int                 sendingPageIndex;       /* 0 for header otherwise 1-N page index */
   
       /* receiving data */
       Batch *             receivingBatch;
       size_t              receivedCurrentBlockBytes;
       int                 receivingPageIndex;     /* 0 for header otherwise 1-N page index */
   
       /* send/recv buffers */
       Header              recv_buffer;
       Header              send_buffer;
   
       /* Auth state */
       Protocol_AuthState  authState;
       /* server side - auhtenticated user's ids */
       AuthInfo            authInfo;
       Protocol_AuthData*  authData;
   
       /* Whether connection has been established */
       MI_Boolean          isConnected;
       volatile ptrdiff_t  connectEventSent;
   
       volatile ptrdiff_t refCount; //used by socket listner for lifetimemanagement
       MI_Boolean          closeOtherScheduled;
   }
   ProtocolSocket;
   
   // Combined with a internal protocol base
   // A connector (PRT_TYPE_CONNECTOR) or either side of an agent connection (PRT_TYPE_FROM_SOCKET)
   typedef struct _ProtocolSocketAndBase
   {
       ProtocolSocket          protocolSocket;
       ProtocolBase            internalProtocolBase;
   }
   ProtocolSocketAndBase;
   
   MI_Result ProtocolBase_New_Listener(
       _Out_       ProtocolBase** selfOut,
       _In_opt_    Selector* selector, /*optional, maybe NULL*/
       _In_        const char* locator,
       _In_        OpenCallback callback,
       _In_        void* callbackData);
  
 /* /*
     Creates new protocol object (client side) and     Creates new protocol object (client side) and
Line 89 
Line 159 
     Returns:     Returns:
     'OK' if succefful, error otherwise     'OK' if succefful, error otherwise
 */ */
 MI_Result Protocol_New_Connector(  MI_Result ProtocolSocketAndBase_New_Connector(
     Protocol** self,      _Out_       ProtocolSocketAndBase** selfOut,
     Selector* selector, /*optional, maybe NULL*/      _In_opt_    Selector*               selector,       // optional, maybe NULL
     const char* locator,      _In_        const char*             locator,
     ProtocolCallback callback,      _In_        InteractionOpenParams*  params,
     void* callbackData,      _In_        const char*             user,
     ProtocolEventCallback eventCallback,      _In_        const char*             password );
     void* eventCallbackData,  
     const char* user,  MI_Result ProtocolSocketAndBase_New_AgentConnector(
     const char* password);      _Out_       ProtocolSocketAndBase** selfOut,
       _In_opt_    Selector*               selector,       // optional, maybe NULL
 /*      _In_        Sock                    s,
     Creates a new protocol object from connected stream socket      _In_        InteractionOpenParams*  params );
     (typically a pipe from server to agent).  
   MI_Result ProtocolSocketAndBase_New_Agent(
     Parameters:      _Out_       ProtocolSocketAndBase** selfOut,
     self - [out] protocol object      _In_opt_    Selector*               selector,       // optional, maybe NULL
     selector - [opt] selector to use for socket monitoring      _In_        Sock                    s,
     s - socket; if protocol created successfully, socket will be closed in Protocol_Delete.      _In_        OpenCallback            callback,
         If operation failed, socket is not closed.      _In_        void*                   callbackData);  // used along with callback
     skipInstanceUnpack - flag to skip instance un-packing; used  
         to skip unpacking instances from agent  MI_Result ProtocolBase_Delete(
     callback - function that protocol calls to inform about new messsages      ProtocolBase* self);
     callbackData -  
     eventCallback - function that protocl calls to inform about socket states  // Call this once it is out of the selector run loop
         connected/disconnected  MI_INLINE void ProtocolSocketAndBase_ReadyToFinish(
       ProtocolSocketAndBase* self)
     Returns:  {
     'OK' if succefful, error otherwise      Strand_ScheduleAux( &self->protocolSocket.strand, PROTOCOLSOCKET_STRANDAUX_READYTOFINISH );
 */  }
 MI_Result Protocol_New_From_Socket(  
     Protocol** self,  
     Selector* selector, /*optional, maybe NULL*/  
     Sock s,  
     MI_Boolean skipInstanceUnpack,  
     ProtocolCallback callback,  
     void* callbackData,  
     ProtocolEventCallback eventCallback,  
     void* eventCallbackData);  
   
 MI_Result Protocol_Delete(  
     Protocol* self);  
  
 MI_Result Protocol_Run( MI_Result Protocol_Run(
     Protocol* self,      ProtocolBase* self,
     MI_Uint64 timeoutUsec);     MI_Uint64 timeoutUsec);
  
 MI_Result Protocol_Send(  
     Protocol* self,  
     Message* message);  
   
 END_EXTERNC END_EXTERNC
  
 #endif /* _omi_protocol_h */ #endif /* _omi_protocol_h */


Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

ViewCVS 0.9.2