summaryrefslogtreecommitdiff
path: root/polux/application/agent/inc/AlarmListManager.h
blob: 31d3370b4a31db01558682cb9bc5997b5337819e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 ****************************************************************************
 *                            PROGRAM MODULE
 *
 *     $Workfile:   systemmanager.h $
 *     $Author: antunes $
 *     $Date: 2006/02/10 08:21:50 $
 *
 *       Copyright (C) 2003 by SPiDCOM Technologies All rights reserved.
 *
 ****************************************************************************
 */

#ifndef __ALARM_LIST_MANAGER__
#define __ALARM_LIST_MANAGER__


#include "AlarmList.h"
#include <pthread.h>




//using namespace threads_namespace;
using namespace agentsnmp;


/**
* Alarm List Manager
* This class is responsible of the list management, but not for the list memory allocation
*		- build the list and the counter Id from flash
*		- save the list and the counter Id in flash
*		- Mutex on file access for saving/creating the list of alarms (ThreadManager)
*/



class AlarmListManager //: public commonThreadManager
	
{


public:

	virtual ~AlarmListManager();


  /**
	 * Get a copy of alarms managed currently: 
	 * During the update WRITING is excluded by LOCK, but READING still allowed
	 */
  void getCopyOfAlarmList(agentsnmp::commonOrderedList<AlarmObjectModel>& oAlarmList);


	/**
	 * Get a copy of alarms managed currently
	 */
	//agentsnmp::commonOrderedList<AlarmObjectModel>* getCopyOfAlarmList();


	/** 
	 * Get the element from the index in the list
	 * return NULL if i> size of list
	 */
	//AlarmObjectModel* getAlarmObjectModel(int indexInList);


	
	/**
	 * Update the list and save it in file. 
	 * Two different updates can happen:
	 *      - create a new alarm if event generates a new alarm object
	 *      - update an existing one if event refers to an already existing alarm
	 *  In the two casses, a pointer on the list contained objet is returned
	 *
	 * During the update WRITING AND READING are excluded by LOCK
	 */
	const AlarmObjectModel* updateAlarmList(AlarmObjectModel& iAlarmFromEvent);


	/**
	 * Modify the status of alarm, in order to terminate it into the equipment
	 */
	void terminateAlarm(unsigned long int& aAlarmId);
	
	/**
	 * Remove all alarms which status is terminate
	 */
	void removeAllTerminateAlarms();
  
	/**
	 * Fill the AlarmListManager list of alarms thanks to reading the dedicated file saved in flash memory
	 * During the creation, WRITING AND READING are excluded by LOCK
	 */
	bool createAlarmListFromFlash();




	/**
	 * To avoid singleton  memory leaks
	 */
	void freeMemory();




	/////////////////////////////////////////////////////////////////////	
	// Singleton static accessor
	static AlarmListManager* instance();
	
	
	
	


private:

	// The attribute m_list is instanciate in the constructor
	AlarmList m_alarmList;

	// Singleton => constructor private
	AlarmListManager();

	//Singleton
	static AlarmListManager* m_instance_p;

  	//Lock read-write access
  	pthread_rwlock_t m_readwrite_lock;
  
  
	/**
	 * The alarmIdCounter is setted in the method createAlarmListFromFlash, defined above in this class
	 * No possibility to manage it directly from another class
	 */
	void setAlarmIdCounter(long i);


	/**
	 * Get/set/increase the counter
	 */
	//long getAlarmIdCounter();

	
	/** 
	 * Get a pointer to the List of alarms
	 */
	//const agentsnmp::commonOrderedList<AlarmObjectModel>* getAlarmList();


  /**
	 * Save the list of alarms thanks to writting in the dedicated file saved in flash memory
	 * Before overwritting, save the old file (sufix Old added in the name)
	 */
	bool saveAlarmListInFlash();
	
	
};



#endif //__ALARM_LIST_MANAGER__