diff options
Diffstat (limited to 'cpp/demo')
-rw-r--r-- | cpp/demo/Glacier2/chat/config.client | 2 | ||||
-rw-r--r-- | cpp/demo/Ice/MFC/client/HelloClientDlg.cpp | 2 | ||||
-rw-r--r-- | cpp/demo/Ice/converter/Client.cpp | 93 | ||||
-rw-r--r-- | cpp/demo/Ice/converter/Client.h | 25 | ||||
-rw-r--r-- | cpp/demo/Ice/converter/ClientWithConverter.cpp | 36 | ||||
-rw-r--r-- | cpp/demo/Ice/converter/ClientWithoutConverter.cpp | 30 | ||||
-rw-r--r-- | cpp/demo/Ice/converter/Makefile | 21 | ||||
-rw-r--r-- | cpp/demo/Ice/converter/Makefile.mak | 27 | ||||
-rw-r--r-- | cpp/demo/Ice/converter/README | 26 | ||||
-rw-r--r-- | cpp/demo/Ice/converter/StringConverterI.cpp | 12 | ||||
-rw-r--r-- | cpp/demo/Ice/converter/StringConverterI.h | 8 | ||||
-rwxr-xr-x | cpp/demo/Ice/converter/expect.py | 21 |
12 files changed, 176 insertions, 127 deletions
diff --git a/cpp/demo/Glacier2/chat/config.client b/cpp/demo/Glacier2/chat/config.client index 3343510feab..0b3f70d0005 100644 --- a/cpp/demo/Glacier2/chat/config.client +++ b/cpp/demo/Glacier2/chat/config.client @@ -58,7 +58,7 @@ Ice.RetryIntervals=-1 # SSL Configuration # Ice.Plugin.IceSSL=IceSSL:createIceSSL -IceSSL.DefaultDir=../../../../certs/wss +IceSSL.DefaultDir=../../../../certs IceSSL.CertAuthFile=cacert.pem IceSSL.CertFile=c_rsa1024_pub.pem IceSSL.KeyFile=c_rsa1024_priv.pem diff --git a/cpp/demo/Ice/MFC/client/HelloClientDlg.cpp b/cpp/demo/Ice/MFC/client/HelloClientDlg.cpp index aaffc82453d..af3a92b9a5f 100644 --- a/cpp/demo/Ice/MFC/client/HelloClientDlg.cpp +++ b/cpp/demo/Ice/MFC/client/HelloClientDlg.cpp @@ -390,7 +390,7 @@ CHelloClientDlg::createProxy() { CString h; _host->GetWindowText(h); - string host = IceUtil::wstringToString(wstring(h)); + string host = IceUtil::wnativeToNative(getProcessStringConverter(), 0, wstring(h)); if(host.size() == 0) { _status->SetWindowText(CString(" No hostname")); diff --git a/cpp/demo/Ice/converter/Client.cpp b/cpp/demo/Ice/converter/Client.cpp index 7f7d39dca86..6b18da8277f 100644 --- a/cpp/demo/Ice/converter/Client.cpp +++ b/cpp/demo/Ice/converter/Client.cpp @@ -7,10 +7,8 @@ // // ********************************************************************** -#include <IceUtil/IceUtil.h> -#include <Ice/Ice.h> +#include <Client.h> #include <Greet.h> -#include <StringConverterI.h> using namespace std; using namespace Demo; @@ -20,14 +18,14 @@ menu() { cout << "usage:\n" - "t: send greeting with conversion\n" - "u: send greeting without conversion\n" + "t: send greeting\n" "s: shutdown server\n" "x: exit\n" "?: help\n"; } -string decodeString(const string& str) +string +decodeString(const string& str) { ostringstream result; for(string::const_iterator p = str.begin(); p != str.end(); ++p) @@ -46,7 +44,7 @@ string decodeString(const string& str) } int -run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator1, const Ice::CommunicatorPtr& communicator2) +Demo::Client::run(int argc, char* argv[]) { if(argc > 1) { @@ -55,15 +53,8 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator1, const Ice } const string proxyProperty = "Greet.Proxy"; - GreetPrx greet1 = GreetPrx::checkedCast(communicator1->propertyToProxy(proxyProperty)); - if(!greet1) - { - cerr << argv[0] << ": invalid proxy" << endl; - return EXIT_FAILURE; - } - - GreetPrx greet2 = GreetPrx::checkedCast(communicator2->propertyToProxy(proxyProperty)); - if(!greet2) + GreetPrx greet = GreetPrx::checkedCast(communicator()->propertyToProxy(proxyProperty)); + if(!greet) { cerr << argv[0] << ": invalid proxy" << endl; return EXIT_FAILURE; @@ -82,17 +73,12 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator1, const Ice cin >> c; if(c == 't') { - string ret = greet1->exchangeGreeting(greeting); - cout << "Received: \"" << decodeString(ret) << '\"' << endl; - } - else if(c == 'u') - { - string ret = greet2->exchangeGreeting(greeting); + string ret = greet->exchangeGreeting(greeting); cout << "Received: \"" << decodeString(ret) << '\"' << endl; } else if(c == 's') { - greet1->shutdown(); + greet->shutdown(); } else if(c == 'x') { @@ -117,64 +103,3 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator1, const Ice return EXIT_SUCCESS; } - -int -main(int argc, char* argv[]) -{ - int status; - Ice::CommunicatorPtr communicator1; - Ice::CommunicatorPtr communicator2; - - try - { - // - // Create two communicators, one with string converter configured - // and one without. - // - Ice::InitializationData initData; - initData.stringConverter = new StringConverterI(); - initData.properties = Ice::createProperties(initData.stringConverter); - initData.properties->load("config.client"); - communicator1 = Ice::initialize(argc, argv, initData); - - Ice::InitializationData initData2; - initData2.properties = Ice::createProperties(); - initData2.properties->load("config.client"); - communicator2 = Ice::initialize(argc, argv, initData2); - - status = run(argc, argv, communicator1, communicator2); - } - catch(const Ice::Exception& ex) - { - cerr << ex << endl; - status = EXIT_FAILURE; - } - - if(communicator1) - { - try - { - communicator1->destroy(); - } - catch(const Ice::Exception& ex) - { - cerr << ex << endl; - status = EXIT_FAILURE; - } - } - - if(communicator2) - { - try - { - communicator2->destroy(); - } - catch(const Ice::Exception& ex) - { - cerr << ex << endl; - status = EXIT_FAILURE; - } - } - - return status; -} diff --git a/cpp/demo/Ice/converter/Client.h b/cpp/demo/Ice/converter/Client.h new file mode 100644 index 00000000000..a8ed20f431c --- /dev/null +++ b/cpp/demo/Ice/converter/Client.h @@ -0,0 +1,25 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef DEMO_CLIENT_H +#define DEMO_CLIENT_H + +#include <Ice/Ice.h> + +namespace Demo +{ + +class Client : public Ice::Application +{ + virtual int run(int, char*[]); +}; + +} + +#endif
\ No newline at end of file diff --git a/cpp/demo/Ice/converter/ClientWithConverter.cpp b/cpp/demo/Ice/converter/ClientWithConverter.cpp new file mode 100644 index 00000000000..567bea9f203 --- /dev/null +++ b/cpp/demo/Ice/converter/ClientWithConverter.cpp @@ -0,0 +1,36 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Client.h> +#include <StringConverterI.h> + +using namespace std; +using namespace Demo; + +int +main(int argc, char* argv[]) +{ + int status = EXIT_SUCCESS; + try + { + // + // Set the process string converter and then initialize the + // aplication. + // + IceUtil::setProcessStringConverter(new StringConverterI()); + Client app; + status = app.main(argc, argv, "config.client"); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + return status; +} diff --git a/cpp/demo/Ice/converter/ClientWithoutConverter.cpp b/cpp/demo/Ice/converter/ClientWithoutConverter.cpp new file mode 100644 index 00000000000..1e04cc4a934 --- /dev/null +++ b/cpp/demo/Ice/converter/ClientWithoutConverter.cpp @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Client.h> + +using namespace std; +using namespace Demo; + +int +main(int argc, char* argv[]) +{ + int status = EXIT_SUCCESS; + try + { + Client app; + status = app.main(argc, argv, "config.client"); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + return status; +} diff --git a/cpp/demo/Ice/converter/Makefile b/cpp/demo/Ice/converter/Makefile index 0bb6cb8def0..3b724a84445 100644 --- a/cpp/demo/Ice/converter/Makefile +++ b/cpp/demo/Ice/converter/Makefile @@ -9,15 +9,20 @@ top_srcdir = ../../.. -CLIENT = client +CLIENT1 = client1 +CLIENT2 = client2 SERVER = server -TARGETS = $(CLIENT) $(SERVER) +TARGETS = $(CLIENT1) $(CLIENT2) $(SERVER) OBJS = Greet.o -COBJS = Client.o \ - StringConverterI.o +C1OBJS = Client.o \ + StringConverterI.o \ + ClientWithConverter.o + +C2OBJS = Client.o \ + ClientWithoutConverter.o SOBJS = GreetI.o \ Server.o @@ -32,9 +37,13 @@ include $(top_srcdir)/config/Make.rules CPPFLAGS := -I. $(CPPFLAGS) -$(CLIENT): $(OBJS) $(COBJS) +$(CLIENT1): $(OBJS) $(C1OBJS) rm -f $@ - $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(COBJS) $(LIBS) + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(C1OBJS) $(LIBS) + +$(CLIENT2): $(OBJS) $(C2OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(C2OBJS) $(LIBS) $(SERVER): $(OBJS) $(SOBJS) rm -f $@ diff --git a/cpp/demo/Ice/converter/Makefile.mak b/cpp/demo/Ice/converter/Makefile.mak index d47a8b8b54c..101bd807310 100644 --- a/cpp/demo/Ice/converter/Makefile.mak +++ b/cpp/demo/Ice/converter/Makefile.mak @@ -9,16 +9,21 @@ top_srcdir = ..\..\.. -CLIENT = client.exe +CLIENT1 = client1.exe +CLIENT2 = client2.exe SERVER = server.exe -TARGETS = $(CLIENT) $(SERVER) +TARGETS = $(CLIENT1) $(CLIENT2) $(SERVER) -OBJS = Greet.obj \ - StringConverterI.obj +OBJS = Greet.obj -COBJS = Client.obj +C1OBJS = Client.obj \ + StringConverterI.obj \ + ClientWithConverter.obj +C2OBJS = Client.obj \ + ClientWithoutConverter.obj + SOBJS = GreetI.obj \ Server.obj @@ -31,12 +36,18 @@ SRCS = $(OBJS:.obj=.cpp) \ CPPFLAGS = -I. $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN !if "$(GENERATE_PDB)" == "yes" -CPDBFLAGS = /pdb:$(CLIENT:.exe=.pdb) +C1PDBFLAGS = /pdb:$(CLIENT1:.exe=.pdb) +C2PDBFLAGS = /pdb:$(CLIENT2:.exe=.pdb) SPDBFLAGS = /pdb:$(SERVER:.exe=.pdb) !endif -$(CLIENT): $(OBJS) $(COBJS) - $(LINK) $(LD_EXEFLAGS) $(CPDBFLAGS) $(SETARGV) $(OBJS) $(COBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) +$(CLIENT1): $(OBJS) $(C1OBJS) + $(LINK) $(LD_EXEFLAGS) $(C1PDBFLAGS) $(SETARGV) $(OBJS) $(C1OBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) + @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ + $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest + +$(CLIENT2): $(OBJS) $(C2OBJS) + $(LINK) $(LD_EXEFLAGS) $(C2PDBFLAGS) $(SETARGV) $(OBJS) $(C2OBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest diff --git a/cpp/demo/Ice/converter/README b/cpp/demo/Ice/converter/README index 2cfbb59525d..87dbb6f8e92 100644 --- a/cpp/demo/Ice/converter/README +++ b/cpp/demo/Ice/converter/README @@ -1,18 +1,26 @@ This demo illustrates how to implement and use string converters -with Ice. In this demo, the client represents an application that -uses ISO-Latin-1 as its character set, while the server uses UTF-8. +with Ice. In this demo, the clients uses ISO-Latin-1 as its +character set, while the server uses UTF-8. -The demo sends and receives the greeting "Bonne journée" which in -Latin-1 encoding is "Bonne journ\351e" and in UTF-8 encoding is -"Bonne journ\303\251e". +The demo sends and receives the greeting "Bonne journée" which +in Latin-1 encoding is "Bonne journ\351e" and in UTF-8 encoding +is "Bonne journ\303\251e". -The demo prints the strings as they are received to show how, without -conversion, they are not in the format expected by the application. +The demo server prints the strings as they are received to show +how, without conversion, they are not in the format expected by +the application. + +There are two clients client1 uses an string converter and, client2 +doesn't use and string converter. To run the demo, first start the server: $ server -In a separate window, start the client: +In a separate window, start the client1: + +$ client1 + +In a separate window, start the client2: -$ client +$ client2 diff --git a/cpp/demo/Ice/converter/StringConverterI.cpp b/cpp/demo/Ice/converter/StringConverterI.cpp index 219d792f1a3..12d83cb39c7 100644 --- a/cpp/demo/Ice/converter/StringConverterI.cpp +++ b/cpp/demo/Ice/converter/StringConverterI.cpp @@ -7,10 +7,10 @@ // // ********************************************************************** -#include <Ice/Ice.h> #include <StringConverterI.h> using namespace std; +using namespace IceUtil; Demo::StringConverterI::StringConverterI() { @@ -20,14 +20,14 @@ Demo::StringConverterI::~StringConverterI() { } -Ice::Byte* -Demo::StringConverterI::toUTF8(const char* sourceStart, const char* sourceEnd, Ice::UTF8Buffer& buffer) const +Byte* +Demo::StringConverterI::toUTF8(const char* sourceStart, const char* sourceEnd, UTF8Buffer& buffer) const { size_t inputSize = static_cast<size_t>(sourceEnd - sourceStart); size_t chunkSize = std::max<size_t>(inputSize, 6); size_t outputBytesLeft = chunkSize; - Ice::Byte* targetStart = buffer.getMoreBytes(chunkSize, 0); + Byte* targetStart = buffer.getMoreBytes(chunkSize, 0); size_t offset = 0; for(unsigned int i = 0; i < inputSize; ++i) @@ -66,7 +66,7 @@ Demo::StringConverterI::toUTF8(const char* sourceStart, const char* sourceEnd, I } void -Demo::StringConverterI::fromUTF8(const Ice::Byte* sourceStart, const Ice::Byte* sourceEnd, +Demo::StringConverterI::fromUTF8(const Byte* sourceStart, const Byte* sourceEnd, string& target) const { size_t inSize = static_cast<size_t>(sourceEnd - sourceStart); @@ -80,7 +80,7 @@ Demo::StringConverterI::fromUTF8(const Ice::Byte* sourceStart, const Ice::Byte* { if(i + 1 >= inSize) { - throw Ice::StringConversionException(__FILE__, __LINE__, "UTF-8 string source exhausted"); + throw IllegalConversionException(__FILE__, __LINE__, "UTF-8 string source exhausted"); } target[targetIndex] = (sourceStart[i] & 0x03) << 6; target[targetIndex] = target[targetIndex] | (sourceStart[i + 1] & 0x3F); diff --git a/cpp/demo/Ice/converter/StringConverterI.h b/cpp/demo/Ice/converter/StringConverterI.h index 2d6d0ded912..ce6602db47e 100644 --- a/cpp/demo/Ice/converter/StringConverterI.h +++ b/cpp/demo/Ice/converter/StringConverterI.h @@ -10,7 +10,7 @@ #ifndef STRING_CONVERTER_I_H #define STRING_CONVERTER_I_H -#include <Ice/StringConverter.h> +#include <IceUtil/StringConverter.h> namespace Demo { @@ -18,15 +18,15 @@ namespace Demo // // UTF-8 converter for LATIN-1 // -class StringConverterI : public Ice::StringConverter +class StringConverterI : public IceUtil::StringConverter { public: StringConverterI(); ~StringConverterI(); - virtual Ice::Byte* toUTF8(const char*, const char*, Ice::UTF8Buffer&) const; - virtual void fromUTF8(const Ice::Byte*, const Ice::Byte*, std::string&) const; + virtual IceUtil::Byte* toUTF8(const char*, const char*, IceUtil::UTF8Buffer&) const; + virtual void fromUTF8(const IceUtil::Byte*, const IceUtil::Byte*, std::string&) const; }; } diff --git a/cpp/demo/Ice/converter/expect.py b/cpp/demo/Ice/converter/expect.py index 87ec5834e9a..fe508333226 100755 --- a/cpp/demo/Ice/converter/expect.py +++ b/cpp/demo/Ice/converter/expect.py @@ -23,20 +23,25 @@ from demoscript import Util server = Util.spawn('./server --Ice.PrintAdapterReady') server.expect('.* ready') -client = Util.spawn('./client') -client.expect('.*==>') + +client = Util.spawn('./client1') +client.expect('.*==>') sys.stdout.write("testing with conversion... ") -sys.stdout.flush() -client.sendline('u') -server.expect('Received \\(UTF-8\\): "Bonne journ\\\\351e"') -client.expect('Received: "Bonne journ\\\\303\\\\251e"') +client.sendline('t') +server.expect('Received \\(UTF-8\\): "Bonne journ\\\\303\\\\251e"') +client.expect('Received: "Bonne journ\\\\351e"') print("ok") +client.sendline('x') +client = Util.spawn('./client2') +client.expect('.*==>') + sys.stdout.write("testing without conversion... ") +sys.stdout.flush() client.sendline('t') -server.expect('Received \\(UTF-8\\): "Bonne journ\\\\303\\\\251e"') -client.expect('Received: "Bonne journ\\\\351e"') +server.expect('Received \\(UTF-8\\): "Bonne journ\\\\351e"') +client.expect('Received: "Bonne journ\\\\303\\\\251e"') print("ok") client.sendline('s') |