Skip to content

Commit acfc4bc

Browse files
committed
Add IceBox CMake files
1 parent 94fa57b commit acfc4bc

File tree

9 files changed

+56
-200
lines changed

9 files changed

+56
-200
lines changed

cpp/IceBox/hello/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(icebox_hello CXX)
4+
5+
include(../../cmake/common.cmake)
6+
7+
add_executable(client Client.cpp Hello.ice)
8+
slice2cpp_generate(client)
9+
target_link_libraries(client Ice::Ice)
10+
11+
add_library(HelloService SHARED HelloI.cpp HelloI.h HelloServiceI.cpp HelloServiceI.h Hello.ice)
12+
slice2cpp_generate(HelloService)
13+
target_link_libraries(HelloService Ice::Ice Ice::IceBox)

cpp/IceBox/hello/Client.cpp

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ main(int argc, char* argv[])
2424
// CommunicatorHolder's ctor initializes an Ice communicator,
2525
// and its dtor destroys this communicator.
2626
//
27-
const Ice::CommunicatorHolder ich(argc, argv, "config.client");
27+
const Ice::CommunicatorHolder ich{argc, argv};
2828

2929
//
3030
// The communicator initialization removes all Ice-related arguments from argc/argv
@@ -53,20 +53,13 @@ void menu();
5353
int
5454
run(const shared_ptr<Ice::Communicator>& communicator)
5555
{
56-
auto twoway =
57-
Ice::checkedCast<HelloPrx>(communicator->propertyToProxy("Hello.Proxy")->ice_twoway()->ice_secure(false));
58-
if (!twoway)
59-
{
60-
cerr << "invalid proxy" << endl;
61-
return 1;
62-
}
56+
HelloPrx twoway{communicator, "hello:tcp -h localhost -p 10000:udp -h localhost -p 10000"};
57+
6358
auto oneway = twoway->ice_oneway();
6459
auto batchOneway = twoway->ice_batchOneway();
6560
auto datagram = twoway->ice_datagram();
6661
auto batchDatagram = twoway->ice_batchDatagram();
6762

68-
bool secure = false;
69-
7063
menu();
7164

7265
char c = 'x';
@@ -90,52 +83,17 @@ run(const shared_ptr<Ice::Communicator>& communicator)
9083
}
9184
else if (c == 'd')
9285
{
93-
if (secure)
94-
{
95-
cout << "secure datagrams are not supported" << endl;
96-
}
97-
else
98-
{
99-
datagram->sayHello();
100-
}
86+
datagram->sayHello();
10187
}
10288
else if (c == 'D')
10389
{
104-
if (secure)
105-
{
106-
cout << "secure datagrams are not supported" << endl;
107-
}
108-
else
109-
{
110-
batchDatagram->sayHello();
111-
}
90+
batchDatagram->sayHello();
11291
}
11392
else if (c == 'f')
11493
{
11594
batchOneway->ice_flushBatchRequests();
116-
if (!secure)
117-
{
118-
batchDatagram->ice_flushBatchRequests();
119-
}
120-
}
121-
else if (c == 'S')
122-
{
123-
secure = !secure;
124-
125-
twoway = twoway->ice_secure(secure);
126-
oneway = oneway->ice_secure(secure);
127-
batchOneway = batchOneway->ice_secure(secure);
128-
datagram = datagram->ice_secure(secure);
129-
batchDatagram = batchDatagram->ice_secure(secure);
95+
batchDatagram->ice_flushBatchRequests();
13096

131-
if (secure)
132-
{
133-
cout << "secure mode is now on" << endl;
134-
}
135-
else
136-
{
137-
cout << "secure mode is now off" << endl;
138-
}
13997
}
14098
else if (c == 'x')
14199
{
@@ -170,7 +128,6 @@ menu()
170128
"d: send greeting as datagram\n"
171129
"D: send greeting as batch datagram\n"
172130
"f: flush all batch requests\n"
173-
"S: switch secure mode on/off\n"
174131
"x: exit\n"
175132
"?: help\n";
176133
}

cpp/IceBox/hello/HelloServiceI.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Copyright (c) ZeroC, Inc.
22

3-
#include <HelloI.h>
4-
#include <HelloServiceI.h>
3+
#include "HelloI.h"
4+
#include "HelloServiceI.h"
5+
56
#include <Ice/Ice.h>
7+
#include <iostream>
68

79
using namespace std;
810

@@ -20,10 +22,10 @@ HelloServiceI::start(
2022
const shared_ptr<Ice::Communicator>& communicator,
2123
const Ice::StringSeq& /*args*/)
2224
{
23-
_adapter = communicator->createObjectAdapter(name);
24-
auto hello = make_shared<HelloI>();
25-
_adapter->add(hello, Ice::stringToIdentity("hello"));
25+
_adapter = communicator->createObjectAdapterWithEndpoints("Hello", "tcp -p 10000:udp -p 10000");
26+
_adapter->add(make_shared<HelloI>(), Ice::stringToIdentity("hello"));
2627
_adapter->activate();
28+
cout << "Listening on port 10000..." << endl;
2729
}
2830

2931
void

cpp/IceBox/hello/README.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
1-
This demo shows how to create an [IceBox][1] service.
1+
# IceBox Hello
2+
3+
This demo shows how to create an [IceBox][1] service.
4+
5+
```shell
6+
cmake -B build
7+
cmake --build build --config Release
8+
```
29

310
To run this demo, open two terminal windows. In the first window,
4-
start the IceBox server:
11+
start the IceBox server from the directory containing the `HelloService` library:
12+
13+
**Linux/macOS:**
14+
15+
```shell
16+
icebox --IceBox.Service.Hello="./build/HelloService:create"
517
```
6-
icebox --Ice.Config=config.icebox
18+
19+
**Linux/macOS:**
20+
21+
```shell
22+
icebox --IceBox.Service.Hello="./build/Release/HelloService:create"
723
```
824

925
In the second window, run the client:
10-
```
11-
client
12-
```
1326

14-
To shut down IceBox, use `iceboxadmin`:
27+
**Linux/macOS:**
28+
29+
```shell
30+
./build/client
1531
```
16-
iceboxadmin --Ice.Config=config.admin shutdown
32+
33+
**Windows:**
34+
35+
```shell
36+
build\Release\client
1737
```
1838

19-
Linux 32-bit
20-
------------
39+
## Linux 32-bit
2140

2241
If you are using 32-bit binaries on a Linux 64-bit host, use
2342
`icebox32` instead of `icebox` to start the IceBox server.

cpp/IceBox/hello/config.admin

Lines changed: 0 additions & 4 deletions
This file was deleted.

cpp/IceBox/hello/config.client

Lines changed: 0 additions & 47 deletions
This file was deleted.

cpp/IceBox/hello/config.icebox

Lines changed: 0 additions & 37 deletions
This file was deleted.

cpp/IceBox/hello/config.service

Lines changed: 0 additions & 47 deletions
This file was deleted.

cpp/cmake/common.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ find_package(Threads REQUIRED)
77

88
set(Ice_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path to Ice CMake configuration file")
99

10-
find_package(Ice REQUIRED CONFIG COMPONENTS DataStorm Glacier2 IceStorm)
10+
find_package(Ice REQUIRED CONFIG COMPONENTS DataStorm Glacier2 IceBox IceStorm)

0 commit comments

Comments
 (0)