Exemplo n.º 1
0
/** \brief Launch the http_sclient_t
 */
upnp_err_t	upnp_call_t::launch_http_sclient()				throw()
{
	// sanity check - http_sclient_t MUST be NULL
	DBG_ASSERT( !http_sclient );
	
	// build the data2post
	datum_t		data2post;
	data2post	= build_soap_req(service_name(), method_name(), strvar_db()).to_datum();
	// build the http_reqhd_t to use for the http_sclient_t
	http_reqhd_t	http_reqhd;
	http_reqhd	= build_soap_reqhd(control_uri(), service_name(), method_name(), data2post);

	// log to debug
	KLOG_DBG("http_reqhd="	<< http_reqhd);
	KLOG_DBG("data2post="	<< data2post.to_stdstring());

	// start the http_sclient_t
	http_err_t	http_err;
	http_sclient	= nipmem_new http_sclient_t();
	http_err	= http_sclient->start(http_reqhd, this, NULL, data2post);
	if( http_err.failed() )	return upnp_err_from_http(http_err);

	// return no error
	return upnp_err_t::OK;
}
Exemplo n.º 2
0
void ServicesList :: AddService (const char * const service_name_s, ServicePrefsWidget *services_widget_p)
{
	char * const icon_path_s = MakeFilename ("images", service_name_s);
	QString service_name (service_name_s);
	ServicesListItem *item_p = 0;

	if (icon_path_s)
		{
			QIcon icon (icon_path_s);

			item_p = new ServicesListItem (icon, service_name, sl_services_p);
			FreeCopiedString (icon_path_s);
		}
	else
		{
			item_p = new ServicesListItem (service_name, sl_services_p);
		}

	sl_services_p -> addItem (item_p);
	int index = sl_stacked_widgets_p -> addWidget (services_widget_p);

	item_p -> setCheckState (Qt :: Unchecked);
	item_p -> setFlags (Qt :: ItemIsEnabled | Qt :: ItemIsUserCheckable | Qt :: ItemIsSelectable);

	connect (services_widget_p, &ServicePrefsWidget :: RunStatusChanged, this, &ServicesList :: SetServiceRunStatus);
}
Exemplo n.º 3
0
/** \brief Build a upnp discovery request packet (for UDP)
 */
