CARDS 2.4.140
Package manager for the NuTyX GNU/Linux distribution
cards_wrapper.h
1/*
2 * cards_wrapper.h
3 *
4 * Copyright 2017 Gianni Peschiutta <artmia@nutyx.org>
5 * Copyright 2017 - 2021 Thierry Nuttens <tnut@nutyx.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
21 *
22 *
23 */
24
25#ifndef CARDS_WRAPPER_H
26#define CARDS_WRAPPER_H
27
28#include <cstddef>
29#include <thread>
30#include <vector>
31#include <algorithm>
32
33#include <libcards.h>
34#include "console_forwarder.h"
35#include "cards_client.h"
36#include "cards_event_handler.h"
37#include "cards_package.h"
38#include "cards_log.h"
39
40using namespace std;
41
42namespace cards
43{
44 enum CW_ACTIONS
45 {
46 SYNC,
47 UPG,
48 DOJOB,
49 REFRESH
50 };
51
59 class CWrapper : public CClientEvents
60 {
61 public:
69 static CWrapper* instance();
70
76 void kill();
77
83 void subscribeToEvents(CEventHandler* pCallBack);
84
90 void unsubscribeFromEvents(CEventHandler* pCallBack);
91
97 void refreshPackageList();
98
104 string getCardsVersion();
105
112 void sync();
113
114 void doJobList();
115
116 const vector<CPackage*>& getPackageList();
117
118 CPackage* getPackage(const string& pName);
119
120 void refreshJobList();
121
122 const vector<CPackage*>& getJobList();
123
124 const set<string>& getSetList();
125
126 bool isJobRunning();
127
128 void getPackageInfo(const string& pName);
129
130 protected:
131 void OnProgressInfo(int percent);
132
133 private:
134
139 CWrapper();
140
145 ~CWrapper();
146
147 static CWrapper* _ptCWrapper; //Static pointer of the singleton
148
150 vector<CEventHandler*> _arrEventHandler; // Std array to store callback event clients
151 vector<CPackage*> _arrPackages;
152 vector<CPackage*> _arrJobList;
153 std::set<std::string> m_arrSets;
154
156 void m_Sync_Thread(); // Main Thread for Cards Sync Operation
157 void m_DoJobList_Thread(); // Thread to install package
158 void m_RefreshPackageList_Thread();
159 void m_GetPackageInfo_Thread(string pName);
160
162 CLogger* _log;
163
165 void m_OnSyncFinished_Callback(const CEH_RC rc); // Callback broadcast for Sync Cards operation
166 void m_OnDoJobListFinished_Callback(const CEH_RC rc);
167 void m_OnRefreshPackageFinished_Callback(const CEH_RC rc);
168 void m_OnJobListChanged_Callback(const CEH_RC rc);
169
170 bool _job_running; //Flag to know if a thread is currently running
171 thread* _job; // Thread handler pointer
172
173 bool m_checkRootAccess(); // Just check if we have root accessing
174 bool m_IsThreadFree();
175 void m_ClearPackagesList();
176
177 };
178}
179#endif // CARDS_WRAPPER_H
Definition: cards_client.h:44
Definition: cards_event_handler.h:63
Definition: cards_log.h:54
Definition: cards_package.h:40
Definition: cards_wrapper.h:60
void kill()
Kill the singleton.
Definition: cards_wrapper.cxx:62
void subscribeToEvents(CEventHandler *pCallBack)
Suscribe to CARDS events.
Definition: cards_wrapper.cxx:69
void unsubscribeFromEvents(CEventHandler *pCallBack)
Unsuscribe from CARDS Events.
Definition: cards_wrapper.cxx:76
void sync()
Sync CARDS database.
Definition: cards_wrapper.cxx:142
const vector< CPackage * > & getJobList()
Definition: cards_wrapper.cxx:132
void OnProgressInfo(int percent)
Definition: cards_wrapper.cxx:445
void refreshJobList()
Update the job list.
Definition: cards_wrapper.cxx:115
string getCardsVersion()
Get CARDS Version.
Definition: cards_wrapper.cxx:396
void refreshPackageList()
list of installed packages
Definition: cards_wrapper.cxx:163
static CWrapper * instance()
Return or create the singleton.
Definition: cards_wrapper.cxx:54
void doJobList()
Definition: cards_wrapper.cxx:153