CARDS 2.4.121
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 - 2020 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 
40 using namespace std;
41 
42 namespace 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 // set<string> _arrCollections;
155 
157  void m_Sync_Thread(); // Main Thread for Cards Sync Operation
158  void m_DoJobList_Thread(); // Thread to install package
159  void m_RefreshPackageList_Thread();
160  void m_GetPackageInfo_Thread(string pName);
161 
163  CLogger* _log;
164 
166  void m_OnSyncFinished_Callback(const CEH_RC rc); // Callback broadcast for Sync Cards operation
167  void m_OnDoJobListFinished_Callback(const CEH_RC rc);
168  void m_OnRefreshPackageFinished_Callback(const CEH_RC rc);
169  void m_OnJobListChanged_Callback(const CEH_RC rc);
170 
171  bool _job_running; //Flag to know if a thread is currently running
172  thread* _job; // Thread handler pointer
173 
174  bool m_checkRootAccess(); // Just check if we have root accessing
175  bool m_IsThreadFree();
176  void m_ClearPackagesList();
177 
178  };
179 }
180 #endif // CARDS_WRAPPER_H
cards::CLogger
Definition: cards_log.h:54
cards::CPackage
Definition: cards_package.h:40
cards::CWrapper
Definition: cards_wrapper.h:60
cards::CClientEvents
Definition: cards_client.h:44
cards::CEventHandler
Definition: cards_event_handler.h:63