From: Roman P. <pu...@x-...> - 2011-09-25 19:54:09
|
/** * $Id$ * */ #include <tcl.h> #ifndef TCL_ARGS # define TCL_ARGS ClientData cdata, Tcl_Interp *interp, int objc, struct Tcl_Obj * const* objv #endif /* ======================================================== * RCP Client Section * ===================================================== */ /** * rpc_request * * send an rpc request over a tcl channel * * usage: rpc::request <OPTIONS> data * OPTIONS see below * data data to send over the channel as rpc request * */ int rpc_request(TCL_ARGS) { // parameters int timeout = 0; int verbose = 0; int maxsize = 0; int port; char *host = NULL; char *userdata = NULL; char *callback = NULL; char *cmd; Tcl_Channel chan; Tcl_Obj **remObjv = NULL; Tcl_ArgvInfo argTable[] = { {TCL_ARGV_STRING, "-host", "127.0.0.1", &host, "connect to host", NULL}, {TCL_ARGV_INT, "-port", (void*)9090, &port, "connect to port", NULL}, {TCL_ARGV_STRING, "-callback",NULL, &callback, "callback on reply code", NULL}, {TCL_ARGV_INT, "-timeout", NULL, &timeout, "set transaction timeout in secods", NULL}, {TCL_ARGV_INT, "-maxsize", (void*)0, &maxsize, "set max, allowed size of reply", NULL}, {TCL_ARGV_STRING, "-userdata",NULL, &userdata, "attach user data to receive in callback", NULL}, {TCL_ARGV_CONSTANT, "-verbose", (void*)1, &verbose, "turn verbose logging on", NULL}, {TCL_ARGV_HELP, "-help", NULL, NULL, "print command line options and return", NULL}, {TCL_ARGV_REST, NULL, NULL, NULL, NULL}, {TCL_ARGV_END, NULL, NULL, NULL, NULL} }; if (Tcl_ParseArgsObjv(interp, argTable, &objc, objv, &remObjv) != TCL_OK) { return TCL_ERROR; }; printf("objc: %d, remObjv: %x\n", objc, remObjv); if (remObjv) { Tcl_Free((void *)remObjv); printf("remObjv successfully released\n"); }; Tcl_SetResult(interp, "ok", TCL_VOLATILE); return(TCL_OK); }; DLLEXPORT int Rpcx_Init(Tcl_Interp *interp) { if (Tcl_PkgProvide(interp, "librpcx", "1.0") == TCL_ERROR) { return TCL_ERROR; }; Tcl_CreateObjCommand(interp, "rpc::request", rpc_request, NULL, NULL); return(TCL_OK); }; DLLEXPORT int Rpcx_Unload(Tcl_Interp *interp, int reason) { return(TCL_OK); }; /* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 * End: */ |