Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
Arquivo: rpc.c Projeto: eroullit/dabba
int dabbad_rpc_msg_poll(void)
{
	for (;;)
		protobuf_c_dispatch_run(protobuf_c_dispatch_default());

	return 0;
}
Exemplo n.º 3
0
int main (int argc, char ** argv) {
  ProtobufCService *service;
  ProtobufC_RPC_Client * client;
  const char * name = NULL;
  unsigned i;

  // the ping message we will be sending
  Ping ping = PING__INIT;

  for (i = 1; i < (unsigned) argc; i++) {
    if (starts_with (argv[i], "--tcp=")) {
      name = strchr (argv[i], '=') + 1;
    }
  }

  if (name == NULL) {
    fprintf(stderr, "missing --tcp=HOST:PORT");
    return 1;
  }

  // service creates an rpc client, and client is a special cast
  service = protobuf_c_rpc_client_new (PROTOBUF_C_RPC_ADDRESS_TCP, name, &ping_service__descriptor, NULL);
  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");

  // create the message
  ping.message = strdup("HELLO WORLD");

  // send it on it's way
  protobuf_c_boolean is_done = 0;
  printf("sending ping... ");
  // handle_ping_response will be called with the resulting PingResponse
  ping_service__reply_to_ping(service, &ping, handle_ping_response, &is_done);

  while (!is_done)
    protobuf_c_dispatch_run (protobuf_c_dispatch_default ());
}
Exemplo n.º 4
0
int main(int argc, char**argv)
{
    ProtobufC_RPC_Server *server;
    ProtobufC_RPC_AddressType address_type=0;
    const char *name = NULL;
    unsigned i;

    for (i = 1; i < (unsigned) argc; i++)
    {
        if (starts_with (argv[i], "--port="))
        {
            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 if (starts_with (argv[i], "--database="))
        {
            load_database (strchr (argv[i], '=') + 1);
        }
        else
            usage ();
    }

    if (database_size == 0)
        die ("missing --database=FILE (try --database=example.database)");
    if (name == NULL)
        die ("missing --port=NUM or --unix=PATH");

    server = protobuf_c_rpc_server_new (address_type, name, (ProtobufCService *) &the_dir_lookup_service, NULL);

    for (;;)
        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;
}