diff --git a/cpp/Chat/client/CMakeLists.txt b/cpp/Chat/client/CMakeLists.txt deleted file mode 100644 index 0b822da79..000000000 --- a/cpp/Chat/client/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -project(chat_client CXX) - -include(../../cmake/common.cmake) - -set(common_sources ChatUtils.cpp ChatUtils.h Chat.ice) - -add_executable(chatgl2client Client.cpp ChatSession.ice ${common_sources}) -slice2cpp_generate(chatgl2client) -target_link_libraries(chatgl2client Ice::Ice Ice::Glacier2) - -add_executable(chatpollclient PollingClient.cpp PollingChat.ice ${common_sources}) -slice2cpp_generate(chatpollclient) -target_link_libraries(chatpollclient Ice::Ice) diff --git a/cpp/Chat/client/Chat.ice b/cpp/Chat/client/Chat.ice deleted file mode 100644 index db36190a1..000000000 --- a/cpp/Chat/client/Chat.ice +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -/** - * - * The Chat module defines types shared by definitions from - * ChatSession.ice and PollingChat.ice. - * - **/ -module Chat -{ - -/** - * - * The InvalidMessageException is raised when a user sends an invalid - * message to the server. A message is considered invalid if the - * message size exceeds the maximum message size. - * - **/ -exception InvalidMessageException -{ - /** - * - * The reason why the message was rejected by the server. - * - **/ - string reason; -} - -} diff --git a/cpp/Chat/client/ChatSession.ice b/cpp/Chat/client/ChatSession.ice deleted file mode 100644 index 53dbde58a..000000000 --- a/cpp/Chat/client/ChatSession.ice +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -#include "Chat.ice" - -#include -#include - -module Chat -{ - -/** - * - * The ChatRoomCallback interface is the interface that clients implement - * as their callback object. - * - * The server calls operations of this interface to communicate - * with connected clients. - * - **/ -interface ChatRoomCallback -{ - /** - * - * The server invokes this operation when the client sets the callback - * for a session. This provides the client with the initial list of users - * currently in the chat room. - * - * @param users The names of users currently in the chat room. - * - **/ - void init(Ice::StringSeq users); - - /** - * - * The server invokes this operation to deliver a message - * that was sent to the chat room. - * - * @param name The name of the user that send the message. - * - * @param message The contents of the message. - * - * @param timestamp The time at which the message was sent. - * - **/ - void send(long timestamp, string name, string message); - - /** - * - * The server invokes this operation when a user joins - * the chat room. - * - * @param name The name of the user that joined the chat room. - * - * @param timestamp The time at which the user joined the chat room. - * - **/ - void join(long timestamp, string name); - - /** - * - * The servers invokes this operation when a user leaves - * the chat room. - * - * @param name The name of the user that left the chat room. - * - * @param timestamp The time at which the user left the chat room. - * - **/ - void leave(long timestamp, string name); -} - -/** - * - * A ChatSession is a custom Glacier2::Session for clients that use - * Glacier2 and support callbacks (such as C++, C# and clients). - * - * @see Glacier2::Session - * - **/ -interface ChatSession extends Glacier2::Session -{ - /** - * - * The setCallback operation is called by clients to set the - * callback used to receive notification of activity in the - * room. Clients receive notifications as soon as they call this - * operation (before setCallback returns). - * - * The first callback made by the server is a call to - * ChatRoomCallback::init, which delivers the current list of - * users to the client. - * - * @param cb The callback the server uses to deliver notifications. - * - * @see ChatRoomCallback - * - **/ - void setCallback(ChatRoomCallback* cb); - - /** - * - * Send a message to the chat room. - * - * @param message The message to be sent. - * - * @return The time at which the message is sent. - * - * @throws InvalidMessageException should the message be invalid. - * - **/ - long send(string message) throws InvalidMessageException; -} - -} diff --git a/cpp/Chat/client/ChatUtils.cpp b/cpp/Chat/client/ChatUtils.cpp deleted file mode 100644 index 770674e54..000000000 --- a/cpp/Chat/client/ChatUtils.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ChatUtils.h" -#include "Chat.h" - -#include - -using namespace std; - -using HtmlEntity = pair; - -constexpr std::array htmlEntities = { - HtmlEntity(""", "\""), - HtmlEntity("'", "'"), - HtmlEntity("<", "<"), - HtmlEntity(">", ">"), - HtmlEntity("&", "&")}; - -string -ChatUtils::unstripHtml(const string& s) -{ - string out = s; - for (const HtmlEntity& entity : htmlEntities) - { - for (string::size_type pos = out.find(entity.first); pos != string::npos; pos = out.find(entity.first, pos)) - { - out.replace(pos, entity.first.size(), entity.second); - } - } - return out; -} - -string -ChatUtils::trim(const string& s) -{ - static const string delims = "\t\r\n "; - const string::size_type last = s.find_last_not_of(delims); - if (last != string::npos) - { - return s.substr(s.find_first_not_of(delims), last + 1); - } - return s; -} diff --git a/cpp/Chat/client/ChatUtils.h b/cpp/Chat/client/ChatUtils.h deleted file mode 100644 index 6ff679565..000000000 --- a/cpp/Chat/client/ChatUtils.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef CHAT_UTILS_H -#define CHAT_UTILS_H - -#include - -namespace ChatUtils -{ - - std::string unstripHtml(const std::string&); - std::string trim(const std::string&); - -} - -#endif diff --git a/cpp/Chat/client/Client.cpp b/cpp/Chat/client/Client.cpp deleted file mode 100644 index 9d8104e89..000000000 --- a/cpp/Chat/client/Client.cpp +++ /dev/null @@ -1,211 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ChatSession.h" -#include "ChatUtils.h" -#include -#include -#include - -using namespace std; - -static const unsigned int maxMessageSize = 1024; - -namespace -{ - // mutex to prevent intertwined cout output - mutex coutMutex; - - void menu() - { - const lock_guard lock(coutMutex); - cout << "enter /quit to exit." << endl; - } -} - -class ChatRoomCallbackI final : public Chat::ChatRoomCallback -{ -public: - void init(Ice::StringSeq names, const Ice::Current&) final - { - const lock_guard lock(coutMutex); - cout << "Users: "; - for (auto it = names.begin(); it != names.end();) - { - cout << *it; - it++; - if (it != names.end()) - { - cout << ", "; - } - } - cout << endl; - } - - void join(int64_t, string name, const Ice::Current&) final - { - const lock_guard lock(coutMutex); - cout << ">>>> " << name << " joined." << endl; - } - - void leave(int64_t, string name, const Ice::Current&) final - { - const lock_guard lock(coutMutex); - cout << "<<<< " << name << " left." << endl; - } - - void send(int64_t, string name, string message, const Ice::Current&) final - { - const lock_guard lock(coutMutex); - cout << name << " > " << ChatUtils::unstripHtml(message) << endl; - } -}; - -Chat::ChatSessionPrx -createSession(const Glacier2::RouterPrx& router) -{ - while (true) - { - cout << "This demo accepts any user ID and password.\n"; - - string id; - cout << "user id: " << flush; - getline(cin, id); - id = ChatUtils::trim(id); - - string pw; - cout << "password: " << flush; - getline(cin, pw); - pw = ChatUtils::trim(pw); - - try - { - auto session = Ice::uncheckedCast(router->createSession(id, pw)); - if (!session) - { - throw runtime_error("Glacier2::createSession return null. Is the SessionManager configured?"); - } - router->ice_getCachedConnection()->setCloseCallback( - [](const Ice::ConnectionPtr&) - { - const lock_guard lock(coutMutex); - cout << "The Glacier2 session has been destroyed." << endl; - }); - return *session; - } - catch (const Glacier2::CannotCreateSessionException& ex) - { - cout << "Login failed:\n" << ex.reason << endl; - } - catch (const Glacier2::PermissionDeniedException& ex) - { - cout << "Login failed:\n" << ex.reason << endl; - } - catch (const Ice::LocalException& ex) - { - cerr << "Communication with the server failed:\n" << ex << endl; - } - } -} - -void -run(const shared_ptr& communicator) -{ - auto router = Ice::uncheckedCast(communicator->getDefaultRouter()); - if (!router) - { - throw runtime_error("Ice.Default.Router property not set."); - } - - // Create a session with the Glacier2 router - Chat::ChatSessionPrx session = createSession(*router); - - auto adapter = communicator->createObjectAdapterWithRouter("", *router); - adapter->activate(); - - // Create a callback object and add it to the adapter using the client's category - // provided by the router - Ice::Identity id{Ice::generateUUID(), router->getCategoryForClient()}; - - auto callbackPrx = adapter->add(make_shared(), id); - - // Set the callback proxy on the session - session->setCallback(callbackPrx); - - menu(); - - do - { - string s; - cout << ""; - getline(cin, s); - s = ChatUtils::trim(s); - - if (!s.empty()) - { - if (s[0] == '/') - { - if (s == "/quit") - { - break; - } - menu(); - } - else - { - if (s.size() > maxMessageSize) - { - const lock_guard lock(coutMutex); - cout << "Message length exceeded, maximum length is " << maxMessageSize << " characters."; - } - else - { - session->send(s); - } - } - } - } while (cin.good()); -} - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - // The communicator initialization removes all Ice-related arguments from argc/argv - Ice::InitializationData initData; - initData.properties = Ice::createProperties(argc, argv); - - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - - // - // Set Ice.Default.Router if not set - // - if (initData.properties->getProperty("Ice.Default.Router").empty()) - { - initData.properties->setProperty("IceSSL.UsePlatformCAs", "1"); - // initData.properties->setProperty("IceSSL.CheckCertName", "2"); - initData.properties->setProperty( - "Ice.Default.Router", - "Glacier2/router:wss -p 443 -h zeroc.com -r /demo-proxy/chat/glacier2"); - } - const Ice::CommunicatorHolder ich(initData); - - run(ich.communicator()); - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} diff --git a/cpp/Chat/client/PollingChat.ice b/cpp/Chat/client/PollingChat.ice deleted file mode 100644 index 1dff5221a..000000000 --- a/cpp/Chat/client/PollingChat.ice +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -#include "Chat.ice" - -#include - -/** - * - * The PollingChat module define types and interfaces for polling clients - * (such as PHP client), which cannot use Glacier2 or callbacks. - * - **/ -module PollingChat -{ - -/** - * - * ChatRoomEvent is an abstract base class used to model a union of - * possible event types. - * - **/ -class ChatRoomEvent -{ - /** The timestamp. */ - long timestamp; - /** The name of the user. */ - string name; -} - -/** - * - * A sequence of state changes in the chat room. - * - * @see ChatRoomEvent - * - **/ -sequence ChatRoomEventSeq; - -/** - * - * This event is generated when a user joins the chat room. - * - * @see ChatRoomEvent - * - **/ -class UserJoinedEvent extends ChatRoomEvent -{ -} - -/** - * - * This event is generated when a user leaves the chat room. - * - * @see ChatRoomEvent - * - **/ -class UserLeftEvent extends ChatRoomEvent -{ -} - -/** - * - * This event is generated when a user sends a message in the chat - * room. - * - * @see ChatRoomEvent - * - **/ -class MessageEvent extends ChatRoomEvent -{ - /** The contents of the message. */ - string message; -} - -/** - * - * PollingChatSession is the session interface for polling clients. - * - **/ -interface PollingChatSession -{ - /** - * - * This operation returns a sequence of string with the names of - * the users in chat when this user connects. This function must - * be called when the session is created and before any call to - * getUpdates. - * - * @return The sequence of user names. - * - **/ - Ice::StringSeq getInitialUsers(); - - /** - * - * This operation returns a sequence of ChatRoomEvent with the - * events that occured in the chat room since the last time the - * client called getUpdates. - * - * @return The sequence of chat room events. - * - **/ - ChatRoomEventSeq getUpdates(); - - /** - * - * Send a message to the chat room. - * - * @param message The message to be sent. - * - * @return The time at which the message is sent. - * - * @throws InvalidMessageException should the message be invalid. - * - **/ - long send(string message) throws Chat::InvalidMessageException; - - /** - * - * Destroy the session and leave the chat room. - * - **/ - void destroy(); -} - -/** - * - * The CannotCreateSessionException indicates that a session could not be - * created, for example, because the user name contains an invalid character. - * - **/ -exception CannotCreateSessionException -{ - string reason; -} - -/** - * - * Factory interface to create PollingChatSession objects. - * - **/ -interface PollingChatSessionFactory -{ - /** - * - * Create a new session and join the chat room. - * - **/ - PollingChatSession* create(string name, string password) throws CannotCreateSessionException; -} - -} diff --git a/cpp/Chat/client/PollingClient.cpp b/cpp/Chat/client/PollingClient.cpp deleted file mode 100644 index 330baa3cb..000000000 --- a/cpp/Chat/client/PollingClient.cpp +++ /dev/null @@ -1,306 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ChatUtils.h" -#include "PollingChat.h" - -#include -#include -#include - -using namespace std; -static const unsigned int maxMessageSize = 1024; - -namespace -{ - // mutex to prevent intertwined cout output - mutex coutMutex; -} - -class GetUpdatesTask -{ -public: - explicit GetUpdatesTask(const optional& session) : _session(session) {} - - ~GetUpdatesTask() - { - { - const lock_guard lock(_mutex); - _done = true; - } - _cond.notify_all(); - - assert(_asyncResult.valid()); - try - { - _asyncResult.get(); - } - catch (const std::exception& ex) - { - cerr << "Update task failed with: " << ex.what() << endl; - } - } - - void start(int period) - { - assert(!_asyncResult.valid()); // run must be called just once - _asyncResult = async(launch::async, [this, period] { run(period); }); - } - - void run(int period) - { - unique_lock lock(_mutex); - while (!_done) - { - lock.unlock(); - try - { - auto updates = _session->getUpdates(); - for (const auto& u : updates) - { - auto joinedEvt = dynamic_pointer_cast(u); - if (joinedEvt) - { - const lock_guard lkg(coutMutex); - cout << ">>>> " << joinedEvt->name << " joined." << endl; - } - else - { - auto leftEvt = dynamic_pointer_cast(u); - if (leftEvt) - { - const lock_guard lkg(coutMutex); - cout << ">>>> " << leftEvt->name << " left." << endl; - } - else - { - auto messageEvt = dynamic_pointer_cast(u); - if (messageEvt) - { - const lock_guard lkg(coutMutex); - cout << messageEvt->name << " > " << ChatUtils::unstripHtml(messageEvt->message) - << endl; - } - } - } - } - } - catch (const Ice::LocalException& ex) - { - { - const lock_guard lkg(_mutex); - _done = true; - } - if (!dynamic_cast(&ex)) - { - cerr << "session lost:" << ex << endl; - } - } - - lock.lock(); - if (!_done) - { - _cond.wait_for(lock, chrono::seconds(period)); - } - } - } - - [[nodiscard]] - bool isDone() const - { - const lock_guard lock(const_cast(_mutex)); - return _done; - } - -private: - const optional _session; - std::future _asyncResult; // only used by the main thread - - bool _done = false; - mutex _mutex; - condition_variable _cond; -}; - -int run(const shared_ptr&); - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - Ice::InitializationData initData; - initData.properties = Ice::createProperties(argc, argv); - - // - // Set PollingChatSessionFactory if not set - // - if (initData.properties->getProperty("PollingChatSessionFactory").empty()) - { - initData.properties->setProperty("IceSSL.UsePlatformCAs", "1"); - initData.properties->setProperty( - "PollingChatSessionFactory", - "PollingChatSessionFactory:wss -h zeroc.com -p 443 -r /demo-proxy/chat/poll"); - initData.properties->setProperty("OverrideSessionEndpoints", "1"); - } - - const Ice::CommunicatorHolder ich(argc, argv, initData); - - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - status = run(ich.communicator()); - } - } - catch (const std::exception& ex) - { - cerr << argv[0] << ": " << ex.what() << endl; - status = 1; - } - - return status; -} - -void menu(); - -int -run(const shared_ptr& communicator) -{ - auto sessionFactory = Ice::checkedCast( - communicator->propertyToProxy("PollingChatSessionFactory")); - - if (!sessionFactory) - { - cerr << "PollingChatSessionFactory proxy is not properly configured" << endl; - return 1; - } - - optional session; - while (!session) - { - cout << "This demo accepts any user ID and password.\n"; - - string id; - cout << "user id: " << flush; - getline(cin, id); - id = ChatUtils::trim(id); - - string pw; - cout << "password: " << flush; - getline(cin, pw); - pw = ChatUtils::trim(pw); - - try - { - session = sessionFactory->create(id, pw); - } - catch (const PollingChat::CannotCreateSessionException& ex) - { - cout << "Login failed:\n" << ex.reason << endl; - } - catch (const Ice::LocalException& ex) - { - cout << "Communication with the server failed:\n" << ex << endl; - } - - if (session) - { - break; - } - } - - // - // Override session proxy's endpoints if necessary - // - if (communicator->getProperties()->getPropertyAsInt("OverrideSessionEndpoints") != 0) - { - session = session->ice_endpoints(sessionFactory->ice_getEndpoints()); - } - - GetUpdatesTask getUpdatesTask(session); - getUpdatesTask.start(1); - - menu(); - - auto users = session->getInitialUsers(); - { - const lock_guard lock(coutMutex); - cout << "Users: "; - for (auto it = users.begin(); it != users.end();) - { - cout << *it; - it++; - if (it != users.end()) - { - cout << ", "; - } - } - cout << endl; - } - - try - { - do - { - string s; - cout << ""; - getline(cin, s); - s = ChatUtils::trim(s); - if (!s.empty()) - { - if (s[0] == '/') - { - if (s == "/quit") - { - break; - } - menu(); - } - else - { - if (s.size() > maxMessageSize) - { - const lock_guard lock(coutMutex); - cout << "Message length exceeded, maximum length is " << maxMessageSize << " characters."; - } - else - { - session->send(s); - } - } - } - } while (cin.good() && !getUpdatesTask.isDone()); - } - catch (const Ice::LocalException& ex) - { - cerr << "Communication with the server failed:\n" << ex << endl; - try - { - session->destroy(); - } - catch (const Ice::LocalException&) - { - } - return 1; - } - - try - { - session->destroy(); - } - catch (const Ice::LocalException&) - { - } - return 0; -} - -void -menu() -{ - const lock_guard lock(coutMutex); - cout << "enter /quit to exit." << endl; -} diff --git a/cpp/Chat/client/README.md b/cpp/Chat/client/README.md deleted file mode 100644 index b0d878236..000000000 --- a/cpp/Chat/client/README.md +++ /dev/null @@ -1,51 +0,0 @@ -# Chat Client - -This demo is a C++ command-line client for the [ZeroC Chat Demo][1]. -It connects to a single chat room, allowing you to chat with other chat -room participants. - -By default, the demo connects to the chat server hosted on demo.zeroc.com -through a WebSocket reverse proxy hosted on zeroc.com. - -You may run either the Glacier2 client (`chatgl2client`) or the polling client -(`chatpollclient`), as well as any username or password to connect. - -If you wish to use your own server from the `server` direcory you should specify -the appropriate custom configuration file when launching the client. - -To build the demo run: - -```shell -cmake -B build -S . -cmake --build build --config Release -``` - -To run the the Glacier2 client: - -**Linux/macOS:** - -```shell -./build/chatgl2client --Ice.Config=config.gl2client -``` - -**Windows:** - -```shell -build\Release\chatgl2client --Ice.Config=config.gl2client -``` - -To run the the Polling client: - -**Linux/macOS:** - -```shell -./build/chatpollclient --Ice.Config=config.pollclient -``` - -**Windows:** - -```shell -build\Release\chatpollclient --Ice.Config=config.pollclient -``` - -[1]: https://doc.zeroc.com/display/Doc/Chat+Demo diff --git a/cpp/Chat/client/config.gl2client b/cpp/Chat/client/config.gl2client deleted file mode 100644 index e4ad2a926..000000000 --- a/cpp/Chat/client/config.gl2client +++ /dev/null @@ -1,47 +0,0 @@ -# -# The proxy to the Glacier2 router for all outgoing connections. This -# must match the value of Glacier2.Client.Endpoints in your Chat server's config. -# -Ice.Default.Router=DemoGlacier2/router:ssl -p 4064 -h 127.0.0.1 - -# -# Warn about connection exceptions -# -#Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Security Tracing -# -# 0 = no security tracing -# 1 = trace messages -# -#IceSSL.Trace.Security=1 - -# -# IceSSL -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=client.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/client.keychain -IceSSL.KeychainPassword=password diff --git a/cpp/Chat/client/config.pollclient b/cpp/Chat/client/config.pollclient deleted file mode 100644 index a135e4124..000000000 --- a/cpp/Chat/client/config.pollclient +++ /dev/null @@ -1,47 +0,0 @@ -# -# The proxy to the Glacier2 router for all outgoing connections. This -# must match the value of Glacier2.Client.Endpoints in your Chat server's config. -# -PollingChatSessionFactory=PollingChatSessionFactory:tcp -h 127.0.0.1 -p 10001 - -# -# Warn about connection exceptions -# -#Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Security Tracing -# -# 0 = no security tracing -# 1 = trace messages -# -#IceSSL.Trace.Security=1 - -# -# IceSSL -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=client.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/client.keychain -IceSSL.KeychainPassword=password diff --git a/cpp/Chat/server/CMakeLists.txt b/cpp/Chat/server/CMakeLists.txt deleted file mode 100644 index ea83b55f6..000000000 --- a/cpp/Chat/server/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -project(chat_client CXX) - -include(../../cmake/common.cmake) - -add_executable(chatserver - ChatRoom.cpp ChatRoom.h - ChatServer.cpp - ChatSessionI.cpp ChatSessionI.h - ChatSessionManagerI.cpp ChatSessionManagerI.h - Chat.ice ChatSession.ice - - PollingChatSessionFactoryI.cpp PollingChatSessionFactoryI.h - PollingChatSessionI.cpp PollingChatSessionI.h - PollingChat.ice - - ChatUtils.cpp ChatUtils.h -) -slice2cpp_generate(chatserver) -target_link_libraries(chatserver Ice::Ice Ice::Glacier2) diff --git a/cpp/Chat/server/Chat.ice b/cpp/Chat/server/Chat.ice deleted file mode 100644 index db36190a1..000000000 --- a/cpp/Chat/server/Chat.ice +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -/** - * - * The Chat module defines types shared by definitions from - * ChatSession.ice and PollingChat.ice. - * - **/ -module Chat -{ - -/** - * - * The InvalidMessageException is raised when a user sends an invalid - * message to the server. A message is considered invalid if the - * message size exceeds the maximum message size. - * - **/ -exception InvalidMessageException -{ - /** - * - * The reason why the message was rejected by the server. - * - **/ - string reason; -} - -} diff --git a/cpp/Chat/server/ChatRoom.cpp b/cpp/Chat/server/ChatRoom.cpp deleted file mode 100644 index 18b186911..000000000 --- a/cpp/Chat/server/ChatRoom.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ChatRoom.h" - -using namespace std; - -ChatRoom::ChatRoom(bool trace, const shared_ptr& logger) : _trace(trace), _logger(logger) {} - -void -ChatRoom::reserve(const string& name) -{ - const lock_guard sync(_mutex); - if (_reserved.find(name) != _reserved.end() || _members.find(name) != _members.end()) - { - throw runtime_error("The name " + name + " is already in use."); - } - _reserved.insert(name); -} - -void -ChatRoom::unreserve(const string& name) -{ - const lock_guard sync(_mutex); - _reserved.erase(name); -} - -void -ChatRoom::join(const string& name, const shared_ptr& callback) -{ - const lock_guard sync(_mutex); - const auto timestamp = - chrono::duration_cast(chrono::system_clock::now().time_since_epoch()).count(); - - _reserved.erase(name); - - Ice::StringSeq names; - for (const auto& q : _members) - { - names.push_back(q.first); - } - - callback->init(std::move(names)); - - _members[name] = callback; - - auto e = make_shared(timestamp, name); - for (const auto& q : _members) - { - q.second->join(e); - } - - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << name << "' joined the chat room."; - } -} - -void -ChatRoom::leave(const string& name) -{ - const lock_guard sync(_mutex); - const auto timestamp = - chrono::duration_cast(chrono::system_clock::now().time_since_epoch()).count(); - - _members.erase(name); - - auto e = make_shared(timestamp, name); - for (const auto& q : _members) - { - q.second->leave(e); - } - - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << name << "' left the chat room."; - } -} - -int64_t -ChatRoom::send(const string& name, const string& message) -{ - const lock_guard sync(_mutex); - const auto timestamp = - chrono::duration_cast(chrono::system_clock::now().time_since_epoch()).count(); - - auto e = make_shared(timestamp, name, message); - for (const auto& q : _members) - { - q.second->send(e); - } - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << name << "' sent a message to the chat room."; - } - return timestamp; -} diff --git a/cpp/Chat/server/ChatRoom.h b/cpp/Chat/server/ChatRoom.h deleted file mode 100644 index 506b83634..000000000 --- a/cpp/Chat/server/ChatRoom.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef CHAT_ROOM_I_H -#define CHAT_ROOM_I_H - -#include -#include -#include - -class ChatRoomCallbackAdapter -{ -public: - virtual ~ChatRoomCallbackAdapter() = default; - - virtual void init(Ice::StringSeq) = 0; - virtual void join(const std::shared_ptr&) = 0; - virtual void leave(const std::shared_ptr&) = 0; - virtual void send(const std::shared_ptr&) = 0; -}; - -class ChatRoom -{ -public: - ChatRoom(bool trace, const std::shared_ptr& logger); - void reserve(const std::string&); - void unreserve(const std::string&); - void join(const std::string&, const std::shared_ptr&); - void leave(const std::string&); - int64_t send(const std::string&, const std::string&); - -private: - using ChatRoomCallbackMap = std::map>; - - ChatRoomCallbackMap _members; - std::set _reserved; - std::mutex _mutex; - const bool _trace; - const std::shared_ptr _logger; -}; - -#endif diff --git a/cpp/Chat/server/ChatServer.cpp b/cpp/Chat/server/ChatServer.cpp deleted file mode 100644 index 56482845f..000000000 --- a/cpp/Chat/server/ChatServer.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ChatSessionManagerI.h" -#include "PollingChatSessionFactoryI.h" -#include -#include -using namespace std; - -class ChatServer final : public Ice::Service -{ -public: - bool start(int argc, char* argv[], int&) final; - bool stop() final; - -private: - shared_ptr _adapter; -}; - -bool -ChatServer::start(int, char*[], int& status) -{ - const bool traceEnabled = communicator()->getProperties()->getPropertyAsIntWithDefault("Server.Trace", 0) != 0; - auto logger = communicator()->getLogger(); - - try - { - _adapter = communicator()->createObjectAdapter("ChatServer"); - - auto chatRoom = make_shared(traceEnabled, logger); - if (traceEnabled) - { - Ice::Trace out(logger, "info"); - out << "Chat room created ok."; - } - _adapter->add( - make_shared(chatRoom, traceEnabled, logger), - Ice::stringToIdentity("ChatSessionManager")); - - if (traceEnabled) - { - Ice::Trace out(logger, "info"); - out << "Chat session manager created ok."; - } - _adapter->add( - make_shared(chatRoom, traceEnabled, logger), - Ice::stringToIdentity("PollingChatSessionFactory")); - - if (traceEnabled) - { - Ice::Trace out(logger, "info"); - out << "Polling chat session factory created ok."; - } - - _adapter->activate(); - if (traceEnabled) - { - Ice::Trace out(logger, "info"); - out << "Chat server started ok."; - } - } - catch (const Ice::LocalException&) - { - status = 1; - throw; - } - status = 0; - return true; -} - -bool -ChatServer::stop() -{ - return true; -} - -int -main(int argc, char* argv[]) -{ - ChatServer app; - return app.main(argc, argv); -} diff --git a/cpp/Chat/server/ChatSession.ice b/cpp/Chat/server/ChatSession.ice deleted file mode 100644 index 53dbde58a..000000000 --- a/cpp/Chat/server/ChatSession.ice +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -#include "Chat.ice" - -#include -#include - -module Chat -{ - -/** - * - * The ChatRoomCallback interface is the interface that clients implement - * as their callback object. - * - * The server calls operations of this interface to communicate - * with connected clients. - * - **/ -interface ChatRoomCallback -{ - /** - * - * The server invokes this operation when the client sets the callback - * for a session. This provides the client with the initial list of users - * currently in the chat room. - * - * @param users The names of users currently in the chat room. - * - **/ - void init(Ice::StringSeq users); - - /** - * - * The server invokes this operation to deliver a message - * that was sent to the chat room. - * - * @param name The name of the user that send the message. - * - * @param message The contents of the message. - * - * @param timestamp The time at which the message was sent. - * - **/ - void send(long timestamp, string name, string message); - - /** - * - * The server invokes this operation when a user joins - * the chat room. - * - * @param name The name of the user that joined the chat room. - * - * @param timestamp The time at which the user joined the chat room. - * - **/ - void join(long timestamp, string name); - - /** - * - * The servers invokes this operation when a user leaves - * the chat room. - * - * @param name The name of the user that left the chat room. - * - * @param timestamp The time at which the user left the chat room. - * - **/ - void leave(long timestamp, string name); -} - -/** - * - * A ChatSession is a custom Glacier2::Session for clients that use - * Glacier2 and support callbacks (such as C++, C# and clients). - * - * @see Glacier2::Session - * - **/ -interface ChatSession extends Glacier2::Session -{ - /** - * - * The setCallback operation is called by clients to set the - * callback used to receive notification of activity in the - * room. Clients receive notifications as soon as they call this - * operation (before setCallback returns). - * - * The first callback made by the server is a call to - * ChatRoomCallback::init, which delivers the current list of - * users to the client. - * - * @param cb The callback the server uses to deliver notifications. - * - * @see ChatRoomCallback - * - **/ - void setCallback(ChatRoomCallback* cb); - - /** - * - * Send a message to the chat room. - * - * @param message The message to be sent. - * - * @return The time at which the message is sent. - * - * @throws InvalidMessageException should the message be invalid. - * - **/ - long send(string message) throws InvalidMessageException; -} - -} diff --git a/cpp/Chat/server/ChatSessionI.cpp b/cpp/Chat/server/ChatSessionI.cpp deleted file mode 100644 index 8e08176ea..000000000 --- a/cpp/Chat/server/ChatSessionI.cpp +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ChatSessionI.h" -#include "ChatUtils.h" - -using namespace std; - -class SessionCallbackAdapter : public ChatRoomCallbackAdapter, public enable_shared_from_this -{ -public: - SessionCallbackAdapter( - const optional& callback, - const optional& session, - bool trace, - const shared_ptr& logger, - std::string name) - : _callback(callback), - _session(session), - _trace(trace), - _logger(logger), - _name(std::move(name)) - { - } - - void init(Ice::StringSeq users) override - { - auto self = shared_from_this(); - try - { - _callback->initAsync(users, nullptr, [self](const exception_ptr&) { self->failed(); }); - } - catch (const Ice::CommunicatorDestroyedException&) - { - // Ignored server is being shutdown - } - } - - void join(const shared_ptr& e) override - { - auto self = shared_from_this(); - try - { - _callback->joinAsync(e->timestamp, e->name, nullptr, [self](const exception_ptr&) { self->failed(); }); - } - catch (const Ice::CommunicatorDestroyedException&) - { - // Ignored server is being shutdown - } - } - - void leave(const shared_ptr& e) override - { - auto self = shared_from_this(); - try - { - _callback->leaveAsync(e->timestamp, e->name, nullptr, [self](const exception_ptr&) { self->failed(); }); - } - catch (const Ice::CommunicatorDestroyedException&) - { - // Ignored server is being shutdown - } - } - - void send(const shared_ptr& e) override - { - auto self = shared_from_this(); - try - { - _callback->sendAsync( - e->timestamp, - e->name, - e->message, - nullptr, - [self](const exception_ptr&) { self->failed(); }); - } - catch (const Ice::CommunicatorDestroyedException&) - { - // Ignored server is being shutdown - } - } - - void failed() - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "Error sending request to user '" << _name << "'. The user's session will be destroyed."; - } - try - { - _session->ice_endpoints(Ice::EndpointSeq())->destroy(); // Collocated call. - } - catch (const Ice::LocalException&) - { - } - } - -private: - const optional _callback; - const optional _session; - const bool _trace; - const shared_ptr _logger; - const string _name; -}; - -ChatSessionI::ChatSessionI( - const shared_ptr& chatRoom, - string name, - bool trace, - const shared_ptr& logger) - : _chatRoom(chatRoom), - _name(std::move(name)), - _trace(trace), - _logger(logger) -{ -} - -void -ChatSessionI::setCallback(optional callback, const Ice::Current& current) -{ - const lock_guard sync(_mutex); - if (_destroy) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << _name << "' tried to set the session callback but the session is already destroyed."; - } - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - - if (_callback || !callback) - { - return; - } - - Ice::Context ctx; - ctx["_fwd"] = "o"; - _callback = make_shared( - callback->ice_context(ctx), - Ice::uncheckedCast(current.adapter->createProxy(current.id)), - _trace, - _logger, - _name); - _chatRoom->join(_name, _callback); -} - -int64_t -ChatSessionI::send(string message, const Ice::Current&) -{ - const lock_guard sync(_mutex); - if (_destroy) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << _name << "' tried to send a message but the session is already destroyed."; - } - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - if (!_callback) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << _name << "' tried to send a message without setting the callback."; - } - throw Chat::InvalidMessageException("You cannot send messages until you join the chat room."); - } - string msg; - try - { - msg = validateMessage(message); - } - catch (const exception& ex) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << _name << "' sent an invalid message:\n" << ex; - } - throw Chat::InvalidMessageException(ex.what()); - } - return _chatRoom->send(_name, msg); -} - -void -ChatSessionI::destroy(const Ice::Current& current) -{ - const lock_guard sync(_mutex); - if (_destroy) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "Trying to destroy the session for user '" << _name << "' but the session is already destroyed."; - } - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - try - { - current.adapter->remove(current.id); - if (_callback) - { - _chatRoom->leave(_name); - } - else - { - _chatRoom->unreserve(_name); - } - } - catch (const Ice::ObjectAdapterDeactivatedException&) - { - // No need to clean up, the server is shutting down. - } - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "Push session for user '" << _name << "' destroyed."; - } - _destroy = true; -} diff --git a/cpp/Chat/server/ChatSessionI.h b/cpp/Chat/server/ChatSessionI.h deleted file mode 100644 index 95c9b80ab..000000000 --- a/cpp/Chat/server/ChatSessionI.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef CHAT_SESSION_I_H -#define CHAT_SESSION_I_H - -#include "ChatRoom.h" -#include "ChatSession.h" - -class ChatSessionI final : public Chat::ChatSession -{ -public: - ChatSessionI(const std::shared_ptr&, std::string, bool trace, const std::shared_ptr& logger); - - void setCallback(std::optional, const Ice::Current&) final; - std::int64_t send(std::string, const Ice::Current&) final; - void destroy(const Ice::Current&) final; - -private: - const std::shared_ptr _chatRoom; - const std::string _name; - std::shared_ptr _callback; - bool _destroy = false; - std::mutex _mutex; - const bool _trace; - const std::shared_ptr _logger; -}; - -#endif diff --git a/cpp/Chat/server/ChatSessionManagerI.cpp b/cpp/Chat/server/ChatSessionManagerI.cpp deleted file mode 100644 index 28081f4cb..000000000 --- a/cpp/Chat/server/ChatSessionManagerI.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ChatSessionManagerI.h" -#include "ChatSessionI.h" -#include "ChatUtils.h" - -using namespace std; - -ChatSessionManagerI::ChatSessionManagerI( - const shared_ptr& chatRoom, - bool trace, - const shared_ptr& logger) - : _chatRoom(chatRoom), - _trace(trace), - _logger(logger) -{ -} - -optional -ChatSessionManagerI::create( - string name, - optional sessionControl, - const Ice::Current& current) -{ - string vname; - try - { - vname = validateName(name); - _chatRoom->reserve(vname); - } - catch (const exception& ex) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "Cannot create push session:\n" << ex; - } - throw Glacier2::CannotCreateSessionException(ex.what()); - } - - optional proxy; - try - { - auto session = make_shared(_chatRoom, vname, _trace, _logger); - proxy = Ice::uncheckedCast(current.adapter->addWithUUID(session)); - - Ice::IdentitySeq ids; - ids.push_back(proxy->ice_getIdentity()); - sessionControl->identities()->add(ids); - } - catch (const Ice::LocalException& ex) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "Cannot create push session for user '" << vname << "':\n" << ex; - } - if (proxy) - { - proxy->destroy(); - } - throw Glacier2::CannotCreateSessionException("internal server error"); - } - - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "Push session created for user '" << vname << "'."; - } - return proxy; -} diff --git a/cpp/Chat/server/ChatSessionManagerI.h b/cpp/Chat/server/ChatSessionManagerI.h deleted file mode 100644 index 80eb30b61..000000000 --- a/cpp/Chat/server/ChatSessionManagerI.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef CHAT_SESSION_MANAGER_I_H -#define CHAT_SESSION_MANAGER_I_H - -#include "ChatRoom.h" - -#include -#include - -class ChatSessionManagerI final : public Glacier2::SessionManager -{ -public: - ChatSessionManagerI(const std::shared_ptr&, bool trace, const std::shared_ptr& logger); - - std::optional - create(std::string, std::optional, const Ice::Current&) final; - -private: - const std::shared_ptr _chatRoom; - const bool _trace; - const std::shared_ptr _logger; -}; - -#endif diff --git a/cpp/Chat/server/ChatUtils.cpp b/cpp/Chat/server/ChatUtils.cpp deleted file mode 100644 index 3cb353054..000000000 --- a/cpp/Chat/server/ChatUtils.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ChatUtils.h" -#include "Chat.h" - -#include -#include - -using namespace std; - -static const unsigned int maxNameSize = 12; -static const unsigned int minNameSize = 3; -constexpr string_view nameRange = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -constexpr string_view isEmptyTokens = "\t\r\n\f\v "; -static const unsigned int maxMessageSize = 1024; - -string -validateName(const string& in) -{ - if (in.size() > maxNameSize || in.size() < minNameSize) - { - ostringstream msg; - msg << "Your name must be between " << minNameSize << " and " << maxNameSize << " characters in length."; - throw invalid_argument(msg.str()); - } - if (in.find_last_not_of(nameRange) != string::npos) - { - throw invalid_argument("Invalid character in name. Valid characters are letter and digits."); - } - string out = in; - transform(out.begin(), out.end(), out.begin(), ::tolower); - if (out.begin() != out.end()) - { - transform(out.begin(), out.begin() + 1, out.begin(), ::toupper); - } - return out; -} - -string -validateMessage(const string& in) -{ - if (in.size() > maxMessageSize) - { - ostringstream os; - os << "Message length exceeded, maximum length is " << maxMessageSize << " characters."; - throw Chat::InvalidMessageException(os.str()); - } - if (in.find_last_not_of(isEmptyTokens) == string::npos) - { - throw invalid_argument("Your message is empty and was ignored."); - } - // Strip html codes in the message - string out; - for (const char c : in) - { - switch (c) - { - case '&': - { - out.append("&"); - break; - } - - case '"': - { - out.append("""); - break; - } - - case '\'': - { - out.append("'"); - break; - } - - case '<': - { - out.append("<"); - break; - } - - case '>': - { - out.append(">"); - break; - } - - case '\r': - case '\n': - case '\v': - case '\f': - case '\t': - { - out.append(" "); - break; - } - - default: - { - out.push_back(c); - break; - } - } - } - return out; -} diff --git a/cpp/Chat/server/ChatUtils.h b/cpp/Chat/server/ChatUtils.h deleted file mode 100644 index 225e14f22..000000000 --- a/cpp/Chat/server/ChatUtils.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef CHAT_UTILS_H -#define CHAT_UTILS_H - -#include - -std::string validateName(const std::string&); -std::string validateMessage(const std::string&); - -#endif diff --git a/cpp/Chat/server/PollingChat.ice b/cpp/Chat/server/PollingChat.ice deleted file mode 100644 index b7b8fe4c1..000000000 --- a/cpp/Chat/server/PollingChat.ice +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -#include "Chat.ice" - -#include - - -/** - * - * The PollingChat module define types and interfaces for polling clients - * (such as PHP client), which cannot use Glacier2 or callbacks. - * - **/ -module PollingChat -{ - -/** - * - * ChatRoomEvent is an abstract base class used to model a union of - * possible event types. - * - **/ -class ChatRoomEvent -{ - /** The timestamp. */ - long timestamp; - /** The name of the user. */ - string name; -} - -/** - * - * A sequence of state changes in the chat room. - * - * @see ChatRoomEvent - * - **/ -sequence ChatRoomEventSeq; - -/** - * - * This event is generated when a user joins the chat room. - * - * @see ChatRoomEvent - * - **/ -class UserJoinedEvent extends ChatRoomEvent -{ -} - -/** - * - * This event is generated when a user leaves the chat room. - * - * @see ChatRoomEvent - * - **/ -class UserLeftEvent extends ChatRoomEvent -{ -} - -/** - * - * This event is generated when a user sends a message in the chat - * room. - * - * @see ChatRoomEvent - * - **/ -class MessageEvent extends ChatRoomEvent -{ - /** The contents of the message. */ - string message; -} - -/** - * - * PollingChatSession is the session interface for polling clients. - * - **/ -interface PollingChatSession -{ - /** - * - * This operation returns a sequence of string with the names of - * the users in chat when this user connects. This function must - * be called when the session is created and before any call to - * getUpdates. - * - * @return The sequence of user names. - * - **/ - Ice::StringSeq getInitialUsers(); - - /** - * - * This operation returns a sequence of ChatRoomEvent with the - * events that occured in the chat room since the last time the - * client called getUpdates. - * - * @return The sequence of chat room events. - * - **/ - ChatRoomEventSeq getUpdates(); - - /** - * - * Send a message to the chat room. - * - * @param message The message to be sent. - * - * @return The time at which the message is sent. - * - * @throws InvalidMessageException should the message be invalid. - * - **/ - long send(string message) throws Chat::InvalidMessageException; - - /** - * - * Destroy the session and leave the chat room. - * - **/ - void destroy(); -} - -/** - * - * The CannotCreateSessionException indicates that a session could not be - * created, for example, because the user name contains an invalid character. - * - **/ -exception CannotCreateSessionException -{ - string reason; -} - -/** - * - * Factory interface to create PollingChatSession objects. - * - **/ -interface PollingChatSessionFactory -{ - /** - * - * Create a new session and join the chat room. - * - **/ - PollingChatSession* create(string name, string password) throws CannotCreateSessionException; -} - -} diff --git a/cpp/Chat/server/PollingChatSessionFactoryI.cpp b/cpp/Chat/server/PollingChatSessionFactoryI.cpp deleted file mode 100644 index 6f7ccf526..000000000 --- a/cpp/Chat/server/PollingChatSessionFactoryI.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "PollingChatSessionFactoryI.h" -#include "ChatUtils.h" -#include "PollingChatSessionI.h" - -#include - -using namespace std; - -PollingChatSessionFactoryI::PollingChatSessionFactoryI( - const shared_ptr& chatRoom, - bool trace, - const shared_ptr& logger) - : _chatRoom(chatRoom), - _trace(trace), - _logger(logger) -{ -} - -optional -PollingChatSessionFactoryI::create(string name, string, const Ice::Current& current) -{ - string vname; - try - { - vname = validateName(name); - _chatRoom->reserve(vname); - } - catch (const exception& ex) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "Cannot create poll session:\n" << ex; - } - throw PollingChat::CannotCreateSessionException(ex.what()); - } - - optional proxy; - - auto session = make_shared(_chatRoom, vname, _trace, _logger); - proxy = Ice::uncheckedCast(current.adapter->addWithUUID(session)); - - auto collocProxy = proxy->ice_endpoints(Ice::EndpointSeq()); - - auto trace = _trace; - auto logger = _logger; - current.con->setCloseCallback( - [collocProxy, trace, logger](const shared_ptr&) - { - try - { - collocProxy->destroy(); - if (trace) - { - Ice::Trace out(logger, "info"); - out << "Session: " << collocProxy << " reaped."; - } - } - catch (const Ice::LocalException&) - { - // Session already destroyed or server shutting down - } - }); - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "Poll session created for user '" << vname << "'."; - } - return proxy; -} diff --git a/cpp/Chat/server/PollingChatSessionFactoryI.h b/cpp/Chat/server/PollingChatSessionFactoryI.h deleted file mode 100644 index 26b4f729a..000000000 --- a/cpp/Chat/server/PollingChatSessionFactoryI.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef POLLING_CHAT_SESSION_FACTORY_I_H -#define POLLING_CHAT_SESSION_FACTORY_I_H - -#include "ChatRoom.h" -#include "PollingChat.h" -#include "PollingChatSessionI.h" -#include - -class PollingChatSessionFactoryI final : public PollingChat::PollingChatSessionFactory -{ -public: - PollingChatSessionFactoryI(const std::shared_ptr&, bool, const std::shared_ptr&); - - std::optional create(std::string, std::string, const Ice::Current&) final; - -private: - const std::shared_ptr _chatRoom; - const bool _trace; - const std::shared_ptr _logger; -}; - -#endif diff --git a/cpp/Chat/server/PollingChatSessionI.cpp b/cpp/Chat/server/PollingChatSessionI.cpp deleted file mode 100644 index d1d4316a5..000000000 --- a/cpp/Chat/server/PollingChatSessionI.cpp +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "PollingChatSessionI.h" -#include "ChatUtils.h" - -using namespace std; - -class PollCallbackAdapter final : public ChatRoomCallbackAdapter -{ -public: - void init(Ice::StringSeq users) final - { - const lock_guard sync(_mutex); - _users = std::move(users); - } - - void send(const shared_ptr& e) final - { - const lock_guard sync(_mutex); - _updates.push_back(e); - } - - void join(const shared_ptr& e) final - { - const lock_guard sync(_mutex); - _updates.push_back(e); - } - - void leave(const shared_ptr& e) final - { - const lock_guard sync(_mutex); - _updates.push_back(e); - } - - Ice::StringSeq getInitialUsers() - { - const lock_guard sync(_mutex); - Ice::StringSeq users; - users.swap(_users); - return users; - } - - PollingChat::ChatRoomEventSeq getUpdates() - { - const lock_guard sync(_mutex); - PollingChat::ChatRoomEventSeq updates; - updates.swap(_updates); - return updates; - } - -private: - Ice::StringSeq _users; - PollingChat::ChatRoomEventSeq _updates; - mutex _mutex; -}; - -PollingChatSessionI::PollingChatSessionI( - const shared_ptr& chatRoom, - const string& name, - bool trace, - const shared_ptr& logger) - : _chatRoom(chatRoom), - _name(name), - _callback(make_shared()), - _trace(trace), - _logger(logger) -{ - _chatRoom->join(name, _callback); -} - -Ice::StringSeq -PollingChatSessionI::getInitialUsers(const Ice::Current&) -{ - const lock_guard sync(_mutex); - if (_destroy) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << _name << "' requested initial users list but the session is already destroyed."; - } - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - return _callback->getInitialUsers(); -} - -PollingChat::ChatRoomEventSeq -PollingChatSessionI::getUpdates(const Ice::Current&) -{ - const lock_guard sync(_mutex); - if (_destroy) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << _name << "' requested session updates list but the session is already destroyed."; - } - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - return _callback->getUpdates(); -} - -int64_t -PollingChatSessionI::send(string message, const Ice::Current&) -{ - const lock_guard sync(_mutex); - if (_destroy) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << _name << "' tried to send a message but the session is already destroyed."; - } - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - string msg; - try - { - msg = validateMessage(message); - } - catch (const exception& ex) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << _name << "' sent an invalid message:\n" << ex; - } - throw Chat::InvalidMessageException(ex.what()); - } - return _chatRoom->send(_name, msg); -} - -void -PollingChatSessionI::destroy(const Ice::Current& current) -{ - const lock_guard sync(_mutex); - if (_destroy) - { - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "User '" << _name << "' tried to destroy the session but the session is already destroyed."; - } - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - try - { - current.adapter->remove(current.id); - _chatRoom->leave(_name); - } - catch (const Ice::ObjectAdapterDeactivatedException&) - { - // No need to clean up, the server is shutting down. - } - if (_trace) - { - Ice::Trace out(_logger, "info"); - out << "Poll session for user '" << _name << "' destroyed."; - } - _destroy = true; -} diff --git a/cpp/Chat/server/PollingChatSessionI.h b/cpp/Chat/server/PollingChatSessionI.h deleted file mode 100644 index 35da16334..000000000 --- a/cpp/Chat/server/PollingChatSessionI.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef POLLING_CHAT_SESSION_I_H -#define POLLING_CHAT_SESSION_I_H - -#include "ChatRoom.h" -#include "PollingChat.h" - -#include - -class PollCallbackAdapter; - -class PollingChatSessionI final : public PollingChat::PollingChatSession -{ -public: - PollingChatSessionI( - const std::shared_ptr&, - const std::string&, - bool trace, - const std::shared_ptr& logger); - - void destroy(const Ice::Current&) final; - Ice::StringSeq getInitialUsers(const Ice::Current&) final; - PollingChat::ChatRoomEventSeq getUpdates(const Ice::Current&) final; - int64_t send(std::string, const Ice::Current&) final; - -private: - const std::shared_ptr _chatRoom; - const std::string _name; - bool _destroy = false; - const std::shared_ptr _callback; - std::mutex _mutex; - const bool _trace; - const std::shared_ptr _logger; -}; - -#endif diff --git a/cpp/Chat/server/README.md b/cpp/Chat/server/README.md deleted file mode 100644 index 1cc49e5ab..000000000 --- a/cpp/Chat/server/README.md +++ /dev/null @@ -1,46 +0,0 @@ -# Chat Server - -This demo is the server for the [ZeroC Chat Demo][1]. - -The chat demo server implements two different session systems, one using -Glacier2 sessions and callbacks, and the other one using a custom session -mechanism for Ice clients that cannot use callbacks. - -The Slice definitions for the chat demo are: - -- `slice/ChatSession.ice`: Definitions for Glacier2 clients (C++, Java, .NET, - `JavaScript) - -- `slice/PollingChat.ice`: Definitions for non-Glacier2 clients (PHP) - -You can use this demo if you want to host your own Chat Demo server. - -To build the demo run: - -```shell -cmake -B build -S . -cmake --build build --config Release -``` - -To run the demo, first start the server: - -**Linux/macOS:** - -```shell -./build/chatserver --Ice.Config=config.chatserver -``` - -**Windows:** - -```shell -build\Release\chatserver --Ice.Config=config.chatserver -``` - -For push clients Glacier2 is also required, to start it run the following in a -new shell: - -```shell -glacier2router --Ice.Config=config.glacier2router -``` - -[1]: https://doc.zeroc.com/display/Doc/Chat+Demo diff --git a/cpp/Chat/server/config.chatserver b/cpp/Chat/server/config.chatserver deleted file mode 100644 index dbb660d78..000000000 --- a/cpp/Chat/server/config.chatserver +++ /dev/null @@ -1,44 +0,0 @@ -# -# The endpoint of the session server's object adapter. This should be -# an endpoint on an internal network (like 192.168.x.x), or on the -# loopback, so that the session server is not directly accessible from -# the Internet. -# -ChatServer.Endpoints=tcp -h 127.0.0.1 -p 10001 - -# -# Warn about connection exceptions -# -#Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=3 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Chat Server Tracing -# -# 0 = disable chat server tracing -# 1 = enable chat server tracing -Server.Trace=1 - -# -# We configure the server thread pool as we want the chatserver -# to be multi threaded. -# -Ice.ThreadPool.Server.Size=4 -Ice.ThreadPool.Server.SizeMax=10 diff --git a/cpp/Chat/server/config.glacier2router b/cpp/Chat/server/config.glacier2router deleted file mode 100644 index 1400c97a6..000000000 --- a/cpp/Chat/server/config.glacier2router +++ /dev/null @@ -1,84 +0,0 @@ -# -# Set the Glacier2 instance name. -# -Glacier2.InstanceName=DemoGlacier2 - -# -# The client-visible endpoint of Glacier2. This should be an endpoint -# visible from the public Internet. -# -Glacier2.Client.Endpoints=ssl -p 4064 -t 10000 -h 127.0.0.1:tcp -p 4502 -t 10000 -h 127.0.0.1 - -# -# The server-visible endpoint of Glacier2. This endpoint is only -# required if callbacks are needed (leave empty otherwise). This -# should be an endpoint on an internal network (like 192.168.x.x), or -# on the loopback, so that the server is not directly accessible from -# the Internet. -# -Glacier2.Server.Endpoints=tcp -h 127.0.0.1 - -# -# The proxy of the session manager. -# -Glacier2.SessionManager=ChatSessionManager:tcp -h 127.0.0.1 -p 10001 - -# -# Accept only requests to the machine where the session manager is -# running. -# -Glacier2.Filter.Address.Accept=127.0.0.1:10001 - -# -# For this demo, we use the null permissions verifier. This permissions -# verifier allows any user-id / password combination. -# -Glacier2.PermissionsVerifier=DemoGlacier2/NullPermissionsVerifier - -# -# The timeout for inactive sessions. If any client session is inactive -# for longer than this value, the session expires and is removed. The -# unit is seconds. -# -Glacier2.SessionTimeout=30 - -# -# Turn off buffering, it's not useful for the chat demo. -# -Glacier2.Server.Buffered=0 -Glacier2.Client.Buffered=0 - -# -# Security Tracing -# -# 0 = no security tracing -# 1 = trace messages -# -#IceSSL.Trace.Security=1 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=server.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/glacier2.keychain -IceSSL.KeychainPassword=password -IceSSL.VerifyPeer=0 - -# -# Ice Tracing -# -#Ice.Trace.Network=1 -#Ice.Warn.Connections=1 -#Ice.Trace.Protocol=1 - -# -# We configure the server thread pool as we want the glacier2router -# to be multi threaded. -# - -Ice.ThreadPool.Server.Size=4 -Ice.ThreadPool.Server.SizeMax=10 diff --git a/cpp/Ice/interleaved/CMakeLists.txt b/cpp/Ice/interleaved/CMakeLists.txt deleted file mode 100644 index 3bbce5a56..000000000 --- a/cpp/Ice/interleaved/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -project(interleaved CXX) - -include(../../cmake/common.cmake) - -add_executable(client Client.cpp Throughput.ice) -slice2cpp_generate(client) -target_link_libraries(client Ice::Ice) - -add_executable(server Server.cpp ThroughputI.cpp ThroughputI.h Throughput.ice) -slice2cpp_generate(server) -target_link_libraries(server Ice::Ice) diff --git a/cpp/Ice/interleaved/Client.cpp b/cpp/Ice/interleaved/Client.cpp deleted file mode 100644 index f725cfd34..000000000 --- a/cpp/Ice/interleaved/Client.cpp +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "Throughput.h" -#include -#include -#include -#include - -using namespace std; -using namespace Demo; - -int run(const shared_ptr&, const string&); - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CtrlCHandler must be created before the communicator or any other threads are started - // - Ice::CtrlCHandler ctrlCHandler; - - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.client"); - const auto& communicator = ich.communicator(); - - ctrlCHandler.setCallback([communicator](int) { communicator->destroy(); }); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - status = run(communicator, argv[0]); - } - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} - -int -run(const shared_ptr& communicator, const string& appName) -{ - auto throughput = Ice::checkedCast(communicator->propertyToProxy("Throughput.Proxy")); - if (!throughput) - { - cerr << appName << ": invalid proxy" << endl; - return 1; - } - - ByteSeq byteSeq(ByteSeqSize); - auto byteArr = make_pair(byteSeq.data(), byteSeq.data() + byteSeq.size()); - - throughput->ice_ping(); // Initial ping to setup the connection. - - // The maximum number of outstanding requests. -1 means - // unlimited. If the number of oustanding requests is unlimited - // and the server is slower than the client in processing the - // requests, high memory consumption will result. - const int maxOutstanding = 8; - - const int repetitions = 1000; - - cout << "sending and receiving " << repetitions << " byte sequences of size " << ByteSeqSize << "..." << endl; - - auto start = chrono::high_resolution_clock::now(); - - list> results; - for (int i = 0; i < repetitions; ++i) - { - results.push_back(throughput->echoByteSeqAsync(byteArr)); - - // Remove any completed requests from the list - auto p = results.begin(); - while (p != results.end()) - { - if (p->wait_for(std::chrono::seconds(0)) == std::future_status::ready) - { - p = results.erase(p); - } - else - { - ++p; - } - } - - // This avoids too many outstanding requests. This is desirable if the server doesn't limit the - // number of threads, or the server process requests slower than then client can send them. - while (maxOutstanding != -1 && static_cast(results.size()) > maxOutstanding) - { - results.front().wait(); - results.pop_front(); - } - } - - // Wait for all outstanding requests to complete - // - while (results.size() > 0) - { - results.front().wait(); - results.pop_front(); - } - - auto duration = chrono::duration(chrono::high_resolution_clock::now() - start); - - cout << "time for " << repetitions << " sequences: " << duration.count() << "ms" << endl; - cout << "time per sequence: " << duration.count() / repetitions << "ms" << endl; - - const double mbit = 2 * repetitions * ByteSeqSize * 1 * 8.0 / duration.count() / 1000; - - cout << "throughput: " << setprecision(5) << mbit << "Mbps" << endl; - - throughput->shutdown(); - - return 0; -} diff --git a/cpp/Ice/interleaved/README.md b/cpp/Ice/interleaved/README.md deleted file mode 100644 index 7d4d9ed87..000000000 --- a/cpp/Ice/interleaved/README.md +++ /dev/null @@ -1,41 +0,0 @@ -The interleaved demo is a variant of the throughput demo that uses asynchronous -requests to send "echo" requests to the server. This way, the client sends -multiple concurrent requests and we maximize the bandwidth usage. - -To build the demo run: - -```shell -cmake -B build -cmake --build build --config Release -``` - -To run the demo, first start the server: - -**Linux/macOS:** - -```shell -./build/server -``` - -**Windows:** - -```shell -build\Release\server -``` - -In a separate window, start the client: - -**Linux/macOS:** - -```shell -./build/client -``` - -**Windows:** - -```shell -build\Release\client -``` - -See the throughput demo for a description of the metadata used in -Throughput.ice. diff --git a/cpp/Ice/interleaved/Server.cpp b/cpp/Ice/interleaved/Server.cpp deleted file mode 100644 index 92c8c8c78..000000000 --- a/cpp/Ice/interleaved/Server.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ThroughputI.h" -#include -#include - -using namespace std; - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CtrlCHandler must be created before the communicator or any other threads are started - // - Ice::CtrlCHandler ctrlCHandler; - - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.server"); - const auto& communicator = ich.communicator(); - - ctrlCHandler.setCallback([communicator](int) { communicator->shutdown(); }); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - auto adapter = communicator->createObjectAdapter("Throughput"); - auto servant = make_shared(); - adapter->add(servant, Ice::stringToIdentity("throughput")); - adapter->activate(); - - communicator->waitForShutdown(); - } - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} diff --git a/cpp/Ice/interleaved/Throughput.ice b/cpp/Ice/interleaved/Throughput.ice deleted file mode 100644 index 834b01660..000000000 --- a/cpp/Ice/interleaved/Throughput.ice +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -module Demo -{ - sequence ByteSeq; - const int ByteSeqSize = 500000; - - interface Throughput - { - ["marshaled-result", "cpp:array"] ByteSeq echoByteSeq(["cpp:array"] ByteSeq seq); - - void shutdown(); - } -} diff --git a/cpp/Ice/interleaved/ThroughputI.cpp b/cpp/Ice/interleaved/ThroughputI.cpp deleted file mode 100644 index 7b5283e93..000000000 --- a/cpp/Ice/interleaved/ThroughputI.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ThroughputI.h" -#include - -Demo::Throughput::EchoByteSeqMarshaledResult -ThroughputI::echoByteSeq(std::pair seq, const Ice::Current& current) -{ - return {seq, current}; -} - -void -ThroughputI::shutdown(const Ice::Current& current) -{ - current.adapter->getCommunicator()->shutdown(); -} diff --git a/cpp/Ice/interleaved/ThroughputI.h b/cpp/Ice/interleaved/ThroughputI.h deleted file mode 100644 index 24e8e0160..000000000 --- a/cpp/Ice/interleaved/ThroughputI.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef THROUGHPUT_I_H -#define THROUGHPUT_I_H - -#include "Throughput.h" - -class ThroughputI final : public Demo::Throughput -{ -public: - EchoByteSeqMarshaledResult echoByteSeq(std::pair, const Ice::Current&) final; - - void shutdown(const Ice::Current&) final; -}; - -#endif diff --git a/cpp/Ice/interleaved/config.client b/cpp/Ice/interleaved/config.client deleted file mode 100644 index 281e7bfbd..000000000 --- a/cpp/Ice/interleaved/config.client +++ /dev/null @@ -1,21 +0,0 @@ -# -# The client reads this property to create the reference to the -# "Throughput" object in the server. -# -Throughput.Proxy=throughput:default -p 10000 -h 127.0.0.1 - -# -# Disable client-side ACM. -# -Ice.ACM.Client.Timeout=0 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=client.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/client.keychain -IceSSL.KeychainPassword=password diff --git a/cpp/Ice/interleaved/config.server b/cpp/Ice/interleaved/config.server deleted file mode 100644 index 3ce2c5c59..000000000 --- a/cpp/Ice/interleaved/config.server +++ /dev/null @@ -1,33 +0,0 @@ -# -# The server creates one single object adapter with the name -# "Throughput". The following line sets the endpoints for this -# adapter. -# -Throughput.Endpoints=default -p 10000 -h localhost - -# -# For this test since the server is constantly receiving requests we -# want two threads in the pool. -# -Ice.ThreadPool.Server.Size=2 - -# -# No warnings please. -# -Ice.ThreadPool.Server.SizeWarn=0 - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=server.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/server.keychain -IceSSL.KeychainPassword=password diff --git a/cpp/Ice/invoke/CMakeLists.txt b/cpp/Ice/invoke/CMakeLists.txt deleted file mode 100644 index 99adfcde5..000000000 --- a/cpp/Ice/invoke/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -project(invoke CXX) - -include(../../cmake/common.cmake) - -add_executable(client Client.cpp Printer.ice) -slice2cpp_generate(client) -target_link_libraries(client Ice::Ice) - -add_executable(server Server.cpp PrinterI.cpp PrinterI.h Printer.ice) -slice2cpp_generate(server) -target_link_libraries(server Ice::Ice) diff --git a/cpp/Ice/invoke/Client.cpp b/cpp/Ice/invoke/Client.cpp deleted file mode 100644 index 55cd95b19..000000000 --- a/cpp/Ice/invoke/Client.cpp +++ /dev/null @@ -1,323 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "Printer.h" -#include -#include - -using namespace std; -using namespace Demo; - -int run(const shared_ptr&); - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.client"); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - status = run(ich.communicator()); - } - } - catch (const std::exception& ex) - { - cerr << argv[0] << ": " << ex.what() << endl; - status = 1; - } - - return status; -} - -void menu(); - -int -run(const shared_ptr& communicator) -{ - auto obj = communicator->propertyToProxy("Printer.Proxy"); - - menu(); - - char ch = 'x'; - do - { - try - { - cout << "==> "; - cin >> ch; - if (ch == '1') - { - // - // Marshal the in parameter. - // - Ice::ByteSeq inParams, outParams; - Ice::OutputStream out(communicator); - out.startEncapsulation(); - out.write("The streaming API works!"); - out.endEncapsulation(); - out.finished(inParams); - - // - // Invoke operation. - // - if (!obj->ice_invoke("printString", Ice::OperationMode::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } - } - else if (ch == '2') - { - // - // Marshal the in parameter. - // - Ice::ByteSeq inParams, outParams; - Ice::OutputStream out(communicator); - out.startEncapsulation(); - const Demo::StringSeq arr({"The", "streaming", "API", "works!"}); - out.write(arr); - out.endEncapsulation(); - out.finished(inParams); - - // - // Invoke operation. - // - if (!obj->ice_invoke("printStringSequence", Ice::OperationMode::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } - } - else if (ch == '3') - { - // - // Marshal the in parameter. - // - Ice::ByteSeq inParams, outParams; - Ice::OutputStream out(communicator); - out.startEncapsulation(); - const Demo::StringDict dict{{"The", "streaming"}, {"API", "works!"}}; - out.write(dict); - out.endEncapsulation(); - out.finished(inParams); - - // - // Invoke operation. - // - if (!obj->ice_invoke("printDictionary", Ice::OperationMode::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } - } - else if (ch == '4') - { - // - // Marshal the in parameter. - // - Ice::ByteSeq inParams, outParams; - Ice::OutputStream out(communicator); - out.startEncapsulation(); - out.write(Color::green); - out.endEncapsulation(); - out.finished(inParams); - - // - // Invoke operation. - // - if (!obj->ice_invoke("printEnum", Ice::OperationMode::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } - } - else if (ch == '5') - { - // - // Marshal the in parameter. - // - Ice::ByteSeq inParams, outParams; - Ice::OutputStream out(communicator); - out.startEncapsulation(); - Demo::Structure s; - s.name = "red"; - s.value = Color::red; - out.write(s); - out.endEncapsulation(); - out.finished(inParams); - - // - // Invoke operation. - // - if (!obj->ice_invoke("printStruct", Ice::OperationMode::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } - } - else if (ch == '6') - { - // - // Marshal the in parameter. - // - Ice::ByteSeq inParams, outParams; - Ice::OutputStream out(communicator); - out.startEncapsulation(); - Demo::StructureSeq arr; - arr.emplace_back(); - arr.back().name = "red"; - arr.back().value = Color::red; - arr.emplace_back(); - arr.back().name = "green"; - arr.back().value = Color::green; - arr.emplace_back(); - arr.back().name = "blue"; - arr.back().value = Color::blue; - out.write(arr); - out.endEncapsulation(); - out.finished(inParams); - - // - // Invoke operation. - // - if (!obj->ice_invoke("printStructSequence", Ice::OperationMode::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } - } - else if (ch == '7') - { - // - // Marshal the in parameter. - // - Ice::ByteSeq inParams, outParams; - Ice::OutputStream out(communicator); - out.startEncapsulation(); - auto c = make_shared(); - c->s.name = "blue"; - c->s.value = Color::blue; - out.write(c); - out.writePendingValues(); - out.endEncapsulation(); - out.finished(inParams); - - // - // Invoke operation. - // - if (!obj->ice_invoke("printClass", Ice::OperationMode::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - } - } - else if (ch == '8') - { - // - // Invoke operation. - // - const Ice::ByteSeq inParams; - Ice::ByteSeq outParams; - if (!obj->ice_invoke("getValues", Ice::OperationMode::Normal, inParams, outParams)) - { - cout << "Unknown user exception" << endl; - continue; - } - - // - // Unmarshal the results. - // - Ice::InputStream in(communicator, outParams); - in.startEncapsulation(); - Demo::CPtr c; - in.read(c); - string str; - in.read(str); - in.readPendingValues(); - in.endEncapsulation(); - cout << "Got string `" << str << "' and class: s.name=" << c->s.name << ", s.value=" << c->s.value - << endl; - } - else if (ch == '9') - { - // - // Invoke operation. - // - const Ice::ByteSeq inParams; - Ice::ByteSeq outParams; - if (obj->ice_invoke("throwPrintFailure", Ice::OperationMode::Normal, inParams, outParams)) - { - cout << "Expected exception" << endl; - continue; - } - - Ice::InputStream in(communicator, outParams); - in.startEncapsulation(); - try - { - in.throwException(); - } - catch (const Demo::PrintFailure&) - { - // Expected. - } - catch (const Ice::UserException&) - { - cout << "Unknown user exception" << endl; - } - in.endEncapsulation(); - } - else if (ch == 's') - { - const Ice::ByteSeq inParams; - Ice::ByteSeq outParams; - obj->ice_invoke("shutdown", Ice::OperationMode::Normal, inParams, outParams); - } - else if (ch == 'x') - { - // Nothing to do. - } - else if (ch == '?') - { - menu(); - } - else - { - cout << "unknown command `" << ch << "'" << endl; - menu(); - } - } - catch (const Ice::Exception& ex) - { - cerr << ex << endl; - } - } while (cin.good() && ch != 'x'); - - return 0; -} - -void -menu() -{ - cout << "usage:\n" - "1: print string\n" - "2: print string sequence\n" - "3: print dictionary\n" - "4: print enum\n" - "5: print struct\n" - "6: print struct sequence\n" - "7: print class\n" - "8: get values\n" - "9: throw exception\n" - "s: shutdown server\n" - "x: exit\n" - "?: help\n"; -} diff --git a/cpp/Ice/invoke/Printer.ice b/cpp/Ice/invoke/Printer.ice deleted file mode 100644 index 5132581e6..000000000 --- a/cpp/Ice/invoke/Printer.ice +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -module Demo -{ - exception PrintFailure - { - string reason; - } - - sequence StringSeq; - - dictionary StringDict; - - enum Color { red, green, blue } - - struct Structure - { - string name; - Color value; - } - - sequence StructureSeq; - - class C - { - Structure s; - } - - interface Printer - { - void printString(string message); - void printStringSequence(StringSeq seq); - void printDictionary(StringDict dict); - void printEnum(Color c); - void printStruct(Structure st); - void printStructSequence(StructureSeq seq); - void printClass(C cls); - C getValues(out string str); - void throwPrintFailure() throws PrintFailure; - void shutdown(); - } -} diff --git a/cpp/Ice/invoke/PrinterI.cpp b/cpp/Ice/invoke/PrinterI.cpp deleted file mode 100644 index 65972914c..000000000 --- a/cpp/Ice/invoke/PrinterI.cpp +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "PrinterI.h" - -#include - -#include - -using namespace std; -using namespace Demo; - -bool -PrinterI::ice_invoke(vector inParams, vector& outParams, const Ice::Current& current) -{ - auto communicator = current.adapter->getCommunicator(); - - bool result = true; // success as opposed to user exception - - Ice::InputStream in(communicator, inParams); - in.startEncapsulation(); - - if (current.operation == "printString") - { - string message; - in.read(message); - cout << "Printing string `" << message << "'" << endl; - } - else if (current.operation == "printStringSequence") - { - Demo::StringSeq seq; - in.read(seq); - cout << "Printing string sequence {"; - for (auto p = seq.begin(); p != seq.end(); ++p) - { - if (p != seq.begin()) - { - cout << ", "; - } - cout << "'" << *p << "'"; - } - cout << "}" << endl; - } - else if (current.operation == "printDictionary") - { - Demo::StringDict dict; - in.read(dict); - cout << "Printing dictionary {"; - for (auto p = dict.begin(); p != dict.end(); ++p) - { - if (p != dict.begin()) - { - cout << ", "; - } - cout << p->first << "=" << p->second; - } - cout << "}" << endl; - } - else if (current.operation == "printEnum") - { - Demo::Color c; - in.read(c); - cout << "Printing enum " << c << endl; - } - else if (current.operation == "printStruct") - { - Demo::Structure s; - in.read(s); - cout << "Printing struct: name=" << s.name << ", value=" << s.value << endl; - } - else if (current.operation == "printStructSequence") - { - Demo::StructureSeq seq; - in.read(seq); - cout << "Printing struct sequence: {"; - for (auto p = seq.begin(); p != seq.end(); ++p) - { - if (p != seq.begin()) - { - cout << ", "; - } - cout << p->name << "=" << p->value; - } - cout << "}" << endl; - } - else if (current.operation == "printClass") - { - shared_ptr c; - in.read(c); - cout << "Printing class: s.name=" << c->s.name << ", s.value=" << c->s.value << endl; - } - else if (current.operation == "getValues") - { - auto c = make_shared(); - c->s.name = "green"; - c->s.value = Color::green; - Ice::OutputStream out(communicator); - out.startEncapsulation(); - out.write(c); - out.write("hello"); - out.endEncapsulation(); - out.finished(outParams); - } - else if (current.operation == "throwPrintFailure") - { - cout << "Throwing PrintFailure" << endl; - Demo::PrintFailure ex; - ex.reason = "paper tray empty"; - Ice::OutputStream out(communicator); - out.startEncapsulation(); - out.write(ex); - out.endEncapsulation(); - out.finished(outParams); - result = false; - } - else if (current.operation == "shutdown") - { - current.adapter->getCommunicator()->shutdown(); - } - else - { - throw Ice::OperationNotExistException(__FILE__, __LINE__, current.id, current.facet, current.operation); - } - - // - // Call endEncapsulation to make sure we read all in parameters - // - in.endEncapsulation(); - return result; -} diff --git a/cpp/Ice/invoke/PrinterI.h b/cpp/Ice/invoke/PrinterI.h deleted file mode 100644 index 19e839d54..000000000 --- a/cpp/Ice/invoke/PrinterI.h +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef PRINTER_I_H -#define PRINTER_I_H - -#include "Printer.h" - -class PrinterI final : public Ice::Blobject -{ -public: - bool ice_invoke(std::vector, std::vector&, const Ice::Current&) final; -}; - -#endif diff --git a/cpp/Ice/invoke/README.md b/cpp/Ice/invoke/README.md deleted file mode 100644 index df6f8ccd7..000000000 --- a/cpp/Ice/invoke/README.md +++ /dev/null @@ -1,40 +0,0 @@ -# Invoke - -This demo illustrates the use of the Ice [streaming API][1]. - -To build the demo run: - -```shell -cmake -B build -cmake --build build --config Release -``` - -To run the demo, first start the server: - -**Linux/macOS:** - -```shell -./build/server -``` - -**Windows:** - -```shell -build\Release\server -``` - -In a separate window, start the client: - -**Linux/macOS:** - -```shell -./build/client -``` - -**Windows:** - -```shell -build\Release\client -``` - -[1]: https://doc.zeroc.com/ice/3.7/client-server-features/dynamic-ice/streaming-interfaces diff --git a/cpp/Ice/invoke/Server.cpp b/cpp/Ice/invoke/Server.cpp deleted file mode 100644 index 7b2ecfe8b..000000000 --- a/cpp/Ice/invoke/Server.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "PrinterI.h" - -#include - -#include - -using namespace std; - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CtrlCHandler must be created before the communicator or any other threads are started - // - Ice::CtrlCHandler ctrlCHandler; - - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.server"); - const auto& communicator = ich.communicator(); - - ctrlCHandler.setCallback([communicator](int) { communicator->shutdown(); }); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - auto adapter = communicator->createObjectAdapter("Printer"); - adapter->add(make_shared(), Ice::stringToIdentity("printer")); - adapter->activate(); - - communicator->waitForShutdown(); - } - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} diff --git a/cpp/Ice/invoke/config.client b/cpp/Ice/invoke/config.client deleted file mode 100644 index 57dbb6bf2..000000000 --- a/cpp/Ice/invoke/config.client +++ /dev/null @@ -1,47 +0,0 @@ -# -# The client reads this property to create the reference to the -# "Printer" object in the server. -# -Printer.Proxy=printer:default -h localhost -p 10000 - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Security Tracing -# -# 0 = no security tracing -# 1 = trace messages -# -#IceSSL.Trace.Security=1 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=client.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/client.keychain -IceSSL.KeychainPassword=password diff --git a/cpp/Ice/invoke/config.server b/cpp/Ice/invoke/config.server deleted file mode 100644 index f3b470e50..000000000 --- a/cpp/Ice/invoke/config.server +++ /dev/null @@ -1,48 +0,0 @@ -# -# The server creates one single object adapter with the name -# "Printer". The following line sets the endpoints for this -# adapter. -# -Printer.Endpoints=default -h localhost -p 10000 - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Security Tracing -# -# 0 = no security tracing -# 1 = trace messages -# -#IceSSL.Trace.Security=1 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=server.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/server.keychain -IceSSL.KeychainPassword=password diff --git a/cpp/Ice/latency/CMakeLists.txt b/cpp/Ice/latency/CMakeLists.txt deleted file mode 100644 index 4186bf4f9..000000000 --- a/cpp/Ice/latency/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -project(latency CXX) - -include(../../cmake/common.cmake) - -add_executable(client Client.cpp Latency.ice) -slice2cpp_generate(client) -target_link_libraries(client Ice::Ice) - -add_executable(server Server.cpp Latency.ice) -slice2cpp_generate(server) -target_link_libraries(server Ice::Ice) diff --git a/cpp/Ice/latency/Client.cpp b/cpp/Ice/latency/Client.cpp deleted file mode 100644 index 7278838b5..000000000 --- a/cpp/Ice/latency/Client.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "Latency.h" -#include -#include - -using namespace std; -using namespace Demo; - -int run(const shared_ptr&, const string&); - -int -main(int argc, char* argv[]) -{ -#ifdef ICE_STATIC_LIBS - Ice::registerIceWS(); -#endif - - int status = 0; - - try - { - // - // CtrlCHandler must be created before the communicator or any other threads are started - // - Ice::CtrlCHandler ctrlCHandler; - - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.client"); - const auto& communicator = ich.communicator(); - - ctrlCHandler.setCallback([communicator](int) { communicator->destroy(); }); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - status = run(communicator, argv[0]); - } - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} - -int -run(const shared_ptr& communicator, const string& appName) -{ - auto ping = Ice::checkedCast(communicator->propertyToProxy("Ping.Proxy")); - if (!ping) - { - cerr << appName << ": invalid proxy" << endl; - return 1; - } - - // Initial ping to setup the connection. - ping->ice_ping(); - - auto start = chrono::high_resolution_clock::now(); - - const int repetitions = 100000; - cout << "pinging server " << repetitions << " times (this may take a while)" << endl; - for (int i = 0; i < repetitions; ++i) - { - ping->ice_ping(); - } - - auto duration = chrono::duration(chrono::high_resolution_clock::now() - start); - cout << "time for " << repetitions << " pings: " << duration.count() << "ms" << endl; - cout << "time per ping: " << duration.count() / repetitions << "ms" << endl; - - return 0; -} diff --git a/cpp/Ice/latency/Latency.ice b/cpp/Ice/latency/Latency.ice deleted file mode 100644 index b684aad95..000000000 --- a/cpp/Ice/latency/Latency.ice +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -module Demo -{ - interface Ping - { - } -} diff --git a/cpp/Ice/latency/README.md b/cpp/Ice/latency/README.md deleted file mode 100644 index 30c208535..000000000 --- a/cpp/Ice/latency/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Latency - -A simple latency test that measures the basic call dispatch delay of Ice. - -To build the demo run: - -```shell -cmake -B build -cmake --build build --config Release -``` - -To run the demo, first start the server: - -**Linux/macOS:** - -```shell -./build/server -``` - -**Windows:** - -```shell -build\Release\server -``` - -In a separate window, start the client: - -**Linux/macOS:** - -```shell -./build/client -``` - -**Windows:** - -```shell -build\Release\client -``` diff --git a/cpp/Ice/latency/Server.cpp b/cpp/Ice/latency/Server.cpp deleted file mode 100644 index 5713e0690..000000000 --- a/cpp/Ice/latency/Server.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "Latency.h" - -#include - -#include - -using namespace std; -using namespace Demo; - -int -main(int argc, char* argv[]) -{ -#ifdef ICE_STATIC_LIBS - Ice::registerIceWS(); -#endif - - int status = 0; - - try - { - // - // CtrlCHandler must be created before the communicator or any other threads are started - // - Ice::CtrlCHandler ctrlCHandler; - - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.server"); - const auto& communicator = ich.communicator(); - - ctrlCHandler.setCallback([communicator](int) { communicator->shutdown(); }); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - auto adapter = communicator->createObjectAdapter("Latency"); - adapter->add(make_shared(), Ice::stringToIdentity("ping")); - adapter->activate(); - - communicator->waitForShutdown(); - } - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} diff --git a/cpp/Ice/latency/config.client b/cpp/Ice/latency/config.client deleted file mode 100644 index dd3b3f64a..000000000 --- a/cpp/Ice/latency/config.client +++ /dev/null @@ -1,41 +0,0 @@ -# -# The client reads this property to create the reference to the "Ping" -# object in the server. -# -Ping.Proxy=ping:tcp -p 10000 -#Ping.Proxy=ping:ssl -p 10001 - -# -# Uncomment to use the WebSocket transports instead. -# -#Ping.Proxy=ping:ws -p 10002 -#Ping.Proxy=ping:wss -p 10003 - -# -# Only connect to the localhost interface by default. -# -Ice.Default.Host=localhost - -# -# Disable client-side ACM. -# -Ice.ACM.Client.Timeout=0 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=client.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/client.keychain -IceSSL.KeychainPassword=password - -# -# IceMX configuration. -# -#Ice.Admin.Endpoints=tcp -p 10004 -Ice.Admin.InstanceName=client -IceMX.Metrics.Debug.GroupBy=id -IceMX.Metrics.ByParent.GroupBy=parent diff --git a/cpp/Ice/latency/config.server b/cpp/Ice/latency/config.server deleted file mode 100644 index abb4ccc34..000000000 --- a/cpp/Ice/latency/config.server +++ /dev/null @@ -1,50 +0,0 @@ -# -# The server creates one single object adapter with the name -# "Latency". The following line sets the endpoints for this adapter. -# -Latency.Endpoints=tcp -p 10000:ssl -p 10001:ws -p 10002:wss -p 10003 - -# -# Only listen on the localhost interface by default. You can comment -# out this property to allow listening on all available interfaces. -# -Ice.Default.Host=localhost - -# -# For JavaScript browser clients using a secure WebSocket (WSS), -# you should disable this property. Client-side authentication -# is not supported with JavaScript browser clients. -# -#IceSSL.VerifyPeer=0 - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# Enable thread pool serialization on the server side. -# This makes the latency slightly lower on Windows as the -# reply is sent to the client prior to the restart of the -# read socket. -# -Ice.ThreadPool.Server.Serialize=1 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=server.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/server.keychain -IceSSL.KeychainPassword=password - -# -# IceMX configuration. -# -#Ice.Admin.Endpoints=tcp -p 10004 -Ice.Admin.InstanceName=server -IceMX.Metrics.Debug.GroupBy=id -IceMX.Metrics.ByParent.GroupBy=parent diff --git a/cpp/Ice/locator/CMakeLists.txt b/cpp/Ice/locator/CMakeLists.txt deleted file mode 100644 index 5c86cbdf1..000000000 --- a/cpp/Ice/locator/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -project(locator CXX) - -include(../../cmake/common.cmake) - -add_executable(client Client.cpp Hello.ice) -slice2cpp_generate(client) -target_link_libraries(client Ice::Ice) - -add_executable(server Server.cpp HelloI.cpp HelloI.h Hello.ice) -slice2cpp_generate(server) -target_link_libraries(server Ice::Ice) - -add_executable(locator Locator.cpp) -slice2cpp_generate(locator) -target_link_libraries(locator Ice::Ice) diff --git a/cpp/Ice/locator/Client.cpp b/cpp/Ice/locator/Client.cpp deleted file mode 100644 index 7ac9c7416..000000000 --- a/cpp/Ice/locator/Client.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include "Hello.h" -#include -#include - -using namespace std; -using namespace Demo; - -int run(const shared_ptr&); - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.client"); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - status = run(ich.communicator()); - } - } - catch (const std::exception& ex) - { - cerr << argv[0] << ": " << ex.what() << endl; - status = 1; - } - - return status; -} - -void menu(); - -int -run(const shared_ptr& communicator) -{ - auto hello = - Ice::checkedCast(communicator->propertyToProxy("Hello.Proxy")->ice_twoway()->ice_secure(false)); - if (!hello) - { - cerr << "invalid proxy" << endl; - return 1; - } - - menu(); - - char c = 'x'; - do - { - try - { - cout << "==> "; - cin >> c; - if (c == 't') - { - hello->sayHello(); - } - else if (c == 's') - { - hello->shutdown(); - } - else if (c == 'x') - { - // Nothing to do - } - else if (c == '?') - { - menu(); - } - else - { - cout << "unknown command `" << c << "'" << endl; - menu(); - } - } - catch (const Ice::Exception& ex) - { - cerr << ex << endl; - } - } while (cin.good() && c != 'x'); - - return 0; -} - -void -menu() -{ - cout << "usage:\n" - "t: send greeting\n" - "s: shutdown server\n" - "x: exit\n" - "?: help\n"; -} diff --git a/cpp/Ice/locator/Hello.ice b/cpp/Ice/locator/Hello.ice deleted file mode 100644 index 7a330b895..000000000 --- a/cpp/Ice/locator/Hello.ice +++ /dev/null @@ -1,14 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#pragma once - -module Demo -{ - interface Hello - { - void sayHello(); - void shutdown(); - } -} diff --git a/cpp/Ice/locator/HelloI.cpp b/cpp/Ice/locator/HelloI.cpp deleted file mode 100644 index 7e91540be..000000000 --- a/cpp/Ice/locator/HelloI.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include "HelloI.h" -#include -#include - -using namespace std; - -void -HelloI::sayHello(const Ice::Current&) -{ - cout << "Hello World!" << endl; -} - -void -HelloI::shutdown(const Ice::Current& c) -{ - cout << "Shutting down..." << endl; - - // - // Unregister from the Locator registry - // - auto communicator = c.adapter->getCommunicator(); - communicator->getDefaultLocator()->getRegistry()->setAdapterDirectProxy("Hello", nullopt); - communicator->shutdown(); -} diff --git a/cpp/Ice/locator/HelloI.h b/cpp/Ice/locator/HelloI.h deleted file mode 100644 index 0719926f3..000000000 --- a/cpp/Ice/locator/HelloI.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#ifndef HELLO_I_H -#define HELLO_I_H - -#include - -class HelloI : public Demo::Hello -{ -public: - void sayHello(const Ice::Current&) override; - void shutdown(const Ice::Current&) override; -}; - -#endif diff --git a/cpp/Ice/locator/Locator.cpp b/cpp/Ice/locator/Locator.cpp deleted file mode 100644 index 033a4f660..000000000 --- a/cpp/Ice/locator/Locator.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include -#include - -using namespace std; - -namespace -{ - - class LocatorRegistryI final : public Ice::LocatorRegistry - { - public: - void setAdapterDirectProxyAsync( - string id, - optional proxy, - function response, - function, - const Ice::Current&) final - { - if (proxy) - { - _adapters.insert({id, std::move(*proxy)}); - } - else - { - _adapters.erase(id); - } - response(); - } - - void setReplicatedAdapterDirectProxyAsync( - string, - string, - optional, - function response, - function, - const Ice::Current&) final - { - assert(false); // Not used by this demo - response(); - } - - void setServerProcessProxyAsync( - string, - optional, - function response, - function, - const Ice::Current&) final - { - assert(false); // Not used by this demo - response(); - } - - optional getAdapter(const string& id) - { - auto p = _adapters.find(id); - if (p == _adapters.end()) - { - throw Ice::AdapterNotFoundException(); - } - return p->second; - } - - private: - map _adapters; - }; - - class LocatorI final : public Ice::Locator - { - public: - LocatorI(shared_ptr registry, optional registryPrx) - : _registry(std::move(registry)), - _registryPrx(std::move(registryPrx)) - { - } - - void findObjectByIdAsync( - Ice::Identity, - function&)> response, - function, - const Ice::Current&) const final - { - response(nullopt); - } - - void findAdapterByIdAsync( - string id, - function&)> response, - function, - const Ice::Current&) const final - { - response(_registry->getAdapter(id)); - } - - [[nodiscard]] - optional getRegistry(const Ice::Current&) const final - { - return _registryPrx; - } - - private: - const shared_ptr _registry; - const optional _registryPrx; - }; - -} - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CtrlCHandler must be created before the communicator or any other threads are started - // - Ice::CtrlCHandler ctrlCHandler; - - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.locator"); - const auto& communicator = ich.communicator(); - - ctrlCHandler.setCallback([communicator](int) { communicator->shutdown(); }); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - auto adapter = communicator->createObjectAdapter("Locator"); - auto registry = make_shared(); - - auto registryPrx = - Ice::uncheckedCast(adapter->add(registry, Ice::stringToIdentity("registry"))); - - adapter->add( - make_shared(std::move(registry), std::move(registryPrx)), - Ice::stringToIdentity("locator")); - adapter->activate(); - - communicator->waitForShutdown(); - } - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} diff --git a/cpp/Ice/locator/README.md b/cpp/Ice/locator/README.md deleted file mode 100644 index 17134fe22..000000000 --- a/cpp/Ice/locator/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# Locator - -This demo illustrates how to write a simple [Locator][1]. - -To build the demo run: - -```shell -cmake -B build -cmake --build build --config Release -``` - -To run the demo, first start the locator: - -**Linux/macOS:** - -```shell -./build/locator -``` - -**Windows:** - -```shell -.\build\Release\locator -``` - -In a separate window, first start the server: - -**Linux/macOS:** - -```shell -./build/server -``` - -**Windows:** - -```shell -.\build\Release\server -``` - -In a separate window, start the client: - -**Linux/macOS:** - -```shell -./build/client -``` - -**Windows:** - -```shell -.\build\Release\client -``` - -[1]: https://doc.zeroc.com/ice/3.7/client-server-features/locators diff --git a/cpp/Ice/locator/Server.cpp b/cpp/Ice/locator/Server.cpp deleted file mode 100644 index 9da1fbff4..000000000 --- a/cpp/Ice/locator/Server.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright (c) ZeroC, Inc. All rights reserved. -// - -#include "HelloI.h" -#include -#include - -using namespace std; - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CtrlCHandler must be created before the communicator or any other threads are started - // - Ice::CtrlCHandler ctrlCHandler; - - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.server"); - const auto& communicator = ich.communicator(); - - ctrlCHandler.setCallback([communicator](int) { communicator->shutdown(); }); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - auto adapter = communicator->createObjectAdapter("Hello"); - adapter->add(make_shared(), Ice::stringToIdentity("hello")); - adapter->activate(); - - communicator->waitForShutdown(); - } - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} diff --git a/cpp/Ice/locator/config.client b/cpp/Ice/locator/config.client deleted file mode 100644 index 4e560844f..000000000 --- a/cpp/Ice/locator/config.client +++ /dev/null @@ -1,37 +0,0 @@ -# -# The custom locator proxy. -# -Ice.Default.Locator=locator:tcp -p 10000 - -# -# The indirect proxy for hello object. -# -Hello.Proxy=hello@Hello - -# -# Only connect to the localhost interface by default. -# -Ice.Default.Host=localhost - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 diff --git a/cpp/Ice/locator/config.locator b/cpp/Ice/locator/config.locator deleted file mode 100644 index 7ea33aa95..000000000 --- a/cpp/Ice/locator/config.locator +++ /dev/null @@ -1,35 +0,0 @@ -# -# The locator creates one single object adapter with the name -# "Locator". The following line sets the endpoints for this -# adapter. -# -Locator.Endpoints=tcp -p 10000 - -# -# Only listen on the localhost interface by default. You can comment -# out this property to allow listening on all available interfaces. -# -Ice.Default.Host=localhost - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 diff --git a/cpp/Ice/locator/config.server b/cpp/Ice/locator/config.server deleted file mode 100644 index 36adc4042..000000000 --- a/cpp/Ice/locator/config.server +++ /dev/null @@ -1,46 +0,0 @@ -# -# The custom locator proxy. -# -Ice.Default.Locator=locator:tcp -p 10000 - -# -# The server creates one single object adapter with the name -# "Hello". The following line sets the endpoints for this -# adapter. Since no port is specified, one will be assigned -# by the OS. -# -Hello.Endpoints=tcp - -# -# The following causes the server to register with the locator -# -Hello.AdapterId=Hello - -# -# Only listen on the localhost interface by default. You can comment -# out this property to allow listening on all available interfaces. -# -Ice.Default.Host=localhost - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 diff --git a/cpp/Ice/locator/log.txt b/cpp/Ice/locator/log.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/cpp/Ice/nested/CMakeLists.txt b/cpp/Ice/nested/CMakeLists.txt deleted file mode 100644 index f2a0205d9..000000000 --- a/cpp/Ice/nested/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -project(nested CXX) - -include(../../cmake/common.cmake) - -add_executable(client Client.cpp NestedI.cpp NestedI.h Nested.ice) -slice2cpp_generate(client) -target_link_libraries(client Ice::Ice) - -add_executable(server Server.cpp NestedI.cpp NestedI.h Nested.ice) -slice2cpp_generate(server) -target_link_libraries(server Ice::Ice) diff --git a/cpp/Ice/nested/Client.cpp b/cpp/Ice/nested/Client.cpp deleted file mode 100644 index 4c8063948..000000000 --- a/cpp/Ice/nested/Client.cpp +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "NestedI.h" -#include -#include - -using namespace std; -using namespace Demo; - -int run(const shared_ptr&); - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.client"); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - status = run(ich.communicator()); - } - } - catch (const std::exception& ex) - { - cerr << argv[0] << ": " << ex.what() << endl; - status = 1; - } - - return status; -} - -int -run(const shared_ptr& communicator) -{ - auto nested = Ice::checkedCast(communicator->propertyToProxy("Nested.Proxy")); - if (!nested) - { - cerr << "invalid proxy" << endl; - return 1; - } - - // - // Ensure the invocation times out if the nesting level is too - // high and there are no more threads in the thread pool to - // dispatch the call. - // - nested = nested->ice_invocationTimeout(5000); - - auto adapter = communicator->createObjectAdapter("Nested.Client"); - auto self = Ice::uncheckedCast(adapter->createProxy(Ice::stringToIdentity("nestedClient"))); - auto servant = make_shared(self); - adapter->add(servant, Ice::stringToIdentity("nestedClient")); - adapter->activate(); - - cout << "Note: The maximum nesting level is sz * 2, with sz being\n" - << "the maximum number of threads in the server thread pool. if\n" - << "you specify a value higher than that, the application will\n" - << "block or timeout.\n" - << endl; - - string s; - do - { - try - { - cout << "enter nesting level or 'x' for exit: "; - cin >> s; - int level = stoi(s.c_str()); - if (level > 0) - { - nested->nestedCall(level, self); - } - } - catch (const Ice::Exception& ex) - { - cerr << ex << endl; - } - } while (cin.good() && s != "x"); - - return 0; -} diff --git a/cpp/Ice/nested/Nested.ice b/cpp/Ice/nested/Nested.ice deleted file mode 100644 index 8399e62fb..000000000 --- a/cpp/Ice/nested/Nested.ice +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -module Demo -{ - interface Nested - { - void nestedCall(int level, Nested* proxy); - } -} diff --git a/cpp/Ice/nested/NestedI.cpp b/cpp/Ice/nested/NestedI.cpp deleted file mode 100644 index 96ca7e6a9..000000000 --- a/cpp/Ice/nested/NestedI.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "NestedI.h" -#include -#include - -using namespace std; -using namespace Demo; - -NestedI::NestedI(optional self) : _self(std::move(self)) {} - -void -NestedI::nestedCall(int level, optional proxy, const Ice::Current&) -{ - cout << level << endl; - if (--level > 0) - { - // - // Ensure the invocation times out if the nesting level is too - // high and there are no more threads in the thread pool to - // dispatch the call. - // - proxy->ice_invocationTimeout(5000)->nestedCall(level, _self); - } -} diff --git a/cpp/Ice/nested/NestedI.h b/cpp/Ice/nested/NestedI.h deleted file mode 100644 index a69e7416e..000000000 --- a/cpp/Ice/nested/NestedI.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef NESTED_I_H -#define NESTED_I_H - -#include "Nested.h" - -class NestedI final : public Demo::Nested -{ -public: - NestedI(std::optional); - void nestedCall(int, std::optional, const Ice::Current&) final; - -private: - const std::optional _self; -}; - -#endif diff --git a/cpp/Ice/nested/README.md b/cpp/Ice/nested/README.md deleted file mode 100644 index ce4e0ecbb..000000000 --- a/cpp/Ice/nested/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# Nested - -A demo to illustrate how [nested callbacks][1] work, and how the size of -the thread pool affects the maximum nesting depth. - -To build the demo run: - -```shell -cmake -B build -cmake --build build --config Release -``` - -To run the demo, first start the server: - -**Linux/macOS:** - -```shell -./build/server -``` - -**Windows:** - -```shell -build\Release\server -``` - -In a separate window, start the client: - -**Linux/macOS:** - -```shell -./build/client -``` - -**Windows:** - -```shell -build\Release\client -``` - -[1]: https://doc.zeroc.com/ice/3.7/client-server-features/the-ice-threading-model/nested-invocations diff --git a/cpp/Ice/nested/Server.cpp b/cpp/Ice/nested/Server.cpp deleted file mode 100644 index 26f113f4d..000000000 --- a/cpp/Ice/nested/Server.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "NestedI.h" -#include -#include - -using namespace std; -using namespace Demo; - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CtrlCHandler must be created before the communicator or any other threads are started - // - Ice::CtrlCHandler ctrlCHandler; - - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.server"); - const auto& communicator = ich.communicator(); - - ctrlCHandler.setCallback([communicator](int) { communicator->shutdown(); }); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - auto adapter = communicator->createObjectAdapter("Nested.Server"); - auto self = Ice::uncheckedCast(adapter->createProxy(Ice::stringToIdentity("nestedServer"))); - auto servant = make_shared(self); - adapter->add(servant, Ice::stringToIdentity("nestedServer")); - adapter->activate(); - - communicator->waitForShutdown(); - } - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} diff --git a/cpp/Ice/nested/config.client b/cpp/Ice/nested/config.client deleted file mode 100644 index 37d73206d..000000000 --- a/cpp/Ice/nested/config.client +++ /dev/null @@ -1,65 +0,0 @@ -# -# The client reads this property to create the reference to the -# "Nested" object in the server. -# -Nested.Proxy=nestedServer:default -h localhost -p 10000 - -# -# The client creates one single object adapter with the name -# "Nested.Client". The following line sets the endpoints for this -# adapter. -# -Nested.Client.Endpoints=default -h localhost - -# -# The following properties configure the server thread pool. The -# thread pool initially contains 5 threads, and the Ice run time -# starts emitting warnings once 5 threads are in use. The Ice run time -# creates more threads once all 5 are in use, up to a maximum of 10 -# threads. -# -Ice.ThreadPool.Server.Size=5 -Ice.ThreadPool.Server.SizeWarn=5 -Ice.ThreadPool.Server.SizeMax=10 - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Security Tracing -# -# 0 = no security tracing -# 1 = trace messages -# -#IceSSL.Trace.Security=1 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=client.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/client.keychain -IceSSL.KeychainPassword=password diff --git a/cpp/Ice/nested/config.server b/cpp/Ice/nested/config.server deleted file mode 100644 index a44ebc21b..000000000 --- a/cpp/Ice/nested/config.server +++ /dev/null @@ -1,59 +0,0 @@ -# -# The server creates one single object adapter with the name -# "Nested.Server". The following line sets the endpoints for this -# adapter. -# -Nested.Server.Endpoints=default -h localhost -p 10000 - -# -# The following properties configure the server thread pool. The -# thread pool initially contains 5 threads, and the Ice run time -# starts emitting warnings once 5 threads are in use. The Ice run time -# creates more threads once all 5 are in use, up to a maximum of 10 -# threads. -# -Ice.ThreadPool.Server.Size=5 -Ice.ThreadPool.Server.SizeWarn=5 -Ice.ThreadPool.Server.SizeMax=10 - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -#Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Security Tracing -# -# 0 = no security tracing -# 1 = trace messages -# -#IceSSL.Trace.Security=1 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=server.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/server.keychain -IceSSL.KeychainPassword=password diff --git a/cpp/Ice/plugin/Client.cpp b/cpp/Ice/plugin/Client.cpp deleted file mode 100644 index de80c845e..000000000 --- a/cpp/Ice/plugin/Client.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "Hello.h" -#include -#include - -using namespace std; -using namespace Demo; - -int run(const shared_ptr&); - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.client"); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - status = run(ich.communicator()); - } - } - catch (const std::exception& ex) - { - cerr << argv[0] << ": " << ex.what() << endl; - status = 1; - } - - return status; -} - -void menu(); - -int -run(const shared_ptr& communicator) -{ - auto hello = Ice::checkedCast(communicator->propertyToProxy("Hello.Proxy")); - if (!hello) - { - cerr << "invalid proxy" << endl; - return 1; - } - - menu(); - - char c = 'x'; - do - { - try - { - cout << "==> "; - cin >> c; - if (c == 't') - { - hello->sayHello(); - } - else if (c == 's') - { - hello->shutdown(); - } - else if (c == 'x') - { - // Nothing to do - } - else if (c == '?') - { - menu(); - } - else - { - cout << "unknown command `" << c << "'" << endl; - menu(); - } - } - catch (const Ice::Exception& ex) - { - cerr << ex << endl; - } - } while (cin.good() && c != 'x'); - - return 0; -} - -void -menu() -{ - cout << "usage:\n" - "t: send greeting\n" - "s: shutdown server\n" - "x: exit\n" - "?: help\n"; -} diff --git a/cpp/Ice/plugin/Hello.ice b/cpp/Ice/plugin/Hello.ice deleted file mode 100644 index 7d6d601b8..000000000 --- a/cpp/Ice/plugin/Hello.ice +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -module Demo -{ - interface Hello - { - idempotent void sayHello(); - void shutdown(); - } -} diff --git a/cpp/Ice/plugin/HelloPluginI.cpp b/cpp/Ice/plugin/HelloPluginI.cpp deleted file mode 100644 index 60526ea88..000000000 --- a/cpp/Ice/plugin/HelloPluginI.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "Hello.h" - -#include - -using namespace std; - -namespace -{ - - class HelloI final : public Demo::Hello - { - public: - void sayHello(const Ice::Current& current) final - { - current.adapter->getCommunicator()->getLogger()->print("Hello World!"); - } - - void shutdown(const Ice::Current& current) final - { - current.adapter->getCommunicator()->getLogger()->print("Shutting down..."); - current.adapter->getCommunicator()->shutdown(); - } - }; - - class HelloPluginI final : public Ice::Plugin - { - public: - HelloPluginI(const shared_ptr& communicator) : _communicator(communicator) {} - - void initialize() final - { - auto adapter = _communicator->createObjectAdapter("Hello"); - adapter->add(make_shared(), Ice::stringToIdentity("hello")); - adapter->activate(); - } - - void destroy() final {} - - private: - shared_ptr _communicator; - }; - -}; - -extern "C" -{ - ICE_DECLSPEC_EXPORT ::Ice::Plugin* - createHello(const shared_ptr& communicator, const string&, const Ice::StringSeq&) - { - return new HelloPluginI(communicator); - } -} diff --git a/cpp/Ice/plugin/LoggerPluginI.cpp b/cpp/Ice/plugin/LoggerPluginI.cpp deleted file mode 100644 index f4429f539..000000000 --- a/cpp/Ice/plugin/LoggerPluginI.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include - -#include - -using namespace std; - -namespace -{ - - class LoggerI final : public Ice::Logger - { - public: - void print(const string& message) final { cout << "PRINT: " << message << endl; } - - void trace(const string& category, const string& message) final - { - cout << "TRACE(" << category << "): " << message << endl; - } - - void warning(const string& message) final { cout << "WARNING: " << message << endl; } - - void error(const string& message) final { cout << "ERROR: " << message << endl; } - - string getPrefix() final { return ""; } - - shared_ptr cloneWithPrefix(std::string) final { return make_shared(); } - }; - -} - -extern "C" -{ - ICE_DECLSPEC_EXPORT ::Ice::Plugin* - createLogger(const shared_ptr& communicator, const string&, const Ice::StringSeq&) - { - return new Ice::LoggerPlugin(communicator, make_shared()); - } -} diff --git a/cpp/Ice/plugin/README.md b/cpp/Ice/plugin/README.md deleted file mode 100644 index 2ccd4b2ac..000000000 --- a/cpp/Ice/plugin/README.md +++ /dev/null @@ -1,22 +0,0 @@ -This demo illustrates how to write and configure a simple Ice [plug-in][1] -as well as an Ice [Logger plug-in][2]. - -To run the demo, first start the server: -``` -server -``` - -In a separate window, start the client: -``` -client -``` - -Both the client and server use a custom logger that is loaded as -a logger plug-in. The server also uses a plug-in to implement the -servant for this demo. - -Please review the client and server configuration files to see the -plug-in configuration. - -[1]: https://doc.zeroc.com/ice/3.7/communicator-and-other-core-local-features/plug-in-facility -[2]: https://doc.zeroc.com/ice/3.7/administration-and-diagnostics/logger-facility/logger-plug-ins diff --git a/cpp/Ice/plugin/Server.cpp b/cpp/Ice/plugin/Server.cpp deleted file mode 100644 index 826ec8591..000000000 --- a/cpp/Ice/plugin/Server.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include -#include - -using namespace std; - -int -main(int argc, char* argv[]) -{ - int status = 0; - - try - { - // - // CtrlCHandler must be created before the communicator or any other threads are started - // - Ice::CtrlCHandler ctrlCHandler; - - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.server"); - const auto& communicator = ich.communicator(); - - ctrlCHandler.setCallback([communicator](int) { communicator->shutdown(); }); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - communicator->waitForShutdown(); - } - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} diff --git a/cpp/Ice/plugin/config.client b/cpp/Ice/plugin/config.client deleted file mode 100644 index 758ecfb80..000000000 --- a/cpp/Ice/plugin/config.client +++ /dev/null @@ -1,33 +0,0 @@ -# -# The client reads this property to create the reference to the -# "hello" object in the server. -# -Hello.Proxy=hello:tcp -h localhost -p 10000 - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Logger Plugin Configuration -# -Ice.Plugin.Logger=./LoggerPlugin:createLogger diff --git a/cpp/Ice/plugin/config.server b/cpp/Ice/plugin/config.server deleted file mode 100644 index 30fa48a67..000000000 --- a/cpp/Ice/plugin/config.server +++ /dev/null @@ -1,33 +0,0 @@ -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# Network Tracing -# -# 0 = no network tracing -# 1 = trace connection establishment and closure -# 2 = like 1, but more detailed -# 3 = like 2, but also trace data transfer -# -Ice.Trace.Network=1 - -# -# Protocol Tracing -# -# 0 = no protocol tracing -# 1 = trace protocol messages -# -#Ice.Trace.Protocol=1 - -# -# Logger Plugin Configuration -# -Ice.Plugin.Logger=./LoggerPlugin:createLogger - -# -# Hello Plugin Configuration -# -Ice.Plugin.Hello=./HelloPlugin:createHello -Hello.Endpoints=tcp -h localhost -p 10000 diff --git a/cpp/Ice/throughput/CMakeLists.txt b/cpp/Ice/throughput/CMakeLists.txt deleted file mode 100644 index f7c30abda..000000000 --- a/cpp/Ice/throughput/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -project(throughput CXX) - -include(../../cmake/common.cmake) - -add_executable(client Client.cpp Throughput.ice) -slice2cpp_generate(client) -target_link_libraries(client Ice::Ice) - -add_executable(server Server.cpp ThroughputI.cpp ThroughputI.h Throughput.ice) -slice2cpp_generate(server) -target_link_libraries(server Ice::Ice) diff --git a/cpp/Ice/throughput/Client.cpp b/cpp/Ice/throughput/Client.cpp deleted file mode 100644 index a25a188ff..000000000 --- a/cpp/Ice/throughput/Client.cpp +++ /dev/null @@ -1,452 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "Throughput.h" -#include -#include -#include - -using namespace std; -using namespace Demo; - -int run(const shared_ptr&); - -int -main(int argc, char* argv[]) -{ -#ifdef ICE_STATIC_LIBS - Ice::registerIceWS(); -#endif - - int status = 0; - - try - { - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.client"); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - status = run(ich.communicator()); - } - } - catch (const std::exception& ex) - { - cerr << argv[0] << ": " << ex.what() << endl; - status = 1; - } - - return status; -} - -void menu(); - -int -run(const shared_ptr& communicator) -{ - auto throughput = Ice::checkedCast(communicator->propertyToProxy("Throughput.Proxy")); - if (!throughput) - { - cerr << "invalid proxy" << endl; - return 1; - } - - auto throughputOneway = throughput->ice_oneway(); - - ByteSeq byteSeq(ByteSeqSize); - auto byteArr = make_pair(byteSeq.data(), byteSeq.data() + byteSeq.size()); - - StringSeq stringSeq(StringSeqSize, "hello"); - const vector stringViewSeq(StringSeqSize, "hello"); - - StringDoubleSeq structSeq(StringDoubleSeqSize, {"hello", 3.14}); - const FixedSeq fixedSeq(FixedSeqSize, {0, 0, 0.0}); - - // - // To allow cross-language tests we may need to "warm up" the - // server. The warm up is to ensure that any JIT compiler will - // have converted any hotspots to native code. This ensures an - // accurate throughput measurement. - // - if (throughput->needsWarmup()) - { - throughput->startWarmup(); - - ByteSeq warmupBytesBuf(1); - auto warmupBytes = make_pair(warmupBytesBuf.data(), warmupBytesBuf.data() + warmupBytesBuf.size()); - - const vector warmupStringViews(1); - const StringDoubleSeq warmupStructs(1); - const FixedSeq warmupFixed(1); - - cout << "warming up the server... " << flush; - for (int i = 0; i < 10000; i++) - { - throughput->sendByteSeq(warmupBytes); - throughput->sendStringSeq(warmupStringViews); - throughput->sendStructSeq(warmupStructs); - throughput->sendFixedSeq(warmupFixed); - - throughput->recvByteSeq(); - throughput->recvStringSeq(); - throughput->recvStructSeq(); - throughput->recvFixedSeq(); - - throughput->echoByteSeq(warmupBytes); - throughput->echoStringSeq(warmupStringViews); - throughput->echoStructSeq(warmupStructs); - throughput->echoFixedSeq(warmupFixed); - } - - throughput->endWarmup(); - - cout << " ok" << endl; - } - else - { - throughput->ice_ping(); // Initial ping to setup the connection. - } - - menu(); - - // - // By default use byte sequence. - // - char currentType = '1'; - int seqSize = ByteSeqSize; - - char c = 'x'; - do - { - try - { - cout << "==> "; - cin >> c; - - auto start = chrono::high_resolution_clock::now(); - int repetitions = 100; - - if (c == '1' || c == '2' || c == '3' || c == '4') - { - currentType = c; - switch (c) - { - case '1': - { - cout << "using byte sequences" << endl; - seqSize = ByteSeqSize; - break; - } - - case '2': - { - cout << "using string sequences" << endl; - seqSize = StringSeqSize; - break; - } - - case '3': - { - cout << "using variable-length struct sequences" << endl; - seqSize = StringDoubleSeqSize; - break; - } - - case '4': - { - cout << "using fixed-length struct sequences" << endl; - seqSize = FixedSeqSize; - break; - } - } - } - else if (c == 't' || c == 'o' || c == 'r' || c == 'e') - { - if (currentType == '1') - { - repetitions = 1000; // Use more iterations for byte sequences as it's a lot faster - } - - switch (c) - { - case 't': - case 'o': - { - cout << "sending"; - break; - } - - case 'r': - { - cout << "receiving"; - break; - } - - case 'e': - { - cout << "sending and receiving"; - break; - } - } - - cout << ' ' << repetitions; - switch (currentType) - { - case '1': - { - cout << " byte"; - break; - } - - case '2': - { - cout << " string"; - break; - } - - case '3': - { - cout << " variable-length struct"; - break; - } - - case '4': - { - cout << " fixed-length struct"; - break; - } - } - cout << " sequences of size " << seqSize; - - if (c == 'o') - { - cout << " as oneway"; - } - - cout << "..." << endl; - - for (int i = 0; i < repetitions; ++i) - { - switch (currentType) - { - case '1': - { - switch (c) - { - case 't': - { - throughput->sendByteSeq(byteArr); - break; - } - - case 'o': - { - throughputOneway->sendByteSeq(byteArr); - break; - } - - case 'r': - { - throughput->recvByteSeq(); - break; - } - - case 'e': - { - throughput->echoByteSeq(byteArr); - break; - } - } - break; - } - - case '2': - { - switch (c) - { - case 't': - { - throughput->sendStringSeq(stringViewSeq); - break; - } - - case 'o': - { - throughputOneway->sendStringSeq(stringViewSeq); - break; - } - - case 'r': - { - throughput->recvStringSeq(); - break; - } - - case 'e': - { - throughput->echoStringSeq(stringViewSeq); - break; - } - } - break; - } - - case '3': - { - switch (c) - { - case 't': - { - throughput->sendStructSeq(structSeq); - break; - } - - case 'o': - { - throughputOneway->sendStructSeq(structSeq); - break; - } - - case 'r': - { - throughput->recvStructSeq(); - break; - } - - case 'e': - { - throughput->echoStructSeq(structSeq); - break; - } - } - break; - } - - case '4': - { - switch (c) - { - case 't': - { - throughput->sendFixedSeq(fixedSeq); - break; - } - - case 'o': - { - throughputOneway->sendFixedSeq(fixedSeq); - break; - } - - case 'r': - { - throughput->recvFixedSeq(); - break; - } - - case 'e': - { - throughput->echoFixedSeq(fixedSeq); - break; - } - } - break; - } - } - } - - auto duration = - chrono::duration(chrono::high_resolution_clock::now() - start); - cout << "time for " << repetitions << " sequences: " << duration.count() << "ms" << endl; - cout << "time per sequence: " << duration.count() / static_cast(repetitions) << "ms" << endl; - int wireSize = 0; - switch (currentType) - { - case '1': - { - wireSize = 1; - break; - } - case '2': - { - wireSize = static_cast(stringSeq[0].size()); - break; - } - case '3': - { - wireSize = static_cast(structSeq[0].s.size()); - wireSize += 8; // Size of double on the wire. - break; - } - case '4': - { - wireSize = 16; // Size of two ints and a double on the wire. - break; - } - } - double mbit = repetitions * seqSize * wireSize * 8.0 / duration.count() / 1000; - if (c == 'e') - { - mbit *= 2; - } - cout << "throughput: " << setprecision(5) << mbit << "Mbps" << endl; - } - else if (c == 's') - { - throughput->shutdown(); - } - else if (c == 'x') - { - // Nothing to do - } - else if (c == '?') - { - menu(); - } - else - { - cout << "unknown command `" << c << "'" << endl; - menu(); - } - } - catch (const Ice::Exception& ex) - { - cerr << ex << endl; - } - } while (cin.good() && c != 'x'); - - return 0; -} - -void -menu() -{ - cout << "usage:\n" - "\n" - "toggle type of data to send:\n" - "1: sequence of bytes (default)\n" - "2: sequence of strings (\"hello\")\n" - "3: sequence of structs with a string (\"hello\") and a double\n" - "4: sequence of structs with two ints and a double\n" - "\n" - "select test to run:\n" - "t: Send sequence as twoway\n" - "o: Send sequence as oneway\n" - "r: Receive sequence\n" - "e: Echo (send and receive) sequence\n" - "\n" - "other commands:\n" - "s: shutdown server\n" - "x: exit\n" - "?: help\n"; -} diff --git a/cpp/Ice/throughput/README.md b/cpp/Ice/throughput/README.md deleted file mode 100644 index 8ddb1f606..000000000 --- a/cpp/Ice/throughput/README.md +++ /dev/null @@ -1,92 +0,0 @@ -A simple throughput demo that allows you to send sequences of various -types between client and server and to measure the maximum bandwidth -that can be achieved using serialized synchronous requests. - -To build the demo run: - -```shell -cmake -B build -cmake --build build --config Release -``` - -To run the demo, first start the server: - -**Linux/macOS:** - -```shell -./build/server -``` - -**Windows:** - -```shell -build\Release\server -``` - -In a separate window, start the client: - -**Linux/macOS:** - -```shell -./build/client -``` - -**Windows:** - -```shell -build\Release\client -``` - -We provide a number of optimizations through metadata in this demo. - -Bytes sequences --------------- - -For in parameters we use the `cpp:array` metadata which on the server -side means that the operation implementation is passed pointers into -the marshaling buffer which eliminates a copy of the sequence data. - -For return parameters we also use the `cpp:array` metadata, but this -time in conjunction with "marshaled result". Doing this also reduces -the number of times the returned sequence is copied during marshaling. - -Strings -------- - -We use a custom mapping for strings: instead of the default `std::string`, -we use our own lightweight `Util::string_view` type, which does not -allocate memory. - -`string_view` is similar to the C++17 `std::string_view`. - -The resulting behavior is similar to the `cpp:array` behavior for bytes -sequences, with the `string_view` "pointing" to the Ice marshaling buffer. - -Like the `cpp:array` metadata, the `cpp:view-type` metadata changes the -mapped type only when it's safe to reference memory. In particular, -`cpp:array` and `cpp:view-type` have no effect for regular returned -parameters and out parameters, such as: -``` -// Slice -["cpp:view-type:`std::vector`<`Util::string_view`>"] StringSeq recvStringSeq(); - -// -// C++ -// Mapped to the default `std::vector`, and not `std::vector`<`Util::string_view`> -// -stringVect = prx->recvStringSeq(); -``` -If you use `cpp:type` above instead of `cpp:view-type`, you would get a -`std::vector`<`Util::string_view`>, with the `string_view` objects pointing to -deallocated memory: -``` -// Slice - you should _not_ use cpp:type here! -["cpp:type:`std::vector`<`Util::string_view`>"] StringSeq recvStringSeq(); - -// -// C++ -// Mapped to `std::vector`<`Util::string_view`> -// -stringViewVect = prx->recvStringSeq(); // very dangerous, as the string_views - // point to deallocated memory -``` diff --git a/cpp/Ice/throughput/Server.cpp b/cpp/Ice/throughput/Server.cpp deleted file mode 100644 index 0ee66fd7e..000000000 --- a/cpp/Ice/throughput/Server.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ThroughputI.h" -#include -#include - -using namespace std; - -int -main(int argc, char* argv[]) -{ -#ifdef ICE_STATIC_LIBS - Ice::registerIceWS(); -#endif - - int status = 0; - - try - { - // - // CtrlCHandler must be created before the communicator or any other threads are started - // - Ice::CtrlCHandler ctrlCHandler; - - // - // CommunicatorHolder's ctor initializes an Ice communicator, - // and its dtor destroys this communicator. - // - const Ice::CommunicatorHolder ich(argc, argv, "config.server"); - const auto& communicator = ich.communicator(); - - ctrlCHandler.setCallback([communicator](int) { communicator->shutdown(); }); - - // - // The communicator initialization removes all Ice-related arguments from argc/argv - // - if (argc > 1) - { - cerr << argv[0] << ": too many arguments" << endl; - status = 1; - } - else - { - auto adapter = communicator->createObjectAdapter("Throughput"); - auto servant = make_shared(); - adapter->add(servant, Ice::stringToIdentity("throughput")); - adapter->activate(); - - communicator->waitForShutdown(); - } - } - catch (const std::exception& ex) - { - cerr << ex.what() << endl; - status = 1; - } - - return status; -} diff --git a/cpp/Ice/throughput/Throughput.ice b/cpp/Ice/throughput/Throughput.ice deleted file mode 100644 index f41fed02f..000000000 --- a/cpp/Ice/throughput/Throughput.ice +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -module Demo -{ - sequence ByteSeq; - const int ByteSeqSize = 500000; - - sequence StringSeq; - const int StringSeqSize = 50000; - - struct StringDouble - { - string s; - double d; - } - sequence StringDoubleSeq; - const int StringDoubleSeqSize = 50000; - - struct Fixed - { - int i; - int j; - double d; - } - sequence FixedSeq; - const int FixedSeqSize = 50000; - - interface Throughput - { - bool needsWarmup(); - void startWarmup(); - void endWarmup(); - - void sendByteSeq(["cpp:array"] ByteSeq seq); - ["marshaled-result", "cpp:array"] ByteSeq recvByteSeq(); - ["marshaled-result", "cpp:array"] ByteSeq echoByteSeq(["cpp:array"] ByteSeq seq); - - void sendStringSeq(StringSeq seq); - ["marshaled-result"] StringSeq recvStringSeq(); - ["marshaled-result"] StringSeq echoStringSeq(StringSeq seq); - - void sendStructSeq(StringDoubleSeq seq); - StringDoubleSeq recvStructSeq(); - StringDoubleSeq echoStructSeq(StringDoubleSeq seq); - - void sendFixedSeq(FixedSeq seq); - FixedSeq recvFixedSeq(); - FixedSeq echoFixedSeq(FixedSeq seq); - - void shutdown(); - } -} diff --git a/cpp/Ice/throughput/ThroughputI.cpp b/cpp/Ice/throughput/ThroughputI.cpp deleted file mode 100644 index 0545ba49f..000000000 --- a/cpp/Ice/throughput/ThroughputI.cpp +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "ThroughputI.h" - -#include - -ThroughputI::ThroughputI() - : _byteSeq(Demo::ByteSeqSize), - _stringSeq(Demo::StringSeqSize, "hello"), - _structSeq(Demo::StringDoubleSeqSize, {"hello", 3.14}), - _fixedSeq(Demo::FixedSeqSize, {0, 0, 0.0}) -{ -} - -bool -ThroughputI::needsWarmup(const Ice::Current&) -{ - _warmup = false; - return false; -} - -void -ThroughputI::startWarmup(const Ice::Current&) -{ - _warmup = true; -} - -void -ThroughputI::endWarmup(const Ice::Current&) -{ - _warmup = false; -} - -void -ThroughputI::sendByteSeq(std::pair, const Ice::Current&) -{ -} - -Demo::Throughput::RecvByteSeqMarshaledResult -ThroughputI::recvByteSeq(const Ice::Current& current) -{ - if (_warmup) - { - Demo::ByteSeq warmupBytesBuf(1); - const std::pair ret = - std::make_pair(warmupBytesBuf.data(), warmupBytesBuf.data() + warmupBytesBuf.size()); - return {ret, current}; - } - else - { - const std::pair ret = - std::make_pair(_byteSeq.data(), _byteSeq.data() + _byteSeq.size()); - return {ret, current}; - } -} - -Demo::Throughput::EchoByteSeqMarshaledResult -ThroughputI::echoByteSeq(std::pair seq, const Ice::Current& current) -{ - return {seq, current}; -} - -void -ThroughputI::sendStringSeq(std::vector, const Ice::Current&) -{ -} - -Demo::Throughput::RecvStringSeqMarshaledResult -ThroughputI::recvStringSeq(const Ice::Current& current) -{ - if (_warmup) - { - return {std::vector(1), current}; - } - else - { - return {_stringSeq, current}; - } -} - -Demo::Throughput::EchoStringSeqMarshaledResult -ThroughputI::echoStringSeq(std::vector seq, const Ice::Current& current) -{ - return {seq, current}; -} - -void -ThroughputI::sendStructSeq(Demo::StringDoubleSeq, const Ice::Current&) -{ -} - -Demo::StringDoubleSeq -ThroughputI::recvStructSeq(const Ice::Current&) -{ - if (_warmup) - { - return Demo::StringDoubleSeq(1); - } - else - { - return _structSeq; - } -} - -Demo::StringDoubleSeq -ThroughputI::echoStructSeq(Demo::StringDoubleSeq seq, const Ice::Current&) -{ - return seq; -} - -void -ThroughputI::sendFixedSeq(Demo::FixedSeq, const Ice::Current&) -{ -} - -Demo::FixedSeq -ThroughputI::recvFixedSeq(const Ice::Current&) -{ - if (_warmup) - { - return Demo::FixedSeq(1); - } - else - { - return _fixedSeq; - } -} - -Demo::FixedSeq -ThroughputI::echoFixedSeq(Demo::FixedSeq seq, const Ice::Current&) -{ - return seq; -} - -void -ThroughputI::shutdown(const Ice::Current& current) -{ - current.adapter->getCommunicator()->shutdown(); -} diff --git a/cpp/Ice/throughput/ThroughputI.h b/cpp/Ice/throughput/ThroughputI.h deleted file mode 100644 index 3e5db9636..000000000 --- a/cpp/Ice/throughput/ThroughputI.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#ifndef THROUGHPUT_I_H -#define THROUGHPUT_I_H - -#include "Throughput.h" - -class ThroughputI final : public Demo::Throughput -{ -public: - ThroughputI(); - - bool needsWarmup(const Ice::Current&) final; - void startWarmup(const Ice::Current&) final; - void endWarmup(const Ice::Current&) final; - - void sendByteSeq(std::pair, const Ice::Current&) final; - RecvByteSeqMarshaledResult recvByteSeq(const Ice::Current&) final; - EchoByteSeqMarshaledResult echoByteSeq(std::pair, const Ice::Current&) final; - - void sendStringSeq(std::vector, const Ice::Current&) final; - RecvStringSeqMarshaledResult recvStringSeq(const Ice::Current&) final; - EchoStringSeqMarshaledResult echoStringSeq(std::vector, const Ice::Current&) final; - - void sendStructSeq(Demo::StringDoubleSeq, const Ice::Current&) final; - Demo::StringDoubleSeq recvStructSeq(const Ice::Current&) final; - Demo::StringDoubleSeq echoStructSeq(Demo::StringDoubleSeq, const Ice::Current&) final; - - void sendFixedSeq(Demo::FixedSeq, const Ice::Current&) final; - Demo::FixedSeq recvFixedSeq(const Ice::Current&) final; - Demo::FixedSeq echoFixedSeq(Demo::FixedSeq, const Ice::Current&) final; - - void shutdown(const Ice::Current&) final; - -private: - Demo::ByteSeq _byteSeq; - Demo::StringSeq _stringSeq; - Demo::StringDoubleSeq _structSeq; - Demo::FixedSeq _fixedSeq; - - bool _warmup{false}; -}; - -#endif diff --git a/cpp/Ice/throughput/config.client b/cpp/Ice/throughput/config.client deleted file mode 100644 index 4c1d6cda9..000000000 --- a/cpp/Ice/throughput/config.client +++ /dev/null @@ -1,41 +0,0 @@ -# -# The client reads this property to create the reference to the -# "Throughput" object in the server. -# -Throughput.Proxy=throughput:tcp -p 10000 -#Throughput.Proxy=throughput:ssl -p 10001 - -# -# Uncomment to use the WebSocket transports instead. -# -#Throughput.Proxy=throughput:ws -p 10002 -#Throughput.Proxy=throughput:wss -p 10003 - -# -# Only connect to the localhost interface by default. -# -Ice.Default.Host=localhost - -# -# Disable client-side ACM. -# -Ice.ACM.Client.Timeout=0 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=client.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/client.keychain -IceSSL.KeychainPassword=password - -# -# IceMX configuration. -# -#Ice.Admin.Endpoints=tcp -p 10004 -Ice.Admin.InstanceName=client -IceMX.Metrics.Debug.GroupBy=id -IceMX.Metrics.ByParent.GroupBy=parent diff --git a/cpp/Ice/throughput/config.server b/cpp/Ice/throughput/config.server deleted file mode 100644 index 43498a932..000000000 --- a/cpp/Ice/throughput/config.server +++ /dev/null @@ -1,43 +0,0 @@ -# -# The server creates one single object adapter with the name -# "Throughput". The following line sets the endpoints for this -# adapter. -# -Throughput.Endpoints=tcp -p 10000:ssl -p 10001:ws -p 10002:wss -p 10003 - -# -# Only listen on the localhost interface by default. You can comment -# out this property to allow listening on all available interfaces. -# -Ice.Default.Host=localhost - -# -# For JavaScript browser clients using a secure WebSocket (WSS), -# you should disable this property. Client-side authentication -# is not supported with JavaScript browser clients. -# -#IceSSL.VerifyPeer=0 - -# -# Warn about connection exceptions -# -Ice.Warn.Connections=1 - -# -# SSL Configuration -# -Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../certs -IceSSL.CAs=cacert.pem -IceSSL.CertFile=server.p12 -IceSSL.Password=password -IceSSL.Keychain=../../../certs/server.keychain -IceSSL.KeychainPassword=password - -# -# IceMX configuration. -# -#Ice.Admin.Endpoints=tcp -p 10004 -Ice.Admin.InstanceName=server -IceMX.Metrics.Debug.GroupBy=id -IceMX.Metrics.ByParent.GroupBy=parent diff --git a/cpp/Manual/README.md b/cpp/Manual/README.md deleted file mode 100644 index aacccdb20..000000000 --- a/cpp/Manual/README.md +++ /dev/null @@ -1,11 +0,0 @@ -Demos in this directory: - -- [printer](./printer) - - An implementation of the simple printer example at the beginning of - the manual. - -- [simpleFilesystem](./simpleFilesystem) - - An implementation of the simple (non-persistent, non-life-cycle) - version of the file system example. diff --git a/cpp/Manual/printer/CMakeLists.txt b/cpp/Manual/printer/CMakeLists.txt deleted file mode 100644 index 2a3e67eed..000000000 --- a/cpp/Manual/printer/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -project(manual_printer CXX) - -include(../../cmake/common.cmake) - -add_executable(client Client.cpp Printer.ice) -slice2cpp_generate(client) -target_link_libraries(client Ice::Ice) - -add_executable(server Server.cpp Printer.ice) -slice2cpp_generate(server) -target_link_libraries(server Ice::Ice) diff --git a/cpp/Manual/printer/Client.cpp b/cpp/Manual/printer/Client.cpp deleted file mode 100644 index 4f4553c1f..000000000 --- a/cpp/Manual/printer/Client.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "Printer.h" -#include -#include - -using namespace std; -using namespace Demo; - -int -main(int argc, char* argv[]) -{ - try - { - const Ice::CommunicatorHolder ich(argc, argv); - auto base = ich->stringToProxy("SimplePrinter:default -p 10000"); - auto printer = Ice::checkedCast(base); - if (!printer) - { - throw std::runtime_error("Invalid proxy"); - } - - printer->printString("Hello World!"); - } - catch (const std::exception& e) - { - cerr << e.what() << endl; - return 1; - } - return 0; -} diff --git a/cpp/Manual/printer/Printer.ice b/cpp/Manual/printer/Printer.ice deleted file mode 100644 index 44acdfec8..000000000 --- a/cpp/Manual/printer/Printer.ice +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#pragma once - -module Demo -{ - interface Printer - { - void printString(string s); - } -} diff --git a/cpp/Manual/printer/README.md b/cpp/Manual/printer/README.md deleted file mode 100644 index f8a081df9..000000000 --- a/cpp/Manual/printer/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Manual Printer - -This demo implements the printer example in the Ice Manual. - -To build the demo run: - -```shell -cmake -B build -cmake --build build --config Release -``` - -To run the demo, first start the server: - -**Linux/macOS:** - -```shell -./build/server -``` - -**Windows:** - -```shell -build\Release\server -``` - -In a separate window, start the client: - -**Linux/macOS:** - -```shell -./build/client -``` - -**Windows:** - -```shell -build\Release\client -``` diff --git a/cpp/Manual/printer/Server.cpp b/cpp/Manual/printer/Server.cpp deleted file mode 100644 index 1e4ae11ae..000000000 --- a/cpp/Manual/printer/Server.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) ZeroC, Inc. - -#include "Printer.h" -#include -#include - -using namespace std; -using namespace Demo; - -class PrinterI final : public Printer -{ -public: - void printString(string s, const Ice::Current&) final; -}; - -void -PrinterI::printString(string s, const Ice::Current&) -{ - cout << s << endl; -} - -int -main(int argc, char* argv[]) -{ - try - { - const Ice::CommunicatorHolder ich(argc, argv); - auto adapter = ich->createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000"); - auto servant = make_shared(); - adapter->add(servant, Ice::stringToIdentity("SimplePrinter")); - adapter->activate(); - - ich->waitForShutdown(); - } - catch (const std::exception& e) - { - cerr << e.what() << endl; - return 1; - } - return 0; -}