| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009 The Native Client Authors. All rights reserved. | 2 * Copyright 2009 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
| 4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 | 7 |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <nacl/nacl_srpc.h> | 9 #include <nacl/nacl_srpc.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| 11 #include <stdlib.h> | 11 #include <stdlib.h> |
| 12 | 12 |
| 13 /* | 13 /* |
| 14 * SetUpcallServices delivers the service discovery string that describes | 14 * SetUpcallServices delivers the service discovery string that describes |
| 15 * those client services that may be called back from the server. | 15 * those client services that may be called back from the server. |
| 16 */ | 16 */ |
| 17 void SetUpcallServices(NaClSrpcRpc *rpc, | 17 void SetUpcallServices(NaClSrpcRpc *rpc, |
| 18 NaClSrpcArg **in_args, | 18 NaClSrpcArg **in_args, |
| 19 NaClSrpcArg **out_args, | 19 NaClSrpcArg **out_args, |
| 20 NaClSrpcClosure *done) { | 20 NaClSrpcClosure *done) { |
| 21 const char* sd_string = (const char*) in_args[0]->u.sval.str; | 21 const char* sd_string = (const char*) in_args[0]->arrays.str; |
| 22 NaClSrpcService* service; | 22 NaClSrpcService* service; |
| 23 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | 23 rpc->result = NACL_SRPC_RESULT_APP_ERROR; |
| 24 printf("SetUpcallServices: %s\n", sd_string); | 24 printf("SetUpcallServices: %s\n", sd_string); |
| 25 service = (NaClSrpcService*) malloc(sizeof(*service)); | 25 service = (NaClSrpcService*) malloc(sizeof(*service)); |
| 26 if (NULL == service) { | 26 if (NULL == service) { |
| 27 printf("malloc failed\n"); | 27 printf("malloc failed\n"); |
| 28 done->Run(done); | 28 done->Run(done); |
| 29 return; | 29 return; |
| 30 } | 30 } |
| 31 if (!NaClSrpcServiceStringCtor(service, sd_string)) { | 31 if (!NaClSrpcServiceStringCtor(service, sd_string)) { |
| 32 printf("CTOR failed\n"); | 32 printf("CTOR failed\n"); |
| 33 done->Run(done); | 33 done->Run(done); |
| 34 return; | 34 return; |
| 35 } | 35 } |
| 36 rpc->channel->client = service; | 36 rpc->channel->client = service; |
| 37 rpc->result = NACL_SRPC_RESULT_OK; | 37 rpc->result = NACL_SRPC_RESULT_OK; |
| 38 done->Run(done); | 38 done->Run(done); |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 /* | 42 /* |
| 43 * TestUpcall requests a server test of a named client method. | 43 * TestUpcall requests a server test of a named client method. |
| 44 */ | 44 */ |
| 45 void TestUpcall(NaClSrpcRpc *rpc, | 45 void TestUpcall(NaClSrpcRpc *rpc, |
| 46 NaClSrpcArg **in_args, | 46 NaClSrpcArg **in_args, |
| 47 NaClSrpcArg **out_args, | 47 NaClSrpcArg **out_args, |
| 48 NaClSrpcClosure *done) { | 48 NaClSrpcClosure *done) { |
| 49 const char* method_name = (const char*) in_args[0]->u.sval.str; | 49 const char* method_name = (const char*) in_args[0]->arrays.str; |
| 50 NaClSrpcError retval; | 50 NaClSrpcError retval; |
| 51 | 51 |
| 52 printf("Testing upcall to method: '%s'\n", method_name); | 52 printf("Testing upcall to method: '%s'\n", method_name); |
| 53 retval = NaClSrpcInvokeBySignature(rpc->channel, method_name, "hello::"); | 53 retval = NaClSrpcInvokeBySignature(rpc->channel, method_name, "hello::"); |
| 54 out_args[0]->u.ival = retval; | 54 out_args[0]->u.ival = retval; |
| 55 | 55 |
| 56 rpc->result = NACL_SRPC_RESULT_OK; | 56 rpc->result = NACL_SRPC_RESULT_OK; |
| 57 done->Run(done); | 57 done->Run(done); |
| 58 } | 58 } |
| 59 | 59 |
| 60 const struct NaClSrpcHandlerDesc srpc_methods[] = { | 60 const struct NaClSrpcHandlerDesc srpc_methods[] = { |
| 61 { "set_upcall_services:s:", SetUpcallServices }, | 61 { "set_upcall_services:s:", SetUpcallServices }, |
| 62 { "test_upcall:s:i", TestUpcall }, | 62 { "test_upcall:s:i", TestUpcall }, |
| 63 { NULL, NULL }, | 63 { NULL, NULL }, |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 int main() { | 66 int main() { |
| 67 if (!NaClSrpcModuleInit()) { | 67 if (!NaClSrpcModuleInit()) { |
| 68 return 1; | 68 return 1; |
| 69 } | 69 } |
| 70 if (!NaClSrpcAcceptClientConnection(srpc_methods)) { | 70 if (!NaClSrpcAcceptClientConnection(srpc_methods)) { |
| 71 return 1; | 71 return 1; |
| 72 } | 72 } |
| 73 NaClSrpcModuleFini(); | 73 NaClSrpcModuleFini(); |
| 74 return 0; | 74 return 0; |
| 75 } | 75 } |
| OLD | NEW |