Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cpp/IceBox/hello/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.16)

project(icebox_hello CXX)

include(../../cmake/common.cmake)

add_executable(client Client.cpp Hello.ice)
slice2cpp_generate(client)
target_link_libraries(client Ice::Ice)

add_library(HelloService SHARED HelloI.cpp HelloI.h HelloServiceI.cpp HelloServiceI.h Hello.ice)
slice2cpp_generate(HelloService)
target_link_libraries(HelloService Ice::Ice Ice::IceBox)
56 changes: 6 additions & 50 deletions cpp/IceBox/hello/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ main(int argc, char* argv[])
// CommunicatorHolder's ctor initializes an Ice communicator,
// and its dtor destroys this communicator.
//
const Ice::CommunicatorHolder ich(argc, argv, "config.client");
const Ice::CommunicatorHolder ich{argc, argv};

//
// The communicator initialization removes all Ice-related arguments from argc/argv
Expand Down Expand Up @@ -53,20 +53,13 @@ void menu();
int
run(const shared_ptr<Ice::Communicator>& communicator)
{
auto twoway =
Ice::checkedCast<HelloPrx>(communicator->propertyToProxy("Hello.Proxy")->ice_twoway()->ice_secure(false));
if (!twoway)
{
cerr << "invalid proxy" << endl;
return 1;
}
HelloPrx twoway{communicator, "hello:tcp -h localhost -p 10000:udp -h localhost -p 10000"};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should further simplify in a follow up PR and have IceBox/greeter, inline with Ice/greeter.

Copy link
Member Author

@externl externl Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could though we'll have to figure out what the behavior will be.


auto oneway = twoway->ice_oneway();
auto batchOneway = twoway->ice_batchOneway();
auto datagram = twoway->ice_datagram();
auto batchDatagram = twoway->ice_batchDatagram();

bool secure = false;

menu();

char c = 'x';
Expand All @@ -90,52 +83,16 @@ run(const shared_ptr<Ice::Communicator>& communicator)
}
else if (c == 'd')
{
if (secure)
{
cout << "secure datagrams are not supported" << endl;
}
else
{
datagram->sayHello();
}
datagram->sayHello();
}
else if (c == 'D')
{
if (secure)
{
cout << "secure datagrams are not supported" << endl;
}
else
{
batchDatagram->sayHello();
}
batchDatagram->sayHello();
}
else if (c == 'f')
{
batchOneway->ice_flushBatchRequests();
if (!secure)
{
batchDatagram->ice_flushBatchRequests();
}
}
else if (c == 'S')
{
secure = !secure;

twoway = twoway->ice_secure(secure);
oneway = oneway->ice_secure(secure);
batchOneway = batchOneway->ice_secure(secure);
datagram = datagram->ice_secure(secure);
batchDatagram = batchDatagram->ice_secure(secure);

if (secure)
{
cout << "secure mode is now on" << endl;
}
else
{
cout << "secure mode is now off" << endl;
}
batchDatagram->ice_flushBatchRequests();
}
else if (c == 'x')
{
Expand Down Expand Up @@ -170,7 +127,6 @@ menu()
"d: send greeting as datagram\n"
"D: send greeting as batch datagram\n"
"f: flush all batch requests\n"
"S: switch secure mode on/off\n"
"x: exit\n"
"?: help\n";
}
12 changes: 7 additions & 5 deletions cpp/IceBox/hello/HelloServiceI.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) ZeroC, Inc.

#include <HelloI.h>
#include <HelloServiceI.h>
#include "HelloServiceI.h"
#include "HelloI.h"

#include <Ice/Ice.h>
#include <iostream>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding a blank like between Ice/IceStorm etc. headers and other system headers.


using namespace std;

Expand All @@ -20,10 +22,10 @@ HelloServiceI::start(
const shared_ptr<Ice::Communicator>& communicator,
const Ice::StringSeq& /*args*/)
{
_adapter = communicator->createObjectAdapter(name);
auto hello = make_shared<HelloI>();
_adapter->add(hello, Ice::stringToIdentity("hello"));
_adapter = communicator->createObjectAdapterWithEndpoints("Hello", "tcp -p 10000:udp -p 10000");
_adapter->add(make_shared<HelloI>(), Ice::stringToIdentity("hello"));
_adapter->activate();
cout << "Listening on port 10000..." << endl;
}

void
Expand Down
39 changes: 29 additions & 10 deletions cpp/IceBox/hello/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
This demo shows how to create an [IceBox][1] service.
# IceBox Hello

This demo shows how to create an [IceBox][1] service.

```shell
cmake -B build
cmake --build build --config Release
```

To run this demo, open two terminal windows. In the first window,
start the IceBox server:
start the IceBox server from the directory containing the `HelloService` library:

**Linux/macOS:**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this relative path to "library", where we don't even provide the actual library name.

That's not how we should recommend using/configuring/starting icebox.

I'd rather show including the directory in LD_LIBRARY_PATH/DYLD_LIBRARY_PATH/PATH before running IceBox, as in

On Linux:

LD_LIBRARY_PATH=./build icebox --Ice.Config=config.icebox


```shell
icebox --IceBox.Service.Hello="./build/HelloService:create"
```
icebox --Ice.Config=config.icebox

**Windows:**

```shell
icebox --IceBox.Service.Hello="./build/Release/HelloService:create"
```

In the second window, run the client:
```
client
```

To shut down IceBox, use `iceboxadmin`:
**Linux/macOS:**

```shell
./build/client
```
iceboxadmin --Ice.Config=config.admin shutdown

**Windows:**

```shell
build\Release\client
```

Linux 32-bit
------------
## Linux 32-bit

If you are using 32-bit binaries on a Linux 64-bit host, use
`icebox32` instead of `icebox` to start the IceBox server.
Expand Down
4 changes: 0 additions & 4 deletions cpp/IceBox/hello/config.admin

This file was deleted.

47 changes: 0 additions & 47 deletions cpp/IceBox/hello/config.client

This file was deleted.

37 changes: 0 additions & 37 deletions cpp/IceBox/hello/config.icebox

This file was deleted.

47 changes: 0 additions & 47 deletions cpp/IceBox/hello/config.service

This file was deleted.

2 changes: 1 addition & 1 deletion cpp/cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ find_package(Threads REQUIRED)

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

find_package(Ice REQUIRED CONFIG COMPONENTS DataStorm Glacier2 IceStorm)
find_package(Ice REQUIRED CONFIG COMPONENTS DataStorm Glacier2 IceBox IceStorm)