Workaround - sending appid during deinstallation
[platform/core/appfw/app-installers.git] / src / common / pkgmgr_signal.h
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMMON_PKGMGR_SIGNAL_H_
6 #define COMMON_PKGMGR_SIGNAL_H_
7
8 #include <pkgmgr_installer.h>
9
10 #include <memory>
11 #include <string>
12
13 #include "common/request.h"
14 #include "common/step/step.h"
15 #include "common/utils/macros.h"
16
17 namespace common_installer {
18
19 //
20 // Utility for sending signal to pkgmgr
21 class PkgmgrSignal {
22  public:
23   enum class State {
24     NOT_SENT,
25     STARTED,
26     FINISHED
27   };
28
29   explicit PkgmgrSignal(pkgmgr_installer* pi, RequestType req_type);
30
31   bool SendStarted(
32       const std::string& type = std::string(),
33       const std::string& pkgid = std::string());
34   bool SendProgress(int progress,
35       const std::string& type = std::string(),
36       const std::string& pkgid = std::string());
37   bool SendFinished(
38       Step::Status result,
39       const std::string& type = std::string(),
40       const std::string& pkgid = std::string());
41   bool IsFinished() const;
42
43   State state() const { return state_; }
44
45  private:
46   bool SendSignal(
47       const char* key,
48       const char* value,
49       const std::string& type = std::string(),
50       const std::string& pkgid = std::string()) const;
51   const char* GetResultKey(Step::Status result) const;
52   bool SendAppids(const std::string& type, const std::string& pkgid) const;
53
54   pkgmgr_installer* pi_;
55   static State state_;
56   RequestType request_type_;
57
58   DISALLOW_COPY_AND_ASSIGN(PkgmgrSignal);
59 };
60
61 }  // namespace common_installer
62
63 #endif  // COMMON_PKGMGR_SIGNAL_H_