File: sub_dev.cpp

package info (click to toggle)
tango 10.0.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 89,936 kB
  • sloc: cpp: 201,786; sh: 1,645; python: 953; java: 800; perl: 467; javascript: 447; xml: 325; makefile: 272; sql: 72; ruby: 24
file content (141 lines) | stat: -rw-r--r-- 4,061 bytes parent folder | download | duplicates (4)
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
// NOLINTBEGIN(*)

#include "old_common.h"

/*
 * Test module for sub device diagnostics in the Tango API.
 */

int main(int argc, char **argv)
{
    DeviceProxy *device;
    DeviceProxy *admin;

    if((argc < 4) || (argc > 5))
    {
        TEST_LOG << "usage: sub_dev <device1> <device2> <device3>" << endl;
        exit(-1);
    }

    string device1_name = argv[1];
    string device2_name = argv[2];
    string device3_name = argv[3];

    // sort device names alphabetically
    vector<string> devices;
    std::transform(device1_name.begin(), device1_name.end(), device1_name.begin(), ::tolower);
    std::transform(device2_name.begin(), device2_name.end(), device2_name.begin(), ::tolower);
    std::transform(device3_name.begin(), device3_name.end(), device3_name.begin(), ::tolower);
    devices.push_back(device1_name);
    devices.push_back(device2_name);
    devices.push_back(device3_name);
    sort(devices.begin(), devices.end());

    try
    {
        // be sure that the device name are lower case letters
        //        std::transform(device1_name.begin(), device1_name.end(),
        //                       device1_name.begin(), ::tolower);

        // connect to device
        device = new DeviceProxy(device1_name);

        // Connect to admin device
        string adm_name = device->adm_name();
        admin = new DeviceProxy(adm_name);
    }
    catch(CORBA::Exception &e)
    {
        Except::print_exception(e);
        exit(1);
    }

    TEST_LOG << endl << "new DeviceProxy(" << device->name() << ") returned" << endl << endl;

    try
    {
        // restart server to clean all sub device lists

        bool except = false;
        try
        {
            admin->command_inout("RestartServer");
        }
        catch(Tango::DevFailed &e)
        {
            Except::print_exception(e);
            except = true;
        }

        assert(except == false);
        TEST_LOG << "  Server restart to clean sub device lists --> OK" << endl;
        std::this_thread::sleep_for(std::chrono::seconds(3));

        // read attribute to have a sub device in the list

        {
            DeviceAttribute da = device->read_attribute("Sub_device_tst");
            TEST_LOG << da << endl;
            bool att_value;
            da >> att_value;
            assert(att_value == true);
        }

        // check the list of sub devices on the administration device

        {
            DeviceData dd = admin->command_inout("QuerySubDevice");
            vector<string> sub_dev_list;
            dd >> sub_dev_list;

            string result = device1_name + " " + devices[1];
            assert(sub_dev_list.size() == 1);
            assert(sub_dev_list[0] == result);

            TEST_LOG << "  Add sub device in attribute method --> OK" << endl;
        }

        // execute command to add sub devices in the list

        {
            DeviceData dd = device->command_inout("SubDeviceTst");
            TEST_LOG << dd << endl;
            bool cmd_value;
            dd >> cmd_value;
            assert(cmd_value == true);

            // let the external thread some time to do its work!
            std::this_thread::sleep_for(std::chrono::seconds(1));
        }

        // check the list of sub devices on the administration device

        {
            DeviceData dd = admin->command_inout("QuerySubDevice");
            vector<string> sub_dev_list;
            dd >> sub_dev_list;

            assert(sub_dev_list.size() == 3);

            string result = devices[1];
            assert(sub_dev_list[0] == result);
            result = device1_name + " " + devices[1];
            assert(sub_dev_list[1] == result);
            result = device1_name + " " + devices[2];
            assert(sub_dev_list[2] == result);

            TEST_LOG << "  Add sub devices in command method and external thread --> OK" << endl;
        }
    }
    catch(Tango::DevFailed &e)
    {
        Except::print_exception(e);
        exit(-1);
    }

    delete admin;
    delete device;
    return 0;
}

// NOLINTEND(*)