liberipc/include/eripc.h File Reference

liberipc - A library to enable IPC on the eReader platform More...

#include "eripcconfig.h"

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ER_TEST_UA_ID   0
#define ER_PDF_VIEWER_UA_ID   1
#define ER_XHTML_VIEWER_UA_ID   2
#define ER_APABI_VIEWER_UA_ID   3
#define ER_ARINC_VIEWER_UA_ID   4
#define ER_ARINC_MENU_UA_ID   5
#define ER_SETUP_UA_ID   100
#define ER_CONTENT_LISTER_UA_ID   101
#define ER_TEXT_VIEWER_UA_ID   102
#define ER_SCRIBBLE_UA_ID   103
#define ER_CONNECT_UA_ID   104
#define ER_POWERMGR_UA_ID   105
#define ER_BUSYD_UA_ID   106
#define ER_PAGEBAR_UA_ID   107
#define ER_TOOLBAR_UA_ID   108
#define ER_EBA_VIEWER_UA_ID   109
#define ER_MOBIPOCKET_VIEWER_UA_ID   110
#define ER_UAID_ILLEGAL   (-1)
#define ER_TOOLBAR_CHANNEL   1
#define ER_TEST_CHANNEL   2
#define ER_PDF_VIEWER_CHANNEL   3
#define ER_XHTML_VIEWER_CHANNEL   4
#define ER_APABI_VIEWER_CHANNEL   5
#define ER_CONTENTLISTER_CHANNEL   6
#define ER_BUSYD_CHANNEL   7
#define ER_POWERMGR_CHANNEL   8
#define ER_PAGEBAR_CHANNEL   9
#define ER_SCRIBBLE_CHANNEL   10
#define ER_SETUP_CHANNEL   11
#define ER_CONNECT_CHANNEL   12
#define ER_ARINC_VIEWER_CHANNEL   13
#define ER_EBA_VIEWER_CHANNEL   14
#define ER_MOBIPOCKET_VIEWER_CHANNEL   15
#define ER_ARINC_MENU_CHANNEL   16
#define ER_CHANNEL_NUM   16
#define ER_CHANNEL_ILLEGAL   (-1)
#define erIpcGetChannel(uaID)
#define ER_IPC_PORT_FIRST   (50065)
#define ER_IPC_PORT_ILLEGAL   (-1)
#define erIpcGetServerPort(channelIdx)   (((channelIdx) > 0 && (channelIdx) <= ER_CHANNEL_NUM) ? (ER_IPC_PORT_FIRST + (channelIdx) - 1) : -1)
#define TOOLBAR_IPC_PORT   (erIpcGetServerPort(ER_TOOLBAR_CHANNEL )
#define TEST_IPC_PORT   (erIpcGetServerPort(ER_TEST_CHANNEL )
#define PDF_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_PDF_VIEWER_CHANNEL )
#define XHTML_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_XHTML_VIEWER_CHANNEL )
#define APABI_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_APABI_VIEWER_CHANNEL )
#define CONTENTLISTER_IPC_PORT   (erIpcGetServerPort(ER_CONTENTLISTER_CHANNEL )
#define BUSYD_IPC_PORT   (erIpcGetServerPort(ER_BUSYD_CHANNEL )
#define POWERMGR_IPC_PORT   (erIpcGetServerPort(ER_POWERMGR_CHANNEL )
#define PAGEBAR_IPC_PORT   (erIpcGetServerPort(ER_PAGEBAR_CHANNEL )
#define SCRIBBLE_IPC_PORT   (erIpcGetServerPort(ER_SCRIBBLE_CHANNEL )
#define SETUP_IPC_PORT   (erIpcGetServerPort(ER_SETUP_CHANNEL )
#define CONNECT_IPC_PORT   (erIpcGetServerPort(ER_CONNECT_CHANNEL )
#define ARINC_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_ARINC_VIEWER_CHANNEL )
#define EBA_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_EBA_VIEWER_CHANNEL )
#define MOBIPOCKET_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_MOBIPOCKET_VIEWER_CHANNEL)
#define ARINC_MENU_IPC_PORT   (erIpcGetServerPort(ER_ARINC_MENU_CHANNEL )
#define ER_IPC_MAJOR_VERSION   0
#define ER_IPC_MINOR_VERSION   1
#define ER_IPC_ITER_VERSION   0
#define ER_IPC_VERSION   (((( ER_IPC_MAJOR_VERSION << 8 ) | ER_IPC_MINOR_VERSION) << 8 ) | ER_IPC_ITER_VERSION)

