bool BrpcCtrlInterface::rpcCheck() { brpc_t *req, *rpl; char *version; bool ret = false; if (! (req = brpc_req(METH_CORE_VER, random()))) { ERROR("failed to build '%.*s' RPC context: %s [%d].\n", (int)METH_CORE_VER.len, METH_CORE_VER.val, brpc_strerror(), brpc_errno); return false; } if (! (rpl = rpcExecute(req))) return false; if (! brpc_dsm(rpl, "c", &version)) { ERROR("failed to retrieve version: %s [%d].\n", brpc_strerror(), brpc_errno); goto end; } if (! version) { ERROR("unexpected NULL string as SER version.\n"); goto end; } INFO("SER Version: %s\n", version); ret = true; end: if (rpl) brpc_finish(rpl); return ret; }
void BrpcCtrlInterface::serResync() { brpc_t *req, *rpl = NULL; brpc_str_t listen, *reason; int *retcode; listen.val = brpc_print_addr(&ctrlSrv->rxAddr); listen.len = strlen(listen.val); if (! ((req = brpc_req(METH_SER_RESYNC, random())) && brpc_asm(req, "dsd", ASI_VERSION, &listen, serial))) { ERROR("failed to build '%.*s' RPC context: %s [%d].\n", (int)METH_SER_RESYNC.len, METH_SER_RESYNC.val, brpc_strerror(), brpc_errno); goto err; } if (! (rpl = rpcExecute(req))) goto err; if (! brpc_dsm(rpl, "ds", &retcode, &reason)) { ERROR("failed disassemble reply: %s [%d].\n", brpc_strerror(), brpc_errno); goto err; } if (! retcode) { ERROR("invalid return code (NULL).\n"); goto err; } if (*retcode / 100 == 2) { // was success char *endptr; long my_as_id; errno = 0; my_as_id = strtol(reason->val, &endptr, 10); if (*endptr || errno) { ERROR("failed to parse AS ID returned by SER (%d: %s).\n", errno, errno ? strerror(errno) : "unexpected characters"); goto err; } else { as_id = (int)my_as_id; } } else { ERROR("resync failed with %d: %s.\n", *retcode, reason ? reason->val : "[NULL]"); goto err; } INFO("SER resync reply: %d: %.*s\n", *retcode, BRPC_STR_FMT(reason)); brpc_finish(rpl); return; err: ERROR("failed to execute SER resync.\n"); if (rpl) brpc_finish(rpl); }
int BrpcCtrlInterface::send(const AmSipRequest &amReq, char *serKey, unsigned int &serKeyLen) { int ret = -1; brpc_t *req, *rpl = NULL; brpc_int_t *code; brpc_str_t *ser_opaque; if (amReq.method == "CANCEL") { req = build_cancel(amReq); } else if (amReq.method == "ACK") { ERROR("ACK support not yet implemented.\n"); return -1; } else { req = build_request(amReq, as_id); } if (! req) return -1; rpl = rpcExecute(req); req = NULL; if (! rpl) goto end; if (! brpc_dsm(rpl, FMT_RPL, &code, &ser_opaque)) { ERROR("failed to disassebmle SER's response: %s [%d].\n", brpc_strerror(), brpc_errno); goto end; } if ((! code) || (! ser_opaque)) { ERROR("unexpected NULLs in SER's response (code@%p, opaque@%p).\n", code, ser_opaque); goto end; } if (300 <= *code) { ERROR("RPC request failed with code: %d, status: '%.*s'.\n", *code, /*misleading var. name!*/BRPC_STR_FMT(ser_opaque)); goto end; } DBG("SER's opaque/reason: `%.*s'.\n", BRPC_STR_FMT(ser_opaque)); //len must be fed, as the opaque could contain 0s memcpy(serKey, ser_opaque->val, ser_opaque->len); serKeyLen = ser_opaque->len; ret = 0; end: if (req) brpc_finish(req); if (rpl) brpc_finish(rpl); return ret; }
int main(void) { if (rpcInit()) { std::cerr << "Error in initialization" << std::endl; return -1; } int count0 = 3; int argTypes0[count0 + 1]; argTypes0[0] = (1 << ARG_OUTPUT) | (ARG_INT << 16); argTypes0[1] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes0[2] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes0[3] = 0; rpcRegister("f0", argTypes0, *f0_Skel); rpcExecute(); }
int main(int argc, char *argv[]) { /* create sockets and connect to the binder */ rpcInit(); /* prepare server functions' signatures */ int count0 = 3; int count1 = 5; int argTypes0[count0 + 1]; int argTypes1[count1 + 1]; argTypes0[0] = (1 << ARG_OUTPUT) | (ARG_INT << 16); argTypes0[1] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes0[2] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes0[3] = 0; argTypes1[0] = (1 << ARG_OUTPUT) | (ARG_LONG << 16); argTypes1[1] = (1 << ARG_INPUT) | (ARG_CHAR << 16); argTypes1[2] = (1 << ARG_INPUT) | (ARG_SHORT << 16); argTypes1[3] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes1[4] = (1 << ARG_INPUT) | (ARG_LONG << 16); argTypes1[5] = 0; /* * register server functions f0~f4 */ rpcRegister("f0", argTypes0, *f0_Skel); rpcRegister("f1", argTypes1, *f1_Skel); /* call rpcExecute */ rpcExecute(); /* return */ return 0; }
int main(int argc, char *argv[]) { /* create sockets and connect to the binder */ rpcInit(); /* prepare server functions' signatures */ int count0 = 3; int count1 = 5; int count2 = 3; int count3 = 1; int count4 = 1; int argTypes0[count0 + 1]; int argTypes1[count1 + 1]; int argTypes2[count2 + 1]; int argTypes3[count3 + 1]; int argTypes4[count4 + 1]; argTypes0[0] = (1 << ARG_OUTPUT) | (ARG_INT << 16); argTypes0[1] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes0[2] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes0[3] = 0; argTypes1[0] = (1 << ARG_OUTPUT) | (ARG_LONG << 16); argTypes1[1] = (1 << ARG_INPUT) | (ARG_CHAR << 16); argTypes1[2] = (1 << ARG_INPUT) | (ARG_SHORT << 16); argTypes1[3] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes1[4] = (1 << ARG_INPUT) | (ARG_LONG << 16); argTypes1[5] = 0; /* * the length in argTypes2[0] doesn't have to be 100, * the server doesn't know the actual length of this argument */ argTypes2[0] = (1 << ARG_OUTPUT) | (ARG_CHAR << 16) | 100; argTypes2[1] = (1 << ARG_INPUT) | (ARG_FLOAT << 16); argTypes2[2] = (1 << ARG_INPUT) | (ARG_DOUBLE << 16); argTypes2[3] = 0; /* * f3 takes an array of long. */ argTypes3[0] = (1 << ARG_OUTPUT) | (1 << ARG_INPUT) | (ARG_LONG << 16) | 11; argTypes3[1] = 0; /* same here, 28 is the exact length of the parameter */ argTypes4[0] = (1 << ARG_INPUT) | (ARG_CHAR << 16) | 28; argTypes4[1] = 0; // int count5 = 3; // int argTypes5[count5 + 1]; // argTypes5[0] = (1 << ARG_OUTPUT) | (ARG_CHAR << 16) | 2;//` | 100; // argTypes5[1] = (1 << ARG_INPUT) | (ARG_FLOAT << 16); // argTypes5[2] = (1 << ARG_INPUT) | (ARG_DOUBLE << 16); // argTypes5[3] = 0; /* * register server functions f0~f4 */ rpcRegister("f0", argTypes0, *f0_Skel); rpcRegister("f1", argTypes1, *f1_Skel); rpcRegister("f2", argTypes2, *f2_Skel); rpcRegister("f3", argTypes3, *f3_Skel); rpcRegister("f4", argTypes4, *f4_Skel); //rpcRegister("f2", argTypes5, *f4_Skel); /* call rpcExecute */ rpcExecute(); /* return */ return 0; }
int BrpcCtrlInterface::send(const AmSipReply &amRpl) { int ret = -1; brpc_t *req, *rpl = NULL; brpc_int_t *retcode; brpc_str_t *ser_opaque; if (amRpl.method == "CANCEL") { DBG("skipping replying to CANCEL, no longer needed with SER2.\n"); return 0; } if (! (req = brpc_req(SER_REPLY, random()))) { ERROR("failed to build RPC context: %s [%d].\n", brpc_strerror(), brpc_errno); return -1; } XTRA_HDRS(xtraHdrs, amRpl); STR2BSTR(_serKey, amRpl.serKey); STR2BSTR(_reason, amRpl.reason); STR2BSTR(_local_tag, amRpl.local_tag); STR2BSTR(_hdrs, xtraHdrs); STR2BSTR(_body, amRpl.body); if (! brpc_asm(req, REPLY_FMT_REQ, &_serKey, amRpl.code, &_reason, &_local_tag, &_hdrs, &_body )) { ERROR("failed to assemble RPC request: %s [%d].\n", brpc_strerror(), brpc_errno); goto end; } rpl = rpcExecute(req); req = NULL; if (! rpl) goto end; if (! brpc_dsm(rpl, FMT_RPL, &retcode, &ser_opaque)) { ERROR("failed to disassebmle SER's response: %s [%d].\n", brpc_strerror(), brpc_errno); goto end; } if ((! retcode) || (! ser_opaque)) { ERROR("unexpected NULLs in SER's response (code@%p, opaque@%p).\n", retcode, ser_opaque); goto end; } if (300 <= *retcode) { #if 0 ERROR("RPC request failed (code: %d, status: '%.*s') for reply: %s\n", *retcode, /*misleading var. name!*/BRPC_STR_FMT(ser_opaque), ((AmSipReply)amRpl).print().c_str()); #else ERROR("RPC request failed (code: %d, status: '%.*s') for reply.\n", *retcode, /*misleading var. name!*/BRPC_STR_FMT(ser_opaque)); #endif goto end; } DBG("successfully posted SER reply event.\n"); ret = 0; end: if (req) brpc_finish(req); if (rpl) brpc_finish(rpl); return ret; }
int main(int argc, char *argv[]) { /* create sockets and connect to the binder */ rpcInit(); /* prepare server functions' signatures */ int count0 = 3; int count1 = 5; int count2 = 3; int count3 = 1; int count4 = 1; int argTypes0[count0 + 1]; int argTypes1[count1 + 1]; int argTypes2[count2 + 1]; int argTypes3[count3 + 1]; int argTypes4[count4 + 1]; argTypes0[0] = (1 << ARG_OUTPUT) | (ARG_INT << 16); argTypes0[1] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes0[2] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes0[3] = 0; argTypes1[0] = (1 << ARG_OUTPUT) | (ARG_LONG << 16); argTypes1[1] = (1 << ARG_INPUT) | (ARG_CHAR << 16); argTypes1[2] = (1 << ARG_INPUT) | (ARG_SHORT << 16); argTypes1[3] = (1 << ARG_INPUT) | (ARG_INT << 16); argTypes1[4] = (1 << ARG_INPUT) | (ARG_LONG << 16); argTypes1[5] = 0; /* * the length in argTypes2[0] doesn't have to be 100, * the server doesn't know the actual length of this argument */ argTypes2[0] = (1 << ARG_OUTPUT) | (ARG_CHAR << 16) | 100; argTypes2[1] = (1 << ARG_INPUT) | (ARG_FLOAT << 16); argTypes2[2] = (1 << ARG_INPUT) | (ARG_DOUBLE << 16); argTypes2[3] = 0; /* * f3 takes an array of long. */ argTypes3[0] = (1 << ARG_OUTPUT) | (1 << ARG_INPUT) | (ARG_LONG << 16) | 11; argTypes3[1] = 0; /* same here, 28 is the exact length of the parameter */ argTypes4[0] = (1 << ARG_INPUT) | (ARG_CHAR << 16) | 28; argTypes4[1] = 0; ////////////////////////////////////////////////////////////////////// /* prepare the arguments for f0 int a0 = 5; int b0 = 10; int return0; void **args0; args0 = (void **)malloc(count0 * sizeof(void *)); args0[0] = (void *)&return0; args0[1] = (void *)&a0; args0[2] = (void *)&b0; f0_Skel(argTypes0, args0); printf("ACTUAL return of f0 is: %d\n", *((int *)(args0[0])));*/ ////////////////////////////////////////////////////////////////////// /* * register server functions f0~f4 */ rpcRegister("f0", argTypes0, *f0_Skel); rpcRegister("f0", argTypes0, *f0_Skel); rpcRegister("f1", argTypes1, *f1_Skel); rpcRegister("f2", argTypes2, *f2_Skel); rpcRegister("f3", argTypes3, *f3_Skel); rpcRegister("f4", argTypes4, *f4_Skel); /* call rpcExecute */ rpcExecute(); /* return */ return 0; }