This file is indexed.

/usr/include/tango/utils.tpp is in libtango8-dev 8.1.2c+dfsg-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
//=============================================================================
//
// file :               utils.tpp
//
// description :        C++ source code for the Attribute class template
//                      methods
//
// project :            TANGO
//
// author(s) :          E.Taurel
//
// Copyright (C) :      2011,2012
//						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$
//
//=============================================================================

#ifndef _UTILS_TPP
#define _UTILS_TPP


template <typename T>
void Util::fill_attr_polling_buffer(DeviceImpl *dev,
				      string &att_name,
				      AttrHistoryStack<T>  &data)
{
//
// Check that the device is polled
//

    if (dev->is_polled() == false)
    {
        TangoSys_OMemStream o;
        o << "Device " << dev->get_name() << " is not polled" << ends;

        Except::throw_exception((const char *)API_DeviceNotPolled,o.str(),
                    (const char *)"Util::fill_attr_polling_buffer");
    }

//
// Attribute name in lower case letters and check that it is marked as polled
//

    string obj_name(att_name);
    transform(obj_name.begin(),obj_name.end(),obj_name.begin(),::tolower);

    dev->get_polled_obj_by_type_name(Tango::POLL_ATTR,obj_name);

//
// Get a reference on the Attribute object
//

    Tango::Attribute &att = dev->get_device_attr()->get_attr_by_name(att_name.c_str());
    Tango::WAttribute *w_att_ptr = NULL;
    Tango::AttrWriteType w_type = att.get_writable();
    if (w_type == Tango::READ_WRITE)
        w_att_ptr = &(dev->get_device_attr()->get_w_attr_by_name(att_name.c_str()));

//
// Check that it is not a WRITE only attribute
//

    if (w_type == Tango::WRITE)
    {
        TangoSys_OMemStream o;
        o << "Attribute " << att_name;
        o << " of device " << dev->get_name() << " is WRITE only" << ends;

        Except::throw_exception((const char *)API_DeviceNotPolled,o.str(),
                    (const char *)"Util::fill_attr_polling_buffer");
    }

//
// If the attribute is not READ_WRITE, the ptr to written part should always be NULL
//

    size_t nb_elt = data.length();
    if (w_type != READ_WRITE)
    {
        for (size_t i = 0;i < nb_elt;i++)
        {
            if ((data.get_data())[i].wr_ptr != NULL)
            {
                TangoSys_OMemStream o;
                o << "The attribute " << att_name;
                o << " for device " << dev->get_name();
                o << " is not a READ_WRITE attribute. You can't set the attribute written part.";
                o << "It is defined for record number " << i + 1 << ends;

                Except::throw_exception((const char *)API_NotSupportedFeature,o.str(),
                                        (const char *)"Util::fill_attr_polling_buffer");
            }
        }
    }

//
// For device implementing IDL 3, DevEncoded data type is not supported
//

    long idl_vers = dev->get_dev_idl_version();
    if ((att.get_data_type() == DEV_ENCODED) && (idl_vers == 3))
    {
        TangoSys_OMemStream o;
        o << "The attribute " << att_name;
        o << " for device " << dev->get_name();
        o << " is of type DEV_ENCODED. Your device supports only IDL V3.";
        o << " DEV_ENCODED data type is supported starting with IDL V4" << ends;

        Except::throw_exception((const char *)API_NotSupportedFeature,o.str(),
                    (const char *)"Util::fill_attr_polling_buffer");
    }

//
// DevEncoded data type is not supported for spectrum or image attribute
// Paranoid code? This case should never happens!
//

    if ((att.get_data_type() == DEV_ENCODED) &&
        (att.get_data_format() != Tango::SCALAR) &&
        (w_type == Tango::READ_WRITE))
    {
        for (size_t i = 0;i < nb_elt;i++)
        {
            if ((data.get_data())[i].wr_ptr != NULL)
            {
                TangoSys_OMemStream o;
                o << "The attribute " << att_name;
                o << " for device " << dev->get_name();
                o << " is of type DEV_ENCODED. Only Scalar attribute are supported for DEV_ENCODED";
                o << "It is defined for record number " << i + 1 << ends;

                Except::throw_exception((const char *)API_NotSupportedFeature,o.str(),
                                        (const char *)"Util::fill_attr_polling_buffer");
            }
        }
    }

//
// Check that the device IDL is at least 3
//

    if (idl_vers <= 2)
    {
        TangoSys_OMemStream o;
        o << "The device " << dev->get_name() << " is too old to support this feature. ";
        o << "Please update your device to IDL 3 or more" << ends;

        Except::throw_exception((const char *)API_NotSupportedFeature,o.str(),
                    (const char *)"Util::fill_attr_polling_buffer");
    }

//
// Check that history is not larger than polling buffer
//

    unsigned long nb_poll = dev->get_attr_poll_ring_depth(att_name);

    if (nb_elt > nb_poll)
    {
        TangoSys_OMemStream o;
        o << "The polling buffer depth for attribute " << att_name;
        o << " for device " << dev->get_name();
        o << " is only " << nb_poll;
        o << " which is less than " << nb_elt << "!" << ends;

        Except::throw_exception((const char *)API_DeviceNotPolled,o.str(),
                    (const char *)"Util::fill_attr_polling_buffer");
    }

//
// A loop on each record
//

    unsigned long i;
    Tango::DevFailed *save_except;
    Tango::AttributeValueList_3 *back_3;
    Tango::AttributeValueList_4 *back_4;
    bool attr_failed;

    struct timeval zero,when;
    zero.tv_sec = zero.tv_usec = 0;

//
// Take the device monitor before the loop
// In case of large element number, it is time cousuming to take/release
// the monitor in the loop
//

    dev->get_poll_monitor().get_monitor();

//
// The loop for each element
//

    for (i = 0;i < nb_elt;i++)
    {
        save_except = NULL;
        back_3 = NULL;
        back_4 = NULL;
        attr_failed = false;

        if ((data.get_data())[i].err.length() != 0)
        {
            attr_failed = true;
            try
            {
                save_except = new Tango::DevFailed((data.get_data())[i].err);
            }
            catch (bad_alloc)
            {
                dev->get_poll_monitor().rel_monitor();
                Except::throw_exception((const char *)API_MemoryAllocation,
                                (const char *)"Can't allocate memory in server",
                                (const char *)"Util::fill_attr_polling_buffer");
            }
        }
        else
        {

//
// Allocate memory for the AttributeValueList sequence
//

            try
            {
                if (idl_vers == 4)
                {
                    back_4 = new Tango::AttributeValueList_4(1);
                    back_4->length(1);
                    (*back_4)[0].value.union_no_data(true);
                }
                else
                {
                    back_3 = new Tango::AttributeValueList_3(1);
                    back_3->length(1);
                }
            }
            catch (bad_alloc)
            {
                dev->get_poll_monitor().rel_monitor();
                Except::throw_exception((const char *)API_MemoryAllocation,
                                (const char *)"Can't allocate memory in server",
                                (const char *)"Util::fill_attr_polling_buffer");
            }

//
// Init name,date and quality factor
//

            Tango::AttrQuality qu = (data.get_data())[i].qual;
            if (idl_vers==4)
            {
                (*back_4)[0].time.tv_sec = (data.get_data())[i].t_val.tv_sec;
                (*back_4)[0].time.tv_usec = (data.get_data())[i].t_val.tv_usec;
                (*back_4)[0].time.tv_nsec = 0;

                (*back_4)[0].quality = qu;
                (*back_4)[0].name = CORBA::string_dup(att_name.c_str());

                (*back_4)[0].w_dim.dim_x = 0;
                (*back_4)[0].w_dim.dim_y = 0;
                (*back_4)[0].r_dim.dim_x = 0;
                (*back_4)[0].r_dim.dim_y = 0;

                (*back_4)[0].data_format = att.get_data_format();
            }
            else
            {
                (*back_3)[0].time.tv_sec = (data.get_data())[i].t_val.tv_sec;
                (*back_3)[0].time.tv_usec = (data.get_data())[i].t_val.tv_usec;
                (*back_3)[0].time.tv_nsec = 0;

                (*back_3)[0].quality = qu;
                (*back_3)[0].name = CORBA::string_dup(att_name.c_str());

                (*back_3)[0].w_dim.dim_x = 0;
                (*back_3)[0].w_dim.dim_y = 0;
                (*back_3)[0].r_dim.dim_x = 0;
                (*back_3)[0].r_dim.dim_y = 0;
            }
            if ((qu == Tango::ATTR_VALID) ||
                (qu == Tango::ATTR_ALARM) ||
                (qu == Tango::ATTR_WARNING) ||
                (qu == Tango::ATTR_CHANGING))
            {

//
// Set Attribute object value
//

                att.set_value((T *)(data.get_data())[i].ptr,
                          (data.get_data())[i].x,
                          (data.get_data())[i].y,
                          (data.get_data())[i].release);
                att.set_date((data.get_data())[i].t_val);
                att.set_quality(qu,false);

//
// Init remaining fields in AttributeValueList
//

                if (w_type == Tango::READ_WITH_WRITE)
                    dev->get_device_attr()->add_write_value(att);
                else if (w_type == Tango::READ_WRITE)
                {
                    if ((data.get_data())[i].wr_ptr != NULL)
                    {
                        w_att_ptr->set_write_value((T *)(data.get_data())[i].wr_ptr,
                                                (data.get_data())[i].wr_x,
                                                (data.get_data())[i].wr_y);
                        dev->get_device_attr()->add_write_value(att);

                        if ((data.get_data())[i].release == true)
                        {
                            if (att.get_data_format() == Tango::SCALAR)
                                delete (data.get_data())[i].wr_ptr;
                            else
                                delete [] (data.get_data())[i].wr_ptr;
                        }
                    }
                    else
                    {
                        dev->get_device_attr()->add_write_value(att);
                    }
                }

//
// Insert data into the AttributeValue object
//

                dev->data_into_net_object(att,back_3,back_4,0,w_type,true);

//
// Init remaining fields
//

                if (idl_vers == 4)
                {
                    (*back_4)[0].r_dim.dim_x = (data.get_data())[i].x;
                    (*back_4)[0].r_dim.dim_y = (data.get_data())[i].y;

                    if ((w_type == Tango::READ_WRITE) || (w_type == Tango::READ_WITH_WRITE))
                    {
                        WAttribute &assoc_att = dev->get_device_attr()->get_w_attr_by_ind(att.get_assoc_ind());
                        (*back_4)[0].w_dim.dim_x = assoc_att.get_w_dim_x();
                        (*back_4)[0].w_dim.dim_y = assoc_att.get_w_dim_y();
                    }
                }
                else
                {
                    (*back_3)[0].r_dim.dim_x = (data.get_data())[i].x;
                    (*back_3)[0].r_dim.dim_y = (data.get_data())[i].y;

                    if ((w_type == Tango::READ_WRITE) || (w_type == Tango::READ_WITH_WRITE))
                    {
                        WAttribute &assoc_att = dev->get_device_attr()->get_w_attr_by_ind(att.get_assoc_ind());
                        (*back_3)[0].w_dim.dim_x = assoc_att.get_w_dim_x();
                        (*back_3)[0].w_dim.dim_y = assoc_att.get_w_dim_y();
                    }
                }
            }
        }

//
// Fill one slot of polling buffer
//

        try
        {
            vector<PollObj *>::iterator ite = dev->get_polled_obj_by_type_name(Tango::POLL_ATTR,obj_name);

            if (attr_failed == false)
            {
                if (idl_vers == 4)
                {
                    when.tv_sec  = (*back_4)[0].time.tv_sec - DELTA_T;
                    when.tv_usec = (*back_4)[0].time.tv_usec;
                    (*ite)->insert_data(back_4,when,zero);
                }
                else
                {
                    when.tv_sec  = (*back_3)[0].time.tv_sec - DELTA_T;
                    when.tv_usec = (*back_3)[0].time.tv_usec;
                    (*ite)->insert_data(back_3,when,zero);
                }
            }
            else
            {
                when = (data.get_data())[i].t_val;
                when.tv_sec = when.tv_sec - DELTA_T;
                (*ite)->insert_except(save_except,when,zero);
            }
        }
        catch (Tango::DevFailed &)
        {
            if (attr_failed == false)
                if (idl_vers == 4)
                    delete back_4;
            else
                    delete back_3;
            else
                delete save_except;
        }

    }

    dev->get_poll_monitor().rel_monitor();
}


