int main(int argc, char**argv) { ProtobufCService *service; ProtobufC_RPC_Client *client; ProtobufC_RPC_AddressType address_type=0; const char *name = NULL; unsigned i; for (i = 1; i < (unsigned) argc; i++) { if (starts_with (argv[i], "--tcp=")) { address_type = PROTOBUF_C_RPC_ADDRESS_TCP; name = strchr (argv[i], '=') + 1; } else if (starts_with (argv[i], "--unix=")) { address_type = PROTOBUF_C_RPC_ADDRESS_LOCAL; name = strchr (argv[i], '=') + 1; } else usage (); } if (name == NULL) die ("missing --tcp=HOST:PORT or --unix=PATH"); service = protobuf_c_rpc_client_new (address_type, name, &foo__dir_lookup__descriptor, NULL); if (service == NULL) die ("error creating client"); client = (ProtobufC_RPC_Client *) service; fprintf (stderr, "Connecting... "); while (!protobuf_c_rpc_client_is_connected (client)) protobuf_c_dispatch_run (protobuf_c_dispatch_default ()); fprintf (stderr, "done.\n"); for (;;) { char buf[1024]; Foo__Name query = FOO__NAME__INIT; protobuf_c_boolean is_done = 0; fprintf (stderr, ">> "); if (fgets (buf, sizeof (buf), stdin) == NULL) break; if (is_whitespace (buf)) continue; chomp_trailing_whitespace (buf); query.name = buf; foo__dir_lookup__by_name (service, &query, handle_query_response, &is_done); while (!is_done) protobuf_c_dispatch_run (protobuf_c_dispatch_default ()); } return 0; }
int main(int argc, char **argv) { ProtobufCService *service; ProtobufCService *service2; ProtobufC_RPC_Client *client; ProtobufC_RPC_Client *client2; ProtobufC_RPC_AddressType address_type = 0; ProtobufC_RPC_AddressType address_type2 = 0; const char *name = NULL; unsigned i; for (i = 1; i < (unsigned) argc; i++) { if (starts_with(argv[i], "--tcp=")) { address_type = PROTOBUF_C_RPC_ADDRESS_TCP; name = strchr(argv[i], '=') + 1; } else if (starts_with(argv[i], "--unix=")) { address_type2 = PROTOBUF_C_RPC_ADDRESS_LOCAL; name = strchr(argv[i], '=') + 1; } else usage(); } if (name == NULL ) die("missing --tcp=HOST:PORT or --unix=PATH"); service = protobuf_c_rpc_client_new(address_type, name, &foo__dir_lookup__descriptor, NULL); if (service == NULL) die("error creating client"); else { client = (ProtobufC_RPC_Client *) service; fprintf(stderr, "Connecting... "); while (!protobuf_c_rpc_client_is_connected(client)) protobuf_c_dispatch_run(protobuf_c_dispatch_default()); fprintf(stderr, "done.\n"); } int choice = 1; char buf[1024]; char *person, *show_arr; for(;;) { fprintf(stderr, ">> "); // fgets(buf, sizeof(buf), stdin) if (gets(buf) == NULL) break; if (starts_with(buf, "name")) { choice =1; person = strchr(buf, '=') + 1; if (is_whitespace(person)) continue; chomp_trailing_whitespace(person); } if(starts_with(buf,"array")) { choice =0; show_arr = strchr(buf, '=') + 1; if (is_whitespace(show_arr)) continue; chomp_trailing_whitespace(show_arr); } if(choice == 1) { choice = -1; Foo__Name query = FOO__NAME__INIT; protobuf_c_boolean is_done = 0; query.name = person; printf("person = %s\n",person); foo__dir_lookup__by_name(service, &query, handle_query_response, &is_done); while (!is_done) protobuf_c_dispatch_run(protobuf_c_dispatch_default()); } else if (choice == 0) { choice = -1; Foo__Name2 query = FOO__NAME2__INIT; protobuf_c_boolean is_done = 0; query.name = show_arr; printf("show_arr name = %s\n",show_arr); foo__dir_lookup__by_name2(service, &query, handle_query_response2, &is_done); while (!is_done) { protobuf_c_dispatch_run(protobuf_c_dispatch_default()); //protobuf_c_dispatch_run(protobuf_c_dispatch_default()) } } else { printf("input wrong!\n"); } } return 0; }