open-vm-tools 9.4.6
lib/include/vmware/tools/guestrpc.h
Go to the documentation of this file.
00001 /*********************************************************
00002  * Copyright (C) 2008 VMware, Inc. All rights reserved.
00003  *
00004  * This program is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License as published
00006  * by the Free Software Foundation version 2.1 and no later version.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00010  * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
00011  * License for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this program; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
00016  *
00017  *********************************************************/
00018 
00019 #ifndef _VMWARE_TOOLS_GUESTRPC_H_
00020 #define _VMWARE_TOOLS_GUESTRPC_H_
00021 
00039 #include <glib.h>
00040 #include "vmware/tools/utils.h"
00041 
00042 G_BEGIN_DECLS
00043 
00045 #define RPCIN_SETRETVALS  RpcChannel_SetRetVals
00046 #define RPCIN_SETRETVALSF RpcChannel_SetRetValsF
00047 
00048 struct RpcChannel;
00049 
00051 typedef struct RpcInData {
00053    const char *name;
00058    const char *args;
00060    size_t argsSize;
00065    char *result;
00067    size_t resultLen;
00072    gboolean freeResult;
00074    void *appCtx;
00076    void *clientData;
00077 } RpcInData;
00078 
00079 
00084 typedef gboolean (*RpcIn_Callback)(RpcInData *data);
00085 
00086 
00088 typedef struct RpcChannelCallback {
00090    const char       *name;
00092    RpcIn_Callback    callback;
00094    gpointer          clientData;
00096    gpointer          xdrIn;
00103    gpointer          xdrOut;
00108    size_t            xdrInSize;
00109 } RpcChannelCallback;
00110 
00111 
00112 typedef gboolean (*RpcChannelStartFn)(struct RpcChannel *);
00113 typedef void (*RpcChannelStopFn)(struct RpcChannel *);
00114 typedef void (*RpcChannelShutdownFn)(struct RpcChannel *);
00115 typedef gboolean (*RpcChannelSendFn)(struct RpcChannel *,
00116                                      char const *data,
00117                                      size_t dataLen,
00118                                      char **result,
00119                                      size_t *resultLen);
00120 typedef void (*RpcChannelSetupFn)(struct RpcChannel *chan,
00121                                   GMainContext *mainCtx,
00122                                   const char *appName,
00123                                   gpointer appCtx);
00124 
00125 
00133 typedef void (*RpcChannelResetCb)(struct RpcChannel *chan,
00134                                   gboolean success,
00135                                   gpointer data);
00136 
00137 
00139 typedef struct RpcChannel {
00140    RpcChannelStartFn       start;
00141    RpcChannelStopFn        stop;
00142    RpcChannelSendFn        send;
00143    RpcChannelSetupFn       setup;
00144    RpcChannelShutdownFn    shutdown;
00145    gpointer                _private;
00146 } RpcChannel;
00147 
00148 
00157 G_INLINE_FUNC gboolean
00158 RpcChannel_Start(RpcChannel *chan)
00159 {
00160    g_return_val_if_fail(chan != NULL, FALSE);
00161    g_return_val_if_fail(chan->start != NULL, FALSE);
00162 
00163    return chan->start(chan);
00164 }
00165 
00166 
00173 G_INLINE_FUNC void
00174 RpcChannel_Stop(RpcChannel *chan)
00175 {
00176    g_return_if_fail(chan != NULL);
00177    g_return_if_fail(chan->stop != NULL);
00178 
00179    chan->stop(chan);
00180 }
00181 
00182 
00195 G_INLINE_FUNC gboolean
00196 RpcChannel_Send(RpcChannel *chan,
00197                 char const *data,
00198                 size_t dataLen,
00199                 char **result,
00200                 size_t *resultLen)
00201 {
00202    g_return_val_if_fail(chan != NULL, FALSE);
00203    g_return_val_if_fail(chan->send != NULL, FALSE);
00204 
00205    return chan->send(chan, data, dataLen, result, resultLen);
00206 }
00207 
00208 gboolean
00209 RpcChannel_BuildXdrCommand(const char *cmd,
00210                            void *xdrProc,
00211                            void *xdrData,
00212                            char **result,
00213                            size_t *resultLen);
00214 
00215 RpcChannel *
00216 RpcChannel_Create(void);
00217 
00218 gboolean
00219 RpcChannel_Destroy(RpcChannel *chan);
00220 
00221 gboolean
00222 RpcChannel_Dispatch(RpcInData *data);
00223 
00224 void
00225 RpcChannel_Setup(RpcChannel *chan,
00226                  const gchar *appName,
00227                  GMainContext *mainCtx,
00228                  gpointer appCtx,
00229                  RpcChannelResetCb resetCb,
00230                  gpointer resetData);
00231 
00232 void
00233 RpcChannel_RegisterCallback(RpcChannel *chan,
00234                             RpcChannelCallback *rpc);
00235 
00236 gboolean
00237 RpcChannel_SetRetVals(RpcInData *data,
00238                       char const *result,
00239                       gboolean retVal);
00240 
00241 gboolean
00242 RpcChannel_SetRetValsF(RpcInData *data,
00243                        char *result,
00244                        gboolean retVal);
00245 
00246 void
00247 RpcChannel_UnregisterCallback(RpcChannel *chan,
00248                               RpcChannelCallback *rpc);
00249 
00250 
00251 RpcChannel *
00252 BackdoorChannel_New(void);
00253 
00254 G_END_DECLS
00255 
00258 #endif
00259