Line |
Branch |
Exec |
Source |
1 |
|
|
// Copyright (c) 2015, Joseph Mirabel |
2 |
|
|
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
// Redistribution and use in source and binary forms, with or without |
6 |
|
|
// modification, are permitted provided that the following conditions are |
7 |
|
|
// met: |
8 |
|
|
// |
9 |
|
|
// 1. Redistributions of source code must retain the above copyright |
10 |
|
|
// notice, this list of conditions and the following disclaimer. |
11 |
|
|
// |
12 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
|
// notice, this list of conditions and the following disclaimer in the |
14 |
|
|
// documentation and/or other materials provided with the distribution. |
15 |
|
|
// |
16 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 |
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 |
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 |
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 |
|
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 |
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 |
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 |
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 |
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
27 |
|
|
// DAMAGE. |
28 |
|
|
|
29 |
|
|
#include "hpp/corbaserver/client.hh" |
30 |
|
|
|
31 |
|
|
#include <iostream> |
32 |
|
|
|
33 |
|
|
namespace hpp { |
34 |
|
|
namespace corbaServer { |
35 |
|
|
using CORBA::Exception; |
36 |
|
|
using CORBA::Object_var; |
37 |
|
|
using CORBA::ORB_init; |
38 |
|
|
using CORBA::PolicyList; |
39 |
|
|
using CORBA::SystemException; |
40 |
|
|
using omniORB::fatalException; |
41 |
|
|
|
42 |
|
✗ |
ClientBase::ClientBase(int argc, char* argv[]) { |
43 |
|
✗ |
orb_ = CORBA::ORB_init(argc, argv); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
✗ |
ClientBase::~ClientBase() {} |
47 |
|
|
|
48 |
|
✗ |
bool ClientBase::createFromDirectLink(const std::string& iiop) { |
49 |
|
✗ |
std::string url = iiop + "/hpp-corbaserver"; |
50 |
|
|
|
51 |
|
✗ |
CORBA::Object_var obj = orb_->string_to_object(url.c_str()); |
52 |
|
✗ |
tools_ = hpp::Tools::_narrow(obj.in()); |
53 |
|
✗ |
return !CORBA::is_nil(tools_); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
✗ |
bool ClientBase::createFromNameService(const std::string& iiop) { |
57 |
|
✗ |
std::string url = iiop + "/NameService"; |
58 |
|
|
|
59 |
|
✗ |
CORBA::Object_var obj = orb_->string_to_object(url.c_str()); |
60 |
|
✗ |
if (CORBA::is_nil(obj)) return false; |
61 |
|
✗ |
CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(obj.in()); |
62 |
|
✗ |
if (CORBA::is_nil(nc)) return false; |
63 |
|
|
|
64 |
|
|
// Bind robotObj with name Robot to the hppContext: |
65 |
|
✗ |
CosNaming::Name objectName; |
66 |
|
✗ |
objectName.length(1); |
67 |
|
✗ |
objectName[0].id = (const char*)"hpp"; // string copied |
68 |
|
✗ |
objectName[0].kind = (const char*)"tools"; // string copied |
69 |
|
|
|
70 |
|
|
// Invoke the root context to retrieve the object reference |
71 |
|
✗ |
obj = nc->resolve(objectName); |
72 |
|
|
// Narrow the previous object to obtain the correct type |
73 |
|
✗ |
tools_ = hpp::Tools::_narrow(obj.in()); |
74 |
|
|
|
75 |
|
✗ |
return CORBA::is_nil(tools_); |
76 |
|
|
} |
77 |
|
|
|
78 |
|
✗ |
void ClientBase::connect(const std::string& iiop) { |
79 |
|
✗ |
bool ok = createFromDirectLink(iiop); |
80 |
|
✗ |
if (!ok) ok = createFromNameService(iiop); |
81 |
|
✗ |
if (!ok) |
82 |
|
✗ |
throw std::runtime_error("Could not connect to hpp server at " + iiop); |
83 |
|
|
} |
84 |
|
|
|
85 |
|
✗ |
Client::Client(int argc, char* argv[]) : ClientBase(argc, argv) {} |
86 |
|
|
|
87 |
|
✗ |
void Client::connect(const char* iiop, const char* context) { |
88 |
|
✗ |
ClientBase::connect(iiop); |
89 |
|
|
|
90 |
|
✗ |
CORBA::Object_var obj; |
91 |
|
|
|
92 |
|
✗ |
obj = tools()->getServer(context, "", "robot"); |
93 |
|
✗ |
robot_ = hpp::corbaserver::Robot::_narrow(obj.in()); |
94 |
|
|
|
95 |
|
✗ |
obj = tools()->getServer(context, "", "problem"); |
96 |
|
✗ |
problem_ = hpp::corbaserver::Problem::_narrow(obj.in()); |
97 |
|
|
|
98 |
|
✗ |
obj = tools()->getServer(context, "", "obstacle"); |
99 |
|
✗ |
obstacle_ = hpp::corbaserver::Obstacle::_narrow(obj.in()); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
✗ |
Client::~Client() {} |
103 |
|
|
} // end of namespace corbaServer. |
104 |
|
|
} // end of namespace hpp. |
105 |
|
|
|