template <typename T>
void Util::fill_cmd_polling_buffer(DeviceImpl *dev,
                 string &cmd_name,
                 CmdHistoryStack<T>  &data)
{

//
// Check that the device is polled
//

    if (dev->is_polled() == false)
    {
        TangoSys_OMemStream o;
        o << "Device " << dev->get_name() << " is not polled" << ends;

        Except::throw_exception((const char *)API_DeviceNotPolled,o.str(),
                    (const char *)"Util::fill_cmd_polling_buffer");
    }

//
// Command name in lower case letters and check that it is marked as polled
//

    string obj_name(cmd_name);
    transform(obj_name.begin(),obj_name.end(),obj_name.begin(),::tolower);

    dev->get_polled_obj_by_type_name(Tango::POLL_CMD,obj_name);

//
// Check that history is not larger than polling buffer
//

    size_t nb_elt = data.length();
    long nb_poll = dev->get_cmd_poll_ring_depth(cmd_name);

    if (nb_elt > (size_t)nb_poll)
    {
        TangoSys_OMemStream o;
        o << "The polling buffer depth for command " << cmd_name;
        o << " for device " << dev->get_name();
        o << " is only " << nb_poll;
        o << " which is less than " << nb_elt << "!" << ends;

        Except::throw_exception((const char *)API_DeviceNotPolled,o.str(),
                    (const char *)"Util::fill_cmd_polling_buffer");
    }

//
// Take the device monitor before the loop
// In case of large element number, it is time cousuming to take/release
// the monitor in the loop
//

    dev->get_poll_monitor().get_monitor();

//
// A loop on each record
//

    size_t i;
    Tango::DevFailed *save_except;
    bool cmd_failed;
    CORBA::Any *any_ptr;

    struct timeval zero,when;
    zero.tv_sec = zero.tv_usec = 0;

    for (i = 0;i < nb_elt;i++)
    {
        save_except = NULL;
        cmd_failed = false;

        if ((data.get_data())[i].err.length() != 0)
        {
            cmd_failed = true;
            try
            {
                save_except = new Tango::DevFailed((data.get_data())[i].err);
            }
            catch (bad_alloc)
            {
                dev->get_poll_monitor().rel_monitor();
                Except::throw_exception((const char *)API_MemoryAllocation,
                                (const char *)"Can't allocate memory in server",
                                (const char *)"Util::fill_cmd_polling_buffer");
            }
        }
        else
        {

//
// Allocate memory for the Any object
//

            try
            {
                any_ptr = new CORBA::Any();
            }
            catch (bad_alloc)
            {
                dev->get_poll_monitor().rel_monitor();
                Except::throw_exception((const char *)API_MemoryAllocation,
                                (const char *)"Can't allocate memory in server",
                                (const char *)"Util::fill_cmd_polling_buffer");
            }

//
// Set command value in Any object
// If the Any insertion is by pointer, with omniORB, it copy data into the Any
// and delete memory. Therefore, no need to delete memory if release is
// true. If release is false, uses the insertion by reference which only
// copy data.
//

            T *tmp_ptr = (data.get_data())[i].ptr;
            if ((data.get_data())[i].release == true)
                (*any_ptr) <<= tmp_ptr;
            else
                (*any_ptr) <<= (*tmp_ptr);

        }

//
// Fill one slot of polling buffer
//

        try
        {
            vector<PollObj *>::iterator ite = dev->get_polled_obj_by_type_name(Tango::POLL_CMD,obj_name);
            when.tv_sec = (data.get_data())[i].t_val.tv_sec - DELTA_T;
            when.tv_usec = (data.get_data())[i].t_val.tv_usec;
            if (cmd_failed == false)
                (*ite)->insert_data(any_ptr,when,zero);
            else
                (*ite)->insert_except(save_except,when,zero);
        }
        catch (Tango::DevFailed &)
        {
            if (cmd_failed == false)
                delete any_ptr;
            else
                delete save_except;
        }

    }

    dev->get_poll_monitor().rel_monitor();
}



#endif /* UTILS_TPP */