/*
 *  ITnMapResourceProxy
 *  
 *  GenericProxy
 *
 *  Created by thant
 *  Copyright 2013 TeleNav Inc. All rights reserved.
 *
 *
 *  Currently the resource proxy is expected to handle both file
 *  resources and URL resources. (In hindsight this was a
 *  mistake. These two services should have been kept seperate.)
 *
 *  In practice, file resource requests are handled synchronously, and
 *  URL resource requests are handled asynchronously. Requests are
 *  handled in order of priority. Within a priority, requests are
 *  handled in order that they are received.
 *
 */


#ifndef ITN_MAP_RESOURCE_PROXY_INCLUDED
#define ITN_MAP_RESOURCE_PROXY_INCLUDED

#include <string>
#include <foundation/TnTypes.h>
#include <foundation/SharedPtr.h>

#include <RenderEngine/ITnMapResourceData.h>


class ITnMapResourceProxy
{
protected:
    virtual ~ITnMapResourceProxy() = 0;
	
public:

    typedef Tn::Foundation::shared_ptr<ITnMapResourceProxy> ptr;
    
    /* The only resources that will be fetched synchronously are file
     * resources--really only configuration files right now. Does
     * it even make sense to support synchronous network resource
     * fetches given the network could be down? More evidence that the
     * file resource proxy needs to be separate.
     */
    virtual bool RequestResourceSynchronously(ITnMapResourceData::ptr const & data) = 0;

    virtual void RequestResource(ITnMapResourceData::ptr const & data, uint32_t priority = 10) = 0;
    virtual void CancelRequest(ITnMapResourceData::ptr const & data) = 0;

    // Default cache name fetched from ITnMapResourceData
    bool PrefetchSupported() const;
    void RequestResourcePrefetch(std::string const & url, uint32_t priority = 0);

    virtual bool PrefetchSupported(std::string const & cacheName) const = 0;
    virtual void RequestResourcePrefetch(std::string const & url, 
                                         std::string const & cacheName, 
                                         uint32_t priority) = 0;

    virtual void EnableHttpProxy(const std::string & url, 
                                 int port, 
                                 const std::string & name = "", 
                                 const std::string & password = "") = 0;
    
    virtual void DisableHttpProxy() = 0;

    /* Returns true if the name of the requested resource is a URL. */
    static bool IsURL(std::string const & name);
    static bool IsURL(ITnMapResourceData const & data);


};


#endif
