Fix inconsistency between cache and database
[platform/core/appfw/pkgmgr-info.git] / src / server / runner.hh
1 /*
2  * Copyright (c) 2021 - 2022 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 SERVER_RUNNER_HH_
18 #define SERVER_RUNNER_HH_
19
20 #include <gio/gio.h>
21 #include <glib-unix.h>
22 #include <vconf.h>
23
24 #include <memory>
25 #include <unordered_map>
26
27 #include "create_cache_request.hh"
28 #include "db_change_observer.hh"
29 #include "server_socket.hh"
30 #include "system_locale.hh"
31 #include "worker_thread.hh"
32
33 namespace pkgmgr_server {
34
35 #ifndef EXPORT_API
36 #define EXPORT_API __attribute__((visibility("default")))
37 #endif
38
39 class EXPORT_API Runner : public pkgmgr_common::SystemLocale::IEvent,
40                           public pkgmgr_common::DbChangeObserver::IEvent,
41                           public CreateCacheRequest::IEvent {
42  public:
43   explicit Runner(unsigned int thread_num);
44   ~Runner();
45   bool QueueRequest(std::shared_ptr<PkgRequest> req);
46
47   void OnChanged(const std::string& locale) override;
48   void OnDbChanged() override;
49   void OnCreateCacheDone(bool success) override;
50
51  private:
52   static int OnReceiveRequest(int fd, GIOCondition cond, void* user_data);
53   bool QueueRequest(int client_fd);
54   void SetCPUInheritance();
55   void SetCreateCacheTimer();
56   static gboolean RetryCreateCache(void* data);
57
58  private:
59   int sid_;
60   unsigned int thread_num_;
61   uid_t default_uid_;
62   std::unique_ptr<pkgmgr_common::socket::ServerSocket> server_;
63   std::unique_ptr<WorkerThread> thread_pool_;
64   guint timer_ = 0;
65 };
66
67 }  // namespace pkgmgr_server
68
69 #endif  // SERVER_RUNNER_HH_