void RuntimeSystem::setInputValue(int moduleID,int inputIndex,
				    const utils::Buffer& buf,
				    IControlValueReceiver* cvr)
  {
    ControlBlockMap::const_iterator 
      it = m_modules.find(moduleID);
    if (it == m_modules.end())
      {
	throw std::runtime_error("Module does not exist at "
				 "RuntimeSystem::setInputValue()");
      }

		
    ModuleControlBlockPtr block = it->second;
    IModule* n = block->module();

    if (inputIndex < 0 ||
        static_cast<unsigned int>(inputIndex) >= n->getInputs().size())
      {
	throw std::runtime_error("Input does not exist at "
				 "RuntimeSystem::setInputValue()");
      }


    block->setChanged(inputIndex);
		
		
    IModule::IInputPtr in = n->getInputs()[inputIndex];
		
    in->setValue(buf);
		
    if (cvr != 0)
      cvr->controlValueChanged(moduleID,inputIndex,buf);
  }
void ModuleManager::updateModules( ModuleState state )
{
	size_t numModules = _modules.size();

	std::vector<IModule*> sortedModules;
	sortedModules.reserve( numModules );

	for( size_t i = 0; i < numModules; ++i )
		sortedModules.push_back( _modules[i].get() );

	std::sort( sortedModules.begin(), sortedModules.end(), sortByIncreasingRank );

	for( size_t i = 0; i < numModules; ++i )
	{
		IModule* module = sortedModules[i];
		try
		{
			updateModule( module, state );
		}
		catch( std::exception& e )
		{
			module->abort();

			CORAL_LOG(WARNING) << "Module '" << module->getNamespace()->getFullName() <<
				"' aborted due to exception: " << e.what();
		}
	}
}
//------------------------------------------------------------------------
bool TGameEngine::CreateModules()
{
  int cntThread = mVecVecStrModule.size();
  for( int iThread = 0; iThread < cntThread ; iThread++ )
  {
    // создать поток и поместить в него модули
    int cntModule = mVecVecStrModule[iThread].size();
    TVecStr& vecStrModule = mVecVecStrModule[iThread];

    TVecPtrModule vecPtrModule;
    for( int iModule = 0 ; iModule < cntModule ; iModule++ )
    {
      IModule* pModule = mDevTool->GetModuleByName(vecStrModule[iModule].data());
      if(pModule!=NULL)
      {
        vecPtrModule.push_back(pModule);
        mMapName_IDModule.insert(TMapStrIntVT(pModule->GetName(), pModule->GetID()));
      }
      else
        Event(nsGameEngine::eModuleNotMade, vecStrModule[iModule].data());
    }
    if(vecPtrModule.size())
      mVecVecModule.push_back(vecPtrModule);
  }

	Event(nsGameEngine::eAfterCreateModules);

  if(mVecVecStrModule.size()==0)
    return false;

  return true;
}
Exemple #4
0
INLINE void ModuleManager::Print()
{
	Info(TAG "Listing current modules:");
	u32 len = arModule.Size();
	for (u32 i = 0; i < len; i++)
	{
		IModule *obj = arModule[i];
		Info(TAG "\tModule: %s.", obj->GetObjectName());
	}
}
Exemple #5
0
	ModuleHandlePtr Moduler::loadModule(const char * fileName)
	{
		LOG_DEBUG_STR("Going to open " << fileName);
		auto *moduleObject(m_private->loaderInstance->loadModule(fileName));
		if (moduleObject) {
			LOG_DEBUG("Object file loaded");
			auto createModuleFunc = static_cast<ModuleHandle::CreateModuleFunc>(m_private->loaderInstance->loadMethod(fileName, CREATE_MODULE_FUNC_NAME_STR));
			auto getModuleFunc = static_cast<ModuleHandle::GetModuleFunc>(m_private->loaderInstance->loadMethod(fileName, GET_MODULE_FUNC_NAME_STR));
			auto deleteModuleFunc = static_cast<ModuleHandle::DeleteModuleFunc>(m_private->loaderInstance->loadMethod(fileName, DELETE_MODULE_FUNC_NAME_STR));
			if (createModuleFunc && getModuleFunc && deleteModuleFunc) {
				LOG_INFO_STR("Module from " << fileName << " has correct interface definition");
				LOG_INFO("Initializing module...");
				createModuleFunc();
				IModule *loadedModule = getModuleFunc();
				if (loadedModule) {
					auto *moduleInfo = loadedModule->moduleInformation();
					if (moduleInfo) {
						LOG_INFO("Module info:");
						LOG_INFO_STR("Name: " << moduleInfo->name);
						LOG_INFO_STR("Version: " << moduleInfo->version << "." << moduleInfo->subVersion << "." << moduleInfo->patch);
						LOG_INFO("Seems module has correct implementation");
						ModuleHandle moduleHandle;
						moduleHandle.fileName = fileName;
						moduleHandle.createModuleFunc = createModuleFunc;
						moduleHandle.getModuleFunc = getModuleFunc;
						moduleHandle.deleteModuleFunc = deleteModuleFunc;

						return m_private->addModule(moduleHandle);
					}
					else {
						LOG_ERROR_STR("Error trying to get the module information");
						return nullptr;
					}
				}
				else {
					LOG_ERROR_STR("The method " << GET_MODULE_FUNC_NAME_STR << " returned nullptr");
					return nullptr;
				}
			}
			else {
				if (!createModuleFunc)
					LOG_ERROR_STR("Cannot read method " << CREATE_MODULE_FUNC_NAME_STR << "()");
				if (!getModuleFunc)
					LOG_ERROR_STR("Cannot read method " << GET_MODULE_FUNC_NAME_STR << "()");
				if (!deleteModuleFunc)
					LOG_ERROR_STR("Cannot read method " << DELETE_MODULE_FUNC_NAME_STR << "()");

				// We are not going to use the loaded instance
				// TO DO: Delete object
//				m_private->loaderInstance->delete();
				return nullptr;
			}
		}
		return nullptr;
	}
