/*
 *  TnCacheResourceData.h
 *  OpenGL Map Engine Proxy Common
 *
 *  Created by Thant on 03/26/2013
 *  Copyright 2013 TeleNav Inc. All rights reserved.
 *
 */

#ifndef TN_CACHE_RESOURCE_DATA_H
#define TN_CACHE_RESOURCE_DATA_H

#include <RenderEngine/ITnMapResourceData.h>
#include <RenderEngine/TnMapResourceData.h>

#include <GenericProxy/TnCache.h>

class TnCacheResourceData : public ITnMapResourceData
{
public:

    typedef Tn::Foundation::shared_ptr<TnCacheResourceData> ptr;

    // Request Resource
    TnCacheResourceData(ITnMapResourceData::ptr const & data,
                        TnCache::ptr const & cache);

    // Request Prefetch
    TnCacheResourceData(std::string const & name,
                        TnCache::ptr const & cache);

    virtual std::string const & GetResourceName() const;

    // Doesn't call SetResource on its data object until
    // SetRequestResult is called.

    virtual void SetResource(TnMapResource const & resource);

    virtual void SetRequestResult(eTnMapRequestResult result);
    
private:

    void StoreToCache();   // On network success.
    void LoadFromCache();  // On network failure. Use stale data if we have it.

    bool m_set;
    TnMapResource m_resource;
    ITnMapResourceData::ptr m_data;
    std::string m_name;                 // resource name
    TnCache::ptr m_cache;
};

#endif