Typedefs

typedef void * erClientChannel_t
typedef void * erServerChannel_t
typedef void(* erMessageCB )(char *szBuffer, int *nBuf, void *data)

Functions

int erIpcGetVersion ()
int erIpcStartServer (int channelIdx, erMessageCB callback, char *szBuffer, int *nBuf, void *data)
int erIpcOpenServerChannel (int channelIdx, erServerChannel_t *channel)
int erIpcGetServerFd (erServerChannel_t channel)
int erIpcGetMessage (erServerChannel_t channel, char *szBuffer, int *nBuf)
int erIpcStartClient (int channelIdx, erClientChannel_t *channel)
int erIpcInitServer (int channelIdx, int *sockfd, int local)


Detailed Description

liberipc - A library to enable IPC on the eReader platform

<File description>="">

Definition in file eripc.h.


Define Documentation

#define APABI_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_APABI_VIEWER_CHANNEL )

Definition at line 118 of file eripc.h.

#define ARINC_MENU_IPC_PORT   (erIpcGetServerPort(ER_ARINC_MENU_CHANNEL )

Definition at line 129 of file eripc.h.

#define ARINC_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_ARINC_VIEWER_CHANNEL )

Definition at line 126 of file eripc.h.

#define BUSYD_IPC_PORT   (erIpcGetServerPort(ER_BUSYD_CHANNEL )

Definition at line 120 of file eripc.h.

#define CONNECT_IPC_PORT   (erIpcGetServerPort(ER_CONNECT_CHANNEL )

Definition at line 125 of file eripc.h.

#define CONTENTLISTER_IPC_PORT   (erIpcGetServerPort(ER_CONTENTLISTER_CHANNEL )

Definition at line 119 of file eripc.h.

#define EBA_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_EBA_VIEWER_CHANNEL )

Definition at line 127 of file eripc.h.

#define ER_APABI_VIEWER_CHANNEL   5

Definition at line 74 of file eripc.h.

#define ER_APABI_VIEWER_UA_ID   3

Definition at line 51 of file eripc.h.

#define ER_ARINC_MENU_CHANNEL   16

Definition at line 85 of file eripc.h.

#define ER_ARINC_MENU_UA_ID   5

Definition at line 53 of file eripc.h.

#define ER_ARINC_VIEWER_CHANNEL   13

Definition at line 82 of file eripc.h.

#define ER_ARINC_VIEWER_UA_ID   4

Definition at line 52 of file eripc.h.

#define ER_BUSYD_CHANNEL   7

Definition at line 76 of file eripc.h.

#define ER_BUSYD_UA_ID   106

Definition at line 60 of file eripc.h.

#define ER_CHANNEL_ILLEGAL   (-1)

Definition at line 88 of file eripc.h.

#define ER_CHANNEL_NUM   16

Definition at line 87 of file eripc.h.

#define ER_CONNECT_CHANNEL   12

Definition at line 81 of file eripc.h.

#define ER_CONNECT_UA_ID   104

Definition at line 58 of file eripc.h.

#define ER_CONTENT_LISTER_UA_ID   101

Definition at line 55 of file eripc.h.

#define ER_CONTENTLISTER_CHANNEL   6

Definition at line 75 of file eripc.h.

#define ER_EBA_VIEWER_CHANNEL   14

Definition at line 83 of file eripc.h.

