void RosCppPluginProvider::init_node()
{
  // initialize ROS node once
  if (!node_initialized_)
  {
    int argc = 0;
    char** argv = 0;
    std::stringstream name;
    name << "rqt_gui_cpp_node_";
    name << getpid();
    qDebug("RosCppPluginProvider::init_node() initialize ROS node '%s'", name.str().c_str());
    ros::init(argc, argv, name.str().c_str(), ros::init_options::NoSigintHandler);
    wait_for_master();
    ros::start();
    node_initialized_ = true;
  }
  else
  {
    wait_for_master();
  }
}
示例#2
0
文件: dc.c 项目: heratgandhi/openssl
int main(int argc, char **argv)
{
	struct sockaddr_in pulladdr;
	struct sockaddr_in pushaddr;
	int pullsock;
	int pushsock;
	int err;
	int recovering = 0;
	struct arguments args;
	struct log *log = NULL;
#ifdef TCPR
	int tcprsock;
	struct tcpr_ip4 state;
#endif

	//OpenSSL
	SSL_load_error_strings();
	ERR_load_BIO_strings();
	ERR_load_SSL_strings();
	SSL_library_init();
	OpenSSL_add_all_algorithms();
	/////////

	memset(&args, 0, sizeof(args));
	parse_arguments(&args, argc, argv);

	err = resolve_address(&pulladdr, args.pullhost, args.pullport);
	if (err) {
		fprintf(stderr, "%s:%s: %s\n", args.pullhost, args.pullport,
			gai_strerror(err));
		exit(EXIT_FAILURE);
	}

	err = resolve_address(&pushaddr, args.pushhost, args.pushport);
	if (err) {
		fprintf(stderr, "%s:%s: %s\n", args.pushhost, args.pushport,
			gai_strerror(err));
		exit(EXIT_FAILURE);
	}

	if (!args.port)
		args.port = 10000;

#ifdef TCPR
	printf("Connecting to TCPR.\n");
	tcprsock = connect_to_tcpr(&pulladdr);
	if (tcprsock < 0) {
		perror("Connecting to TCPR");
		exit(EXIT_FAILURE);
	}
	
	pulladdr1 = pulladdr;
	port1 = args.port;
	tcpr_sock = tcprsock;
	
	printf("Waiting for existing master, if any.\n");
	if (get_tcpr_state(&state, tcprsock, &pulladdr, args.port) < 0) {
		perror("Getting TCPR state");
		exit(EXIT_FAILURE);
	}
	
	recovering = wait_for_master(&state);
	if (recovering) {
		printf("Recovering from failed master.\n");
		if (claim_tcpr_state(&state, tcprsock, &pulladdr, args.port) < 0) {
			perror("Claiming TCPR state");
			exit(EXIT_FAILURE);
		}
	} else {
		printf("Creating fresh connection.\n");
	}

	handle_slaves();
#endif /* TCPR */
			
	printf("Connecting to data source.\n");
	pullsock = connect_to_peer(&pulladdr, args.port);
	if (pullsock < 0) {
		perror("Connecting to data source");
		exit(EXIT_FAILURE);
	}

	printf("Connecting to data sink.\n");
	pushsock = connect_to_peer(&pushaddr, 0);
	if (pushsock < 0) {
		perror("Connecting to data sink");
		exit(EXIT_FAILURE);
	}
	
	if (args.logprefix) {
		printf("Opening log.\n");
		log = log_start(args.logprefix, args.logbytes, args.logcount);
	}

#ifdef TCPR
	if (get_tcpr_state(&state, tcprsock, &pulladdr, args.port) < 0) {
		perror("Getting TCPR state");
		exit(EXIT_FAILURE);
	}
#endif

	if (!recovering) {
		printf("Sending ID to data source.\n");
		if (send(pullsock, args.id, strlen(args.id), 0) < 0) {
			perror("Sending session ID");
			exit(EXIT_FAILURE);
		}
	}
	
	get_tcpr_state(&state1, tcpr_sock, &pulladdr1, port1);
	get_tcpr_state(&state, tcpr_sock, &pulladdr, args.port);
	
	//BIO_set_callback(sbio,test_write);
	//BIO_set_callback(sbio1,test_write);
	printf("Copying data from source to sink.\n");
#ifdef TCPR
	if (copy_data(&state, log, pullsock, pushsock, tcprsock) < 0) {
#else
	if (copy_data(log, pullsock, pushsock) < 0) {
#endif
		perror("Copying data");
		exit(EXIT_FAILURE);
	}

	printf("Done.\n");
#ifdef TCPR
	close(tcprsock);
#endif
	close(pullsock);
	close(pushsock);
	return EXIT_SUCCESS;
}