Esempio n. 1
0
void collectUniqueResource(const OCClientResponse * clientResponse)
{
    OCResourcePayload* res = ((OCDiscoveryPayload*)clientResponse->payload)->resources;
    char sidStr[UUID_LENGTH];

    while(res) {

        int ret = snprintf(sidStr, UUID_LENGTH,
                "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
                res->sid[0], res->sid[1], res->sid[2], res->sid[3],
                res->sid[4], res->sid[5], res->sid[6], res->sid[7],
                res->sid[8], res->sid[9], res->sid[10], res->sid[11],
                res->sid[12], res->sid[13], res->sid[14], res->sid[15]
                );

        if (ret == UUID_LENGTH - 1)
        {
            if(insertResource(sidStr, res->uri, clientResponse) == 1)
            {
                OC_LOG_V(INFO,TAG,"%s%s%s%s\n",sidStr, ":", res->uri, " is new");
                printResourceList();
                queryResource();
            }
            else {
                OC_LOG_V(INFO,TAG,"%s%s%s%s\n",sidStr, ":", res->uri, " is old");
            }
        }
        else
        {
            OC_LOG(ERROR, TAG, "Could Not Retrieve the Server ID");
        }

        res = res->next;
    }
}
Esempio n. 2
0
void collectUniqueResource(const OCClientResponse * clientResponse)
{
    char * sid = NULL;
    char ** uri = NULL;
    int totalRes = 0;

    if(parseJSON(clientResponse->resJSONPayload, & sid, & uri, &totalRes)
            != OC_STACK_OK)
    {
        OC_LOG(ERROR, TAG, "Error while parsing JSON payload in OCClientResponse");
        OICFree(sid);
        OICFree(uri);
        return;
    }

    int i;
    for(i = 0; i < totalRes; i++)
    {
        if(insertResource(sid, uri[i], clientResponse) == 1)
        {
            printf("%s%s%s%s\n",sid, ":", uri[i], " is new");
            printResourceList();
            queryResource();
        }
        else
        {
            printf("%s%s%s%s\n\n",sid, ":", uri[i], " has been seen before");
        }
    }

    OICFree(sid);
    OICFree(uri);
 }
void ResourceHolder<Resource, Identifier>::load(Identifier id, const std::string& filename)
{
	std::unique_ptr<Resource> resource(new Resource());
	auto loaded = resource->loadFromFile(filename);
	assert(loaded);
	insertResource(id, std::move(resource));
}
Esempio n. 4
0
	/**
	 * Returns an image resource.
	 *
	 * @param fileName The filename of the image.
	 *
	 * @return The image.
	 *
	 * @throw ResourceNotLoadedExcpetion
	*/
	ImageResource* ResourceManager::image(std::string fileName) {
		std::string id = ImageResource::createID(fileName);
		if (!hasResource(id)) {
			ImageResource* res = ImageResource::open(fileName);
			insertResource(res->getName(), res);
			
			return res;
		} else {
			return static_cast<ImageResource*>(getResource(id));
		}
	}
Esempio n. 5
0
	/**
	 * Opens a music file.
	 *
	 * @param name The name of the music file.
	 *
	 * @return The music file.
	*/
	MusicResource* ResourceManager::music(std::string name) {
		std::string id = "music_" + name;
		if (!hasResource(id)) {
			MusicResource* music = MusicResource::open(name);
			insertResource(id, music);
			
			return music;
		} else {
			return static_cast<MusicResource*>(getResource(id));
		}
	}
Esempio n. 6
0
	/**
	 * Opens a small audio file.
	 *
	 * @param name The name of the audio file.
	 *
	 * @return The Audio file.
	*/
	SoundResource* ResourceManager::sound(std::string name) {
		std::string id = "audio_" + name;
		if (!hasResource(id)) {
			SoundResource* sound = SoundResource::open(name);
			insertResource(id, sound);
			
			return sound;
		} else {
			return static_cast<SoundResource*>(getResource(id));
		}
	}
Esempio n. 7
0
	/**
	 * Opens a font.
	 *
	 * @param name The name of the font.
	 * @param ptSize The size of the font in points.
	 *
	 * @return The Font.
	 *
	 * @throw ResourceNotLoadedExcpetion
	*/
	FontResource* ResourceManager::font(std::string name, int ptSize) {
		std::string fontID = FontResource::getID(name, ptSize);
		if (!hasResource(fontID)) {
			FontResource* font = FontResource::open(name, ptSize);
			insertResource(fontID, font);
			
			return font;
		} else {
			return static_cast<FontResource*>(getResource(fontID));
		}
	}