#define ER_EBA_VIEWER_UA_ID   109

Definition at line 63 of file eripc.h.

#define ER_IPC_ITER_VERSION   0

Definition at line 134 of file eripc.h.

#define ER_IPC_MAJOR_VERSION   0

Definition at line 132 of file eripc.h.

#define ER_IPC_MINOR_VERSION   1

Definition at line 133 of file eripc.h.

#define ER_IPC_PORT_FIRST   (50065)

Definition at line 109 of file eripc.h.

#define ER_IPC_PORT_ILLEGAL   (-1)

Definition at line 110 of file eripc.h.

#define ER_IPC_VERSION   (((( ER_IPC_MAJOR_VERSION << 8 ) | ER_IPC_MINOR_VERSION) << 8 ) | ER_IPC_ITER_VERSION)

Definition at line 136 of file eripc.h.

#define ER_MOBIPOCKET_VIEWER_CHANNEL   15

Definition at line 84 of file eripc.h.

#define ER_MOBIPOCKET_VIEWER_UA_ID   110

Definition at line 64 of file eripc.h.

#define ER_PAGEBAR_CHANNEL   9

Definition at line 78 of file eripc.h.

#define ER_PAGEBAR_UA_ID   107

Definition at line 61 of file eripc.h.

#define ER_PDF_VIEWER_CHANNEL   3

Definition at line 72 of file eripc.h.

#define ER_PDF_VIEWER_UA_ID   1

Definition at line 49 of file eripc.h.

#define ER_POWERMGR_CHANNEL   8

Definition at line 77 of file eripc.h.

#define ER_POWERMGR_UA_ID   105

Definition at line 59 of file eripc.h.

#define ER_SCRIBBLE_CHANNEL   10

Definition at line 79 of file eripc.h.

#define ER_SCRIBBLE_UA_ID   103

Definition at line 57 of file eripc.h.

#define ER_SETUP_CHANNEL   11

Definition at line 80 of file eripc.h.

#define ER_SETUP_UA_ID   100

Definition at line 54 of file eripc.h.

#define ER_TEST_CHANNEL   2

Definition at line 71 of file eripc.h.

#define ER_TEST_UA_ID   0

Definition at line 48 of file eripc.h.

#define ER_TEXT_VIEWER_UA_ID   102

Definition at line 56 of file eripc.h.

#define ER_TOOLBAR_CHANNEL   1

Definition at line 70 of file eripc.h.

#define ER_TOOLBAR_UA_ID   108

Definition at line 62 of file eripc.h.

#define ER_UAID_ILLEGAL   (-1)

Definition at line 65 of file eripc.h.

#define ER_XHTML_VIEWER_CHANNEL   4

Definition at line 73 of file eripc.h.

#define ER_XHTML_VIEWER_UA_ID   2

Definition at line 50 of file eripc.h.

#define erIpcGetChannel ( uaID   ) 

#define erIpcGetServerPort ( channelIdx   )     (((channelIdx) > 0 && (channelIdx) <= ER_CHANNEL_NUM) ? (ER_IPC_PORT_FIRST + (channelIdx) - 1) : -1)

Definition at line 112 of file eripc.h.

#define MOBIPOCKET_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_MOBIPOCKET_VIEWER_CHANNEL)

Definition at line 128 of file eripc.h.

#define PAGEBAR_IPC_PORT   (erIpcGetServerPort(ER_PAGEBAR_CHANNEL )

Definition at line 122 of file eripc.h.

#define PDF_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_PDF_VIEWER_CHANNEL )

Definition at line 116 of file eripc.h.

#define POWERMGR_IPC_PORT   (erIpcGetServerPort(ER_POWERMGR_CHANNEL )

Definition at line 121 of file eripc.h.

#define SCRIBBLE_IPC_PORT   (erIpcGetServerPort(ER_SCRIBBLE_CHANNEL )

Definition at line 123 of file eripc.h.

#define SETUP_IPC_PORT   (erIpcGetServerPort(ER_SETUP_CHANNEL )