pkt_t	upnp_disc_t::build_upnp_disc_req()					const throw()
{
	std::ostringstream	oss;
	// sanity check - the service_name MUST be set
	DBG_ASSERT( !service_name().empty() );
	// build the upnp_req
	oss << "M-SEARCH * HTTP/1.1\r\n"; 
	oss << "Host:239.255.255.250:1900\r\n";
	oss << "ST: urn:schemas-upnp-org:service:" << service_name() << ":1\r\n";
	oss << "Man:\"ssdp:discover\"\r\n";
	oss << "MX:3\r\n";
	oss << "\r\n";
	oss << "\r\n";
	// return the pkt_t for it
	return pkt_t(oss.str().c_str(), oss.str().size());
}
/*
*	Implements a synchronous call to the mvn_pln node to move the robot a specified distance and angle
*	Receives:
*		bearing : the angle the robot must turn
*		distance : the distance the robot must move
*		traveledBearing : the angle the robot actually turn after perform the command (reference)
*		traveledDistance : the distance the robot actually moves after perform the command (reference)
*	Returns:
*		true : if the robot performs correctly the move action
*		false : otherwise
*/
bool ServiceManager::mpMove(std_msgs::Float32 bearing, std_msgs::Float32 distance, std_msgs::Float32 &traveledBearing, std_msgs::Float32 &traveledDistance)
{
	std::string service_name ("/mp_move_dist_angle");
	ros::NodeHandle n;
	ros::ServiceClient client = n.serviceClient<mvn_pln::mp_move_dist_angle>(service_name);	//create the service caller

	mvn_pln::mp_move_dist_angle srv;	//create the service and fill it with the parameters
	srv.request.bearing = bearing;
	srv.request.distance = distance;

	if(client.call(srv))	//call the service with the parameters contained in srv
	{
		ROS_DEBUG_STREAM_NAMED("action_planner", service_name << " service called successfully with parameters (bearing, distance) = (" << bearing << ", " << distance << ")");
		traveledBearing = srv.response.traveledBearing;
		traveledDistance = srv.response.traveledDistance;
		return true;
	}
	else
	{
		ROS_ERROR_STREAM_NAMED("action_planner", "an error acurred when trying to call the " << service_name << " service with parameters (bearing, distance) = (" << bearing << ", " << distance << ")");
		traveledBearing = srv.response.traveledBearing;
		traveledDistance = srv.response.traveledDistance;
	}
	return false;
}
Exemplo n.º 5
0
int BinderManager::registerBinderService(struct wpa_global *global)
{
	/* Create the main binder service object and register with
	 * system service manager. */
	supplicant_object_ = new Supplicant(global);
	android::String16 service_name(binder_constants::kServiceName);
	android::defaultServiceManager()->addService(
	    service_name, android::IInterface::asBinder(supplicant_object_));
	return 0;
}
/*
* Implements a call to the prsfnd BB module to perform the pf_find (find a human) command
* Receives:
*	personToFind	:	a string containing the name of the human to find
*	timeout	:	timeout for the bb command
*/
bool ServiceManager::prsfndFind(std::string personToFind, int timeout)
{
	std::string service_name ("/pf_find");
	ros::NodeHandle n;
	ros::ServiceClient client = n.serviceClient<bbros_bridge::Default_ROS_BB_Bridge>(service_name);	//create the service caller

	bbros_bridge::Default_ROS_BB_Bridge srv;	//create the service and fill it with the parameters
	srv.request.parameters = personToFind;
	srv.request.timeout = timeout;

	if(client.call(srv))	//call the service with the parameters contained in srv
	{
		ROS_DEBUG_STREAM_NAMED("action_planner", service_name << " service called successfully with parameters " << srv.request);
		return srv.response.success;
	}
	else
	{
		ROS_ERROR_STREAM_NAMED("action_planner", "an error acurred when trying to call the " << service_name << " service with parameters" << srv.request);
	}
	return false;
}
/*
*	Implements a synchronous call to the mvn_pln node to move the robot to a specified string location
*	Receives:
*		location : the name of the map location (goalpoint)
*	Returns:
*		true : if the robot reach the location
*		false : otherwise
*/
bool ServiceManager::mpGetClose(std_msgs::String location)
{
	std::string service_name ("/mp_getclose");
	ros::NodeHandle n;
	ros::ServiceClient client = n.serviceClient<mvn_pln::mp_getclose>(service_name);	//create the service caller

	mvn_pln::mp_getclose srv;	//create the service and fill it with the parameters
	srv.request.location = location;

	if(client.call(srv))	//call the service with the parameters contained in srv
	{
		ROS_DEBUG_STREAM_NAMED("action_planner", service_name << " service called successfully with parameters: " << location);
		return true;
	}
	else
	{
		ROS_ERROR_STREAM_NAMED("action_planner", "an error acurred when trying to call the " << service_name << " service with parameters: " << location);
		ROS_ERROR_STREAM_NAMED("action_planner", "Error message received from " << service_name << " : " << srv.response.error);
	}
	return false;
}
Exemplo n.º 8
0
static void msg_start(const std::string& name)
{
    Service* svc = nullptr;
    std::vector<std::string> vargs;

    size_t colon_pos = name.find(':');
    if (colon_pos == std::string::npos) {
        svc = ServiceManager::GetInstance().FindServiceByName(name);
    } else {
        std::string service_name(name.substr(0, colon_pos));
        std::string args(name.substr(colon_pos + 1));
        vargs = android::base::Split(args, " ");

        svc = ServiceManager::GetInstance().FindServiceByName(service_name);
    }

    if (svc) {
        svc->Start(vargs);
    } else {
        ERROR("no such service '%s'\n", name.c_str());
    }
}
/*! Simply pings the graph_based_segmentation segmentation and recognition services and prints out the result.*/
int main(int argc, char **argv)
{
  ros::init(argc, argv, "ping_graph_segment_node");
  ros::NodeHandle nh;

  std::string service_name("/graph_segment_srv");
  while ( !ros::service::waitForService(service_name, ros::Duration().fromSec(3.0)) && nh.ok() )
  {
    ROS_INFO("Waiting for service %s...", service_name.c_str());
  }
  if (!nh.ok()) exit(0);

  sensor_msgs::Image::ConstPtr input = ros::topic::waitForMessage<sensor_msgs::Image>("/Honeybee/left/image_rect_color", nh, ros::Duration(5.0));

  graph_based_segmentation::GraphSegment segmentation_srv;
  segmentation_srv.request.rgb = *input;

  if (!ros::service::call(service_name, segmentation_srv))
  {
    ROS_ERROR("Call to segmentation service failed");
    exit(0);
  }
  if (segmentation_srv.response.result == segmentation_srv.response.FAILED)
  {
    ROS_ERROR("Segmentation service returned error %d", segmentation_srv.response.result);
    exit(0);
  }

  ROS_INFO("Segmentation service succeeded. Segmented Image");

  // DEBUG of projection
  if(segmentation_srv.response.result == segmentation_srv.response.SUCCESS)
	  dumpCVImage(segmentation_srv.response.segment,"segmented_image.png");

  return true;
}
//! Pings the segment object in hand service and broadcasts the result 
int main(int argc, char **argv)
{
  ros::init(argc, argv, "ping_segment_object_in_hand");
  ros::NodeHandle nh;
  ros::Publisher pub_cloud = nh.advertise<sensor_msgs::PointCloud2>("segmented_object_in_hand", 1);

  std::string service_name("/segment_object_in_hand_srv");
  while ( !ros::service::waitForService(service_name, ros::Duration().fromSec(3.0)) && nh.ok() )
  {
    ROS_INFO("Waiting for service %s...", service_name.c_str());
  }
  if (!nh.ok()) exit(0);

  tabletop_object_segmentation::SegmentObjectInHand segmentation_srv;
  segmentation_srv.request.wrist_frame = std::string("r_wrist_roll_link");
  if (!ros::service::call(service_name, segmentation_srv))
  {
    ROS_ERROR("Call to segmentation service failed");
    exit(0);
  }

  pub_cloud.publish(segmentation_srv.response.cluster);

}
Exemplo n.º 11
0
/** \brief Parse the http_sclient_t reply and fill the this->current_res with it
 */
