Beispiel #1
0
   bool Process::create(const String& classname, const String& basedir)
   {
      // initialize the modules
      mpModuleManager = new ModuleManager();
      if ( !mpModuleManager->initialize() )
      {
         return false;
      }

      // initialize the content manager
      mpContentManager = new ContentManager();
      mpContentManager->setBaseDir(basedir);
      mpContentManager->initialize(getModuleManager());
      
      // initialize the scripting engine
      ScriptModule* pmod = static_cast<ScriptModule*>(mpModuleManager->lookup(UUID_ScriptModule));
      if ( pmod == NULL )
      {
         return false;
      }

      mpScriptManager = &pmod->getManager();
      script_engine_register(*mpScriptManager);
      mpScript = mpScriptManager->load(classname, this, false);
      if ( mpScript == NULL )
      {
         return false;
      }

      // make me a root objects
      mpScriptManager->addRootObject(*mpScript);

      // run the onCreated function
      return mpScript->call(UTEXT("onCreated")).asBool();
   }
ServerMethods::ServerMethods (const boost::property_tree::ptree &config) :
  config (config), moduleManager (getModuleManager() )
{
  std::string version (get_version() );
  std::vector<std::shared_ptr<ModuleInfo>> modules;
  std::shared_ptr<ServerType> type (new ServerType (ServerType::KMS) );
  std::vector<std::string> capabilities;
  std::shared_ptr <ServerInfo> serverInfo;
  std::shared_ptr<MediaObjectImpl> serverManager;

  resourceLimitPercent =
    config.get<float> ("mediaServer.resources.exceptionLimit",
                       DEFAULT_RESOURCE_LIMIT_PERCENT);

  GST_INFO ("Not enough resources exception will be raised when resources reach %f ",
            resourceLimitPercent);

  instanceId = generateUUID();

  for (auto moduleIt : moduleManager.getModules () ) {
    std::vector<std::string> factories;

    for (auto factIt : moduleIt.second->getFactories() ) {
      factories.push_back (factIt.first);
    }

    modules.push_back (std::shared_ptr<ModuleInfo> (new ModuleInfo (
                         moduleIt.second->getVersion(), moduleIt.second->getName(), factories) ) );
  }

  capabilities.push_back ("transactions");

  serverInfo = std::shared_ptr <ServerInfo> (new ServerInfo (version, modules,
               type, capabilities) );

  serverManager = MediaSet::getMediaSet ()->ref (new ServerManagerImpl (
                    serverInfo, config, moduleManager) );
  MediaSet::getMediaSet ()->setServerManager (std::dynamic_pointer_cast
      <ServerManagerImpl> (serverManager) );

  cache = std::shared_ptr<RequestCache> (new RequestCache (REQUEST_TIMEOUT) );

  handler.setPreProcess (std::bind (&ServerMethods::preProcess, this,
                                    std::placeholders::_1,
                                    std::placeholders::_2) );
  handler.setPostProcess (std::bind (&ServerMethods::postProcess, this,
                                     std::placeholders::_1,
                                     std::placeholders::_2) );

  handler.addMethod ("connect", std::bind (&ServerMethods::connect, this,
                     std::placeholders::_1,
                     std::placeholders::_2) );
  handler.addMethod ("create", std::bind (&ServerMethods::create, this,
                                          std::placeholders::_1,
                                          std::placeholders::_2) );
  handler.addMethod ("invoke", std::bind (&ServerMethods::invoke, this,
                                          std::placeholders::_1,
                                          std::placeholders::_2) );
  handler.addMethod ("subscribe", std::bind (&ServerMethods::subscribe, this,
                     std::placeholders::_1,
                     std::placeholders::_2) );
  handler.addMethod ("unsubscribe", std::bind (&ServerMethods::unsubscribe,
                     this, std::placeholders::_1,
                     std::placeholders::_2) );
  handler.addMethod ("release", std::bind (&ServerMethods::release,
                     this, std::placeholders::_1,
                     std::placeholders::_2) );
  handler.addMethod ("ref", std::bind (&ServerMethods::ref,
                                       this, std::placeholders::_1,
                                       std::placeholders::_2) );
  handler.addMethod ("unref", std::bind (&ServerMethods::unref,
                                         this, std::placeholders::_1,
                                         std::placeholders::_2) );
  handler.addMethod ("keepAlive", std::bind (&ServerMethods::keepAlive,
                     this, std::placeholders::_1,
                     std::placeholders::_2) );
  handler.addMethod ("describe", std::bind (&ServerMethods::describe,
                     this, std::placeholders::_1,
                     std::placeholders::_2) );
  handler.addMethod ("transaction", std::bind (&ServerMethods::transaction,
                     this, std::placeholders::_1, std::placeholders::_2) );
}