CARDS 2.4.87
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  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  *
21  *
22  */
23 
24 #ifndef CARDS_WRAPPER_H
25 #define CARDS_WRAPPER_H
26 
27 #include <cstddef>
28 #include <thread>
29 #include <vector>
30 #include <algorithm>
31 
32 #include <libcards.h>
33 #include "console_forwarder.h"
34 #include "cards_client.h"
35 #include "cards_event_handler.h"
36 #include "cards_package.h"
37 #include "cards_log.h"
38 
39 using namespace std;
40 
41 namespace cards
42 {
43  enum CW_ACTIONS
44  {
45  SYNC,
46  UPG,
47  DOJOB,
48  REFRESH
49  };
50 
58  class CWrapper : public CClientEvents
59  {
60  public:
68  static CWrapper* instance();
69 
75  void kill();
76 
82  void subscribeToEvents(CEventHandler* pCallBack);
83 
89  void unsubscribeFromEvents(CEventHandler* pCallBack);
90 
96  void refreshPackageList();
97 
103  string getCardsVersion();
104 
111  void sync();
112 
113  void doJobList();
114 
115  const vector<CPackage*>& getPackageList();
116 
117  CPackage* getPackage(const string& pName);
118 
119  void refreshJobList();
120 
121  const vector<CPackage*>& getJobList();
122 
123  const set<string>& getCollectionList();
124 
125  bool isJobRunning();
126 
127  void getPackageInfo(const string& pName);
128 
129  protected:
130  void OnProgressInfo(int percent);
131 
132  private:
133 
138  CWrapper();
139 
144  ~CWrapper();
145 
146  static CWrapper* _ptCWrapper; //Static pointer of the singleton
147 
149  vector<CEventHandler*> _arrEventHandler; // Std array to store callback event clients
150  vector<CPackage*> _arrPackages;
151  vector<CPackage*> _arrJobList;
152  set<string> _arrCollections;
153 
155  void m_Sync_Thread(); // Main Thread for Cards Sync Operation
156  void m_DoJobList_Thread(); // Thread to install package
157  void m_RefreshPackageList_Thread();
158  void m_GetPackageInfo_Thread(string pName);
159 
161  CLogger* _log;
162 
164  void m_OnSyncFinished_Callback(const CEH_RC rc); // Callback broadcast for Sync Cards operation
165  void m_OnDoJobListFinished_Callback(const CEH_RC rc);
166  void m_OnRefreshPackageFinished_Callback(const CEH_RC rc);
167  void m_OnJobListChanged_Callback(const CEH_RC rc);
168 
169  bool _job_running; //Flag to know if a thread is currently running
170  thread* _job; // Thread handler pointer
171 
172  bool m_checkRootAccess(); // Just check if we have root accessing
173  bool m_IsThreadFree();
174  void m_ClearPackagesList();
175 
176  };
177 }
178 #endif // CARDS_WRAPPER_H
Definition: cards_wrapper.h:58
Definition: cards_package.h:38
Definition: cards_event_handler.h:61
Definition: cards_log.h:52
Definition: cards_client.cxx:26
Definition: cards_client.h:42