File: utils_shut.cpp

package info (click to toggle)
tango 8.1.2c%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 21,964 kB
  • ctags: 14,286
  • sloc: cpp: 133,954; sh: 14,704; ansic: 1,083; makefile: 944; java: 215; python: 55
file content (183 lines) | stat: -rw-r--r-- 4,558 bytes parent folder | download | duplicates (2)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
static const char *RcsId = "$Id: utils_shut.cpp 22213 2013-03-07 14:32:56Z taurel $";

//+=============================================================================
//
// file :               utils_shut.cpp
//
// description :        C++ source for some methods of the Util class related
//						to server shutdown
//
// project :            TANGO
//
// author(s) :         	E.Taurel
//
// Copyright (C) :      2004,2005,2006,2007,2008,2009,2010,2011,2012,2013
//						European Synchrotron Radiation Facility
//                      BP 220, Grenoble 38043
//                      FRANCE
//
// This file is part of Tango.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tango.  If not, see <http://www.gnu.org/licenses/>.
//
// $Revision: 22213 $
//
//-=============================================================================

#if HAVE_CONFIG_H
#include <ac_config.h>
#endif

#include <tango.h>
#include <eventconsumer.h>
#include <eventsupplier.h>

extern omni_thread::key_t key_py_data;

namespace Tango
{
//+----------------------------------------------------------------------------
//
// method : 		Util::shutdown_server()
//
// description : 	This method sends command to the polling thread for
//			all cmd/attr with polling configuration stored in db.
//			This is done in separate thread in order to equally
//			spread all the polled objects polling time on the
//			smallest polling period.
//
//-----------------------------------------------------------------------------

void Util::shutdown_server()
{

//
// Stopping a device server means :
//		- Mark the server as shutting down
//		- Send kill command to the polling thread
//		- Join with this polling thread
//		- Unregister server in database
//		- Delete devices (except the admin one)
//		- Stop the KeepAliveThread and the EventConsumer Thread when
//		  they have been started to receive events
//		- Force writing file database in case of
//		- Shutdown the ORB
//		- Cleanup Logging
//

	set_svr_shutting_down(true);

//
// send the exit command to all the polling threads in the pool
//

	stop_all_polling_threads();
	stop_heartbeat_thread();
	clr_heartbeat_th_ptr();

//
// Unregister the server in the database
//

	try
	{
		unregister_server();
	}
	catch(...) {}

//
// Delete the devices (except the admin one)
// Protect python data
//

	omni_thread::value_t *tmp_py_data = omni_thread::self()->get_value(key_py_data);
	PyLock *lock_ptr = (static_cast<PyData *>(tmp_py_data))->PerTh_py_lock;
	lock_ptr->Get();

	get_dserver_device()->delete_devices();

	lock_ptr->Release();

//
// 	Stop the KeepAliveThread and the EventConsumer thread when
//  they have been started to receive events.
//

	ApiUtil *au = ApiUtil::instance();
	if (au->is_notifd_event_consumer_created() == true)
	{
		NotifdEventConsumer *ec = ApiUtil::instance()->get_notifd_event_consumer();
		if (ec != NULL)
			ec->shutdown();
	}
	if (au->is_zmq_event_consumer_created() == true)
	{
		ZmqEventConsumer *ec = ApiUtil::instance()->get_zmq_event_consumer();
		if (ec != NULL)
			ec->shutdown();
	}

//
// Disconnect the server from the notifd, when it was connected
//

	NotifdEventSupplier *ev = get_notifd_event_supplier();
	if (ev != NULL)
		ev->disconnect_from_notifd();

//
// Delete ZmqEventSupplier
//

	ZmqEventSupplier *zev = get_zmq_event_supplier();
	delete zev;

//
// Close access to file database when used
//

	if (_FileDb == true)
	{
		Database *db_ptr = get_database();
		db_ptr->write_filedatabase();
		delete db_ptr;
		cout4 << "Database object deleted" << endl;
	}

//
// If the server uses its own event loop, do not call it any more
//

	if (is_server_event_loop_set())
		set_shutdown_server(true);

//
// Shutdown the ORB
//

	cout4 << "Going to shutdown ORB" << endl;
	CORBA::ORB_ptr loc_orb = get_orb();
	loc_orb->shutdown(true);

	cout4 << "ORB shutdown" << endl;

#ifdef TANGO_HAS_LOG4TANGO
// clean-up the logging system

	Logging::cleanup();
	cout4 << "Logging cleaned-up" << endl;
#endif
}

} // End of Tango namespace