00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _RPCCHANNEL_H_
00020 #define _RPCCHANNEL_H_
00021
00039 #if !defined(VMTOOLS_USE_GLIB)
00040 # error "This library needs to be compiled with VMTOOLS_USE_GLIB."
00041 #endif
00042
00043 #include <rpc/rpc.h>
00044 #include "vm_basic_types.h"
00045 #include "vm_assert.h"
00046 #include "rpcin.h"
00047
00048 struct RpcChannel;
00049
00051 typedef struct RpcChannelCallback {
00053 const char *name;
00055 RpcIn_Callback callback;
00057 gpointer clientData;
00059 gpointer xdrIn;
00066 gpointer xdrOut;
00071 size_t xdrInSize;
00072 } RpcChannelCallback;
00073
00074
00075 typedef Bool (*RpcChannelStartFn)(struct RpcChannel *);
00076 typedef void (*RpcChannelStopFn)(struct RpcChannel *);
00077 typedef void (*RpcChannelShutdownFn)(struct RpcChannel *);
00078 typedef Bool (*RpcChannelSendFn)(struct RpcChannel *,
00079 char *data,
00080 size_t dataLen,
00081 char **result,
00082 size_t *resultLen);
00083
00084
00092 typedef void (*RpcChannelResetCb)(struct RpcChannel *chan,
00093 gboolean success,
00094 gpointer data);
00095
00096
00098 typedef struct RpcChannel {
00099 RpcChannelStartFn start;
00100 RpcChannelStopFn stop;
00101 RpcChannelSendFn send;
00102
00103 RpcChannelShutdownFn shutdown;
00104 gchar *appName;
00105 GHashTable *rpcs;
00106 GMainContext *mainCtx;
00107 GSource *resetCheck;
00108 gpointer appCtx;
00109 RpcChannelCallback resetReg;
00110 RpcChannelResetCb resetCb;
00111 gpointer resetData;
00112 gboolean rpcError;
00113 guint rpcErrorCount;
00114 gpointer _private;
00115 } RpcChannel;
00116
00117
00125 static INLINE Bool
00126 RpcChannel_Start(RpcChannel *chan)
00127 {
00128 ASSERT(chan != NULL);
00129 ASSERT(chan->start != NULL);
00130
00131 return chan->start(chan);
00132 }
00133
00134
00141 static INLINE void
00142 RpcChannel_Stop(RpcChannel *chan)
00143 {
00144 ASSERT(chan != NULL);
00145 ASSERT(chan->stop != NULL);
00146
00147 chan->stop(chan);
00148 }
00149
00162 static INLINE Bool
00163 RpcChannel_Send(RpcChannel *chan,
00164 char *data,
00165 size_t dataLen,
00166 char **result,
00167 size_t *resultLen)
00168 {
00169 ASSERT(chan != NULL);
00170 ASSERT(chan->send != NULL);
00171
00172 return chan->send(chan, data, dataLen, result, resultLen);
00173 }
00174
00175 Bool
00176 RpcChannel_BuildXdrCommand(const char *cmd,
00177 void *xdrProc,
00178 void *xdrData,
00179 char **result,
00180 size_t *resultLen);
00181
00182 gboolean
00183 RpcChannel_Destroy(RpcChannel *chan);
00184
00185 Bool
00186 RpcChannel_Dispatch(RpcInData *data);
00187
00188 void
00189 RpcChannel_Setup(RpcChannel *chan,
00190 const gchar *appName,
00191 GMainContext *mainCtx,
00192 gpointer appCtx,
00193 RpcChannelResetCb resetCb,
00194 gpointer resetData);
00195
00196 void
00197 RpcChannel_RegisterCallback(RpcChannel *chan,
00198 RpcChannelCallback *rpc);
00199
00200 void
00201 RpcChannel_UnregisterCallback(RpcChannel *chan,
00202 RpcChannelCallback *rpc);
00203
00204
00205 RpcChannel *
00206 RpcChannel_NewBackdoorChannel(GMainContext *mainCtx);
00207
00210 #endif
00211