Refactor slp-pkgmgr with tidl
[platform/core/appfw/slp-pkgmgr.git] / installer / src / control.hh
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
18 #ifndef INSTALLER_SRC_CONTROL_H_
19 #define INSTALLER_SRC_CONTROL_H_
20
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <list>
25 #include <functional>
26
27 #include "PkgSignal.h"
28 #include "request.hh"
29
30 namespace pkgmgr {
31 namespace installer {
32
33 namespace pkg_group = rpc_port::PkgSignal::group;
34
35 class Control {
36  public:
37   Control(bool offline = false);
38   virtual ~Control();
39   int SetRequestFromArgv(const int argc, char** argv);
40   const std::unique_ptr<Request>& GetRequest() const;
41   int SendSignal(std::string pkg_type, std::string pkgid,
42       std::string appid, std::string key, std::string val);
43   int SendSignals(std::string key, std::string val);
44   int SendSignalForResource(std::string pkgid, std::string status,
45     rpc_port::PkgSignal::ExtraData* event_info);
46   int SendSignalForUid(uid_t uid, std::string pkg_type, std::string pkgid,
47       std::string appid, std::string key, std::string val);
48   int SendSignalsForUid(uid_t uid, std::string key, std::string val);
49   int SendSignalForResourceForUid(uid_t uid, std::string pkgid,
50     std::string status, rpc_port::PkgSignal::ExtraData* event_info);
51   void AddPkg(std::string pkgid, std::string pkg_type);
52
53  private:
54   void ParseMultiplePkgs(const std::unique_ptr<Request>& req);
55
56  private:
57   std::unique_ptr<Request> request_;
58   std::unique_ptr<pkg_group::PkgSignal> signal_;
59   std::map<int, std::function<int(const std::unique_ptr<Request>&)>>
60       option_map_;
61   std::vector<rpc_port::PkgSignal::PkgInfo> pkgs_;
62   int argc_ = 0;
63   char** argv_ = nullptr;
64   int mode_ = 0;
65 };
66
67 }  // namespace installer
68 }  // namespace pkgmgr
69
70 #endif  // INSTALLER_SRC_CONTROL_H_