File: findservicebytype.cpp

package info (click to toggle)
robotraconteur 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,380 kB
  • sloc: cpp: 1,149,268; cs: 87,653; java: 58,127; python: 26,897; ansic: 356; sh: 152; makefile: 90; xml: 51
file content (70 lines) | stat: -rw-r--r-- 2,400 bytes parent folder | download
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
#include <RobotRaconteur.h>

using namespace RobotRaconteur;
using namespace std;

int main(int argc, char* argv[])
{
    if (argc < 3)
    {
        cout << "Usage for findservicebytype:  findservicebytype servicetype schemes" << endl;
        return -1;
    }

    string servicetype = string(argv[1]);
    vector<string> schemes;
    boost::split(schemes, argv[2], boost::is_from_range(',', ','));

    RobotRaconteurNode::s()->SetLogLevelFromEnvVariable();

    RR_SHARED_PTR<TcpTransport> t = RR_MAKE_SHARED<TcpTransport>();
    t->EnableNodeDiscoveryListening();
    RobotRaconteurNode::s()->RegisterTransport(t);

    RR_SHARED_PTR<LocalTransport> c2 = RR_MAKE_SHARED<LocalTransport>();
    RobotRaconteurNode::s()->RegisterTransport(c2);

    RR_SHARED_PTR<HardwareTransport> c5 = RR_MAKE_SHARED<HardwareTransport>();
    RobotRaconteurNode::s()->RegisterTransport(c5);

    boost::this_thread::sleep(boost::posix_time::seconds(6));

    vector<ServiceInfo2> r = RobotRaconteurNode::s()->FindServiceByType(servicetype, schemes);

    for (vector<ServiceInfo2>::iterator e = r.begin(); e != r.end(); e++)
    {
        cout << "Name: " << e->Name << endl;
        cout << "RootObjectType: " << e->RootObjectType << endl;
        cout << "RootObjectImplements: " << boost::join(e->RootObjectImplements, ", ") << endl;
        cout << "ConnectionURL: " << boost::join(e->ConnectionURL, ", ") << endl;

        vector<string> a;
        for (std::map<std::string, RR_INTRUSIVE_PTR<RRValue> >::iterator ee = e->Attributes.begin();
             ee != e->Attributes.end(); ee++)
        {
            RR_INTRUSIVE_PTR<RRArray<char> > d = RR_DYNAMIC_POINTER_CAST<RRArray<char> >(ee->second);
            if (d)
            {
                a.push_back(ee->first + "=" + RRArrayToString(d));
            }

            RR_INTRUSIVE_PTR<RRArray<int32_t> > d2 = RR_DYNAMIC_POINTER_CAST<RRArray<int32_t> >(ee->second);
            if (d2)
            {
                if (d2->size() > 0)
                {
                    a.push_back(ee->first + "=" + boost::lexical_cast<string>((*d2)[0]));
                }
            }
        }

        cout << "Attributes: " + boost::join(a, ", ") << endl;
        cout << "NodeID: " << e->NodeID.ToString() << endl;
        cout << "NodeName: " << e->NodeName << endl;
        cout << endl;
    }

    RobotRaconteurNode::s()->Shutdown();

    return 0;
}