[Common][Package] Avoid recalling app_info_create() for consecutive calls
[platform/core/api/webapi-plugins.git] / src / package / package_info_provider.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef PACKAGE_PACKAGE_INFO_PROVIDER_H_
18 #define PACKAGE_PACKAGE_INFO_PROVIDER_H_
19
20 #include <pkgmgr-info.h>
21
22 #include "common/extension.h"
23 #include "common/picojson.h"
24 #include "common/platform_exception.h"
25
26 namespace extension {
27 namespace package {
28
29 class PackageInfoProvider {
30  public:
31   PackageInfoProvider();
32   virtual ~PackageInfoProvider();
33
34   /* out["status"] = "success" or "error"
35   * If status is "success", then the result(picojson::value)
36   * will be stored in out["informationArray"].
37   * If status is "error", then the error(picojson::value)
38   * will be stored in out["error"].
39   */
40   static void GetPackagesInfo(picojson::object& out);
41
42   /* out["status"] = "success" or "error"
43   * If status is "success", then the result(picojson::value)
44   * will be stored in out["result"].
45   * If status is "error", then the error(picojson::value)
46   * will be stored in out["error"].
47   */
48   static void GetPackageInfo(picojson::object& out);
49   static void GetPackageInfo(const char* package_id, picojson::object& out);
50
51   static bool ConvertToPackageToObject(const pkgmgrinfo_pkginfo_h info, picojson::object& out);
52
53   static void GetTotalSize(const std::string& id, picojson::object* out);
54   static void GetDataSize(const std::string& id, picojson::object* out);
55
56  private:
57   static bool GetCurrentPackageId(std::string* package_id);
58 };
59
60 }  // namespace package
61 }  // namespace extension
62
63 #endif  // PACKAGE_PACKAGE_INFO_PROVIDER_H_