[Jderobot-admin] jderobot-r1192 - in trunk/src/stable/libs: . ns

rocapal en jderobot.org rocapal en jderobot.org
Lun Mar 17 11:12:51 CET 2014


Author: rocapal
Date: 2014-03-17 11:12:51 +0100 (Mon, 17 Mar 2014)
New Revision: 1192

Added:
   trunk/src/stable/libs/ns/
   trunk/src/stable/libs/ns/CMakeLists.txt
   trunk/src/stable/libs/ns/ns.cpp
   trunk/src/stable/libs/ns/ns.h
Log:
#195 client lib to naming service


Added: trunk/src/stable/libs/ns/CMakeLists.txt
===================================================================
--- trunk/src/stable/libs/ns/CMakeLists.txt	                        (rev 0)
+++ trunk/src/stable/libs/ns/CMakeLists.txt	2014-03-17 10:12:51 UTC (rev 1192)
@@ -0,0 +1,17 @@
+include_directories(${SLICE_DIR}) # Aquí se alojan las cabeceras de las interfaces ICE en C++
+include_directories(${INTERFACES_CPP_DIR}) # Aquí se alojan las cabeceras de las interfaces ICE en C++
+include_directories(${LIBS_DIR}) # Aquí se alojan las cabeceras de las interfaces ICE en C++
+include_directories( ${LIBS_DIR}/)
+
+
+set(SRC_FILES ns.h ns.cpp) 
+ 
+ADD_LIBRARY(ns SHARED ${SRC_FILES})
+
+target_link_libraries(ns 
+	${Boost_LIBRARIES}
+	${ZeroCIce_LIBRARIES}
+)
+
+SET_PROPERTY(TARGET ns PROPERTY SOVERSION 0.1.0)
+ 

Added: trunk/src/stable/libs/ns/ns.cpp
===================================================================
--- trunk/src/stable/libs/ns/ns.cpp	                        (rev 0)
+++ trunk/src/stable/libs/ns/ns.cpp	2014-03-17 10:12:51 UTC (rev 1192)
@@ -0,0 +1,106 @@
+/*
+ *  Copyright (C) 2014 JdeRobot developers
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see http://www.gnu.org/licenses/.
+ *
+ *  Authors : Roberto Calvo Palomino <rocapal [at] gsyc [dot] urjc [dot] es>
+ *
+ */
+
+#include "ns.h"
+
+namespace jderobot
+{
+
+ns::ns(Ice::CommunicatorPtr& ic, std::string proxy)
+{
+
+	Ice::ObjectPrx namingService = ic->stringToProxy(proxy);
+
+	if (0==namingService)
+		throw "namingService: Could not create proxy with namingService";
+
+	mNamingService = NamingServicePrx::checkedCast(namingService);
+
+	if (0==mNamingService)
+		throw "NamingService: Invalid proxy to remote namingService";
+	else
+		jderobot::Logger::getInstance()->info("NamingService connection OK! - " + proxy);
+
+}
+ns::~ns()
+{
+}
+void ns::bind (std::string name, std::string Endpoint, std::string interface )
+{
+	NamingNode* node = new NamingNode();
+
+	std::vector<std::string> elems;
+	split(Endpoint, ' ', elems);
+
+	node->name = name;
+	node->interfaceName = interface;
+	node->ip = elems[2];
+	node->port = boost::lexical_cast<int>(elems[4]);
+	node->protocol = elems[0];
+
+	jderobot::Logger::getInstance()->info("ns::bind:: " + node->name + " - " + node->interfaceName + " - " + node->protocol + " - " +
+					node->ip + ":" + boost::lexical_cast<std::string>(node->port) );
+
+	mNamingService->bind(node);
+}
+
+void ns::unbind (std::string name)
+{
+
+	NamingNodePtr node = new NamingNode();
+	node->name = name;
+
+	mNamingService->unbind(node);
+}
+
+jderobot::NodeContainerPtr ns::resolveByName(std::string name)
+{
+	return mNamingService->resolveByName(name);
+}
+
+jderobot::NodeContainerPtr ns::resolveByInterface(std::string name)
+{
+	return mNamingService->resolveByInterface(name);
+}
+
+std::string ns::getProxyStr (const NamingNode& node)
+{
+	std::stringstream proxy;
+	proxy << node.name << ":" << node.protocol;
+	proxy << " -h " << node.ip << " -p " << node.port;
+
+	return proxy.str();
+}
+
+
+std::vector<std::string>& ns::split(const std::string &s, char delim, std::vector<std::string> &elems) {
+
+    std::stringstream ss(s);
+    std::string item;
+    while (std::getline(ss, item, delim)) {
+        elems.push_back(item);
+    }
+    return elems;
+}
+
+
+
+
+}

Added: trunk/src/stable/libs/ns/ns.h
===================================================================
--- trunk/src/stable/libs/ns/ns.h	                        (rev 0)
+++ trunk/src/stable/libs/ns/ns.h	2014-03-17 10:12:51 UTC (rev 1192)
@@ -0,0 +1,101 @@
+/*
+ *  Copyright (C) 2014 JdeRobot developers
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see http://www.gnu.org/licenses/.
+ *
+ *  Authors : Roberto Calvo Palomino <rocapal [at] gsyc [dot] urjc [dot] es>
+ *
+ */
+
+#ifndef NS_H
+#define NS_H
+
+
+#include <namingService.h>
+#include <log/Logger.h>
+#include <Ice/Ice.h>
+#include <IceUtil/IceUtil.h>
+#include <boost/lexical_cast.hpp>
+
+namespace jderobot
+{
+
+	/**
+	 * ns class implements facade to access namingService ICE
+	 */
+
+	class ns
+	{
+	public:
+
+		/**
+		 * \brief Constructor
+		 *
+		 * @param ic The communicator ICE
+		 * @param proxy The proxy to connect with naming service
+		 */
+		ns(Ice::CommunicatorPtr& ic, std::string proxy);
+		~ns();
+
+		/**
+		 * \brief Send bind petition to naming service
+		 *
+		 * @param name The name of the component
+		 * @param EndPoint The endpoint well formed (default -h 0.0.0.0 -p 9999)
+		 * @param interface The name of interface well formed (use ice_staticId() of your ObjectPtr)
+		 */
+		void bind (std::string name, std::string Endpoint, std::string interface );
+
+
+		/**
+		 * \brief Send Unbind petition to naming service
+		 *
+		 * @param name The name of component
+		 *
+		 */
+		void unbind (std::string name);
+
+		/**
+		 * \brief Send a resolve petition given a name of component
+		 *
+		 * @param name The name of component to search
+		 */
+		jderobot::NodeContainerPtr resolveByName(std::string name);
+
+		/**
+		 * \brief Send a resolve petition given a name of interface
+		 *
+		 * @param name The name of component to search
+		 */
+		jderobot::NodeContainerPtr resolveByInterface(std::string name);
+
+		/**
+		 * \brief Translate a naming node to proxy string
+		 *
+		 * @param node The naming node well formed
+		 *
+		 * @return string The string that represents the connection (example: cameraA:tcp -h 127.0.0.1 -p 9999)
+		 */
+		std::string getProxyStr (const NamingNode& node);
+
+	private:
+
+		NamingServicePrx mNamingService;
+
+		std::vector<std::string>& split(const std::string &s, char delim, std::vector<std::string> &elems);
+	};
+
+}
+
+#endif



More information about the Jderobot-admin mailing list