Example #1
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
I_GameClientManager::pService_type
GameClientManager::create(const std::string& _type, config_type& _config)
{
    Threading::CriticalSection guard(this->m_serviceCache.getLock());

    // Check to see if the service already exists in the service cache
    {
        pService_type pService(this->m_serviceCache.getCachedService(_type));

        if( pService.isValid() )
        {
            return pService;
        }
    }

    // Else, get the service factory
    I_GameClientFactory* pFactory = this->m_serviceCache.getFactory(_type);

    if( pFactory == NULL )
    {
        Utility::runtime_exception("GameClientManager::create(): Error, could not get factory.");
    }

    windowHandle_type handle = NULL;

    // Check to see if the desired parent service exists in the service cache
    config_type::iterator iter = _config.find("parent");
    if( iter != _config.end() )
    {
        pService_type pService(this->m_serviceCache.getCachedService(iter->second));

        if( pService.isValid() )
        {
            handle = pService->getHandle();
        }
        else
        {
            Utility::runtime_exception("GameClientManager::create(): Error, parent window does not exist in service cache.");
        }
    }

    // Create and cache the service
    pService_type pService(this->m_serviceCache.cacheService( _type, pFactory->create(_type, handle, _config) ));

    // Connect GameClientManager::onFrame() to the GameClient onFrameEvent
    pService->onFrameEvent.connect(boost::bind(&GameClientManager::onFrame,this,_1));

    // Create and cache the service
    return pService;
}
Example #2
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
I_SoundManager::pService_type
SoundManager::create(const std::string& _type, config_type& _config)
{
    Threading::CriticalSection guard(m_soundServiceCache.getLock());

    pService_type pService(m_soundServiceCache.getCachedService(_type));

    if( pService.isValid() )
    {
        return pService;
    }

    I_SoundServiceFactory* pFactory = m_soundServiceCache.getFactory(_type);

    if( pFactory == NULL )
    {
        throw Zen::Utility::runtime_exception("SoundManager::create() : Error finding sound service factory.");
    }

    pService = pFactory->create(_type, _config);

    if (!pService.isValid())
    {
        throw Zen::Utility::runtime_exception("SoundManager::create() : Sound factory create() did not return a valid pointer.");
    }

    if (m_pSoundModule != NULL)
    {
        pService->registerScriptModule(*m_pSoundModule);
    }

    return m_soundServiceCache.cacheService(_type, pService);
}
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
InputServiceManager::pService_type
InputServiceManager::create(const std::string& _type, config_type& _config)
{
    Threading::CriticalSection guard(m_inputServiceCache.getLock());

    pInputService_type pService(m_inputServiceCache.getCachedService(_type));

    if (pService.isValid())
    {
        return pService;
    }

    I_InputServiceFactory* pFactory = m_inputServiceCache.getFactory(_type);

    if (pFactory == NULL)
    {
        // TODO Error
        return pService;
    }

    pService = pFactory->create(_type, _config);

    if (m_pInputModule != NULL)
    {
        pService->registerScriptModule(*m_pInputModule);
    }

    return m_inputServiceCache.cacheService(_type, pService);
}
Example #4
0
StatusCode
ServiceB::initialize() {
  Service::initialize().ignore();
  IService *pService(0);
  const bool CREATENOW(true);
  return service("ServiceA", pService, CREATENOW);
}
Example #5
0
//------------------------------------------------------------------------------
StatusCode LoopAlg::initialize()
//------------------------------------------------------------------------------
{
  IService *pService(0);
  const bool CREATENOW(true);
  return service("ServiceB", pService, CREATENOW);
}
Example #6
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
I_RenderingManager::pRenderingService_type
RenderingManager::create(const std::string& _type)
{
    Threading::CriticalSection guard(m_renderingServiceCache.getLock());

    pRenderingService_type pService(m_renderingServiceCache.getCachedService(_type));

    if (pService.isValid())
    {
        return pService;
    }

    I_RenderingServiceFactory* pFactory = m_renderingServiceCache.getFactory(_type);

    if (pFactory == NULL)
    {
        std::stringstream errorMessage;
        errorMessage << "Zen::Rendering::RenderingManager::create() : Error: could not create service factory for type " << _type;

        throw Utility::runtime_exception(errorMessage.str());
    }

    pService = pFactory->create();

    if (m_pDefaultScriptEngine.isValid())
    {
        pService->registerScriptModule(*m_pRenderingModule);
    }

    m_renderingServiceCache.cacheService(_type, pService);

    return pService;

}
NS_INTERFACE_MAP_END