void CThingTreeCtrl::OnReloadModule() 
{
	// FireReLoadModule();
	HTREEITEM hSelected;
	CString	strModuleName;
	IModule *pModule = NULL;
	HRESULT hr = S_OK;

	if (!m_pWorld)
		return;

	hSelected = m_treeCtrl.GetNextItem(m_hModules, TVGN_CARET);

	if (!hSelected)
		return;

	// get the module name from the tree
	strModuleName = m_treeCtrl.GetItemText(hSelected);

	// get the module from the world
	if (FAILED(hr = m_pWorld->get_Module(CComBSTR(strModuleName), &pModule)))
		goto exit;

	// call reload on the module
	if (FAILED(hr = pModule->Reload(VARIANT_TRUE)))
	{
		CComBSTR bstrDescription("Error reloading module.");
		CComPtr<IErrorInfo> pErrorInfo;
		CString strError;
		CString strTitle;
		CString strInfo;

		strTitle.LoadString(IDS_RELOAD_MODULE);
		strInfo.LoadString(IDS_ERROR_MODULE_RELOAD);

		::GetErrorInfo(0L, &pErrorInfo);

		// we possibly could have no errorinfo from server-side/sync method,
		// if HRESULT isn't in the IThing range (the ReportThingError above will format
		// error strings in the proper range)
		if (pErrorInfo)
		{
			//pErrorInfo->GetSource(&bstrSource.m_str);
			pErrorInfo->GetDescription(&bstrDescription.m_str);
		}
		strError = strInfo + CString(bstrDescription);

		MessageBox(strError, strTitle, MB_ICONERROR);
	}


exit:
	SAFERELEASE(pModule);
}
Exemple #7
0
BOOL ModuleManager::Reset()
{
	BOOL ret = TRUE;

	u32 len = arModule.Size();
	for (u32 i = 0; i < len; i++)
	{
		IModule *obj = arModule[i];
		ret = ret && (obj->Reset() || !obj->IsRequired());
	}

	return ret;
}
Exemple #8
0
BOOL ModuleManager::Shutdown()
{
	BOOL ret = TRUE;

	u32 len = arModule.Size() - 1;
	for (s32 i = len; i >= 0; i--)
	{
		IModule *obj = arModule[i];
		ret = ret && (obj->Shutdown() || !obj->IsRequired());
	}

	return ret;
}
Exemple #9
0
    virtual bool OnBreakpoint( IProcess* process, uint32_t threadId, Address address, Enumerator< BPCookie >* iter )
    {
        if ( sizeof( Address ) == sizeof( uintptr_t ) )
            printf( "  breakpoint at %p\n", address );
        else
            printf( "  breakpoint at %08I64x\n", address );

        while ( iter->MoveNext() )
        {
            BPCookie    cookie = iter->GetCurrent();

            printf( "    %I64x\n", cookie );
        }

        mHitBp = true;

        UINT_PTR    baseAddr = (UINT_PTR) mMod->GetImageBase();

        //mExec->RemoveBreakpoint( process, baseAddr + 0x0001137A, (void*) 257 );
        //mExec->SetBreakpoint( process, baseAddr + 0x0001137A, (void*) 257 );
        //mExec->RemoveBreakpoint( process, baseAddr + 0x00011395, (void*) 129 );
        //mExec->SetBreakpoint( process, baseAddr + 0x00011395, (void*) 129 );

        return false;
    }
  void RuntimeSystem::disconnect(int moduleID,int inputNumber)
  {
    ControlBlockMap::iterator i = m_modules.find(moduleID);
    if (i == m_modules.end())
      throw std::runtime_error("module does not exist "
			       "(RuntimeSystem::disconnect)");
		
    IModule* m = i->second->module();
		
    //TODO: input number is unchecked
    IModule::IInputPtr in = m->getInputs()[inputNumber];

    in->unPlug();

    i->second->hasChanged(inputNumber);
  }
