CARDS 2.3.99
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 
38 using namespace std;
39 
48 {
49 public:
57 static Cards_wrapper* instance();
58 
64  void kill();
65 
71  void subscribeToEvents(Cards_event_handler* pCallBack);
72 
78  void unsubscribeFromEvents(Cards_event_handler* pCallBack);
79 
85  void refreshPackageList();
86 
92  void printCardsVersion();
93 
100  void sync();
101 
102  void doJobList();
103 
104  const vector<Cards_package*>& getPackageList();
105 
106  Cards_package* getPackage(const string& pName);
107 
108  void refreshJobList();
109 
110  const vector<Cards_package*>& getJobList();
111 
112  void JoinThreads();
113 private:
114 
119  Cards_wrapper();
120 
125  ~Cards_wrapper();
126 
127 static Cards_wrapper* _ptCards_wrapper; //Static pointer of the singleton
128 
130  vector<Cards_event_handler*> _arrCardsEventHandler; // Std array to store callback event clients
131  vector<Cards_package*> _arrCardsPackages;
132  vector<Cards_package*> _arrCardsJobList;
133 
135  void m_Sync_Thread(); // Main Thread for Cards Sync Operation
136  void m_DoJobList_Thread(); // Thread to install package
137  void m_RefreshPackageList_Thread();
138 
139 
141 static void m_OnLogMessage_Callback(const char *ptr, std::streamsize count); //Callback for all cout text output from libcards
142  void m_OnSyncFinished_Callback(const CEH_RC rc); // Callback broadcast for Sync Cards operation
143  void m_OnDoJobListFinished_Callback(const CEH_RC rc);
144  void m_OnRefreshPackageFinished_Callback(const CEH_RC rc);
145  void m_OnJobListChanged_Callback(const CEH_RC rc);
146 
148  console_forwarder<>* redirect_cout; // Forwarding cout message to LogCallback callback
149 #ifndef NDEBUG
150  console_forwarder<>* redirect_cerr; // Forwarding cerr message to LogCallback callback
151 #endif
152  bool _job_running; //Flag to know if a thread is currently running
153  thread* _job; // Thread handler pointer
154 
155  bool m_checkRootAccess(); // Just check if we have root accessing
156  bool m_IsThreadFree();
157  void m_ClearPackagesList();
158 
159 };
160 
161 #endif // CARDS_WRAPPER_H
GUI interfacing wrapper for CARDS.
Definition: cards_wrapper.h:47
Forward standard output console to specific listener.
Definition: console_forwarder.h:40
Definition: cards_package.h:42
Abstract class to handle event from cards_wrapper.
Definition: cards_event_handler.h:51