nsresult
nsViewSourceChannel::Init(nsIURI* uri)
{
    mOriginalURI = uri;

    nsAutoCString path;
    nsresult rv = uri->GetPath(path);
    if (NS_FAILED(rv))
      return rv;

    nsCOMPtr<nsIIOService> pService(do_GetIOService(&rv));
    if (NS_FAILED(rv)) return rv;

    nsAutoCString scheme;
    rv = pService->ExtractScheme(path, scheme);
    if (NS_FAILED(rv))
      return rv;

    // prevent viewing source of javascript URIs (see bug 204779)
    if (scheme.LowerCaseEqualsLiteral("javascript")) {
      NS_WARNING("blocking view-source:javascript:");
      return NS_ERROR_INVALID_ARG;
    }

    // This function is called from within nsViewSourceHandler::NewChannel2
    // and sets the right loadInfo right after returning from this function.
    // Until then we follow the principal of least privilege and use
    // nullPrincipal as the loadingPrincipal.
    nsCOMPtr<nsIPrincipal> nullPrincipal = nsNullPrincipal::Create();
    NS_ENSURE_TRUE(nullPrincipal, NS_ERROR_FAILURE);

    rv = pService->NewChannel2(path,
                               nullptr, // aOriginCharset
                               nullptr, // aCharSet
                               nullptr, // aLoadingNode
                               nullPrincipal,
                               nullptr, // aTriggeringPrincipal
                               nsILoadInfo::SEC_NORMAL,
                               nsIContentPolicy::TYPE_OTHER,
                               getter_AddRefs(mChannel));
    NS_ENSURE_SUCCESS(rv, rv);

    mIsSrcdocChannel = false;

    mChannel->SetOriginalURI(mOriginalURI);
    mHttpChannel = do_QueryInterface(mChannel);
    mHttpChannelInternal = do_QueryInterface(mChannel);
    mCachingChannel = do_QueryInterface(mChannel);
    mCacheInfoChannel = do_QueryInterface(mChannel);
    mApplicationCacheChannel = do_QueryInterface(mChannel);
    mUploadChannel = do_QueryInterface(mChannel);
    mPostChannel = do_QueryInterface(mChannel);
    
    return NS_OK;
}
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
DatabaseServiceFactory::pDatabaseService_type
DatabaseServiceFactory::create(const std::string &_type, DatabaseServiceFactory::Configuration_type _config)
{
    DatabaseService* pRawService = new DatabaseService(_config);

    pDatabaseService_type pService(pRawService, boost::bind(&DatabaseServiceFactory::destroy, this, _1));

    wpDatabaseService_type pWeakPtr(pService);

    pRawService->setSelfReference(pWeakPtr);

    return pService;
}
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
SoundServiceFactory::pSoundService_type
SoundServiceFactory::create(const std::string& _type, config_type& _config)
{
    SoundService* pRawService = new SoundService(_config);

    pSoundService_type pService(pRawService, boost::bind(&SoundServiceFactory::onDestroy,this,_1));

    wpSoundService_type pWeakPtr(pService);

    pRawService->setSelfReference(pWeakPtr);

    return pService;
}
Example #10
0
NS_INTERFACE_MAP_END

