Example #1
0
/**
* @brief Connect one input given the content of the config. Used by Connect
*
* @param x_inputConfig Config of the input
* @param xr_module     Module to connect
* @param x_inputName   Name of input
*/
void Manager::ConnectInput(const mkconf& x_inputConfig, Module& xr_module, const string& x_inputName) const
{
	// Check if connected to our previous module
	try
	{
		string conMod = x_inputConfig.at("connected").at("module").get<string>();
		string conOut = x_inputConfig.at("connected").at("output").get<string>();
		// Connection of a simple input
		LOG_DEBUG(m_logger, "Connect input " + x_inputName + " of module " + xr_module.GetName() + " to output " + conMod + ":" + conOut);

		Stream& inputStream  = xr_module.RefInputStreamByName(x_inputName);
		inputStream.SetBlocking(x_inputConfig.value<int>("block", 1));
		inputStream.SetSynchronized(x_inputConfig.value<int>("sync", 1));
		Stream& outputStream = RefModuleByName(conMod).RefOutputStreamByName(conOut);

		// Connect input and output streams
		inputStream.Connect(outputStream);
		if(xr_module.GetParameters().GetParameterByName("master").GetValue().get<string>().empty())
			RefModuleByName(conMod).AddDependingModule(xr_module);
	}
	catch(MkException& e)
	{
		LOG_ERROR(m_logger, "Cannot connect input " << x_inputName << " of module " << xr_module.GetName() << ". Reason: " << string(e.what()));
		throw;
	}
}
Example #2
0
US_USE_NAMESPACE

