00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _PACKAGE_MANAGER_H
00014 #define _PACKAGE_MANAGER_H
00015
00016 #include <services/IInformant.h>
00017 #include <support/Catalog.h>
00018 #include <support/Node.h>
00019 #include <support/KeyedVector.h>
00020 #include <package_p/ManifestParser.h>
00021
00022 #if _SUPPORTS_NAMESPACE
00023 namespace palmos {
00024 namespace package {
00025 using namespace palmos::services;
00026 using namespace palmos::support;
00027 #endif
00028
00029 class BPackageManager : public BCatalog
00030 {
00031 public:
00032 BPackageManager(const SContext& context);
00033
00034 virtual void InitAtom();
00035
00036 status_t AddQuery(const SString& dirName, const SString& property);
00037 void Start(bool verbose = false);
00038
00039 uint32_t NextDatabaseID();
00040
00041 static void UnpackPackageFileToFolder(const SString & packageFile, const SString & folder);
00042 static void PackFolderToPackageFile(const SString & folder, const SString & packageFile);
00043 static SValue ManifestForPackageFolder(const SString& packageFolder);
00044 static SValue ManifestForPackageFile(const SString& packageFile);
00045
00046 class Package;
00047
00048
00049 class Component : public SLightAtom
00050 {
00051 public:
00052 Component(const sptr<Package>& package, const SString& id, const SValue& value);
00053 ~Component();
00054 const sptr<Package> GetPackage() const;
00055 const SString& Id() const;
00056 const SString& Local() const;
00057 uint32_t Version() const;
00058 time_t Modified() const;
00059 const SValue& Value() const;
00060 sptr<Component> Next() const;
00061 sptr<Component> Prev() const;
00062 void SetNext(const sptr<Component>& next);
00063 void SetPrev(const sptr<Component>& prev);
00064 void Remove();
00065 private:
00066 SAtom* const m_package;
00067 const SString m_id;
00068 const SString m_local;
00069 const SValue m_value;
00070
00071 mutable SLocker m_lock;
00072 sptr<Component> m_next;
00073 sptr<Component> m_prev;
00074 };
00075
00076 class Package : public SAtom
00077 {
00078 public:
00079 Package(const SString& path, const SString& name);
00080 ~Package();
00081
00082 SString Path() const;
00083 SString Name() const;
00084 uint32_t DbID() const;
00085 ssize_t AddComponent(const sptr<Component>& component);
00086 void RemoveComponentAt(size_t index);
00087 size_t CountComponents() const;
00088 const sptr<Component>& ComponentAt(size_t index) const;
00089
00090
00091 void SetDbID(uint32_t dbid);
00092
00093 private:
00094 mutable SLocker m_lock;
00095 SVector< sptr<Component> > m_components;
00096 SString m_path;
00097 SString m_name;
00098 uint32_t m_dbid;
00099 };
00100
00101 class Query : public SLightAtom
00102 {
00103 public:
00104 SString property;
00105 SKeyedVector<SString, SValue> entries;
00106 SKeyedVector<SString, wptr<IDatum> > datums;
00107 };
00108
00109 class Data
00110 {
00111 public:
00112 Data();
00113
00114 void add_package_l(const sptr<BPackageManager::Package>& package);
00115 sptr<BPackageManager::Package> remove_package_l(const SValue& key);
00116
00117 SLocker lock;
00118 SKeyedVector<sptr<IBinder>, sptr<Query> > queries;
00119 SVector< sptr<BPackageManager::Package> > packages;
00120 SKeyedVector< SString, sptr<BPackageManager::Component> > components;
00121 SKeyedVector< SString, sptr<BPackageManager::Component> > applications;
00122 SKeyedVector< SString, sptr<BPackageManager::Component> > addons;
00123 };
00124
00125 protected:
00126 virtual ~BPackageManager();
00127
00128 private:
00129 sptr<Package> scan_for_packages(const SString& packagesPath, const SString& pkgName, const SString& filePath, int32_t file, const SValue& info, bool verbose);
00130 uint32_t look_for_databases(const SString& dirPath, const sptr<BCatalog>& catalog);
00131 void register_with_informant(const sptr<IInformant>& informant);
00132 void run_queries();
00133
00134 SVector<SString> m_packagesPath;
00135
00136 uint32_t m_nextDatabaseID;
00137 Data m_data;
00138 };
00139
00140
00141 #if _SUPPORTS_NAMESPACE
00142 } }
00143 #endif
00144
00145 #endif // _PACKAGE_MANAGER_H