ErrorCode ComponentManager::LoadLibrary( const char *name )
{
	TRACE_BEGIN( LOG_LVL_INFO );
	IModule *mod = NULL;
	ErrorCode result = kNoError;
	
	LOG_NOTICE( "Opening Library: %s", name );
	
	ErrorCode (*LoadLibrary)( IComponentManager *mgr );
	IModule *(*GetModule)();
	void *handle = dlopen( name, RTLD_LAZY );
	
	if ( handle == NULL )
	{
		result = kLoadFailed;
		LOG_WARN( "Failed to open shared lib \"%s\": %s", name, dlerror() );
	}
	else
	{
		LoadLibrary = (ErrorCode (*)(IComponentManager *mgr))dlsym( handle, "JHCOM_LibraryEntry" );
		GetModule = (IModule *(*)())dlsym( handle, "JHCOM_GetModule" );

		if ( GetModule == NULL || LoadLibrary == NULL )
		{
			result = kLoadFailed;
			LOG_WARN( "Failed to get symbol" );
		}
		else
		{
			LOG( "LoadLibrary is %p", LoadLibrary );
			LOG( "RegisterServices is %p", GetModule );
			result = LoadLibrary( this );
			
			if ( result == kNoError )
			{
				mod = GetModule();
				mod->AddRef();
				mod->loadComponents();
				ModuleInfo *info = jh_new ModuleInfo( name, mod, handle );
				mModules.push_back( info );
			}
		}
	}
	
	return result;
}
Exemple #12
0
bool ClientThread::_pre_thread_foo()
{
    _tp->inc();
    //preload  singletons modules if configured
    // therefore we keep them from destroy when lasy context releases them

    if(GCFG->_pool.cache_singletons) {
        const SoMap& rm =__modules->get_modules();
        SoMapIt it = rm.begin();
        for(; it != rm.end(); it++) {
            kchar* ks = (*it).first.c_str();
            SoEntry* pe = (*it).second;
            IModule* pm = pe->_so_get(ks);
            if(pm && pm->is_singleton()) {
                _pmodules.push(pm);
            }
        }
    }
    return true;
}
  void RuntimeSystem::addModule(const std::string& moduleClassName,
				int moduleID)
  {
    IModule* newModule = moduleFactory.buildNewModule(moduleClassName,
						      typeFactory);
    newModule->setID(moduleID);
		
    ModuleControlBlockPtr newBlock ( new ModuleControlBlock(newModule) );
		
    m_modules[moduleID] = newBlock;
    
    // no output or notdeterministic => module is a sink
    if (( newModule->getOutputs().size() == 0 ) ||
	( !newModule->isDeterministic()) ) 
      m_sinks.push_front(newBlock);
    
#if (ENGINE_VERBOSITY > 0)
    std::cout << "Added new Module (id " << moduleID << ") of Class " 
	      << moduleClassName << std::endl;
#endif
  }
 unsigned GetModules(const std::_tstring & module, IModuleVector & modules, bool GetChecksum = false, bool noRefresh=false) const
 {
     IModuleVector allModules;
     GetAllModules(allModules, GetChecksum, noRefresh);
     for(IModuleVector::iterator itr = allModules.begin(); itr != allModules.end(); ++itr)
     {
         IModule * parent = itr->get()->GetParentModule();
         if ((!parent && module.empty()) || (parent && boost::algorithm::equals(module, parent->GetQualifiedLabel())))
             modules.push_back(itr->get());
     }
     return 0;
 }
  void RuntimeSystem::syncInputValue(int moduleID, int inputIndex,
				     IControlValueReceiver* cvr) const
  {
    if (!cvr)
      return;
		
    ControlBlockMap::const_iterator 
      it = m_modules.find(moduleID);
    if (it == m_modules.end())
      {
	throw std::runtime_error("Module does not exist at "
				 "RuntimeSystem::syncInputValue()");
      }
		
    DoSync sync(cvr);
		
    ModuleControlBlockPtr block = it->second;
		
    IModule* n = block->module();
		
    IModule::IInputPtr in = n->getInputs()[inputIndex];
		
    sync(in);
  }
