/*
 *  TnMapResourceData.h
 *  OpenGL Map Engine
 *
 *  Created by Thant on 4/7/2010
 *  Copyright 2009 TeleNav Inc. All rights reserved.
 *
 */

#ifndef TN_MAP_RESOURCE_DATA_H
#define TN_MAP_RESOURCE_DATA_H

#include <vector>
#include <string>

#include <foundation/SharedPtr.h>
#include <foundation/WeakPtr.h>
#include <foundation/SharedArray.h>
#include <foundation/TnTypes.h>
#include <foundation/ConditionVariable.h>
#include <foundation/Mutex.h>

#include "ITnMapResourceData.h"


class TnMapResourceData : public ITnMapResourceData
{
public:

    virtual ~TnMapResourceData();
    
    
    typedef Tn::Foundation::weak_ptr<TnMapResourceData> wptr;
    typedef Tn::Foundation::shared_ptr<TnMapResourceData> ptr;

    std::string const & GetResourceName() const;
    void SetResource(TnMapResource const & resource);

    virtual void SetRequestResult(eTnMapRequestResult result);

    bool                Ready() const;
    eTnMapRequestResult GetResult() const;
    
    // Wait for resource load to complete and return its request result
    eTnMapRequestResult Wait(long milliseconds=0);

private:

    TnMapResourceData(TnMapResourceData const &);               // not defined
    TnMapResourceData & operator=(TnMapResourceData const &);   // not defined

protected:
    
    std::string m_resourceName;
    
    // Synchronization objects
    Tn::Foundation::mutex m_mutex;
    Tn::Foundation::condition_variable m_cond;
    
    // Stored result (in case someone calls Wait())
    bool m_resultReady;
    eTnMapRequestResult m_result;

    TnMapResource m_resource;

    TnMapResourceData(std::string const & resourceName);
    TnMapResourceData(char const * resourceName);
};


#endif