void RetrieveModuleContext()
{
    ModuleContext* context = GetModuleContext();
    Module* module = context->GetModule();
    std::cout << "Module name: " << module->GetName() << " [id: " << module->GetModuleId() << "]\n";
}
int usModuleResourceTest(int /*argc*/, char* /*argv*/[])
{
  US_TEST_BEGIN("ModuleResourceTest");

  ModuleContext* mc = GetModuleContext();
  assert(mc);

#ifdef US_BUILD_SHARED_LIBS
  SharedLibrary libR(LIB_PATH, "TestModuleR");
  try
  {
    libR.Load();
  }
  catch (const std::exception& e)
  {
    US_TEST_FAILED_MSG(<< "Load module exception: " << e.what())
  }
#endif

  Module* moduleR = ModuleRegistry::GetModule("TestModuleR");
  US_TEST_CONDITION_REQUIRED(moduleR != nullptr, "Test for existing module TestModuleR")

  US_TEST_CONDITION(moduleR->GetName() == "TestModuleR", "Test module name")

  testInvalidResource(moduleR);

  testResourceFromExecutable(mc->GetModule());

  testResourceTree(moduleR);

  testResourceOperators(moduleR);

  testTextResource(moduleR);
  testTextResourceAsBinary(moduleR);
  testSpecialCharacters(moduleR);

  testBinaryResource(moduleR);

  testCompressedResource(moduleR);

  ModuleResource foo = moduleR->GetResource("foo.txt");
  US_TEST_CONDITION(foo.IsValid() == true, "Valid resource")
#ifdef US_BUILD_SHARED_LIBS
  libR.Unload();
  US_TEST_CONDITION(foo.IsValid() == true, "Still valid resource")
#endif

  testResourcesFrom("TestModuleRL");
  testResourcesFrom("TestModuleRA");

  US_TEST_END()
}
Example #4
0
/**
* @brief Connect one input given the content of the config. Used by Connect
*
* @param x_inputConfig Config of the input
* @param xr_module     Module to connect
* @param x_inputId     Id of input
*/
void Manager::ConnectInput(const ConfigReader& x_inputConfig, Module& xr_module, int x_inputId) const
{
	// Check if connected to our previous module
	try
	{
		const string& tmp1 = x_inputConfig.GetAttribute("moduleid", "");
		const string& tmp2 = x_inputConfig.GetAttribute("outputid", "");
		const string& tmp3 = x_inputConfig.GetAttribute("block", "1");
		const string& tmp4 = x_inputConfig.GetAttribute("sync", "1");

		// Connection of a simple input
		if(tmp1 != "" && tmp2 != "")
		{
			LOG_DEBUG(m_logger, "Connect input " + to_string(x_inputId) + " of module " + xr_module.GetName() + " to output " + tmp1 + ":" + tmp2);

			int outputModuleId   = boost::lexical_cast<int>(tmp1);
			int outputId         = boost::lexical_cast<int>(tmp2);
			Stream& inputStream  = xr_module.RefInputStreamById(x_inputId);
			inputStream.SetBlocking(boost::lexical_cast<bool>(tmp3));
			inputStream.SetSynchronized(boost::lexical_cast<bool>(tmp4));
			Stream& outputStream = RefModuleById(outputModuleId).RefOutputStreamById(outputId);

			// Connect input and output streams
			inputStream.Connect(&outputStream);
			if(xr_module.GetParameters().GetParameterByName("master").GetValueString().empty())
				RefModuleById(outputModuleId).AddDependingModule(xr_module);
		}
		else if(tmp1.empty() && ! tmp2.empty()) throw MkException("Exception while connecting input: missing moduleid in config", LOC);
		else if(! tmp1.empty() && tmp2.empty()) throw MkException("Exception while connecting input: missing outputid in config", LOC);
	}
	catch(MkException& e)
	{
		LOG_ERROR(m_logger, "Cannot connect input "<<x_inputConfig.GetAttribute("id", "(unknown)")<<" of module "<<xr_module.GetName());
		throw;
	}
}
Example #5
0
void			Manager::process_modules( const Tsk::Task< Manager >& task )
{
	

	Module*					next;
	Module*					current;
	Lst::Search< Module >	sh;

	Manager&	manager = task.GetData();

	if ( !manager.control_change )
	{
		return; // nothing to do
	}

	manager.control_change = false;
	
	next = sh.FirstItem( manager.module_list );

	while ( next )
	{
		current = next;
		next = sh.NextItem();			// get next item before excuting callback

		switch ( current->state )
		{
			case Module::vSTOPPED :
			{
				if (( current->command == Module::vSTART ) ||
					( current->command == Module::vRESTART ))
				{
#ifndef __PLAT_XBOX__
#ifndef __PLAT_NGC__
#ifdef __NOPT_DEBUG__
				Dbg_Notify ( "Starting module %s @ %d", current->GetName(), 
					Tmr::GetTime() ); // should use Game Clock not system clock
#endif
#endif
#endif
					current->v_start_cb();
					current->state = Module::vRUNNING;
					current->command = Module::vNONE;
				}
				
				break;
			}
			
			case Module::vRUNNING :
			{
				if ( current->command == Module::vSTOP )
				{
#ifndef __PLAT_XBOX__
#ifndef __PLAT_NGC__
#ifdef __NOPT_DEBUG__
					Dbg_Notify ( "Stopping module %s @ %d", current->GetName(), 
						 Tmr::GetTime() ); // should use Game Clock not system clock
#endif
#endif
#endif
					current->v_stop_cb();
					current->state = Module::vSTOPPED;
					current->command = Module::vNONE;
				}
				else if ( current->command == Module::vRESTART ) 
				{
#ifndef __PLAT_XBOX__
#ifndef __PLAT_NGC__
#ifdef __NOPT_DEBUG__
					Dbg_Notify ( "Restarting module %s @ %d", current->GetName(), 
						Tmr::GetTime() ); // should use Game Clock not system clock
#endif
#endif
#endif
					current->v_stop_cb();
					current->v_start_cb();               
					current->command = Module::vNONE;
				}

				break;
			}        

			default:
			{
				Dbg_MsgAssert( false,( "Invalid module control state" ));
			}
		}
	}
}