ipc.c File Reference

#include <strings.h>
#include "ipc_p.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/io_packets.h>
#include <gwenhywfar/iomanager.h>
#include <gwenhywfar/text.h>

Go to the source code of this file.

Functions

void GWEN_Ipc__Request_AddRequestMsg (GWEN_IPC__REQUEST *r, GWEN_IPCMSG *m)
void GWEN_Ipc__Request_AddResponseMsg (GWEN_IPC__REQUEST *r, GWEN_IPCMSG *m)
void GWEN_Ipc__Request_Attach (GWEN_IPC__REQUEST *r)
void GWEN_Ipc__Request_Dump (GWEN_IPC__REQUEST *r, FILE *f, int indent)
void GWEN_Ipc__Request_free (GWEN_IPC__REQUEST *r)
GWEN_IPCMSG_LIST * GWEN_Ipc__Request_GetRequestMsgList (const GWEN_IPC__REQUEST *r)
int GWEN_Ipc__Request_HasRequestMsg (GWEN_IPC__REQUEST *r, uint32_t nid, uint32_t id)
GWEN_IPC__REQUEST * GWEN_Ipc__Request_new ()
int GWEN_IpcManager__CheckRequests (GWEN_IPCMANAGER *mgr)
GWEN_IPC__REQUEST * GWEN_IpcManager__FindRequest (GWEN_IPCMANAGER *mgr, uint32_t rid, GWEN_IPC__REQUEST *r)
int GWEN_IpcManager__HandlePacket (GWEN_IPCMANAGER *mgr, GWEN_IPCNODE *n, GWEN_IO_REQUEST *pk)
GWEN_IPCMSG * GWEN_IpcManager__MakeErrorResponse (GWEN_UNUSED GWEN_IPCMANAGER *mgr, GWEN_IPCMSG *m, int code, const char *txt)
void GWEN_IpcManager__RemoveNodeRequestMessages (GWEN_UNUSED GWEN_IPCMANAGER *mgr, GWEN_IPCNODE *n, GWEN_IPC__REQUEST_LIST *rl, const char *msgType)
int GWEN_IpcManager__SendMsg (GWEN_UNUSED GWEN_IPCMANAGER *mgr, GWEN_IPCMSG *m)
int GWEN_IpcManager__Work (GWEN_IPCMANAGER *mgr)
uint32_t GWEN_IpcManager_AddClient (GWEN_IPCMANAGER *mgr, GWEN_IO_LAYER *ioBase, uint32_t mark)
uint32_t GWEN_IpcManager_AddServer (GWEN_IPCMANAGER *mgr, GWEN_IO_LAYER *ioBase, uint32_t mark)
void GWEN_IpcManager_Attach (GWEN_IPCMANAGER *mgr)
int GWEN_IpcManager_Disconnect (GWEN_IPCMANAGER *mgr, uint32_t nid)
void GWEN_IpcManager_Dump (GWEN_IPCMANAGER *mgr, FILE *f, int indent)
void GWEN_IpcManager_free (GWEN_IPCMANAGER *mgr)
const char * GWEN_IpcManager_GetApplicationName (const GWEN_IPCMANAGER *mgr)
uint32_t GWEN_IpcManager_GetClientForNetLayer (const GWEN_IPCMANAGER *mgr, const GWEN_IO_LAYER *io)
GWEN_DB_NODEGWEN_IpcManager_GetInRequestData (GWEN_IPCMANAGER *mgr, uint32_t rid)
GWEN_IO_LAYERGWEN_IpcManager_GetIoLayer (GWEN_IPCMANAGER *mgr, uint32_t nid)
uint32_t GWEN_IpcManager_GetNextInRequest (GWEN_IPCMANAGER *mgr, uint32_t mark)
GWEN_DB_NODEGWEN_IpcManager_GetResponseData (GWEN_IPCMANAGER *mgr, uint32_t rid)
GWEN_IPCMANAGERGWEN_IpcManager_new ()
GWEN_DB_NODEGWEN_IpcManager_PeekResponseData (GWEN_IPCMANAGER *mgr, uint32_t rid)
int GWEN_IpcManager_RemoveClient (GWEN_IPCMANAGER *mgr, uint32_t nid)
int GWEN_IpcManager_RemoveRequest (GWEN_IPCMANAGER *mgr, uint32_t rid, int inOrOut)
int GWEN_IpcManager_SendRequest (GWEN_IPCMANAGER *mgr, uint32_t nid, GWEN_DB_NODE *req, uint32_t *pReqId)
int GWEN_IpcManager_SendResponse (GWEN_IPCMANAGER *mgr, uint32_t rid, GWEN_DB_NODE *rsp)
void GWEN_IpcManager_SetApplicationName (GWEN_IPCMANAGER *mgr, const char *s)
void GWEN_IpcManager_SetClientDownFn (GWEN_IPCMANAGER *mgr, GWEN_IPCMANAGER_CLIENTDOWN_FN f, void *user_data)
int GWEN_IpcManager_Work (GWEN_IPCMANAGER *mgr)
void GWEN_IpcMsg_Dump (GWEN_IPCMSG *m, FILE *f, int indent)
void GWEN_IpcMsg_free (GWEN_IPCMSG *m)
GWEN_IPCMSG * GWEN_IpcMsg_new (GWEN_IPCNODE *n)
void GWEN_IpcNode_Attach (GWEN_IPCNODE *n)
void GWEN_IpcNode_Dump (GWEN_IPCNODE *n, FILE *f, int indent)
void GWEN_IpcNode_free (GWEN_IPCNODE *n)
GWEN_IPCNODE * GWEN_IpcNode_new ()

