Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 0 additions & 9 deletions cpp/C++ demos.sln
Original file line number Diff line number Diff line change
Expand Up @@ -458,20 +458,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "Ice\greeter\msbui
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "Ice\greeter\msbuild\server\server.vcxproj", "{E4B54261-3921-40D9-AA09-C3C89D096350}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "greeterAsync", "greeterAsync", "{2E31C2CA-8493-4957-9E89-FC9546C2F70B}"
ProjectSection(SolutionItems) = preProject
Ice\greeterAsync\README.md = Ice\greeterAsync\README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "secure", "secure", "{DD1B1121-F502-4AB7-8012-633DDC3DD610}"
ProjectSection(SolutionItems) = preProject
Ice\secure\README.md = Ice\secure\README.md
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "Ice\greeterAsync\msbuild\client\client.vcxproj", "{BEB2285A-1D68-4B0B-BFDC-4DC9AFE43A75}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "Ice\greeterAsync\msbuild\server\server.vcxproj", "{9D71F7CB-6F15-41DC-B6D7-69A144513FC3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "Ice\secure\msbuild\client\client.vcxproj", "{651398C4-452B-4E64-8536-4DD9FA88AE1A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "Ice\secure\msbuild\server\server.vcxproj", "{A80500EC-13A8-4E5C-AE4D-5168572B9D11}"
Expand Down
4 changes: 4 additions & 0 deletions cpp/Ice/greeter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ target_link_libraries(client Ice::Ice)
add_executable(server Server.cpp Chatbot.cpp Chatbot.h Greeter.ice)
slice2cpp_generate(server)
target_link_libraries(server Ice::Ice)

add_executable(serveramd ServerAMD.cpp ChatbotAMD.cpp ChatbotAMD.h GreeterAMD.ice)
slice2cpp_generate(serveramd)
target_link_libraries(serveramd Ice::Ice)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) ZeroC, Inc.

#include "Chatbot.h"
#include "ChatbotAMD.h"

#include <chrono>
#include <future>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) ZeroC, Inc.

#ifndef CHATBOT_H
#define CHATBOT_H
#ifndef CHATBOT_AMD_H
#define CHATBOT_AMD_H

#include "Greeter.h"
#include "GreeterAMD.h"

namespace GreeterServer
{
Expand Down
29 changes: 26 additions & 3 deletions cpp/Ice/greeter/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Greeter.h"

#include <cstdlib>
#include <future>
#include <iostream>

using namespace std;
Expand All @@ -18,7 +19,7 @@ main(int argc, char* argv[])
}
if (name == nullptr)
{
name = "alice";
name = "masked user";
}

// Create an Ice communicator to initialize the Ice runtime. The CommunicatorHolder is a RAII helper that creates
Expand All @@ -32,10 +33,32 @@ main(int argc, char* argv[])
// or IP address.
VisitorCenter::GreeterPrx greeter{communicator, "greeter:tcp -h localhost -p 4061"};

// Send a request to the remote object and get the response. Both the -> and . syntax can be used to make
// invocations with the proxy.
// Send a request to the remote object and wait synchronously for the response.
// Both the -> and . syntax can be used to make invocations with the proxy.
string greeting = greeter->greet(name);
cout << greeting << endl;

// Send another request to the remote object, this time with greetAsync. greetAsync returns a future immediately.
future<string> futureGreeting = greeter->greetAsync("alice");

// Wait for the response.
greeting = futureGreeting.get();
cout << greeting << endl;

// Send a third request to the remote object, this time with the greetAsync overload that accepts callbacks.
promise<void> promise;
greeter->greetAsync(
"bob",
[&promise](string_view greeting) // response callback
{
cout << greeting << endl;
promise.set_value();
},
[&promise](std::exception_ptr exceptionPtr) // exception callback
{ promise.set_exception(exceptionPtr); });

// Wait for the response/exception callback to be called.
promise.get_future().get();

return 0;
}
File renamed without changes.
31 changes: 27 additions & 4 deletions cpp/Ice/greeter/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# Greeter

The Greeter demo illustrates how to send a request and wait for the response.
The Greeter demo illustrates how to build a simple application with Ice.

To build the demo run:
It features a client which demonstrates the 3 APIs you can use to make remote invocations using generated Ice proxies:

- synchronous (`greet`),
- asynchronous with futures (`greetAsync`); and
- asynchronous with callbacks (another `greetAsync`)

This demo also provides two implementations for the server: a synchronous dispatch implementation (`server`), and an
asynchronous dispatch implementation (`serveramd`). The client works with both.

To build the demo, run:

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

The build produces 3 executables: client, server, and serveramd.

To run the demo, first start the server:

**Linux/macOS:**
Expand All @@ -17,10 +28,22 @@ To run the demo, first start the server:
./build/server
```

or

```shell
./build/serveramd
```

**Windows:**

```shell
.\build\Release\server
build\Release\server
```

or

```shell
build\Release\serveramd
```

In a separate window, start the client:
Expand All @@ -34,5 +57,5 @@ In a separate window, start the client:
**Windows:**

```shell
.\build\Release\client
build\Release\client
```
1 change: 1 addition & 0 deletions cpp/Ice/greeter/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ main(int argc, char* argv[])

// Start dispatching requests.
adapter->activate();
cout << "Listening on port 4061..." << endl;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is new too: I find it clearer when the server outputs something at startup.


// Wait until the user presses Ctrl+C.
int signal = ctrlCHandler.wait();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) ZeroC, Inc.

#include "Chatbot.h"
#include "ChatbotAMD.h"

#include <iostream>

Expand All @@ -26,6 +26,7 @@ main(int argc, char* argv[])

// Start dispatching requests.
adapter->activate();
cout << "Listening on port 4061..." << endl;

// Wait until the user presses Ctrl+C.
int signal = ctrlCHandler.wait();
Expand Down
13 changes: 0 additions & 13 deletions cpp/Ice/greeterAsync/CMakeLists.txt

This file was deleted.

55 changes: 0 additions & 55 deletions cpp/Ice/greeterAsync/Client.cpp

This file was deleted.

37 changes: 0 additions & 37 deletions cpp/Ice/greeterAsync/README.md

This file was deleted.

Loading
Loading