Exemplo n.º 1
0
	void start(BundleContext::Ptr pContext)
	{
		_pContext = pContext;
		_pPrefs = ServiceFinder::find<PreferencesService>(pContext);
		
		Poco::Util::AbstractConfiguration::Keys keys;
		_pPrefs->configuration()->keys("serial.ports", keys);
		int index = 0;
		for (std::vector<std::string>::const_iterator it = keys.begin(); it != keys.end(); ++it)
		{
			std::string baseKey = "serial.ports.";
			baseKey += *it;

			std::string device = _pPrefs->configuration()->getString(baseKey + ".device", "");
			std::string params = _pPrefs->configuration()->getString(baseKey + ".params", "8N1");
			int speed = _pPrefs->configuration()->getInt(baseKey + ".speed", 9600);
		
			try
			{
				pContext->logger().information(Poco::format("Creating serial port for device '%s'.", device));

				SerialDeviceImpl::SerialPortPtr pSerialPort = new SerialPort(device, speed, params);
				createSerialDevice(Poco::NumberFormatter::format(index), pSerialPort);
			}
			catch (Poco::Exception& exc)
			{
				pContext->logger().error(Poco::format("Cannot create serial port for device '%s': %s", device, exc.displayText())); 
			}
			index++;
		}
	}
Exemplo n.º 2
0
	void start(BundleContext::Ptr pContext)
	{
		ServiceRef::Ptr pPrefsRef = pContext->registry().findByName(PreferencesService::SERVICE_NAME);
		AutoPtr<PreferencesService> pPrefs = pPrefsRef->castedInstance<PreferencesService>();
		
		bool enable = pPrefs->configuration()->getBool("auth.simple.enable", true);
		if (enable)
		{
			std::string adminName = pPrefs->configuration()->getString("auth.simple.admin.name", "admin");
			std::string adminPasswordHash = pPrefs->configuration()->getString("auth.simple.admin.passwordHash", ""); 
			std::string userName = pPrefs->configuration()->getString("auth.simple.user.name", "user");
			std::string userPasswordHash = pPrefs->configuration()->getString("auth.simple.user.passwordHash", "");
			std::string salt = pPrefs->configuration()->getString("auth.simple.salt", "");
			std::string perms = pPrefs->configuration()->getString("auth.simple.user.permissions", "");
			StringTokenizer tok(perms, ",;", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY);
			std::set<std::string> userPermissions;
			for (StringTokenizer::Iterator it = tok.begin(); it != tok.end(); ++it)
			{
				userPermissions.insert(*it);
			}
			
			AutoPtr<SimpleAuthService> pService = new SimpleAuthService(adminName, adminPasswordHash, userName, userPasswordHash, userPermissions, salt);
			_pService = pContext->registry().registerService("osp.auth", pService, Properties());
		}
		else
		{
			pContext->logger().information("Simple authentication service disabled.");
		}
	}
