File: restart_device.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 (137 lines) | stat: -rw-r--r-- 2,945 bytes parent folder | download | duplicates (3)
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
// NOLINTBEGIN(*)

#include "old_common.h"

/*
 * Send the DevRestart command to the admin device of the
 * server in charg eof the device with name given as parameter.
 *
 * Possible return code:
 *  -1 : major error
 *   0 : success
 *   1 : Exception API_DeviceLocked
 *   2 : All other exceptions
 */

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

    if((argc < 3) || (argc > 4))
    {
        TEST_LOG << "usage: restart_device device cmd" << endl;
        exit(-1);
    }

    string device_name = argv[1];
    string cmd_name = argv[2];
    transform(cmd_name.begin(), cmd_name.end(), cmd_name.begin(), ::tolower);

    try
    {
        device = new DeviceProxy(device_name);
    }
    catch(CORBA::Exception &e)
    {
        Except::print_exception(e);
        return -1;
    }

    try
    {
        DeviceProxy *admin;
        string adm_name = device->adm_name();

        admin = new DeviceProxy(adm_name);

        DeviceData din;
        if(cmd_name == "devrestart")
        {
            din << device_name;
        }
        else if(cmd_name == "addobjpolling")
        {
            vector<Tango::DevLong> vl;
            vector<string> vs;

            vl.push_back(2000);
            vs.push_back(device_name);
            vs.push_back("command");
            vs.push_back("state");

            din.insert(vl, vs);
        }
        else if(cmd_name == "remobjpolling")
        {
            vector<string> vs;

            vs.push_back(device_name);
            vs.push_back("command");
            vs.push_back("state");

            din << vs;
        }
        else if(cmd_name == "updobjpollingperiod")
        {
            vector<Tango::DevLong> vl;
            vector<string> vs;

            vl.push_back(4000);
            vs.push_back(device_name);
            vs.push_back("command");
            vs.push_back("state");

            din.insert(vl, vs);
        }
        else if(cmd_name == "addloggingtarget")
        {
            vector<string> vs;

            vs.push_back(device_name);
            vs.push_back("file::/tmp/bid.log");

            din << vs;
        }
        else if(cmd_name == "removeloggingtarget")
        {
            vector<string> vs;

            vs.push_back(device_name);
            vs.push_back("file:/tmp/bid.log");

            din << vs;
        }
        else if(cmd_name == "setlogginglevel")
        {
            vector<Tango::DevLong> vl;
            vector<string> vs;

            vl.push_back(5);
            vs.push_back(device_name);

            din.insert(vl, vs);
        }
        else
        {
            return -1;
        }

        admin->command_inout(cmd_name, din);
    }
    catch(Tango::DevFailed &e)
    {
        if(::strcmp(e.errors[0].reason.in(), API_DeviceLocked) == 0)
        {
            return 1;
        }
        else
        {
            return 2;
        }
    }

    delete device;
    return 0;
}

// NOLINTEND(*)