Variables

static uint32_t gwen_ipc__lastid = 0

Function Documentation

void GWEN_Ipc__Request_AddRequestMsg ( GWEN_IPC__REQUEST *  r,
GWEN_IPCMSG *  m 
)

Definition at line 248 of file ipc.c.

Referenced by GWEN_IpcManager__HandlePacket(), and GWEN_IpcManager_SendRequest().

void GWEN_Ipc__Request_AddResponseMsg ( GWEN_IPC__REQUEST *  r,
GWEN_IPCMSG *  m 
)

Definition at line 265 of file ipc.c.

Referenced by GWEN_IpcManager__HandlePacket(), and GWEN_IpcManager_SendResponse().

void GWEN_Ipc__Request_Attach ( GWEN_IPC__REQUEST *  r  ) 

Definition at line 239 of file ipc.c.

void GWEN_Ipc__Request_Dump ( GWEN_IPC__REQUEST *  r,
FILE *  f,
int  indent 
)

Definition at line 296 of file ipc.c.

References GWEN_IpcMsg_Dump().

Referenced by GWEN_IpcManager_Dump().

void GWEN_Ipc__Request_free ( GWEN_IPC__REQUEST *  r  ) 
GWEN_IPCMSG_LIST* GWEN_Ipc__Request_GetRequestMsgList ( const GWEN_IPC__REQUEST *  r  ) 

Definition at line 257 of file ipc.c.

int GWEN_Ipc__Request_HasRequestMsg ( GWEN_IPC__REQUEST *  r,
uint32_t  nid,
uint32_t  id 
)

Definition at line 274 of file ipc.c.

Referenced by GWEN_IpcManager__HandlePacket().

GWEN_IPC__REQUEST* GWEN_Ipc__Request_new (  ) 

Definition at line 207 of file ipc.c.

References DBG_MEM_INC, GWEN_LIST_INIT, and GWEN_NEW_OBJECT.

Referenced by GWEN_IpcManager__HandlePacket(), and GWEN_IpcManager_SendRequest().

int GWEN_IpcManager__CheckRequests ( GWEN_IPCMANAGER mgr  ) 
GWEN_IPC__REQUEST* GWEN_IpcManager__FindRequest ( GWEN_IPCMANAGER mgr,
uint32_t  rid,
GWEN_IPC__REQUEST *  r 
)

Definition at line 569 of file ipc.c.

