#include <vector>
#include <ctime>
+#include <map>
+
+#include <boost/bind.hpp>
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx>
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
+#include <simgear/structure/function_list.hxx>
+#include <simgear/io/HTTPRequest.hxx>
#include <simgear/package/Delegate.hxx>
namespace simgear
{
-
+
namespace HTTP { class Client; }
-
+
namespace pkg
{
class Package;
class Catalog;
class Root;
+class Install;
typedef SGSharedPtr<Package> PackageRef;
typedef SGSharedPtr<Catalog> CatalogRef;
typedef SGSharedPtr<Install> InstallRef;
-
+
typedef std::vector<PackageRef> PackageList;
typedef std::vector<CatalogRef> CatalogList;
- class Catalog : public SGReferenced
+class Catalog : public SGReferenced
{
public:
virtual ~Catalog();
-
+
static CatalogRef createFromUrl(Root* aRoot, const std::string& aUrl);
-
+
static CatalogRef createFromPath(Root* aRoot, const SGPath& aPath);
-
- static CatalogList allCatalogs();
-
+
Root* root() const
{ return m_root;};
-
+
+ /**
+ * uninstall this catalog entirely, including all installed packages
+ */
+ bool uninstall();
+
/**
* perform a refresh of the catalog contents
*/
/**
* retrieve all the packages in the catalog which are installed
* and have a pendig update
- */
+ */
PackageList packagesNeedingUpdate() const;
-
+
SGPath installRoot() const
{ return m_installRoot; }
-
+
std::string id() const;
-
+
std::string url() const;
-
+
+ std::string name() const;
+
std::string description() const;
-
+
PackageRef getPackageById(const std::string& aId) const;
-
+
+ PackageRef getPackageByPath(const std::string& aPath) const;
+
/**
* test if the catalog data was retrieved longer ago than the
* maximum permitted age for this catalog.
*/
bool needsRefresh() const;
-
+
unsigned int ageInSeconds() const;
-
+
/**
* access the raw property data in the catalog
*/
SGPropertyNode* properties() const;
+
+ Delegate::StatusCode status() const;
+
+ typedef boost::function<void(Catalog*)> Callback;
+
+ void addStatusCallback(const Callback& cb);
+
+ template<class C>
+ void addStatusCallback(C* instance, void (C::*mem_func)(Catalog*))
+ {
+ return addStatusCallback(boost::bind(mem_func, instance, _1));
+ }
private:
Catalog(Root* aRoot);
-
+
class Downloader;
friend class Downloader;
-
+
void parseProps(const SGPropertyNode* aProps);
-
- void refreshComplete(Delegate::FailureCode aReason);
-
+
+ void refreshComplete(Delegate::StatusCode aReason);
+
void parseTimestamp();
void writeTimestamp();
-
+
std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
-
+
+ void changeStatus(Delegate::StatusCode newStatus);
+
Root* m_root;
SGPropertyNode_ptr m_props;
SGPath m_installRoot;
std::string m_url;
-
+ Delegate::StatusCode m_status;
+ HTTP::Request_ptr m_refreshRequest;
+
PackageList m_packages;
time_t m_retrievedTime;
-};
-
+
+ typedef std::map<std::string, Package*> PackageWeakMap;
+ PackageWeakMap m_variantDict;
+
+ function_list<Callback> m_statusCallbacks;
+};
+
} // of namespace pkg
} // of namespace simgear