Definition at line 124 of file eripc.h.

#define TEST_IPC_PORT   (erIpcGetServerPort(ER_TEST_CHANNEL )

Definition at line 115 of file eripc.h.

#define TOOLBAR_IPC_PORT   (erIpcGetServerPort(ER_TOOLBAR_CHANNEL )

Definition at line 114 of file eripc.h.

#define XHTML_VIEWER_IPC_PORT   (erIpcGetServerPort(ER_XHTML_VIEWER_CHANNEL )

Definition at line 117 of file eripc.h.


Typedef Documentation

typedef void* erClientChannel_t

Definition at line 44 of file eripc.h.

typedef void(* erMessageCB)(char *szBuffer, int *nBuf, void *data)

Definition at line 138 of file eripc.h.

typedef void* erServerChannel_t

Definition at line 45 of file eripc.h.


Function Documentation

int erIpcGetMessage ( erServerChannel_t  channel,
char *  szBuffer,
int *  nBuf 
)

Get a message from the channel, will block when no message is available

Cf. erIpcOpenServerChannel

Parameters:
channel Communication channel
szBuffer Buffer that will be used by callback
nBuf size of szBuffer
Returns:
The file descriptor associated with the channel

Definition at line 184 of file eripc.c.

00185 {
00186     char    szClientIP[INET_ADDRSTRLEN + 1];
00187     struct sockaddr_in clientAdr;
00188     socklen_t len;
00189     int     sockfd;
00190     erInternalServerChannel_t *serverChannel;
00191     int     nBufsize;
00192     int n;
00193 
00194     nBufsize = *nBuf;
00195     serverChannel = (erInternalServerChannel_t *) channel;
00196     sockfd = serverChannel->sockfd;
00197 
00198     // Blocking call.
00199     len = sizeof(clientAdr);
00200     n = recvfrom(sockfd, szBuffer, nBufsize, 0, (struct sockaddr *) &clientAdr, &len);
00201     szBuffer[n] = '\0';
00202     // Who's sending this message?
00203     // clientAdr.sin_addr.s_addr // 32-bit IPv4 address, network byte ordered.
00204     if (inet_ntop(AF_INET, &clientAdr.sin_addr, szClientIP, sizeof(szClientIP)))
00205     {
00206         ERIPC_LOGPRINTF("Message %s received from %s", szBuffer, szClientIP);
00207     }
00208     *nBuf = n;
00209     return 0;
00210 }

int erIpcGetServerFd ( erServerChannel_t  channel  ) 

Fetch the filedescriptor associated with the channel

Cf. erIpcOpenServerChannel

Parameters:
channel Communication channel
Returns:
The file descriptor associated with the channel

Definition at line 176 of file eripc.c.

00177 {
00178     erInternalServerChannel_t *serverChannel;
00179 
00180     serverChannel = (erInternalServerChannel_t *) channel;
00181     return serverChannel->sockfd;
00182 }

int erIpcGetVersion (  ) 

Definition at line 39 of file eripc.c.

00040 {
00041     return ER_IPC_VERSION;
00042 }

int erIpcInitServer ( int  channelIdx,
int *  sockfd,
int  local 
)

Initializes the server. Only use this function when you don't want a dedicated thread for IPC handling.

Parameters:
channelIdx Communication channel identifier
sockfd The socket filedescriptor
local Set to 1 if only local addresses need to be served
Returns:
A value of 0 signals success

Definition at line 48 of file eripc.c.

