Skeloton for update installation
[platform/core/appfw/app-installers.git] / src / common / pkgmgr_interface.h
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMMON_PKGMGR_INTERFACE_H_
6 #define COMMON_PKGMGR_INTERFACE_H_
7
8 #include <pkgmgr_installer.h>
9
10 #include <memory>
11
12 #include "utils/macros.h"
13 #include "utils/logging.h"
14
15 namespace common_installer {
16
17 class PkgMgrInterface;
18 typedef std::shared_ptr<PkgMgrInterface> PkgMgrPtr;
19
20 /** Class that covers pkgmgr_installer basic platform calls.
21  *
22  *  PkgMgr covers all pkgmgr_installer platform calls (and manages its
23  *  creation/destruction.
24  */
25 class PkgMgrInterface {
26  public:
27   /** Request type received from pkgmgr_installer
28    */
29   enum class Type {
30     Unknown,
31     Install,
32     Update,
33     Uninstall,
34     Reinstall
35   };
36
37   /** Returns Request type passed from pkgmgr_installer
38    */
39   PkgMgrInterface::Type GetRequestType() const;
40
41   /** Returns Request info passed from pkgmgr_installer
42    */
43   const char *GetRequestInfo() const;
44
45   /** Returns instance of PkgrMgr (Singleton pattern).
46    *
47    *  However, Init method has to be called first (otherwise, this Instance
48    *  returns nullptr).
49    *
50    *  @see PkgMgr::Init(int argc, char** argv)
51    */
52   static PkgMgrPtr Instance();
53
54   /** Initialize PkgMgrInterface.
55    */
56   static int Init(int argc, char** argv);
57
58   /** Get Raw pointer to pkgmgr_installer object
59    *
60    *  It should not be used (PkgMgrInterface can destroy it
61    */
62   DEPRECATED pkgmgr_installer *GetRawPi() const { return pi_; }
63
64   /** PkgMgrInstance destructor.
65    *
66    */
67   ~PkgMgrInterface();
68
69  private:
70   PkgMgrInterface() :pi_(nullptr) {}
71   int InitInternal(int argc, char** argv);
72
73   pkgmgr_installer* pi_;
74   static PkgMgrPtr instance_;
75
76   SCOPE_LOG_TAG(PkgMgrInterface)
77   DISALLOW_COPY_AND_ASSIGN(PkgMgrInterface);
78 };
79
80 }  // namespace common_installer
81
82 #endif  // COMMON_PKGMGR_INTERFACE_H_