nsresult
nsViewSourceChannel::Init(nsIURI* uri)
{
    mOriginalURI = uri;

    nsAutoCString path;
    nsresult rv = uri->GetPath(path);
    if (NS_FAILED(rv))
      return rv;

    nsCOMPtr<nsIIOService> pService(do_GetIOService(&rv));
    if (NS_FAILED(rv)) return rv;

    nsAutoCString scheme;
    rv = pService->ExtractScheme(path, scheme);
    if (NS_FAILED(rv))
      return rv;

    // prevent viewing source of javascript URIs (see bug 204779)
    if (scheme.LowerCaseEqualsLiteral("javascript")) {
      NS_WARNING("blocking view-source:javascript:");
      return NS_ERROR_INVALID_ARG;
    }

    rv = pService->NewChannel(path, nullptr, nullptr, getter_AddRefs(mChannel));
    if (NS_FAILED(rv))
      return rv;

    mIsSrcdocChannel = false;

    mChannel->SetOriginalURI(mOriginalURI);
    mHttpChannel = do_QueryInterface(mChannel);
    mHttpChannelInternal = do_QueryInterface(mChannel);
    mCachingChannel = do_QueryInterface(mChannel);
    mApplicationCacheChannel = do_QueryInterface(mChannel);
    mUploadChannel = do_QueryInterface(mChannel);
    
    return NS_OK;
}
Example #11
0
std::size_t ServiceRegistry::find(const std::string& query, std::vector<ServiceRef::Ptr>& results) const
{
	QLParser parser(query);
	QLExpr::Ptr pExpr(parser.parse());
	
	results.clear();
	
	FastMutex::ScopedLock lock(_mutex);

	std::size_t count(0);
	for (ServiceMap::const_iterator it = _services.begin(); it != _services.end(); ++it)
	{
		ServiceRef::Ptr pService(it->second);
		if (pExpr->evaluate(pService->properties()))
		{
			results.push_back(pService);
			++count;
		}
	}
	return count;
}
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
ProjectServiceManager::pProjectService_type
ProjectServiceManager::createProjectService(const I_ProjectType& _projectType, wpWorkbench_type _pWorkbench)
{
    Threading::CriticalSection guard(m_projectServiceCache.getLock());

    pProjectService_type pService(m_projectServiceCache.getCachedService(_projectType.getType()));

    if( pService.isValid() )
    {
        return pService;
    }

    I_ProjectServiceFactory* pFactory = m_projectServiceCache.getFactory(_projectType.getType());

    if( pFactory == NULL )
    {
        // TODO: Error
        return pService;
    }

    return m_projectServiceCache.cacheService(_projectType.getType(), pFactory->create());
}
Example #13
0
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
I_CinematicManager::pCinematicService_type
CinematicManager::createCinematicService(const std::string& _type)
{
    Threading::CriticalSection guard(m_cinematicServiceCache.getLock());

    pCinematicService_type pService(m_cinematicServiceCache.getCachedService(_type));

    if (pService.isValid())
    {
        return pService;
    }

    I_CinematicServiceFactory* pFactory = m_cinematicServiceCache.getFactory(_type);

    if (pFactory == NULL)
    {
        // TODO Error
        return pService;
    }

    return m_cinematicServiceCache.cacheService(_type, pFactory->createCinematicService(_type));

}
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
I_ProjectWizardManager::pProjectWizardService_type
ProjectWizardManager::create(I_ProjectWizardType& _wizardType)
{
    const std::string& type(_wizardType.getType());

    Threading::CriticalSection guard(m_serviceCache.getLock());

    pProjectWizardService_type pService(m_serviceCache.getCachedService(type));

    if(pService.isValid())
    {
        return pService;
    }

    I_ProjectWizardFactory* pFactory = m_serviceCache.getFactory(type);

    if(pFactory == NULL)
    {
        // TODO: Error
        return pService;
    }

    return m_serviceCache.cacheService(type, pFactory->create(type));
}