00049 {
00050     int     error;
00051     int     port;
00052     struct sockaddr_in serverAdr;
00053     int on = 1;
00054 
00055     // test code
00056     ERIPC_WARNPRINTF("Version: %d\n", erIpcGetVersion());
00057 
00058 
00059     *sockfd = socket(AF_INET, SOCK_DGRAM, 0);
00060     error = setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *) &on, sizeof(on));
00061     if (error)
00062     {
00063         perror("Unable to set socket options to SO_REUSEADDR");
00064     }
00065 
00066     port = erIpcGetServerPort(channelIdx);
00067     if (port == ER_IPC_PORT_ILLEGAL)
00068     {
00069         ERIPC_ERRORPRINTF("Could not allocate channel %d", channelIdx);
00070         return -1;
00071     }
00072 
00073     bzero(&serverAdr, sizeof(serverAdr));
00074     serverAdr.sin_family = AF_INET;
00075     // NOTE :
00076     //   Setting the address to INADDR_LOOPBACK will only allow processes running
00077     // on the same host to send messages to the displayMgrServer
00078     //   Setting the address to INADDR_ANY will allow a process on any host to 
00079     // send messages to the displayMgrServer
00080     if (local == 1)
00081     {
00082         serverAdr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
00083     }
00084     else
00085     {
00086         serverAdr.sin_addr.s_addr = htonl(INADDR_ANY);
00087     }
00088     serverAdr.sin_port = htons(port);
00089 
00090     error = bind(*sockfd, (struct sockaddr *) &serverAdr, sizeof(serverAdr));
00091     if (error)
00092     {
00093         perror("Error invoking bind");
00094         return -1;
00095     }
00096     else
00097     {
00098         char    szServerIP[INET_ADDRSTRLEN + 1];
00099 
00100         inet_ntop(AF_INET, &serverAdr.sin_addr, szServerIP, sizeof(szServerIP));
00101         ERIPC_WARNPRINTF("Bound successfully to %s:%d.", szServerIP, port);
00102     }
00103     return 0;
00104 }

Here is the call graph for this function:

int erIpcOpenServerChannel ( int  channelIdx,
erServerChannel_t channel 
)

Create the server side of the IPC communication channel.

After calling this function. Use erIpcGetServerFd() to fetch the filedescriptor associated with this channel. Monitor the filedescriptor for data. When data is available use erIpcGetMessage to fetch the data.

Parameters:
channelIdx Communication channel identifier
channel Opaque datastructure that contains info on communication channel
Returns:
A value of -1 signals failure

Definition at line 147 of file eripc.c.

00148 {
00149     erInternalServerChannel_t *serverChannel;
00150     int     sockfd;
00151     int     nErr;
00152     int     fLocal = 1;
00153 
00154     nErr = erIpcInitServer(channelIdx, &sockfd, fLocal);
00155     if (nErr != 0)
00156     {
00157         ERIPC_ERRORPRINTF("Failed to initialize IPC server");
00158         return -1;
00159     }
00160 
00161     serverChannel = (erInternalServerChannel_t *) malloc(sizeof(erInternalServerChannel_t));
00162 
00163     if (serverChannel != NULL)
00164     {
00165         *channel = (erServerChannel_t) serverChannel;
00166     }
00167     else
00168     {
00169         ERIPC_ERRORPRINTF("Out of memory.");
00170         return -1;
00171     }
00172     serverChannel->sockfd = sockfd;
00173     return 0;
00174 }

Here is the call graph for this function:

int erIpcStartClient ( int  channelIdx,
erClientChannel_t channel 
)

Start the client side of the IPC communication channel

Parameters:
channelIdx Communication channel identifier
channel Opaque datastructure that contains info on communication channel
Returns:
A value of 0 signals success

Definition at line 213 of file eripc.c.

