summaryrefslogtreecommitdiff
path: root/cppe/demo/IceE/throughput/WinCEServer.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2005-08-08 13:33:04 +0000
committerDwayne Boone <dwayne@zeroc.com>2005-08-08 13:33:04 +0000
commitdf8cf81989c083af7861b9bec0f05d40d9cd195b (patch)
tree2e0e0444e84444aa2620e55e78e2365554f2010d /cppe/demo/IceE/throughput/WinCEServer.cpp
parentadded missing files. (diff)
downloadice-df8cf81989c083af7861b9bec0f05d40d9cd195b.tar.bz2
ice-df8cf81989c083af7861b9bec0f05d40d9cd195b.tar.xz
ice-df8cf81989c083af7861b9bec0f05d40d9cd195b.zip
Ported throughput to WinCE
Diffstat (limited to 'cppe/demo/IceE/throughput/WinCEServer.cpp')
-rwxr-xr-xcppe/demo/IceE/throughput/WinCEServer.cpp182
1 files changed, 182 insertions, 0 deletions
diff --git a/cppe/demo/IceE/throughput/WinCEServer.cpp b/cppe/demo/IceE/throughput/WinCEServer.cpp
new file mode 100755
index 00000000000..4985806763f
--- /dev/null
+++ b/cppe/demo/IceE/throughput/WinCEServer.cpp
@@ -0,0 +1,182 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice-E is licensed to you under the terms described in the
+// ICEE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <IceE/IceE.h>
+#include <ThroughputI.h>
+
+using namespace std;
+using namespace Demo;
+
+static HWND editHwnd;
+
+static LRESULT CALLBACK
+WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch(msg)
+ {
+ case WM_CREATE:
+ {
+ RECT rcClient;
+ GetClientRect(hWnd, &rcClient);
+ editHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"",
+ WS_CHILD | WS_VISIBLE | WS_VSCROLL /*| WS_HSCROLL*/ | ES_MULTILINE,
+ 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
+ hWnd, (HMENU)101, GetModuleHandle(NULL), NULL);
+ assert(editHwnd != NULL);
+ }
+ break;
+
+ case WM_SIZE:
+ {
+ RECT rcClient;
+ GetClientRect(hWnd, &rcClient);
+ SetWindowPos(editHwnd, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
+ }
+ break;
+
+ case WM_CLOSE:
+ DestroyWindow(hWnd);
+ break;
+
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+
+ default:
+ return DefWindowProc(hWnd, msg, wParam, lParam);
+ }
+ return 0;
+}
+
+int WINAPI
+WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
+{
+ static const TCHAR windowClassName[] = L"Throughput Server";
+ WNDCLASS wc;
+
+ wc.style = CS_HREDRAW|CS_VREDRAW;
+ wc.lpfnWndProc = (WNDPROC)WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = hInstance;
+ wc.hIcon = LoadIcon(NULL, 0);
+ wc.hCursor = 0;
+ wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = windowClassName;
+
+ if(!RegisterClass(&wc))
+ {
+ MessageBox(NULL, L"Window Registration Failed!", L"Error!",
+ MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
+
+ RECT rect;
+ GetClientRect(GetDesktopWindow(), &rect);
+ int width = rect.right - rect.left;
+ if(width > 320)
+ {
+ width = 320;
+ }
+ int height = rect.bottom - rect.top;
+ if(height > 200)
+ {
+ height = 200;
+ }
+ HWND mainWnd = CreateWindow(windowClassName, L"Throughput Server", WS_VISIBLE|WS_OVERLAPPED|WS_SYSMENU|WS_SIZEBOX,
+ CW_USEDEFAULT, CW_USEDEFAULT, width, height,
+ NULL, NULL, hInstance, NULL);
+ if(mainWnd == NULL)
+ {
+ MessageBox(NULL, L"Window Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
+
+ ShowWindow(mainWnd, SW_SHOW);
+ UpdateWindow(mainWnd);
+
+ int status = EXIT_SUCCESS;
+
+ extern int __argc;
+ extern char **__argv;
+
+ Ice::CommunicatorPtr communicator;
+
+ try
+ {
+ Ice::PropertiesPtr properties = Ice::createProperties();
+ //
+ // Set a default value for Latency.Endpoints so that the demo
+ // will run without a configuration file.
+ //
+ properties->setProperty("Throughput.Endpoints","tcp -p 10000");
+
+ //
+ // Now, load the configuration file if present.
+ //
+ try
+ {
+ properties->load("config");
+ }
+ catch(const Ice::FileException&)
+ {
+ }
+
+ communicator = Ice::initializeWithProperties(__argc, __argv, properties);
+
+ Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("Throughput");
+ Ice::ObjectPtr object = new ThroughputI(100);
+ adapter->add(object, Ice::stringToIdentity("throughput"));
+ adapter->activate();
+
+ //
+ // Display a helpful message to the user.
+ //
+ ::SendMessage(editHwnd, EM_REPLACESEL,
+ (WPARAM)FALSE, (LPARAM)L"Close the window to terminate the server.\r\n");
+
+ //
+ // Run the message pump.
+ //
+ MSG Msg;
+ while(GetMessage(&Msg, NULL, 0, 0) > 0)
+ {
+ TranslateMessage(&Msg);
+ DispatchMessage(&Msg);
+ }
+ }
+ catch(const Ice::Exception& ex)
+ {
+ TCHAR wtext[1024];
+ string err = ex.toString();
+ mbstowcs(wtext, err.c_str(), err.size());
+ MessageBox(mainWnd, wtext, L"Error", MB_ICONEXCLAMATION | MB_OK);
+
+ status = EXIT_FAILURE;
+ }
+
+ if(communicator)
+ {
+ try
+ {
+ communicator->destroy();
+ }
+ catch(const Ice::Exception& ex)
+ {
+ TCHAR wtext[1024];
+ string err = ex.toString();
+ mbstowcs(wtext, err.c_str(), err.size());
+ MessageBox(mainWnd, wtext, L"Error", MB_ICONEXCLAMATION | MB_OK);
+
+ status = EXIT_FAILURE;
+ }
+ }
+ return status;
+}