Mixe for Privacy and Anonymity in the Internet
CAStatusManager.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) The JAP-Team, JonDos GmbH
3 
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice,
10  this list of conditions and the following disclaimer in the documentation and/or
11  other materials provided with the distribution.
12  * Neither the name of the University of Technology Dresden, Germany, nor the name of
13  the JonDos GmbH, nor the names of their contributors may be used to endorse or
14  promote products derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 #ifndef CASTATUSMANAGER_HPP_
29 #define CASTATUSMANAGER_HPP_
30 
38 #include "StdAfx.h"
39 
40 #ifdef SERVER_MONITORING
41 
42 #include "CASocket.hpp"
43 #include "CAThread.hpp"
44 #include "CASocketAddrINet.hpp"
45 /* This contains the whole state machine
46  * definitions including typedefs
47  */
48 #include "monitoringDefs.h"
49 
50 struct dom_state_info
51 {
52  DOMElement *dsi_stateType;
53  DOMElement *dsi_stateLevel;
54  DOMElement *dsi_stateDesc;
55 };
56 
57 typedef struct dom_state_info dom_state_info_t;
58 
65 THREAD_RETURN serveMonitoringRequests(void* param);
66 
67 class CAStatusManager
68 {
69 
70 public:
71 
72  static void init();
73  static void cleanup();
74  /* Function to be called when an event occured,
75  * may cause changing of current state
76  */
77  static SINT32 fireEvent(event_type_t e_type, status_type_t s_type);
78 
79 private:
80  /* current states for each status type */
81  state_t **m_pCurrentStates;
82  /* Keeps references to the nodes of the DOM tree
83  * where the current Status informations are set
84  */
85  dom_state_info_t *m_pCurrentStatesInfo;
86  /* synchronized access to all fields */
87  CAMutex *m_pStatusLock;
88  /* ServerSocket to listen for monitoring requests */
89  CASocket *m_pStatusSocket;
90  CASocketAddrINet *m_pListenAddr;
91  volatile bool m_bTryListen;
92  /* Thread to answer monitoring requests */
93  CAThread *m_pMonitoringThread;
94  /* the DOM structure to create the XML status message */
95  XERCES_CPP_NAMESPACE::DOMDocument* m_pPreparedStatusMessage;
96 
97  /* StatusManger singleton */
98  static CAStatusManager *ms_pStatusManager;
99  /* holds the references of all defined states
100  * accessed by [status_type][state_type]
101  */
102  static state_t ***ms_pAllStates;
103  /* holds the references of all defined events
104  * accessed by [status_type][event_type]
105  */
106  static event_t ***ms_pAllEvents;
107 
108  CAStatusManager();
109  virtual ~CAStatusManager();
110 
111  SINT32 initSocket();
112 
113  static void initStates();
114  static void initEvents();
115 
116  static void deleteStates();
117  static void deleteEvents();
118 
119  /* changes state (only called by fireEvent) */
120  SINT32 transition(event_type_t e_type, status_type_t s_type);
121  SINT32 initStatusMessage();
122 
123  /* monitoring server routine */
124  friend THREAD_RETURN serveMonitoringRequests(void* param);
125 };
126 
127 #define MONITORING_FIRE_NET_EVENT(e_type) \
128  MONITORING_FIRE_EVENT(e_type, stat_networking)
129 #define MONITORING_FIRE_PAY_EVENT(e_type) \
130  MONITORING_FIRE_EVENT(e_type, stat_payment)
131 #define MONITORING_FIRE_SYS_EVENT(e_type) \
132  MONITORING_FIRE_EVENT(e_type, stat_system)
133 
134 #define MONITORING_FIRE_EVENT(e_type, s_type) \
135  CAStatusManager::fireEvent(e_type, s_type)
136 
137 #else /* SERVER_MONITORING */
138 
139 #define MONITORING_FIRE_NET_EVENT(e_type)
140 #define MONITORING_FIRE_PAY_EVENT(e_type)
141 #define MONITORING_FIRE_SYS_EVENT(e_type)
142 
143 #define MONITORING_FIRE_EVENT(e_type, s_type)
144 
145 #endif /* SERVER_MONITORING */
146 
147 #endif /*CASTATUSMANAGER_HPP_*/
#define THREAD_RETURN
Definition: StdAfx.h:540
signed int SINT32
Definition: basetypedefs.h:132
This class represents a socket address for Internet (IP) connections.
enum event_type event_type_t
enum status_type status_type_t
void init()
do necessary initialisations of libraries etc.
Definition: proxytest.cpp:145
void cleanup()
do necessary cleanups of libraries etc.
Definition: proxytest.cpp:151