////////////////////////////////////////////////////////////////////////// // getContext //virtual RsContext* RsCoreImplGL::getContext( OsClient* pClient ) { BcAssert( BcIsGameThread() ); TContextMapIterator It = ContextMap_.find( pClient ); if( It != ContextMap_.end() ) { return It->second; } else { if( pClient != NULL ) { RsContextGL* pResource = new RsContextGL( pClient, ContextMap_[ NULL ] ); createResource( pResource ); // If we have no default context, set it. if( ContextMap_[ NULL ] == NULL ) { ContextMap_[ NULL ] = pResource; } // Store mapped to client. ContextMap_[ pClient ] = pResource; return pResource; } } return NULL; }
CachedResource* CachedResourceLoader::revalidateResource(CachedResource* resource, ResourceLoadPriority priority, const ResourceLoaderOptions& options) { ASSERT(resource); ASSERT(resource->inCache()); ASSERT(!memoryCache()->disabled()); ASSERT(resource->canUseCacheValidator()); ASSERT(!resource->resourceToRevalidate()); // Copy the URL out of the resource to be revalidated in case it gets deleted by the remove() call below. String url = resource->url(); bool urlProtocolIsData = resource->url().protocolIsData(); CachedResource* newResource = createResource(resource->type(), resource->resourceRequest(), resource->encoding()); LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource, resource); newResource->setResourceToRevalidate(resource); memoryCache()->remove(resource); memoryCache()->add(newResource); newResource->setLoadPriority(priority); newResource->load(this, options); if (!urlProtocolIsData) m_validatedURLs.add(url); return newResource; }
CachedResource* CachedResourceLoader::loadResource(CachedResource::Type type, ResourceRequest& request, const String& charset, ResourceLoadPriority priority) { ASSERT(!memoryCache()->resourceForURL(request.url())); LOG(ResourceLoading, "Loading CachedResource for '%s'.", request.url().string().latin1().data()); CachedResource* resource = createResource(type, request, charset); bool inCache = memoryCache()->add(resource); // Pretend the resource is in the cache, to prevent it from being deleted during the load() call. // FIXME: CachedResource should just use normal refcounting instead. if (!inCache) resource->setInCache(true); resource->setLoadPriority(priority); resource->load(this); if (!inCache) { resource->setOwningCachedResourceLoader(this); resource->setInCache(false); } // We don't support immediate loads, but we do support immediate failure. if (resource->errorOccurred()) { if (inCache) memoryCache()->remove(resource); else delete resource; return 0; } m_validatedURLs.add(request.url()); return resource; }
QSharedPointer<Resource> ResourceCache::getResource(const QUrl& url, const QUrl& fallback, bool delayLoad, void* extra) { QSharedPointer<Resource> resource = _resources.value(url); if (!resource.isNull()) { removeUnusedResource(resource); return resource; } if (QThread::currentThread() != thread()) { assert(delayLoad); getResourceAsynchronously(url); return QSharedPointer<Resource>(); } if (!url.isValid() && !url.isEmpty() && fallback.isValid()) { return getResource(fallback, QUrl(), delayLoad); } resource = createResource(url, fallback.isValid() ? getResource(fallback, QUrl(), true) : QSharedPointer<Resource>(), delayLoad, extra); resource->setSelf(resource); resource->setCache(this); _resources.insert(url, resource); removeUnusedResource(resource); resource->ensureLoading(); return resource; }
ResourcePtr<Resource> ResourceFetcher::createResourceForRevalidation(const FetchRequest& request, Resource* resource) { ASSERT(resource); ASSERT(memoryCache()->contains(resource)); ASSERT(resource->isLoaded()); ASSERT(resource->canUseCacheValidator()); ASSERT(!resource->resourceToRevalidate()); ResourceRequest revalidatingRequest(resource->resourceRequest()); revalidatingRequest.clearHTTPReferrer(); addAdditionalRequestHeaders(revalidatingRequest, resource->type()); const AtomicString& lastModified = resource->response().httpHeaderField("Last-Modified"); const AtomicString& eTag = resource->response().httpHeaderField("ETag"); if (!lastModified.isEmpty() || !eTag.isEmpty()) { ASSERT(context().cachePolicy(document()) != CachePolicyReload); if (context().cachePolicy(document()) == CachePolicyRevalidate) revalidatingRequest.setHTTPHeaderField("Cache-Control", "max-age=0"); } if (!lastModified.isEmpty()) revalidatingRequest.setHTTPHeaderField("If-Modified-Since", lastModified); if (!eTag.isEmpty()) revalidatingRequest.setHTTPHeaderField("If-None-Match", eTag); ResourcePtr<Resource> newResource = createResource(resource->type(), revalidatingRequest, resource->encoding()); WTF_LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource.get(), resource); newResource->setResourceToRevalidate(resource); memoryCache()->remove(resource); memoryCache()->add(newResource.get()); return newResource; }
/** * Creates a new resource with of certain type. * @param type Resource type name. * @param name Resource name. * @return Resource with the given name or 0 if no resource could be * created. * @note This function only does a static check of the pointer, so * take care that the factory produces instances of the correct * class. */ template<class T> typename T::Ptr createResource(const std::string &type, const std::string &name = "") { // TODO: Dynamic checks in debug version? Resource::Ptr res = createResource(type, name); typename T::Ptr derived = (T*)res.get(); return derived; }
////////////////////////////////////////////////////////////////////////// // createRenderTarget //virtual RsRenderTarget* RsCoreImplGL::createRenderTarget( const RsRenderTargetDesc& Desc ) { RsRenderBufferGL* pColourBuffer = new RsRenderBufferGL( getContext( NULL ), Desc.ColourFormats_[ 0 ], Desc.Width_, Desc.Height_ ); RsRenderBufferGL* pDepthStencilBuffer = new RsRenderBufferGL( getContext( NULL ), Desc.DepthStencilFormat_, Desc.Width_, Desc.Height_ ); RsFrameBufferGL* pFrameBuffer = new RsFrameBufferGL( getContext( NULL ) ); RsTextureGL* pTexture = new RsTextureGL( getContext( NULL ), Desc.Width_, Desc.Height_, 1, rsTF_RGBA8, NULL ); createResource( pColourBuffer ); createResource( pDepthStencilBuffer ); createResource( pFrameBuffer ); createResource( pTexture ); // Create the render target. RsRenderTargetGL* pRenderTarget = new RsRenderTargetGL( getContext( NULL ), Desc, pColourBuffer, pDepthStencilBuffer, pFrameBuffer, pTexture ); createResource( pRenderTarget ); return pRenderTarget; }
std::vector<CL_SharedPtr<Resource> > ResourceManager::createAllResources(const std::string &fileName) { CL_ResourceManager resourceManager = loadResourceFile(fileName); std::vector<CL_String> names = resourceManager.get_resource_names(); std::vector<CL_SharedPtr<Resource> > resources; for (std::vector<CL_String>::const_iterator it = names.begin(); it != names.end(); ++it) resources.push_back(createResource(*it, fileName)); return resources; }
Resource* ResourceManager::loadResource( const string& name, const string& path ) { Resource* resource = createResource(name, path); resource->load(); return resource; }
Resource* ResourceManager::createResourceThrowing(const std::string& resourceType, const std::string& resourceName, Resource* parent) { std::exception_ptr exception; Resource* res = createResource(resourceType, resourceName, parent, exception); if (exception) { std::rethrow_exception(exception); } return res; }
void DpmsManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { auto c = display->getConnection(client); wl_resource *dpms = c->createResource(&org_kde_kwin_dpms_manager_interface, qMin(version, s_version), id); if (!dpms) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(dpms, &s_interface, this, nullptr); }
CLuaScriptPtr CLuaScriptManager::load(const Ogre::String &name, const Ogre::String &group) { CLuaScriptPtr ptr = getResourceByName(name, group).dynamicCast<CLuaScript>(); if (ptr.isNull()) ptr = createResource(name, group).dynamicCast<CLuaScript>(); ptr->load(); return ptr; }
void ResourceManager::loadResource(const std::string &name, const std::string &fileName) { CL_SharedPtr<Resource> resource = createResource(name, fileName); std::vector<std::string> dependencies = resource->getDependencies(); for (std::vector<std::string>::const_iterator it = dependencies.begin(); it != dependencies.end(); ++it) loadResource(*it, fileName); resource->load(); }
void PointerConstraintsUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { auto c = display->getConnection(client); wl_resource *resource = c->createResource(&zwp_pointer_constraints_v1_interface, qMin(version, s_version), id); if (!resource) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(resource, &s_interface, this, unbind); // TODO: should we track? }
ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(Resource::Type type, FetchRequest& request, const String& charset) { ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url())); WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceRequest().url().elidedString().latin1().data()); addAdditionalRequestHeaders(request.mutableResourceRequest(), type); ResourcePtr<Resource> resource = createResource(type, request.resourceRequest(), charset); memoryCache()->add(resource.get()); return resource; }
Resource* MemoryCacheCorrectnessTestHelper::resourceFromResourceRequest( ResourceRequest request) { if (request.url().isNull()) request.setURL(KURL(ParsedURLString, kResourceURL)); Resource* resource = createResource(request, Resource::Raw); resource->setResponse(ResourceResponse(KURL(ParsedURLString, kResourceURL), "text/html", 0, nullAtom, String())); resource->finish(); memoryCache()->add(resource); return resource; }
////////////////////////////////////////////////////////////////////////// // createProgram @deprecated //virtual RsProgram* RsCoreImplGL::createProgram( RsShader* pVertexShader, RsShader* pFragmentShader ) { RsShader* Shaders[] = { pVertexShader, pFragmentShader }; RsProgramGL* pResource = new RsProgramGL( getContext( NULL ), 2, &Shaders[ 0 ] ); createResource( pResource ); return pResource; }
/** * @brief createResource * * @param uri Path and name of the resource * @param type Resource interface * @param interface Resource type * @param properties Allowed properties of the resource * @param OCIOhandler Callback called when a PUT request is received * * @return */ OCBaseResourceT * createResource(char *uri, const char* type, const char* interface, uint8_t properties, OCIOHandler OCIOhandler) { OCResourceType resourceType; resourceType.resourcetypename = (char*) type; resourceType.next = NULL; OCResourceInterface resourceInterface; resourceInterface.name = (char*) interface; resourceInterface.next = NULL; return(createResource(uri, &resourceType, &resourceInterface, properties, OCIOhandler)); }
//----------------------------------------------------------------------- ResourcePtr BspResourceManager::load(DataStreamPtr& stream, const String& group) { // Only 1 BSP level allowed loaded at once removeAll(); ResourcePtr ret = createResource("bsplevel", group, true, 0); BspLevelPtr bspLevel = static_pointer_cast<BspLevel>(ret); bspLevel->load(stream); return ret; }
//The setup function is called once at startup of the sketch void setup() { // Add your initialization code here // Note : This will initialize Serial port on Arduino at 115200 bauds OIC_LOG_INIT(); OIC_LOG(DEBUG, TAG, ("OCServer is starting...")); // Connect to Ethernet or WiFi network if (ConnectToNetwork() != 0) { Serial.print("Unable to connect to Network"); OIC_LOG(ERROR, TAG, ("Unable to connect to network")); return; } // Initialize the OC Stack in Server mode if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK) { OIC_LOG(ERROR, TAG, ("OCStack init error")); return; } // DEBUG PIN pinMode(LED_PIN, OUTPUT); // Button resource OCBaseResourceT *temperatureResource = createResource("/a/temperatureSensor", OIC_DEVICE_SENSOR, OC_RSRVD_INTERFACE_DEFAULT, (OC_DISCOVERABLE | OC_OBSERVABLE | OC_SLOW | OC_ACTIVE), temperatureIOHandler); temperatureResource->name = "LM35 Temperature Sensor"; addType(temperatureResource, OIC_TYPE_TEMPERATURE); // READ only interface addInterface(temperatureResource, OC_RSRVD_INTERFACE_READ); OCIOPort port; port.pin = TEMPERATURE_PIN_IN; port.type = IN; // Setup ADC analogReference(INTERNAL1V1); ResourceData data; data.str = "0.0"; addAttribute(&temperatureResource->attribute, "temperature", data, STRING, &port); printResource(temperatureResource); }
CachedResourceHandle<CachedResource> CachedResourceLoader::loadResource(CachedResource::Type type, CachedResourceRequest& request, const String& charset) { ASSERT(!memoryCache()->resourceForRequest(request.resourceRequest())); LOG(ResourceLoading, "Loading CachedResource for '%s'.", request.resourceRequest().url().elidedString().latin1().data()); CachedResourceHandle<CachedResource> resource = createResource(type, request.mutableResourceRequest(), charset); if (!memoryCache()->add(resource.get())) resource->setOwningCachedResourceLoader(this); #if ENABLE(RESOURCE_TIMING) storeResourceTimingInitiatorInformation(resource, request); #endif return resource; }
void BMISensorBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer, std::string bundleId) { m_pResourceContainer = resourceContainer; m_bundleId = bundleId; std::vector<resourceInfo> resourceConfig; resourceContainer->getResourceConfiguration(m_bundleId, &resourceConfig); for (vector<resourceInfo>::iterator itor = resourceConfig.begin(); itor != resourceConfig.end(); itor++) { createResource(*itor); } }
Resource* MemoryCacheCorrectnessTestHelper::resourceFromResourceResponse( ResourceResponse response, Resource::Type type) { if (response.url().isNull()) response.setURL(KURL(ParsedURLString, kResourceURL)); Resource* resource = createResource(ResourceRequest(response.url()), type); resource->setResponse(response); resource->finish(); // Because we didn't give any real data, an image will have set its status // to DecodeError. Override it so the resource is cacaheable for testing // purposes. if (type == Resource::Image) resource->setStatus(Resource::Cached); memoryCache()->add(resource); return resource; }
Resource* ResourceManagerBase::load(const Path& path) { Resource* resource = get(path); if(nullptr == resource) { resource = createResource(path); m_resources.insert(path.getHash(), resource); } if(resource->isEmpty()) { resource->doLoad(); } resource->addRef(); return resource; }
//----------------------------------------------------------------------- ResourceManager::ResourceCreateOrRetrieveResult ResourceManager::createOrRetrieve( const String& name, const String& group, bool isManual, ManualResourceLoader* loader, const NameValuePairList* params) { // Lock for the whole get / insert OGRE_LOCK_AUTO_MUTEX; ResourcePtr res = getResourceByName(name, group); bool created = false; if (!res) { created = true; res = createResource(name, group, isManual, loader, params); } return ResourceCreateOrRetrieveResult(res, created); }
//The setup function is called once at startup of the sketch void setup() { // Add your initialization code here // Note : This will initialize Serial port on Arduino at 115200 bauds OIC_LOG_INIT(); OIC_LOG(DEBUG, TAG, ("OCServer is starting...")); // Connect to Ethernet or WiFi network if (ConnectToNetwork() != 0) { Serial.print("Unable to connect to Network"); OIC_LOG(ERROR, TAG, ("Unable to connect to network")); return; } // Initialize the OC Stack in Server mode if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK) { OIC_LOG(ERROR, TAG, ("OCStack init error")); return; } // DEBUG PIN pinMode(LED_PIN, OUTPUT); // Button resource OCBaseResourceT *buttonResource = createResource("/a/button", OIC_DEVICE_BUTTON, OC_RSRVD_INTERFACE_DEFAULT, (OC_DISCOVERABLE | OC_OBSERVABLE | OC_SLOW), buttonIOHandler); buttonResource->name = "Marks Button"; OCIOPort port; port.pin = TEST_BUT_PIN; port.type = IN; ResourceData data; data.b = false; addAttribute(&buttonResource->attribute, "state", data, BOOL, &port); printResource(buttonResource); }
//The setup function is called once at startup of the sketch void setup() { Serial.begin(115200); // Add your initialization code here OC_LOG_INIT(); OC_LOG(DEBUG, TAG, PCF("OCServer is starting...")); // uint16_t port = OC_WELL_KNOWN_PORT; // Connect to Ethernet or WiFi network if (ConnectToNetwork() != 0) { OC_LOG(ERROR, TAG, "Unable to connect to network"); return; } // Initialize the OC Stack in Server mode if (OCInit(NULL, OC_WELL_KNOWN_PORT, OC_SERVER) != OC_STACK_OK) { OC_LOG(ERROR, TAG, PCF("OCStack init error")); return; } OCStartPresence(60); // Declare and create the example resource createResource(); // This call displays the amount of free SRAM available on Arduino PrintArduinoMemoryStats(); #if (ARDUINO == 0) ble.init( (long)115200, BLE_MASTER, trackeeID); #elif (ARDUINO == 1) ble.init( (long)115200, BLE_SLAVER, slaveList[0]); #elif (ARDUINO == 2) ble.init( (long)115200, BLE_SLAVER, slaveList[1]); #endif // ble.StatusRead(); OC_LOG_V(INFO, TAG, "Program Start-\r\n"); }
void GameController::receiveResources(Network::TcpPacket* packet) { uint32 nb; *packet >> nb; for (uint32 i = 0; i < nb; ++i) { Resource* resource = createResource(*packet); if (resource) _resources.push_back(resource); } *packet >> nb; for (uint32 i = 0; i < nb; ++i) { Graphic::Texture* texture = createTexture(*packet); if (texture) _textures.push_back(texture); } *packet >> nb; for (uint32 i = 0; i < nb; ++i) { Graphic::Sprite* sprite = createSprite(*packet); if (sprite) _sprites.push_back(sprite); } *packet >> nb; for (uint32 i = 0; i < nb; ++i) { Graphic::Element* element = createGraphicElement(*packet); if (element) _elements.push_back(element); } *packet >> nb; for (uint32 i = 0; i < nb; ++i) { Graphic::Scenery* scenery = createScenery(*packet); if (scenery) { _sceneries.push_back(scenery); } } *packet >> nb; for (uint32 i = 0; i < nb; ++i) { Sound::Sound* sound = createSound(*packet); if (sound) _sounds.push_back(sound); } }
bool TextureResourceLoader::loadResource(Core::Resource* &resource, Core::File const& file, std::string const& mappingName) { bool result = false; if(isFileValid(file)) { std::vector<Core::Color> pixels; unsigned width = 0; unsigned height = 0; if(readFile(file, pixels, width, height)) { if((width > 0) && (height > 0)) { unsigned totalSize = width * height; if(createResource(resource, file, pixels, width, height)) { result = true; } else { OcularLogger->error("Failed to create Resource", OCULAR_INTERNAL_LOG("TextureResourceLoader", "loadResource")); } } else { OcularLogger->error("Invalid image dimensions of (", width, ", ", height, ")", OCULAR_INTERNAL_LOG("TextureResourceLoader", "loadResource")); } } else { OcularLogger->error("Failed to parse the Resource file at '", file.getFullPath(), "'", OCULAR_INTERNAL_LOG("TextureResourceLoader", "loadResource")); } } return result; }
CachedResource* CachedResourceLoader::revalidateResource(CachedResource* resource, ResourceLoadPriority priority) { ASSERT(resource); ASSERT(resource->inCache()); ASSERT(!memoryCache()->disabled()); ASSERT(resource->canUseCacheValidator()); ASSERT(!resource->resourceToRevalidate()); // Copy the URL out of the resource to be revalidated in case it gets deleted by the remove() call below. String url = resource->url(); CachedResource* newResource = createResource(resource->type(), KURL(ParsedURLString, url), resource->encoding()); LOG(ResourceLoading, "Resource %p created to revalidate %p", newResource, resource); newResource->setResourceToRevalidate(resource); memoryCache()->remove(resource); memoryCache()->add(newResource); newResource->setLoadPriority(priority); newResource->load(this); m_validatedURLs.add(url); return newResource; }