Exemplo n.º 3
0
	void start(BundleContext::Ptr pContext)
	{
		_pTimer = new Poco::Util::Timer;
		_pContext = pContext;
		_pPrefs = ServiceFinder::find<PreferencesService>(pContext);

		Poco::Util::AbstractConfiguration::Keys keys;
		_pPrefs->configuration()->keys("simulation.sensors", keys);
		for (std::vector<std::string>::const_iterator it = keys.begin(); it != keys.end(); ++it)
		{
			std::string baseKey = "simulation.sensors.";
			baseKey += *it;

			SimulatedSensor::Params params;
			params.id = SimulatedSensor::SYMBOLIC_NAME;
			params.id += "#";
			params.id += Poco::NumberFormatter::format(_serviceRefs.size());

			params.physicalQuantity = _pPrefs->configuration()->getString(baseKey + ".physicalQuantity", "");
			params.physicalUnit     = _pPrefs->configuration()->getString(baseKey + ".physicalUnit", "");
			params.initialValue     = _pPrefs->configuration()->getDouble(baseKey + ".initialValue", 0.0);
			params.delta            = _pPrefs->configuration()->getDouble(baseKey + ".delta", 0.0);
			params.cycles           = _pPrefs->configuration()->getInt(baseKey + ".cycles", 0);
			params.updateRate       = _pPrefs->configuration()->getDouble(baseKey + ".updateRate", 0.0);

			std::string mode = _pPrefs->configuration()->getString(baseKey + ".mode", "linear");
			if (mode == "linear")
				params.mode = SimulatedSensor::SIM_LINEAR;
			else if (mode == "random")
				params.mode = SimulatedSensor::SIM_RANDOM;

			try
			{
				createSensor(params);
			}
			catch (Poco::Exception& exc)
			{
				pContext->logger().error(Poco::format("Cannot create simulated sensor: %s", exc.displayText()));
			}
		}

		std::string gpxPath = _pPrefs->configuration()->getString("simulation.gnss.gpxPath", "");
		if (!gpxPath.empty())
		{
			SimulatedGNSSSensor::Params params;
			params.id = SimulatedGNSSSensor::SYMBOLIC_NAME;
			params.gpxPath = gpxPath;
			params.loopReplay = _pPrefs->configuration()->getBool("simulation.gnss.loopReplay", true);
			params.speedUp = _pPrefs->configuration()->getDouble("simulation.gnss.speedUp", 1.0);

			try
			{
				createGNSSSensor(params);
			}
			catch (Poco::Exception& exc)
			{
				pContext->logger().error(Poco::format("Cannot create simulated GNSS sensor: %s", exc.displayText()));
			}
		}
	}
	void handleExtension(Bundle::ConstPtr pBundle, Poco::XML::Element* pExtensionElem)
	{
		std::string name = pBundle->name();
		std::string symbolicName = pBundle->symbolicName();
		std::string msg(Poco::format("Running tests in bundle \"%s\" (%s)...", name, symbolicName));

		_pContext->logger().information(std::string(msg.size(), '='));
		_pContext->logger().information(msg);
		_pContext->logger().information(std::string(msg.size(), '-'));
		
		BundleContext::Ptr pContext = _pContext->contextForBundle(pBundle);
		TestCase::resetContext(pContext);

		LogStream logStream(pContext->logger());
		TestFactory::TestVec tests = TestFactory::instance().get(name);
		TestFactory::TestVec::iterator it = tests.begin();
		TestFactory::TestVec::iterator end = tests.end();
		int nTests = 0;
		int nErrors = 0;
		int nFailures = 0;
		for (; it != end; ++it)
		{
			LogTestResult ltr(logStream);
			(*it)->run(&ltr);
			ltr.print(logStream);
			nTests += ltr.runTests();
			nErrors += ltr.testErrors();
			nFailures += ltr.testFailures();
		}
		
		if (nErrors > 0)
		{
			if (nErrors == 1)
				_pContext->logger().error("There was 1 error in bundle \"%s\" (%s).", name, symbolicName);
			else
				_pContext->logger().error("There were %d errors in bundle \"%s\" (%s).", nErrors, name, symbolicName);
		}

		if (nFailures > 0)
		{
			if (nFailures == 1)
				_pContext->logger().error("There was 1 failure in bundle \"%s\" (%s).", name, symbolicName);
			else
				_pContext->logger().error("There were %d failures in bundle \"%s\" (%s).", nFailures, name, symbolicName);
		}
		
		if (nTests == 1)
			msg = Poco::format("Ran 1 test in bundle \"%s\" (%s).", name, symbolicName);
		else
			msg = Poco::format("Ran %d tests in bundle \"%s\" (%s).", nTests, name, symbolicName);

		_pContext->logger().information(std::string(msg.size(), '-'));
		_pContext->logger().information(msg);
		_pContext->logger().information(std::string(msg.size(), '='));

	}
	void stop(BundleContext::Ptr pContext)
	{
		pContext->registry().unregisterService(_pWebSessionManagerSvc);
		pContext->registry().unregisterService(_pWebServerDispatcherSvc);
		pContext->registry().unregisterService(_pMediaTypeMapperSvc);
		_pWebSessionManagerSvc = 0;
		_pWebServerDispatcherSvc = 0;
		_pMediaTypeMapperSvc = 0;
		_pWebServerExtensionPoint = 0;
		_pWebFilterExtensionPoint = 0;
	}
Exemplo n.º 6
0
	void stop(BundleContext::Ptr pContext)
	{
		if (_pService)
		{
			pContext->registry().unregisterService(_pService);
		}
	}
	void start(BundleContext::Ptr pContext)
	{
		// Create an instance of the GreetingService
		GreetingService::Ptr pService = new GreetingServiceImpl(pContext);
		// Register the GreetingService with the ServiceRegistry.
		_pService = pContext->registry().registerService("com.appinf.osp.samples.GreetingService", pService, Properties());
	}