00214 {
00215     erInternalClientChannel_t *clientChannel;
00216     int     port;
00217     int     ret;
00218     struct in_addr destinationAdr;
00219 
00220     // Note. The following variable can be turned into an argument later
00221     //   INADDR_LOOPBACK : "127.0.0.1"
00222     //   INADDR_ANY      : "0.0.0.0"
00223     char    szDestination[] = "127.0.0.1";
00224     int     sockfd;
00225     struct sockaddr_in serverAdr;
00226 
00227     clientChannel = (erInternalClientChannel_t *) malloc(sizeof(erInternalClientChannel_t));
00228 
00229     if (clientChannel != NULL)
00230     {
00231         *channel = (erClientChannel_t) clientChannel;
00232     }
00233     else
00234     {
00235         ERIPC_ERRORPRINTF("Out of memory.");
00236         return -1;
00237     }
00238     clientChannel->sockfd = -1;
00239 
00240     if ((ret = inet_pton(AF_INET, szDestination, &destinationAdr)) == 1)
00241     {
00242         ERIPC_LOGPRINTF("Sending messages to %s", szDestination);
00243     }
00244     else if (ret == 0)
00245     {
00246         ERIPC_WARNPRINTF("%s not a presentation IP address (not in dotted decimal format)", szDestination);
00247         return -1;
00248     }
00249     else
00250     {
00251         ERIPC_WARNPRINTF("Failed to convert to a numeric IP address");
00252         return -2;
00253     }
00254 
00255     port = erIpcGetServerPort(channelIdx);
00256     if (port == ER_IPC_PORT_ILLEGAL)
00257     {
00258         ERIPC_ERRORPRINTF("Could not allocate channel %d", channelIdx);
00259         return -1;
00260     }
00261 
00262 
00263     sockfd = socket(AF_INET, SOCK_DGRAM, 0);
00264     bzero(&serverAdr, sizeof(serverAdr));
00265     serverAdr.sin_family = AF_INET;
00266     serverAdr.sin_addr.s_addr = destinationAdr.s_addr;
00267     serverAdr.sin_port = htons(port);
00268 
00269     clientChannel->sockfd = sockfd;
00270     clientChannel->serverAdr = serverAdr;
00271 
00272     return 0;
00273 }

int erIpcStartServer ( int  channelIdx,
erMessageCB  callback,
char *  szBuffer,
int *  nBuf,
void *  data 
)

Start the server side of the IPC communication channel. Under normal circumstances this function will not return. It invokes a callback when a message is received. It requires its own thread and is the easiest way to establish the server side. Note: Use erIpcOpenServerChannel(), erIpcGetServerFd() and * erIpcGetMessage() if you don't want to create a server specific thread.

Parameters:
channelIdx Communication channel identifier
callback Will be called when a message is received
szBuffer Buffer that will be used by callback
nBuf size of szBuffer
data pointer to opaque datastructure.
Returns:
A value of -1 signals failure

Definition at line 108 of file eripc.c.

00109 {
00110     int     sockfd;
00111     struct sockaddr_in clientAdr;
00112     socklen_t len;
00113     int     n;
00114     int     nErr;
00115     int     fLocal = 1;
00116     erMessageCB messageCallback = NULL;
00117     int     nBufsize;
00118 
00119     nErr = erIpcInitServer(channelIdx, &sockfd, fLocal);
00120     if (nErr != 0)
00121     {
00122         ERIPC_ERRORPRINTF("Failed to start IPC server");
00123         return -1;
00124     }
00125 
00126     nBufsize = *nBuf;
00127     messageCallback = callback;
00128     while (1)
00129     {
00130         char    szClientIP[INET_ADDRSTRLEN + 1];
00131 
00132         // Blocking call.
00133         len = sizeof(clientAdr);
00134         n = recvfrom(sockfd, szBuffer, nBufsize, 0, (struct sockaddr *) &clientAdr, &len);
00135         szBuffer[n] = '\0';
00136         // Who's sending this message?
00137         // clientAdr.sin_addr.s_addr // 32-bit IPv4 address, network byte ordered.
00138         if (inet_ntop(AF_INET, &clientAdr.sin_addr, szClientIP, sizeof(szClientIP)))
00139         {
00140             ERIPC_LOGPRINTF("Message %s received from %s", szBuffer, szClientIP);
00141         }
00142         *nBuf = n;
00143         messageCallback(szBuffer, nBuf, data);
00144     }
00145 }

Here is the call graph for this function:


Generated on Sun Dec 14 17:11:30 2008 by  doxygen 1.5.6