Esempio n. 8
0
	/**
	 * Returns an image resource. The image will be scaled and rotated.
	 *
	 * @param fileName The filename of the image.
	 * @param width The width of the image.
	 * @param height The height of the image.
	 * @param keepRatio True if to keep the aspect ratio of the original image.
	 *        It is possible that the width or height of the image will be less than the given values.
	 * @param angle The angle of the rotation (in degrees).
	 *
	 * @return The image.
	 *
	 * @throw ResourceNotLoadedExcpetion
	*/
	ImageResource* ResourceManager::image(std::string fileName, int width,
	                                      int height, bool keepRatio, int angle) {
		std::string id = ImageResource::createID(fileName, width, height, keepRatio, angle);
		if (!hasResource(id)) {
			ImageResource* res = image(fileName);
			ImageResource* scaled = res->scaleAndRotate(width, height, keepRatio, angle);
			free(res);
			insertResource(scaled->getName(), scaled);
			
			return scaled;
		} else {
			return static_cast<ImageResource*>(getResource(id));
		}
	}
Esempio n. 9
0
ResourceSelector::ResourceSelector( const ResourcesList resourcesList )
{
    resourcesIDs_.reserve( resourcesList.size() );

    for( auto category : resourcesList ){
        insertResource( category.first, category.second );
    }

    // Select the first element as the current one.
    if( count() > 0 ){
        setCurrentIndex( 0 );
    }

    // Whenever the current index changes, emit a signal with the associated
    // ResourceID.
    void (QComboBox::*signal)( int ) = &ResourceSelector::activated;
    QObject::connect( this, signal, [this]( int index ){
        emit resourceSelected( resourcesIDs_.at( index ) );
    });
}
Esempio n. 10
0
void collectUniqueResource(const OCClientResponse * clientResponse)
{
    OCResourcePayload* res = ((OCDiscoveryPayload*)clientResponse->payload)->resources;

    // Including the NUL terminator, length of UUID string of the form:
    //   "a62389f7-afde-00b6-cd3e-12b97d2fcf09"
#   define UUID_LENGTH 37

    char sidStr[UUID_LENGTH];

    while(res) {

        int ret = snprintf(sidStr, UUID_LENGTH,
                "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
                res->sid[0], res->sid[1], res->sid[2], res->sid[3],
                res->sid[4], res->sid[5], res->sid[6], res->sid[7],
                res->sid[8], res->sid[9], res->sid[10], res->sid[11],
                res->sid[12], res->sid[13], res->sid[14], res->sid[15]
                );

        if (ret == UUID_LENGTH - 1)
        {
            if(insertResource(sidStr, res->uri, clientResponse) == 1)
            {
                OC_LOG_V(INFO,TAG,"%s%s%s%s\n",sidStr, ":", res->uri, " is new");
                printResourceList();
                queryResource();
            }
            else {
                OC_LOG_V(INFO,TAG,"%s%s%s%s\n",sidStr, ":", res->uri, " is old");
            }
        }
        else
        {
            OC_LOG(ERROR, TAG, "Could Not Retrieve the Server ID");
        }

        res = res->next;
    }
}
Esempio n. 11
0
/*
 * Return a pointer to the requested resource.if
 * the resource is not in memory,load it and
 * return a pointer.
 * 
 * This function MUST always return a valid reference
 * to a resource,if the resource exists.
 *
 * Returns NULL when file isn't found.
 */
void* getResource(char *filename, int type){
	
	if( !filename ){
		xxh_error = XXH_INVALID_FILENAME;
		return NULL;
	}
	
	/* check if the file is in memory */
	RESOURCE_NODE *curr;
	
	for( curr = head ; curr != NULL; curr = curr->next){
	
		if( type == curr->type && ( !strcmp(filename,curr->filename)) ){
			curr->refereces++;
			return curr->data;
		}
	}
	/* resource is not in memory */	
	curr = insertResource(filename,type);
	if( curr != NULL )
		return curr->data;
		
	return NULL;
}