librime: deployer.h Source File

| librime 1.2 Rime Input Method Engine, the core library

deployer.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2011-12-01 GONG Chen <chen.sst@gmail.com>
6//
7#ifndef RIME_DEPLOYER_H_
8#define RIME_DEPLOYER_H_
9
10#include <future>
11#include <mutex>
12#include <queue>
13#include <any>
14#include <rime/common.h>
15#include <rime/component.h>
16#include <rime/messenger.h>
17
18namespace rime {
19
20class Deployer;
21
22 using TaskInitializer = std::any;
23
24 class DeploymentTask : public Class<DeploymentTask, TaskInitializer> {
25 public:
26 DeploymentTask() = default;
27 virtual ~DeploymentTask() = default;
28
29 virtual bool Run(Deployer* deployer) = 0;
30};
31
32 class Deployer : public Messenger {
33 public:
34 // read-only access after library initialization {
35 path shared_data_dir;
36 path user_data_dir;
37 path prebuilt_data_dir;
38 path staging_dir;
39 path sync_dir;
40 string user_id;
41 string distribution_name;
42 string distribution_code_name;
43 string distribution_version;
44 string app_name;
45 bool backup_config_files;
46 // }
47
48 RIME_DLL Deployer();
49 RIME_DLL ~Deployer();
50
51 bool RunTask(const string& task_name,
52 TaskInitializer arg = TaskInitializer());
53 bool ScheduleTask(const string& task_name,
54 TaskInitializer arg = TaskInitializer());
55 void ScheduleTask(an<DeploymentTask> task);
56 an<DeploymentTask> NextTask();
57 bool HasPendingTasks();
58
59 bool Run();
60 bool StartWork(bool maintenance_mode = false);
61 bool StartMaintenance();
62 bool IsWorking();
63 bool IsMaintenanceMode();
64 // the following two methods equally wait until all threads are joined
65 void JoinWorkThread();
66 void JoinMaintenanceThread();
67
68 path user_data_sync_dir() const;
69
70 private:
71 std::queue<of<DeploymentTask>> pending_tasks_;
72 std::mutex mutex_;
73 std::future<void> work_;
74 bool maintenance_mode_ = false;
75};
76
77} // namespace rime
78
79#endif // RIME_DEPLOYER_H_
RIME_DLL
#define RIME_DLL
Definition rime_api.h:33
common.h
component.h
messenger.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::TaskInitializer
std::any TaskInitializer
Definition deployer.h:22
rime::path
Definition common.h:84
rime::Class
Definition component.h:21
rime::DeploymentTask::~DeploymentTask
virtual ~DeploymentTask()=default
rime::DeploymentTask::Run
virtual bool Run(Deployer *deployer)=0
rime::DeploymentTask::DeploymentTask
DeploymentTask()=default
rime::Deployer
Definition deployer.h:32
rime::Deployer::backup_config_files
bool backup_config_files
Definition deployer.h:45
rime::Deployer::HasPendingTasks
bool HasPendingTasks()
Definition deployer.cc:74
rime::Deployer::app_name
string app_name
Definition deployer.h:44
rime::Deployer::shared_data_dir
path shared_data_dir
Definition deployer.h:35
rime::Deployer::distribution_name
string distribution_name
Definition deployer.h:41
rime::Deployer::user_data_dir
path user_data_dir
Definition deployer.h:36
rime::Deployer::Deployer
RIME_DLL Deployer()
Definition deployer.cc:15
rime::Deployer::user_id
string user_id
Definition deployer.h:40
rime::Deployer::JoinWorkThread
void JoinWorkThread()
Definition deployer.cc:141
rime::Deployer::prebuilt_data_dir
path prebuilt_data_dir
Definition deployer.h:37
rime::Deployer::distribution_version
string distribution_version
Definition deployer.h:43
rime::Deployer::NextTask
an< DeploymentTask > NextTask()
Definition deployer.cc:62
rime::Deployer::StartWork
bool StartWork(bool maintenance_mode=false)
Definition deployer.cc:106
rime::Deployer::ScheduleTask
bool ScheduleTask(const string &task_name, TaskInitializer arg=TaskInitializer())
Definition deployer.cc:42
rime::Deployer::Run
bool Run()
Definition deployer.cc:79
rime::Deployer::IsWorking
bool IsWorking()
Definition deployer.cc:130
rime::Deployer::StartMaintenance
bool StartMaintenance()
Definition deployer.cc:126
rime::Deployer::user_data_sync_dir
path user_data_sync_dir() const
Definition deployer.cc:150
rime::Deployer::RunTask
bool RunTask(const string &task_name, TaskInitializer arg=TaskInitializer())
Definition deployer.cc:28
rime::Deployer::IsMaintenanceMode
bool IsMaintenanceMode()
Definition deployer.cc:137
rime::Deployer::distribution_code_name
string distribution_code_name
Definition deployer.h:42
rime::Deployer::JoinMaintenanceThread
void JoinMaintenanceThread()
Definition deployer.cc:146
rime::Deployer::staging_dir
path staging_dir
Definition deployer.h:38
rime::Deployer::sync_dir
path sync_dir
Definition deployer.h:39
rime::Messenger
Definition messenger.h:14