Exemplo n.º 8
0
	void start(BundleContext::Ptr pContext)
	{
		typedef Poco::RemotingNG::ServerHelper<IoT::WebEvent::WebEventNotifier> ServerHelper;
		
		Poco::SharedPtr<IoT::WebEvent::WebEventNotifier> pWebEventNotifier = new WebEventNotifierImpl(pContext);
		std::string oid("io.macchina.services.webeventnotifier");
		ServerHelper::RemoteObjectPtr pWebEventNotifierRemoteObject = ServerHelper::createRemoteObject(pWebEventNotifier, oid);		
		ServiceRef::Ptr pServiceRef = pContext->registry().registerService(oid, pWebEventNotifierRemoteObject, Properties());
	}
Exemplo n.º 9
0
	void start(BundleContext::Ptr pContext)
	{
		// Obtain the GreetingService object from the Service Registry.
		ServiceRef::Ptr pServiceRef = pContext->registry().findByName("com.appinf.osp.samples.GreetingService");
		if (pServiceRef)
		{
			// Service is available - let's invoke it
			GreetingService::Ptr pService = pServiceRef->castedInstance<GreetingService>();
			std::string greeting = pService->greeting();
			std::string msg("****** ");
			msg += greeting;
			msg += " ******";
			pContext->logger().information(msg);
		}
		else
		{
			// The service is not available
			pContext->logger().error("The GreetingService is not available.");
		}
	}
	void start(BundleContext::Ptr pContext)
	{
		// find ExtensionPointService using the Service Registry
		ServiceRef::Ptr pXPSRef = pContext->registry().findByName("osp.core.xp");
		if (pXPSRef)
		{
			// ExtensionPointService is available
			AutoPtr<ExtensionPointService> pXPS = pXPSRef->castedInstance<ExtensionPointService>();
			
			// Create an ExtensionPoint
			ExtensionPoint::Ptr pXP = new TestExtensionPoint(pContext);
			
			// Register ExtensionPoint
			pXPS->registerExtensionPoint(pContext->thisBundle(), "com.appinf.osp.unit.test", pXP);
		}
		else
		{
			// The service is not available
			pContext->logger().error("The ExtensionPointService is not available.");
		}
	}
Exemplo n.º 11
0
	void stop(BundleContext::Ptr pContext)
	{
		for (std::vector<Poco::OSP::ServiceRef::Ptr>::iterator it = _serviceRefs.begin(); it != _serviceRefs.end(); ++it)
		{
			pContext->registry().unregisterService(*it);
		}
		_serviceRefs.clear();
		for (std::vector<MQTTClientImpl::Ptr>::iterator it = _clients.begin(); it != _clients.end(); ++it)
		{
			try
			{
				(*it)->disconnect(200);
			}
			catch (Poco::Exception& exc)
			{
				pContext->logger().log(exc);
			}
		}
		_clients.clear();
		
		ServerHelper::shutdown();
	}
