fintp_log
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LogManager.h
Go to the documentation of this file.
1 /*
2 * FinTP - Financial Transactions Processing Application
3 * Copyright (C) 2013 Business Information Systems (Allevo) S.R.L.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
17 * or contact Allevo at : 031281 Bucuresti, 23C Calea Vitan, Romania,
18 * phone +40212554577, office@allevo.ro <mailto:office@allevo.ro>, www.allevo.ro.
19 */
20 
21 #ifndef LOGMANAGER_H
22 #define LOGMANAGER_H
23 
24 #include <exception>
25 #include <string>
26 #include <iostream>
27 #include <vector>
28 
29 #include "pthread.h"
30 
31 #include <xercesc/dom/DOM.hpp>
32 
33 //#include "AppSettings.h"
34 #include "Collections.h"
35 #include "WorkItemPool.h"
36 
37 #include "AbstractLogPublisher.h"
38 #include "AppExceptions.h"
39 
40 using namespace std;
41 XERCES_CPP_NAMESPACE_USE
42 
43 namespace FinTP
44 {
45  //EXPIMP_TEMPLATE template class ExportedLogObject std::vector< AbstractLogPublisher* >;
46 
48  {
49  public :
50  typedef WorkItemPool< AppException > EventsPool;
51 
52  ~LogManager();// Terminate XML4C2 and delete m_AppException
53 
54  // methods
55  static void Publish( const AppException& except );
56  static void Publish( const string& message, const EventType::EventTypeEnum eventType = EventType::Error );
57  static void Publish( const char* message, const EventType::EventTypeEnum eventType = EventType::Error );
58  static void Publish( const std::exception& innerException, const EventType::EventTypeEnum eventType = EventType::Error, const string& message="" );
59 
60  // initialize m_PropSettings
61  static void Initialize( const NameValueCollection& applicationSettings, bool threaded = false );
62 
63  static bool isInitialized();
64  static void setCorrelationId( const string& value );
65 
66  static void setSessionId( const string& value );
67 
68  static void Terminate();
69 
70  static pthread_t getPublisherThreadId();
71  static void Register( AbstractLogPublisher* logPublisher, bool isDefault );
72 
73  private :
74 
75  static void CreateKeys();
76  static void DeleteCorrelIds( void* data );
77 
78  LogManager();// Initialize the XML4C2 system
80  bool m_Threaded;
81 
82  // the one and only instance
84 
85  static pthread_once_t KeysCreate;
86  static pthread_key_t CorrelationKey;
87  static pthread_mutex_t InstanceMutex;
88  pthread_t m_PublishThreadId;
89 
90  void setThreaded( const bool threaded );
91  static void* PublisherThread( void *param );
92 
93  string m_SessionId;
94 
95  // default publisher and all other publishers
97  vector< AbstractLogPublisher* > m_Publishers;
98 
99  void setDefaultPublisher( AbstractLogPublisher* defaultPublisher );
100 
101  void ClearPublishers();
102 
103  // either inserts the event to the pool or publishers the event ( regarding m_Threaded attribute )
104  void InternalPublish( const AppException& except ) throw();
105  void InternalPublishProc( const AppException& except );
106 
108  };
109 }
110 
111 #endif // LOGMANAGER_H