source: trunk/external/atnf/pks/pksmb_support.cc@ 2126

Last change on this file since 2126 was 1720, checked in by Malte Marquarding, 15 years ago

Update from livedata CVS repository

File size: 7.5 KB
Line 
1//#---------------------------------------------------------------------------
2//# pksmb_support.cc: Support functions for Parkes glish clients.
3//#---------------------------------------------------------------------------
4//# livedata - processing pipeline for single-dish, multibeam spectral data.
5//# Copyright (C) 1997-2009, Australia Telescope National Facility, CSIRO
6//#
7//# This file is part of livedata.
8//#
9//# livedata is free software: you can redistribute it and/or modify it under
10//# the terms of the GNU General Public License as published by the Free
11//# Software Foundation, either version 3 of the License, or (at your option)
12//# any later version.
13//#
14//# livedata is distributed in the hope that it will be useful, but WITHOUT
15//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17//# more details.
18//#
19//# You should have received a copy of the GNU General Public License along
20//# with livedata. If not, see <http://www.gnu.org/licenses/>.
21//#
22//# Correspondence concerning livedata may be directed to:
23//# Internet email: mcalabre@atnf.csiro.au
24//# Postal address: Dr. Mark Calabretta
25//# Australia Telescope National Facility, CSIRO
26//# PO Box 76
27//# Epping NSW 1710
28//# AUSTRALIA
29//#
30//# http://www.atnf.csiro.au/computing/software/livedata.html
31//# $Id: pksmb_support.cc,v 19.10 2009-09-29 07:45:02 cal103 Exp $
32//#---------------------------------------------------------------------------
33//# Original: David Barnes, February 1997
34//#---------------------------------------------------------------------------
35
36// AIPS++ includes.
37#include <casa/sstream.h>
38#include <casa/Arrays/Array.h>
39#include <casa/BasicSL/Complex.h>
40#include <casa/BasicSL/String.h>
41
42// ATNF includes.
43#include <atnf/pksGlish/GlishArray.h>
44#include <atnf/pksGlish/GlishSysEvent.h>
45#include <atnf/pksGlish/GlishRecord.h>
46#include <atnf/pks/pksmb_support.h>
47
48
49GlishSysEventSource *g_glishStream;
50GlishRecord g_msg;
51
52//----------------------------------------------------------------- pksmbSetup
53
54void pksmbSetup(GlishSysEventSource &glishStream, String clientName)
55{
56 glishStream.addTarget(shutdown_event, "shutdown");
57 glishStream.setDefault(unknown_event);
58
59 // Set up message handling.
60 g_glishStream = &glishStream;
61 g_msg.add("location", clientName);
62
63 // Install client.
64 glishStream.loop();
65}
66
67//------------------------------------------------------------- shutdown_event
68
69// Handler for "shutdown" event.
70
71Bool shutdown_event(GlishSysEvent &, void *)
72{
73 exit(0);
74
75 return True;
76}
77
78//-------------------------------------------------------------- unknown_event
79
80// Handler for "unknown" event.
81
82Bool unknown_event(GlishSysEvent &event, void *)
83{
84 logWarning("WARNING: Unknown event: " + event.type());
85 return True;
86}
87
88//-------------------------------------------------------------------- getParm
89
90// Utility functions for extracting parameter values from a Glish record.
91
92template<class T>
93Bool getParm(const GlishRecord &parms,
94 const String &item,
95 const T &default_val,
96 T &value)
97{
98 if (parms.exists(item)) {
99 GlishArray tmp = parms.get(item);
100 tmp.get(value);
101 return True;
102 } else {
103 value = default_val;
104 return False;
105 }
106}
107
108template Bool getParm(const GlishRecord &parms, const String &item,
109 const Bool &default_val, Bool &value);
110template Bool getParm(const GlishRecord &parms, const String &item,
111 const Int &default_val, Int &value);
112template Bool getParm(const GlishRecord &parms, const String &item,
113 const Float &default_val, Float &value);
114template Bool getParm(const GlishRecord &parms, const String &item,
115 const Double &default_val, Double &value);
116template Bool getParm(const GlishRecord &parms, const String &item,
117 const Complex &default_val, Complex &value);
118template Bool getParm(const GlishRecord &parms, const String &item,
119 const String &default_val, String &value);
120
121template<class T>
122Bool getParm(const GlishRecord &parms,
123 const String &item,
124 const T &default_val,
125 Array<T> &value)
126{
127 if (parms.exists(item)) {
128 GlishArray tmp = parms.get(item);
129 tmp.get(value);
130 return True;
131 } else {
132 value = default_val;
133 return False;
134 }
135}
136
137template Bool getParm(const GlishRecord &parms, const String &item,
138 const Bool &default_val, Array<Bool> &value);
139template Bool getParm(const GlishRecord &parms, const String &item,
140 const Int &default_val, Array<Int> &value);
141template Bool getParm(const GlishRecord &parms, const String &item,
142 const Float &default_val, Array<Float> &value);
143template Bool getParm(const GlishRecord &parms, const String &item,
144 const Double &default_val, Array<Double> &value);
145template Bool getParm(const GlishRecord &parms, const String &item,
146 const Complex &default_val, Array<Complex> &value);
147template Bool getParm(const GlishRecord &parms, const String &item,
148 const String &default_val, Array<String> &value);
149
150template<class T>
151Bool getParm(const GlishRecord &parms,
152 const String &item,
153 const Array<T> &default_val,
154 Array<T> &value)
155{
156 if (parms.exists(item)) {
157 GlishArray tmp = parms.get(item);
158 tmp.get(value);
159 return True;
160 } else {
161 value.assign(default_val);
162 return False;
163 }
164}
165
166template Bool getParm(const GlishRecord &parms, const String &item,
167 const Array<Bool> &default_val, Array<Bool> &value);
168template Bool getParm(const GlishRecord &parms, const String &item,
169 const Array<Int> &default_val, Array<Int> &value);
170template Bool getParm(const GlishRecord &parms, const String &item,
171 const Array<Float> &default_val, Array<Float> &value);
172template Bool getParm(const GlishRecord &parms, const String &item,
173 const Array<Double> &default_val, Array<Double> &value);
174template Bool getParm(const GlishRecord &parms, const String &item,
175 const Array<Complex> &default_val, Array<Complex> &value);
176template Bool getParm(const GlishRecord &parms, const String &item,
177 const Array<String> &default_val, Array<String> &value);
178
179//----------------------------------------------------------------- logMessage
180
181// Log message.
182
183void logMessage(String msg)
184{
185 g_msg.add("message", msg);
186 g_msg.add("priority", "NORMAL");
187
188 g_glishStream->postEvent("log", g_msg);
189}
190
191void logMessage(String msg, uInt val, String suffix)
192{
193 logMessage(msg, Int(val), suffix);
194}
195
196void logMessage(String msg, Int val, String suffix)
197{
198 ostringstream buf;
199
200 buf << msg << val;
201 if (suffix != "") {
202 buf << suffix;
203 }
204
205 logMessage(String(buf.str()));
206}
207
208void logMessage(String msg, Double val, String suffix)
209{
210 ostringstream buf;
211
212 buf << msg << val;
213 if (suffix != "") {
214 buf << suffix;
215 }
216
217 logMessage(String(buf.str()));
218}
219
220//----------------------------------------------------------------- logWarning
221
222// Log warning.
223
224void logWarning(String warn)
225{
226 g_msg.add("message", warn);
227 g_msg.add("priority", "WARN");
228
229 g_glishStream->postEvent("log", g_msg);
230}
231
232//------------------------------------------------------------------- logError
233
234// Log error.
235
236void logError(String err)
237{
238 g_msg.add("message", err);
239 g_msg.add("priority", "SEVERE");
240
241 g_glishStream->postEvent("log", g_msg);
242}
Note: See TracBrowser for help on using the repository browser.