// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include LOG_SETUP("rpc_client"); #include class RPCClient : public FastOS_Application { public: virtual int Main() override; }; int RPCClient::Main() { if (_argc < 2) { printf("usage : rpc_client \n"); return 1; } FRT_Supervisor supervisor; supervisor.Start(); FRT_Target *target = supervisor.GetTarget(_argv[1]); const char *str1 = "abc"; const char *str2 = "def"; float float1 = 20.5; float float2 = 60.5; double double1 = 25.5; double double2 = 5.5; fprintf(stdout, "\nTesting concat method\n"); FRT_RPCRequest *req = supervisor.AllocRPCRequest(); req->SetMethodName("concat"); req->GetParams()->AddString(str1); req->GetParams()->AddString(str2); target->InvokeSync(req, 5.0); if (req->GetErrorCode() == FRTE_NO_ERROR) { fprintf(stdout, "%s + %s = %s\n", str1, str2, req->GetReturn()->GetValue(0)._string._str); } else { fprintf(stdout, "error(%d): %s\n", req->GetErrorCode(), req->GetErrorMessage()); } fprintf(stdout, "\nTesting addFloat method\n"); req->SubRef(); req = supervisor.AllocRPCRequest(); req->SetMethodName("addFloat"); req->GetParams()->AddFloat(float1); req->GetParams()->AddFloat(float2); target->InvokeSync(req, 5.0); if (req->GetErrorCode() == FRTE_NO_ERROR) { fprintf(stdout, "%f + %f = %f\n", float1, float2, req->GetReturn()->GetValue(0)._float); } else { fprintf(stdout, "error(%d): %s\n", req->GetErrorCode(), req->GetErrorMessage()); } fprintf(stdout, "\nTesting addDouble method\n"); req->SubRef(); req = supervisor.AllocRPCRequest(); req->SetMethodName("addDouble"); req->GetParams()->AddDouble(double1); req->GetParams()->AddDouble(double2); target->InvokeSync(req, 5.0); if (req->GetErrorCode() == FRTE_NO_ERROR) { fprintf(stdout, "%f + %f = %f\n", double1, double2, req->GetReturn()->GetValue(0)._double); } else { fprintf(stdout, "error(%d): %s\n", req->GetErrorCode(), req->GetErrorMessage()); } req->SubRef(); target->SubRef(); supervisor.ShutDown(true); return 0; } int main(int argc, char **argv) { RPCClient myapp; return myapp.Entry(argc, argv); }