Exemple #16
0
    virtual RunMode OnBreakpoint( IProcess* process, uint32_t threadId, Address address, bool embedded )
    {
        if ( sizeof( Address ) == sizeof( uintptr_t ) )
            printf( "  breakpoint at %p\n", address );
        else
            printf( "  breakpoint at %08I64x\n", address );

        mHitBp = true;

        UINT_PTR    baseAddr = (UINT_PTR) mMod->GetImageBase();

        //mExec->RemoveBreakpoint( process, baseAddr + 0x0001137A, (void*) 257 );
        //mExec->SetBreakpoint( process, baseAddr + 0x0001137A, (void*) 257 );
        //mExec->RemoveBreakpoint( process, baseAddr + 0x00011395, (void*) 129 );
        //mExec->SetBreakpoint( process, baseAddr + 0x00011395, (void*) 129 );

        return RunMode_Break;
    }
Exemple #17
0
    virtual void OnLoadComplete( IProcess* process, DWORD threadId )
    {
        UINT_PTR    baseAddr = (UINT_PTR) mMod->GetImageBase();

        // 0x003C137A, 0x003C1395
        // 1137A, 11395

#if 0
        mExec->SetBreakpoint( process, baseAddr + 0x0001137A, (void*) 33 );
        mExec->SetBreakpoint( process, baseAddr + 0x00011395, (void*) 17 );

        //mExec->SetBreakpoint( process, 0x003C137A, (void*) 257 );

        //mExec->RemoveBreakpoint( process, 0x003C137A, (void*) 33 );
        //mExec->RemoveBreakpoint( process, 0x003C137A, (void*) 257 );

        //mExec->RemoveBreakpoint( process, 0x003C1395, (void*) 33 );

        //mExec->RemoveBreakpoint( process, 0x003C1395, (void*) 17 );
#endif
    }
Exemple #18
0
    virtual void OnModuleLoad( IProcess* process, IModule* module )
    {
        char*   macName = "";

        switch ( module->GetMachine() )
        {
        case IMAGE_FILE_MACHINE_I386: macName = "x86"; break;
        case IMAGE_FILE_MACHINE_IA64: macName = "ia64"; break;
        case IMAGE_FILE_MACHINE_AMD64: macName = "x64"; break;
        }

        if ( sizeof( Address ) == sizeof( uintptr_t ) )
            printf( "  %p %d %s '%ls'\n", module->GetImageBase(), module->GetSize(), macName, module->GetPath() );
        else
            printf( "  %08I64x %d %s '%ls'\n", module->GetImageBase(), module->GetSize(), macName, module->GetPath() );

        if ( mMod == NULL )
        {
            mMod = module;
            mMod->AddRef();
        }
    }
Exemple #19
0
 ~_EventCallback()
 {
     if ( mMod != NULL )
         mMod->Release();
 }