int GWEN_IpcManager__HandlePacket ( GWEN_IPCMANAGER mgr,
GWEN_IPCNODE *  n,
GWEN_IO_REQUEST pk 
)
GWEN_IPCMSG* GWEN_IpcManager__MakeErrorResponse ( GWEN_UNUSED GWEN_IPCMANAGER mgr,
GWEN_IPCMSG *  m,
int  code,
const char *  txt 
)
void GWEN_IpcManager__RemoveNodeRequestMessages ( GWEN_UNUSED GWEN_IPCMANAGER mgr,
GWEN_IPCNODE *  n,
GWEN_IPC__REQUEST_LIST *  rl,
const char *  msgType 
)
int GWEN_IpcManager__SendMsg ( GWEN_UNUSED GWEN_IPCMANAGER mgr,
GWEN_IPCMSG *  m 
)
int GWEN_IpcManager__Work ( GWEN_IPCMANAGER mgr  ) 
uint32_t GWEN_IpcManager_AddClient ( GWEN_IPCMANAGER mgr,
GWEN_IO_LAYER ioBase,
uint32_t  mark 
)

Adds a client to the IPC manager. The connection will not be established until needed.

Returns:
node id of the node created (0 on error)
Parameters:
mgr pointer to the IPC manager object
ioBase io layer over which the IPC is to be transfered. This module stacks some more layers on top of this: LayerPackets-LayerHttp->LayerBuffered. The given base layer MUST be neither connected nor in listening state)
mark a value assigned to the new connection. This value can be used for functions GWEN_IpcManager_GetNextInRequest and GWEN_IpcManager_SendMultiRequest, it is not otherwise used by the IPC manager

Definition at line 453 of file ipc.c.

References DBG_INFO, GWEN_Io_Layer_free(), GWEN_Io_LayerPackets_new(), GWEN_Io_Manager_RegisterLayer(), GWEN_IpcNode_new(), and GWEN_LOGDOMAIN.

uint32_t GWEN_IpcManager_AddServer ( GWEN_IPCMANAGER mgr,
GWEN_IO_LAYER ioBase,
uint32_t  mark 
)

Adds a server to the IPC manager. The IPC manager will immediately enter listen mode on the given transport layer.

Returns:
node id of the node created (0 on error)
Parameters:
mgr pointer to the IPC manager object
ioBase io layer over which the IPC is to be transfered. This module stacks some more layers on top of this: LayerPackets-LayerHttp->LayerBuffered. The given base layer MUST be neither connected nor in listening state)
mark a value assigned to the new connection. This value can be used for functions GWEN_IpcManager_GetNextInRequest and GWEN_IpcManager_SendMultiRequest, it is not otherwise used by the IPC manager

Definition at line 417 of file ipc.c.

References DBG_INFO, GWEN_Io_Layer_free(), GWEN_Io_Layer_ListenRecursively(), GWEN_Io_LayerPackets_new(), GWEN_Io_Manager_RegisterLayer(), GWEN_IpcNode_new(), GWEN_LOGDOMAIN, and NULL.

void GWEN_IpcManager_Attach ( GWEN_IPCMANAGER mgr  ) 

Definition at line 371 of file ipc.c.

References DBG_MEM_INC.

int GWEN_IpcManager_Disconnect ( GWEN_IPCMANAGER mgr,
uint32_t  nid 
)

Starts disconnecting the given client/server.

Definition at line 966 of file ipc.c.

References DBG_ERROR, GWEN_Io_Layer_DisconnectRecursively(), GWEN_IpcManager__RemoveNodeRequestMessages(), GWEN_LOGDOMAIN, and NULL.

void GWEN_IpcManager_Dump ( GWEN_IPCMANAGER mgr,
FILE *  f,
int  indent 
)
void GWEN_IpcManager_free ( GWEN_IPCMANAGER mgr  ) 

Definition at line 381 of file ipc.c.

References DBG_MEM_DEC, and GWEN_FREE_OBJECT.

const char* GWEN_IpcManager_GetApplicationName ( const GWEN_IPCMANAGER mgr  ) 

Definition at line 400 of file ipc.c.

uint32_t GWEN_IpcManager_GetClientForNetLayer ( const GWEN_IPCMANAGER mgr,
const GWEN_IO_LAYER io 
)

Definition at line 775 of file ipc.c.

