summaryrefslogtreecommitdiff
path: root/cppe/demo/IceE/chat/ChatClient.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2005-07-13 17:40:46 +0000
committerDwayne Boone <dwayne@zeroc.com>2005-07-13 17:40:46 +0000
commit6535f926382842de14a36f1354cb08c86cbab28c (patch)
tree50d98021e0e50a1539a7cc35594fc63c58ddc361 /cppe/demo/IceE/chat/ChatClient.cpp
parentDon't copy the testCommon libs. (diff)
downloadice-6535f926382842de14a36f1354cb08c86cbab28c.tar.bz2
ice-6535f926382842de14a36f1354cb08c86cbab28c.tar.xz
ice-6535f926382842de14a36f1354cb08c86cbab28c.zip
Commited first stab at MFC chat demo
Diffstat (limited to 'cppe/demo/IceE/chat/ChatClient.cpp')
-rw-r--r--cppe/demo/IceE/chat/ChatClient.cpp158
1 files changed, 158 insertions, 0 deletions
diff --git a/cppe/demo/IceE/chat/ChatClient.cpp b/cppe/demo/IceE/chat/ChatClient.cpp
new file mode 100644
index 00000000000..553ce8dcdbb
--- /dev/null
+++ b/cppe/demo/IceE/chat/ChatClient.cpp
@@ -0,0 +1,158 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 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 "stdafx.h"
+#include "ChatClient.h"
+#include "ChatClientDlg.h"
+#include "Router.h"
+#include "Chat.h"
+#include "LogI.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+BEGIN_MESSAGE_MAP(CChatClientApp, CWinApp)
+ ON_COMMAND(ID_HELP, CWinApp::OnHelp)
+END_MESSAGE_MAP()
+
+class ChatCallbackI : public Demo::ChatCallback
+{
+public:
+
+ ChatCallbackI(LogIPtr log)
+ : _log(log)
+ {
+ }
+
+ virtual void
+ message(const std::string& data, const Ice::Current&)
+ {
+ _log->message(data);
+ }
+
+private:
+
+ LogIPtr _log;
+};
+
+
+CChatClientApp::CChatClientApp()
+{
+ // Place all significant initialization in InitInstance
+}
+
+// The one and only CChatClientApp object
+
+CChatClientApp theApp;
+
+BOOL CChatClientApp::InitInstance()
+{
+ //
+ // InitCommonControls() is required on Windows XP if an application
+ // manifest specifies use of ComCtl32.dll version 6 or later to enable
+ // visual styles. Otherwise, any window creation will fail.
+ //
+ InitCommonControls();
+
+ CWinApp::InitInstance();
+
+ //
+ // Create a communicator and object adapter.
+ //
+ Ice::CommunicatorPtr communicator;
+ Ice::ObjectAdapterPtr adapter;
+ LogIPtr log;
+ Demo::ChatSessionPrx session;
+ try
+ {
+ int argc = 0;
+ Ice::PropertiesPtr properties = Ice::createProperties();
+ //properties->setProperty("Hello.Endpoints", "tcp -p 10000");
+ properties->load("config");
+
+ communicator = Ice::initializeWithProperties(argc, 0, properties);
+ log = new LogI;
+ communicator->setLogger(log);
+
+ Ice::RouterPrx defaultRouter = communicator->getDefaultRouter();
+ if(!defaultRouter)
+ {
+ AfxMessageBox(CString("No default router set"), MB_OK|MB_ICONEXCLAMATION);
+ return FALSE;
+ }
+
+ Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(defaultRouter);
+ if(!router)
+ {
+ AfxMessageBox(CString("Configured router is not a Glacier2 router"), MB_OK|MB_ICONEXCLAMATION);
+ return FALSE;
+ }
+
+ try
+ {
+ session = Demo::ChatSessionPrx::uncheckedCast(router->createSession("username", "password"));
+ }
+ catch(const Glacier2::PermissionDeniedException& ex)
+ {
+ AfxMessageBox(CString(ex.toString().c_str()), MB_OK|MB_ICONEXCLAMATION);
+ return FALSE;
+ }
+
+ std::string category = router->getServerProxy()->ice_getIdentity().category;
+ Ice::Identity callbackReceiverIdent;
+ callbackReceiverIdent.name = "callbackReceiver";
+ callbackReceiverIdent.category = category;
+
+ Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("Chat.Client");
+ Demo::ChatCallbackPrx callback = Demo::ChatCallbackPrx::uncheckedCast(
+ adapter->add(new ChatCallbackI(log), callbackReceiverIdent));
+ adapter->activate();
+
+ session->setCallback(callback);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ AfxMessageBox(CString(ex.toString().c_str()), MB_OK|MB_ICONEXCLAMATION);
+ return FALSE;
+ }
+
+ //
+ // Create the dialog.
+ //
+ CChatClientDlg dlg(communicator, session, log);
+
+ //
+ // Show dialog and wait until it is closed, or until the servant receives
+ // a shutdown request.
+ //
+ m_pMainWnd = &dlg;
+ dlg.DoModal();
+
+ //
+ // Edit control no longer exists.
+ //
+ log->setControl(0);
+
+ //
+ // Clean up.
+ //
+ try
+ {
+ communicator->destroy();
+ }
+ catch(const Ice::Exception&)
+ {
+ }
+
+ // Since the dialog has been closed, return FALSE so that we exit the
+ // application, rather than start the application's message pump.
+ return FALSE;
+}