Exemple #20
0
int _tmain( int argc, _TCHAR* argv[] )
{
    BOOL                bRet = FALSE;
    STARTUPINFO         startupInfo = { sizeof startupInfo };
    PROCESS_INFORMATION procInfo = { 0 };
    DEBUG_EVENT         event = { 0 };
    _EventCallback   callback;
    Exec        exec;
    HRESULT     hr = S_OK;
    LaunchInfo  info = { 0 };

    InitDebug();

    //char*   s1 = new ( _NORMAL_BLOCK, __FILE__, __LINE__ ) char[100];
    //strcpy( s1, "hello, yo!" );
    //char*   s2 = (char*) malloc( 300 );
    //strcpy( s2, "say what?" );

    callback.SetExec( &exec );

    hr = exec.Init( &callback );
    if ( FAILED( hr ) )
        goto Error;
    
#if 0
    bRet = CreateProcess( L"F:\\Users\\Magus\\Documents\\Visual Studio 2008\\Projects\\test1\\Debug\\test1.exe",
    //bRet = CreateProcess( L"F:\\Users\\Magus\\Documents\\Visual Studio 2008\\Projects\\test1\\x64\\Debug\\test1.exe",
        NULL,
        NULL,
        NULL,
        FALSE,
        DEBUG_ONLY_THIS_PROCESS,
        NULL,
        NULL,
        &startupInfo,
        &procInfo );
    if ( !bRet )
        goto Error;
#else

//#define TEST_APP64

#ifndef TEST_APP64
    info.CommandLine = L"\"F:\\Users\\Magus\\Documents\\Visual Studio 2008\\Projects\\Debugger1\\Debug\\test1.exe\"";
    info.Exe = L"F:\\Users\\Magus\\Documents\\Visual Studio 2008\\Projects\\Debugger1\\Debug\\test1.exe";
#else
    info.CommandLine =L"\"F:\\Users\\Magus\\Documents\\Visual Studio 2008\\Projects\\Debugger1\\x64\\Debug\\test1.exe\"";
    info.Exe = L"\"F:\\Users\\Magus\\Documents\\Visual Studio 2008\\Projects\\Debugger1\\x64\\Debug\\test1.exe\"";
#endif

    IProcess*   proc = NULL;

    //hr = exec.Attach( 5336, proc );
    hr = exec.Launch( &info, proc );
    if ( FAILED( hr ) )
        goto Error;
#endif

#if 0
    bRet = WaitForDebugEvent( &event, INFINITE );
    if ( !bRet )
        goto Error;
#else
    int stepCount = 0;

    for ( int i = 0; /* doesn't end */ ; i++ )
    {
        hr = exec.WaitForEvent( 1000 );
        if ( FAILED( hr ) )
            goto Error;

        hr = exec.DispatchEvent();
        if ( FAILED( hr ) )
            goto Error;

#if 1
        if ( proc->IsStopped() )
        {
            if ( callback.GetHitBp() )
            {
                stepCount++;

                //11728
                IModule*    mod = NULL;
                UINT_PTR    baseAddr = 0;

                callback.GetModule( mod );
                baseAddr = (UINT_PTR) mod->GetImageBase();
                mod->Release();

                //hr = exec.StepOut( proc, (void*) (baseAddr + 0x00011728) );
                //hr = exec.StepInstruction( proc, true );

                if ( stepCount > 1 )
                    hr = exec.StepInstruction( proc, true, true );
                else
                {
                    //113A5
                    AddressRange    range = { baseAddr + 0x0001137A, baseAddr + 0x000113A5 };
                    hr = exec.StepRange( proc, false, range, true );
                }

                if ( FAILED( hr ) )
                    goto Error;
            }
            else
            {
                hr = exec.Continue( proc, true );
                if ( FAILED( hr ) )
                    goto Error;
            }
        }
#endif

#if 1
        if ( i == 0 )
        {
            IModule*    mod = NULL;
            UINT_PTR    baseAddr = 0;

            callback.GetModule( mod );
            baseAddr = (UINT_PTR) mod->GetImageBase();

            // 0x003C137A, 0x003C1395
            // 1137A, 11395

            //exec.SetBreakpoint( proc, baseAddr + 0x0001138C, 255 );
            exec.SetBreakpoint( proc, baseAddr + 0x0001137A );
            //exec.SetBreakpoint( proc, baseAddr + 0x00011395, 129 );

            mod->Release();
        }
#endif
    }
#endif

Error:
    //exec.Detach( proc );

    // when the debugger goes away, so does the debuggee automatically

    //if ( procInfo.hThread != NULL )
    //{
    //    CloseHandle( procInfo.hThread );
    //}

    //if ( procInfo.hProcess != NULL )
    //{
    //    TerminateProcess( procInfo.hProcess, MAXINT );
    //    CloseHandle( procInfo.hProcess );
    //}

    if ( proc != NULL )
        proc->Release();

    return 0;
}
  void RuntimeSystem::deleteModule(int moduleID)
  {
    // get the control block for the moduleid
    ControlBlockMap::iterator it = m_modules.find(moduleID);
    
    if (it == m_modules.end())
      {
	// a module with that id doesnt exist
	throw std::runtime_error("Module does not exist at "
				 "RuntimeSystem::deleteModule()");
      }

    // a module with that id must exist
    assert(it != m_modules.end());

    ModuleControlBlockPtr block = it->second;  
    IModule* n = block->module();

    // disconnect all modules that are connected to an output
    for (ControlBlockMap::iterator i = m_modules.begin(); 
	 i != m_modules.end(); ++i)
      {
	// is this possible?
	// if (i->second == 0) continue;
	assert(i->second != 0);

	ModuleControlBlockPtr block = i->second;
	IModule* m = block->module();	

	// check all inputs of that module
	for (unsigned int j = 0; j < m->getInputs().size(); ++j)
	  {
	    IModule::IInputPtr in = m->getInputs()[j];

	    // is it connected?
	    if (in->getConnectedModule() == n) 
	      {
		// yes, the unplug it
		in->unPlug();
		// and signal change
		block->hasChanged(j);
	      }
	  }
      }

    // disconnect all modules that are connected to an input
    for (unsigned int j = 0; j < n->getInputs().size(); ++j)
      {
	IModule::IInputPtr in = n->getInputs()[j];

	if (in->getConnectedModule() != 0)
	  in->unPlug();
      }
		
    // remove the module from the sink list	  

    if (n->getOutputs().size() == 0 || !n->isDeterministic())
	m_sinks.remove(block);

    // remove it from the module set
    // the module control block should be deleted here by its autoptr
    m_modules.erase(it);
		
#if (ENGINE_VERBOSITY > 0)
    std::cout << "Deleted Module # " << moduleID << std::endl;
#endif
  }
  void RuntimeSystem::update(IControlValueReceiver* cvr,
			     IModuleStatisticsReceiver* msr)
  {	
    std::stack<ModuleControlBlockPtr> stack;
    
    // push the sinks (modules with no output) on the stack
    for (std::list<ModuleControlBlockPtr>::iterator sink = m_sinks.begin();
	 sink != m_sinks.end(); ++sink)
      {
	(*sink)->activate();
	stack.push(*sink);
      }

#if (ENGINE_VERBOSITY > 2)
    std::cout << " ***** update begins\n";
    std::cout << "Pushed all m_sinks onto the stack." << std::endl;
    std::cout << "Number of m_sinks: " << m_sinks.size() << std::endl;
#endif
		
    while (!stack.empty())
      {
	ModuleControlBlockPtr block = stack.top();
			
	IModule* m = block->module();
			
	assert (block->isActive());

#if (ENGINE_VERBOSITY > 3)
        std::cout << "On Stack: " << m->getID() << "\n";
#endif
			
	IInput* dep = m->dependencies();
			
	// is there a not satisfied dependency left?
	if (dep != 0)
	  {
	    IModule* temp = dep->getConnectedModule();
	
	    // is the input connected to an other module?
	    if (temp != 0)
              {
#if (ENGINE_VERBOSITY > 3)
                std::cout << "   Following connection to " << temp->getID()
                          << "\n";
#endif    
		// check that module
		ModuleControlBlockPtr current = getControlBlock(temp);
		
		// 1. in case the module is on the stack we detected a cycle
		// the solution is to use the old value of that output
		// 2. the module is already updatet in this cycle
		// we dont want do update it again
		if (current->isActive()||(current->lastUpdated()==frameCount))
		  {
		    // it could be that the value changed (conservative)
		    block->setChanged(dep->getIndex());
#if (ENGINE_VERBOSITY > 3)
                    std::cout << "     [already done]" << temp->getID()
                              << "\n";
#endif    
		  }
		else
		  {
#if (ENGINE_VERBOSITY > 3)
                    std::cout << "     [pushed on stack]" << temp->getID()
                              << "\n";
#endif
		    // we must update this module
		    current->activate();
		    stack.push(current);		    
		  }
              }
	  }
	else
	  {
	    // all dependencies are satisfied

	    // is a update necessary?
	    if (!m->isDeterministic() || block->hasChanged())
	      {
#if (ENGINE_VERBOSITY > 3)
                std::cout << "   Updating...\n";
#endif    
		// lets update the module
		unsigned long startTime = utils::Timing::getTimeInMillis();
		//TODO: if an exception is caught, remove the module!
		try {
                  m->update();
		}
		catch (std::exception& e){
                  std::ostringstream os;
                  os << "error at update: " << e.what() << "\n"
                     << "module id = " << m->getID() << "\n"
                     << "module class = " << m->module_class_name() << "\n";

                  m_logger->error("Runtimesystem", os.str());
		}
		catch (...) {
                  std::ostringstream os;
                  os << "error at update\n"
                     << "module id = " << m->getID() << "\n"
                     << "module class = " << m->module_class_name() << "\n";

                  m_logger->error("Runtimesystem", os.str());
		}
		unsigned long stopTime = utils::Timing::getTimeInMillis();
		block->addTime(stopTime-startTime);
			
		// should we send the statistic data?
		// is there a receiver?
		// is it the right time?
		if (msr != 0 && (frameCount & 7) == 7)
		  {
		    // send statistic data
		    msr->modExecTimeSignal(m->getID(),block->avgTime());
		  }

		// send the changes values to the controlValueReceiver
		// and set them there to changed
		sendInputValues(block,cvr,m_modules,frameCount);
	      }
            else
              {
#if (ENGINE_VERBOSITY > 3)
                std::cout << "   Skipping update (deterministic and no "
                          << "needed input changed)...\n";
#endif    
              }
		
	    // this module is now updated
	    stack.pop(); 
	    block->reset();
	    block->updated(frameCount);
	  }
      }
		
    // all sinks are uptodate we can finish now
    // increase the timestamp
    ++frameCount;

#if (ENGINE_VERBOSITY > 2)
    std::cout << "**** update finished" << std::endl;
#endif
  }