upnp_err_t	upnp_disc_t::parse_upnp_http_rep(const http_sclient_res_t &sclient_res)	throw(xml_except_t)
{
	// get the reply_body which is in xml
	std::string	xml_str	= sclient_res.reply_body().to_stdstring();
	// some router get the idea it is good to put additionnal \r\n, so i strip them :)
	xml_str		= string_t::strip(xml_str, "\r\n \t");

	// set the document to parse
	xml_parse_doc_t	xml_parse_doc;
	xml_parse_doc.set_document(datum_t(xml_str));
	// check that the parsing suceed
	if( xml_parse_doc.is_null() )	return upnp_err_t(upnp_err_t::ERROR, "unable to parse the upnp_disc_t http reply as xml"); 

	// extract the urlbase from the description response
	http_uri_t	urlbase	= sclient_res.http_reqhd().uri();
	if( xml_parse_t(&xml_parse_doc).has_path("/root/URLBase") )
		urlbase	= xml_parse_t(&xml_parse_doc).path_content_opt("/root/URLBase");
	// log to debug
	KLOG_DBG("urlbase=" << urlbase);


	// init the xml_parse_t on this document
	xml_parse_t	xml_parse(&xml_parse_doc);
	xml_parse.goto_children();
	
	// go thru all the device to find the one acting as InternetGatewayDevice
	while( 1 ){
		// find the next sibling called "device"
		xml_parse.goto_firstsib("device");
		// extract the device type from it
		std::string device_type	= xml_parse_t(xml_parse).path_content_opt("device/deviceType");
		// if this device_type is the one of a InternetGatewayDevice, leave the loop
		if( device_type == "urn:schemas-upnp-org:device:InternetGatewayDevice:1" )	break;
		// goto the next sibling
		xml_parse.goto_nextsib();		
	}

	// go inside the device for InternetGatewayDevice section
	xml_parse.goto_children();
	// go inside the deviceList section
	xml_parse.goto_firstsib("deviceList");
	xml_parse.goto_children();

	// go thru all the device to find the one acting as WANDevice
	while( 1 ){
		// find the next sibling called "device"
		xml_parse.goto_firstsib("device");
		// extract the device type from it
		std::string device_type	= xml_parse_t(xml_parse).path_content_opt("device/deviceType");
		// if this device_type is the one of a WANDevice, leave the loop
		if( device_type == "urn:schemas-upnp-org:device:WANDevice:1" )	break;
		// goto the next sibling
		xml_parse.goto_nextsib();		
	}
	
	// go inside the device for WANDevice
	xml_parse.goto_children();
	// go inside the deviceList section
	xml_parse.goto_firstsib("deviceList");
	xml_parse.goto_children();

	// go thru all the device to find the one acting as WANConnectionDevice
	while( 1 ){
		// find the next sibling called "device"
		xml_parse.goto_firstsib("device");
		// extract the device type from it
		std::string device_type	= xml_parse_t(xml_parse).path_content_opt("device/deviceType");
		// if this device_type is the one of a WANConnectionDevice, leave the loop
		if( device_type == "urn:schemas-upnp-org:device:WANConnectionDevice:1" )	break;
		// goto the next sibling
		xml_parse.goto_nextsib();		
	}

	// go inside the device for WANConnectionDevice
	xml_parse.goto_children();
	// go inside the serviceList section
	xml_parse.goto_firstsib("serviceList");
	xml_parse.goto_children();

	// go thru all the device to find the one acting as the service_name variable
	// - service_name is [WANIPConnection|WANPPPConnection]
	while( 1 ){
		// find the next sibling called "service"
		xml_parse.goto_firstsib("service");
		// extract the device type from it
		std::string device_type	= xml_parse_t(xml_parse).path_content_opt("service/serviceType");
		// if this device_type is the one of the service_name, leave the loop
		if( device_type == std::string("urn:schemas-upnp-org:service:")+service_name()+":1") break;
		// goto the next sibling
		xml_parse.goto_nextsib();		
	}

	// go inside the device for this service_name
	xml_parse.goto_children();
	// extract the controlURL content
	std::string	constrolURL	= xml_parse.goto_firstsib("controlURL").node_content();
	
	// build the definitive control_uri base on the constrolURL and the baseurl
	http_uri_t	control_uri;
	if( !string_t::casecmp("http://", constrolURL.substr(0, strlen("http://"))) ){
		// if control url start with a http://. this is a full url
		control_uri	= constrolURL;
	}else if( constrolURL.substr(0, 1) == "/" ){
		// if control url start with /, this is the absolute path for the baseurl
		control_uri	= std::string("http://") + urlbase.hostport_str() + constrolURL + urlbase.query_str();
	}else{
		// if control url start with somehting else, this is a relative path for the baseurl
		control_uri	= std::string("http://") + urlbase.hostport_str() + urlbase.path_str() + "/" + constrolURL + urlbase.query_str();
	} 
	// copy the control_uri in the upnp_disc_res_t
	current_res.control_uri	(control_uri);

	// log to debug	
	KLOG_DBG("control_uri=" << control_uri);

	// return no error
	return upnp_err_t::OK;
}
Exemplo n.º 12
0
void
configuration_t::parse_services_settings(const Json::Value& config_value) {
	const Json::Value services_list = config_value["services"];

	if (!services_list.isObject() || !services_list.size()) {
		std::string error_str = "\"services\" section is malformed, it must have at least one service defined, ";
		error_str += "see documentation for more info.";
		throw internal_error(error_str);
	}

	Json::Value::Members services_names(services_list.getMemberNames());
	for (Json::Value::Members::iterator it = services_names.begin(); it != services_names.end(); ++it) {
	    std::string service_name(*it);
	    Json::Value service_data(services_list[service_name]);

	    if (!service_data.isObject()) {
			std::string error_str = "\"service\" (with alias: " + service_name + ") is malformed, ";
			error_str += "see documentation for more info.";
			throw internal_error(error_str);
		}

	    service_info_t si;
		si.name = service_name;
		boost::trim(si.name);

	    if (si.name.empty()) {
	    	std::string error_str = "malformed \"service\" section found, alias must me non-empty string";
			throw internal_error(error_str);
	    }

	    si.description = service_data.get("description", "").asString();
	    boost::trim(si.description);

		si.app = service_data.get("app", "").asString();
		boost::trim(si.app);
		
		if (si.app.empty()) {
			std::string error_str = "malformed \"service\" " + si.name + " section found, field";
			error_str += "\"app\" must me non-empty string";
			throw internal_error(error_str);
		}

		// cocaine nodes autodiscovery
		const Json::Value autodiscovery = service_data["autodiscovery"];
		if (!autodiscovery.isObject()) {
			std::string error_str = "\"autodiscovery\" section for service " + service_name + " is malformed, ";
			error_str += "see documentation for more info.";
			throw internal_error(error_str);
		}

		si.hosts_source = autodiscovery.get("source", "").asString();
		boost::trim(si.hosts_source);

		if (si.hosts_source.empty()) {
			std::string error_str = "malformed \"service\" " + si.name + " section found, field";
			error_str += "\"source\" must me non-empty string";
			throw internal_error(error_str);
		}

		char* absolute_source_path = realpath(si.hosts_source.c_str(), NULL);
		if (NULL != absolute_source_path) {
    		si.hosts_source = absolute_source_path;
    	}

		std::string autodiscovery_type_str = autodiscovery.get("type", "").asString();

		if (autodiscovery_type_str == "FILE") {
			si.discovery_type = AT_FILE;
		}
		else if (autodiscovery_type_str == "HTTP") {
			si.discovery_type = AT_HTTP;
		}
		else if (autodiscovery_type_str == "MULTICAST") {
			si.discovery_type = AT_MULTICAST;
		}
		else {
			std::string error_str = "\"autodiscovery\" section for service " + service_name;
			error_str += " has malformed field \"type\", which can only take values FILE, HTTP, MULTICAST.";
			throw internal_error(error_str);
		}

		// default message policy
		const Json::Value mpolicy = service_data["policy"];
		if (mpolicy.isObject()) {
			si.policy.urgent = mpolicy.get("urgent", defaults_t::policy_urgent).asBool();
			si.policy.persistent = mpolicy.get("persistent", defaults_t::policy_persistent).asBool();
			si.policy.timeout = mpolicy.get("timeout", defaults_t::policy_chunk_timeout).asFloat();
			si.policy.ack_timeout = mpolicy.get("ack_timeout", defaults_t::policy_ack_timeout).asFloat();
			si.policy.deadline = mpolicy.get("deadline", defaults_t::policy_message_deadline).asFloat();
			si.policy.max_retries = mpolicy.get("max_retries", defaults_t::policy_max_retries).asInt();
		}

		// check for duplicate services
		std::map<std::string, service_info_t>::iterator lit = m_services_list.begin();
		for (;lit != m_services_list.end(); ++lit) {
			if (lit->second.name == si.name) {
				throw internal_error("duplicate service with name " + si.name + " was found in config!");
			}
		}

		m_services_list[si.name] = si;
	}
}