References DBG_ERROR, and GWEN_LOGDOMAIN.

GWEN_DB_NODE* GWEN_IpcManager_GetInRequestData ( GWEN_IPCMANAGER mgr,
uint32_t  rid 
)

Returns the GWEN_DB of the incoming request with the given id. The IPC manager remains the owner of the DB returned.

The DB returned contains a special group called IPC, which in turn contains some interesting variables:

  • nodeId: Id of the node via which this request has been received
  • msgId: id of the message
Parameters:
mgr pointer to the IPC manager object
rid request id returned by GWEN_IpcManager_GetNextInRequest

Definition at line 730 of file ipc.c.

References DBG_ERROR, and GWEN_LOGDOMAIN.

GWEN_IO_LAYER* GWEN_IpcManager_GetIoLayer ( GWEN_IPCMANAGER mgr,
uint32_t  nid 
)

Returns a pointer to the connection used by the given node.

Definition at line 755 of file ipc.c.

References DBG_ERROR, and GWEN_LOGDOMAIN.

uint32_t GWEN_IpcManager_GetNextInRequest ( GWEN_IPCMANAGER mgr,
uint32_t  mark 
)

Returns the id of the next incoming request with the given mark. This request will then be taken of the list of new requests, so the next call to this function will return another request id (or 0 if there is none left). So you will have to preserve the id returned in order to use it.

Parameters:
mgr pointer to the IPC manager object
mark,0 matches any (see GWEN_IpcManager_AddServer)

Definition at line 700 of file ipc.c.

GWEN_DB_NODE* GWEN_IpcManager_GetResponseData ( GWEN_IPCMANAGER mgr,
uint32_t  rid 
)

Returns the next response to the given outbound request. The data returned is taken off the list of responses, so any call to this function will return the next response (if any). The caller takes over ownership of the data returned.

Parameters:
mgr pointer to the IPC manager object
rid request id returned by GWEN_IpcManager_SendRequest or GWEN_IpcManager_SendMultiRequest

Definition at line 826 of file ipc.c.

References DBG_ERROR, DBG_VERBOUS, GWEN_IpcMsg_free(), and GWEN_LOGDOMAIN.

GWEN_IPCMANAGER* GWEN_IpcManager_new (  ) 

Definition at line 354 of file ipc.c.

References DBG_MEM_INC, and GWEN_NEW_OBJECT.

GWEN_DB_NODE* GWEN_IpcManager_PeekResponseData ( GWEN_IPCMANAGER mgr,
uint32_t  rid 
)

Returns the next response to the given outbound request. The data returned is not taken off the list of responses, so the next call to this function will return the same response (if any). The caller does NOT take over ownership of the data returned.

Parameters:
mgr pointer to the IPC manager object
rid request id returned by GWEN_IpcManager_SendRequest or GWEN_IpcManager_SendMultiRequest

Definition at line 795 of file ipc.c.

References DBG_DEBUG, DBG_ERROR, and GWEN_LOGDOMAIN.

int GWEN_IpcManager_RemoveClient ( GWEN_IPCMANAGER mgr,
uint32_t  nid 
)

Removes a client which was previously added using GWEN_IpcManager_AddClient. This function removes all pending messages and/or requests for/from this client.

Definition at line 530 of file ipc.c.

References DBG_DEBUG, DBG_ERROR, DBG_NOTICE, GWEN_Io_Layer_DisconnectRecursively(), GWEN_Io_Manager_UnregisterLayer(), GWEN_IO_REQUEST_FLAGS_FORCE, GWEN_IpcManager__RemoveNodeRequestMessages(), GWEN_IpcNode_free(), GWEN_LOGDOMAIN, and NULL.

int GWEN_IpcManager_RemoveRequest ( GWEN_IPCMANAGER mgr,
uint32_t  rid,
int  outbound 
)

Removes a request.

Parameters:
mgr pointer to the IPC manager object
rid id of the request to which this is a response (as returned by GWEN_IpcManager_GetNextInRequest, GWEN_IpcManager_SendRequest or GWEN_IpcManager_SendMultiRequest)
outbound if 0 then an incoming request is to be removed, otherwise an outgoing request is to be deleted