Exemple #23
0
bool ScriptEngine::OnChildReload(IModule& child, IEventArg& e /*= IEventArg::Empty*/)
{
	UserDataEventArg<ScriptState*> e1(mCurrent->CurrentState());
	return child.Reload(e1);
}
Exemple #24
0
bool Logicmgr::Initialize() {
    const sModuleConfig * pConfig = Configmgr::getInstance()->GetModuleConfig();
    TASSERT(pConfig, "can't load module config");

    vector<string>::const_iterator itor = pConfig->vctModules.begin();
    vector<string>::const_iterator iend = pConfig->vctModules.end();
    while (itor != iend) {
        char path[512] = {0};
#ifdef linux
        SafeSprintf(path, sizeof (path), "%s/%slib%s.so",
                tools::GetAppPath(), pConfig->strModulePath.c_str(), (*itor).c_str());

        void * handle = dlopen(path, RTLD_LAZY);
        TASSERT(handle, "open %s error %d", path, errno);

        GetModuleFun fun = (GetModuleFun) dlsym(handle, "GetLogicModule");
        TASSERT(fun, "get function:GetLogicModule error");
#endif //linux

#ifdef WIN32
        SafeSprintf(path, sizeof (path), "%s/%s/%s.dll",
            tools::GetAppPath(), pConfig->strModulePath.c_str(), (*itor).c_str());

        HINSTANCE hinst = ::LoadLibrary(path);
        GetModuleFun fun = (GetModuleFun)::GetProcAddress(hinst, NAME_OF_GET_LOGIC_FUN);
        TASSERT(fun, "get function:GetLogicModule error");
#endif //WIN32

        IModule * plogic = fun();
        TASSERT(plogic, "can't get module from lig%s.so", (*itor).c_str());

        while (plogic) {
            const char * pName = plogic->GetName();
            map<string, IModule *>::iterator mitor = m_mapModules.find(pName);
            if (mitor != m_mapModules.end()) {
                TASSERT(false, "LogicModule Name %s is exists", pName);
                return false;
            }

            m_vctModules.push_back(plogic);
            m_mapModules.insert(make_pair(pName, plogic));
            plogic = plogic->GetNext();
        }

        itor++;
    }

	{
		vector<IModule *>::iterator vitor = m_vctModules.begin();
		vector<IModule *>::iterator viend = m_vctModules.end();
		while (vitor != viend) {
			(*vitor)->Initialize(Kernel::getInstance());

			vitor ++;
		}

		vitor = m_vctModules.begin();
		while(vitor != viend) {
			(*vitor)->Launched(Kernel::getInstance());
			vitor++;
		}
	}

    return true;
}