Exemplo n.º 12
0
	void start(BundleContext::Ptr pContext)
	{
		_pContext = pContext;
		_pPrefs = ServiceFinder::find<PreferencesService>(pContext);

		std::string device = _pPrefs->configuration()->getString("gnss.nmea.device", "");
		std::string params = _pPrefs->configuration()->getString("gnss.nmea.params", "8N1");
		int speed = _pPrefs->configuration()->getInt("gnss.nmea.speed", 4800);
		
		try
		{
			if (!device.empty())
			{
				pContext->logger().information(Poco::format("Creating GNSSSensor for serial port '%s'.", device));

				createGNSSSensor(new Poco::Serial::SerialPort(device, speed, params));
			}
		}
		catch (Poco::Exception& exc)
		{
			pContext->logger().error(Poco::format("Cannot create serial port for device '%s': %s", device, exc.displayText())); 
		}
	}
	void start(BundleContext::Ptr pContext)
	{
		MediaTypeMapper::Ptr pMediaTypeMapper = new MediaTypeMapper;
#if __cplusplus < 201103L
		std::auto_ptr<std::istream> pStream(pContext->thisBundle()->getResource("mime.types"));
#else
		std::unique_ptr<std::istream> pStream(pContext->thisBundle()->getResource("mime.types"));
#endif
		if (pStream.get())
		{
			pMediaTypeMapper->load(*pStream);
		}
		_pMediaTypeMapperSvc = pContext->registry().registerService(MediaTypeMapper::SERVICE_NAME, pMediaTypeMapper, Properties());
		ServiceRef::Ptr pPrefsSvcRef = pContext->registry().findByName("osp.core.preferences");

		std::string authServiceName(pContext->thisBundle()->properties().getString("authServiceName", ""));
		bool cacheResources(pContext->thisBundle()->properties().getBool("cacheResources", false));
		bool compressResponse(pContext->thisBundle()->properties().getBool("compressResponses", false));
		std::string compressedMediaTypesString(pContext->thisBundle()->properties().getString("compressedMediaTypes", ""));
		std::string sessionCookiePersistence(pContext->thisBundle()->properties().getString("cookiePersistence", "persistent"));
		if (pPrefsSvcRef)
		{
			Poco::AutoPtr<PreferencesService> pPrefsSvc = pPrefsSvcRef->castedInstance<PreferencesService>();
			authServiceName = pPrefsSvc->configuration()->getString("osp.web.authServiceName", authServiceName);
			cacheResources = pPrefsSvc->configuration()->getBool("osp.web.cacheResources", cacheResources);
			compressResponse = pPrefsSvc->configuration()->getBool("osp.web.compressResponses", compressResponse);
			compressedMediaTypesString = pPrefsSvc->configuration()->getString("osp.web.compressedMediaTypes", compressedMediaTypesString);
			sessionCookiePersistence = pPrefsSvc->configuration()->getString("osp.web.sessionManager.cookiePersistence", sessionCookiePersistence);
		}

		Poco::StringTokenizer tok(compressedMediaTypesString, ",", Poco::StringTokenizer::TOK_TRIM | Poco::StringTokenizer::TOK_IGNORE_EMPTY);
		std::set<std::string> compressedMediaTypes(tok.begin(), tok.end());
		
		AutoPtr<WebServerDispatcher> pWebServerDispatcher = new WebServerDispatcher(pContext, pMediaTypeMapper, authServiceName, compressResponse, compressedMediaTypes, cacheResources);
		_pWebServerDispatcherSvc = pContext->registry().registerService(WebServerDispatcher::SERVICE_NAME, pWebServerDispatcher, Properties());
		
		WebSessionManager::CookiePersistence cookiePersistence = WebSessionManager::COOKIE_PERSISTENT;
		if (sessionCookiePersistence == "transient")
			cookiePersistence = WebSessionManager::COOKIE_TRANSIENT;
		else if (sessionCookiePersistence != "persistent")
			pContext->logger().warning(Poco::format("Ignoring invalid value for osp.web.sessionManager.cookiePersistence: '%s'. Valid values are 'transient' or 'persistent'.", sessionCookiePersistence));
		
		AutoPtr<WebSessionManager> pWebSessionManager = new WebSessionManager;
		pWebSessionManager->setCookiePersistence(cookiePersistence);
		_pWebSessionManagerSvc = pContext->registry().registerService(WebSessionManager::SERVICE_NAME, pWebSessionManager, Properties());

		ServiceRef::Ptr pXPSRef = pContext->registry().findByName("osp.core.xp");
		if (pXPSRef)
		{
			AutoPtr<ExtensionPointService> pXPS = pXPSRef->castedInstance<ExtensionPointService>();
			_pWebServerExtensionPoint = new WebServerExtensionPoint(pContext, pWebServerDispatcher);
			pXPS->registerExtensionPoint(pContext->thisBundle(), WebServerExtensionPoint::EXTPOINT_DIRECTORY, _pWebServerExtensionPoint);
			pXPS->registerExtensionPoint(pContext->thisBundle(), WebServerExtensionPoint::EXTPOINT_HANDLER, _pWebServerExtensionPoint);
			_pWebFilterExtensionPoint = new WebFilterExtensionPoint(pContext, pWebServerDispatcher);
			pXPS->registerExtensionPoint(pContext->thisBundle(), WebFilterExtensionPoint::EXTPOINT_FILTER, _pWebFilterExtensionPoint);
		}
		else
		{
			pContext->logger().error("The ExtensionPointService is not available.");
		}		
	}
Exemplo n.º 14
0
	void stop(BundleContext::Ptr pContext)
	{
		// Unregister the GreetingService
		pContext->registry().unregisterService(_pService);
	}