Definition at line 673 of file ipc.c.

References DBG_ERROR, GWEN_Ipc__Request_free(), and GWEN_LOGDOMAIN.

int GWEN_IpcManager_SendRequest ( GWEN_IPCMANAGER mgr,
uint32_t  nid,
GWEN_DB_NODE req,
uint32_t *  pReqId 
)

Sends a request via the given connection. It takes over the ownership of the given GWEN_DB in any case.

Returns:
request id of the request created (0 on error)
Parameters:
mgr pointer to the IPC manager object
nid value returned by GWEN_IpcManager_AddClient or by GWEN_IpcManager_GetInRequestData (in variable "ipc/nodeId");
req DB containing the request

Definition at line 586 of file ipc.c.

References DBG_ERROR, DBG_INFO, GWEN_ERROR_NOT_FOUND, gwen_ipc__lastid, GWEN_Ipc__Request_AddRequestMsg(), GWEN_Ipc__Request_new(), GWEN_IpcManager__SendMsg(), GWEN_IpcMsg_free(), GWEN_IpcMsg_new(), and GWEN_LOGDOMAIN.

int GWEN_IpcManager_SendResponse ( GWEN_IPCMANAGER mgr,
uint32_t  rid,
GWEN_DB_NODE rsp 
)

Sends a response to a request received.

Returns:
0 if ok, !=0 on error
Parameters:
mgr pointer to the IPC manager object
rid id of the request to which this is a response (as returned by GWEN_IpcManager_GetNextInRequest)
rsp DB containing the response

Definition at line 629 of file ipc.c.

References DBG_DEBUG, DBG_ERROR, DBG_INFO, GWEN_ERROR_NOT_FOUND, GWEN_Ipc__Request_AddResponseMsg(), GWEN_IpcManager__SendMsg(), GWEN_IpcMsg_free(), GWEN_IpcMsg_new(), and GWEN_LOGDOMAIN.

void GWEN_IpcManager_SetApplicationName ( GWEN_IPCMANAGER mgr,
const char *  s 
)

Definition at line 407 of file ipc.c.

void GWEN_IpcManager_SetClientDownFn ( GWEN_IPCMANAGER mgr,
GWEN_IPCMANAGER_CLIENTDOWN_FN  f,
void *  user_data 
)

Definition at line 1402 of file ipc.c.

int GWEN_IpcManager_Work ( GWEN_IPCMANAGER mgr  ) 

Lets the IPC manager do its work. You need to call GWEN_Net2_HeartBeat before this function to catch changes in the network connections used.

Definition at line 948 of file ipc.c.

References DBG_ERROR, GWEN_IpcManager__CheckRequests(), GWEN_IpcManager__Work(), and GWEN_LOGDOMAIN.

void GWEN_IpcMsg_Dump ( GWEN_IPCMSG *  m,
FILE *  f,
int  indent 
)

Definition at line 161 of file ipc.c.

References GWEN_DB_Dump().

Referenced by GWEN_Ipc__Request_Dump().

void GWEN_IpcMsg_free ( GWEN_IPCMSG *  m  ) 
GWEN_IPCMSG* GWEN_IpcMsg_new ( GWEN_IPCNODE *  n  ) 
void GWEN_IpcNode_Attach ( GWEN_IPCNODE *  n  ) 

Definition at line 75 of file ipc.c.

References DBG_MEM_INC.

Referenced by GWEN_IpcManager__Work(), and GWEN_IpcMsg_new().

void GWEN_IpcNode_Dump ( GWEN_IPCNODE *  n,
FILE *  f,
int  indent 
)

Definition at line 84 of file ipc.c.

Referenced by GWEN_IpcManager_Dump().

void GWEN_IpcNode_free ( GWEN_IPCNODE *  n  ) 
GWEN_IPCNODE* GWEN_IpcNode_new (  ) 

Variable Documentation

uint32_t gwen_ipc__lastid = 0 [static]

Definition at line 32 of file ipc.c.

Referenced by GWEN_IpcManager__HandlePacket(), and GWEN_IpcManager_SendRequest().


Generated by  doxygen 1.6.2