diff options
Diffstat (limited to 'cpp/demo/Ice/MFC')
-rw-r--r-- | cpp/demo/Ice/MFC/client/Hello.ice | 4 | ||||
-rw-r--r-- | cpp/demo/Ice/MFC/client/HelloClient.cpp | 11 | ||||
-rw-r--r-- | cpp/demo/Ice/MFC/client/HelloClient.rc | 62 | ||||
-rw-r--r-- | cpp/demo/Ice/MFC/client/HelloClientDlg.cpp | 255 | ||||
-rw-r--r-- | cpp/demo/Ice/MFC/client/HelloClientDlg.h | 11 | ||||
-rw-r--r-- | cpp/demo/Ice/MFC/client/Resource.h | 7 | ||||
-rw-r--r-- | cpp/demo/Ice/MFC/client/config | 6 |
7 files changed, 276 insertions, 80 deletions
diff --git a/cpp/demo/Ice/MFC/client/Hello.ice b/cpp/demo/Ice/MFC/client/Hello.ice index 11b714f01c8..a21b43ace2c 100644 --- a/cpp/demo/Ice/MFC/client/Hello.ice +++ b/cpp/demo/Ice/MFC/client/Hello.ice @@ -15,8 +15,8 @@ module Demo interface Hello { - ["cpp:const"] idempotent void sayHello(int delay); - void shutdown(); + ["ami", "cpp:const"] idempotent void sayHello(int delay); + ["ami"] void shutdown(); }; }; diff --git a/cpp/demo/Ice/MFC/client/HelloClient.cpp b/cpp/demo/Ice/MFC/client/HelloClient.cpp index 58deb943950..767bd89f646 100644 --- a/cpp/demo/Ice/MFC/client/HelloClient.cpp +++ b/cpp/demo/Ice/MFC/client/HelloClient.cpp @@ -66,17 +66,6 @@ CHelloClientApp::InitInstance() m_pMainWnd = &dlg; dlg.DoModal(); - // - // Clean up. - // - try - { - communicator->destroy(); - } - catch(const IceUtil::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; diff --git a/cpp/demo/Ice/MFC/client/HelloClient.rc b/cpp/demo/Ice/MFC/client/HelloClient.rc index 5e1ddc6f299..ba21c69ff1c 100644 --- a/cpp/demo/Ice/MFC/client/HelloClient.rc +++ b/cpp/demo/Ice/MFC/client/HelloClient.rc @@ -1,4 +1,4 @@ -//Microsoft Developer Studio generated resource script.
+// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
@@ -27,18 +27,18 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // TEXTINCLUDE
//
-1 TEXTINCLUDE MOVEABLE PURE
+1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
-2 TEXTINCLUDE MOVEABLE PURE
+2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
-3 TEXTINCLUDE MOVEABLE PURE
+3 TEXTINCLUDE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
@@ -64,7 +64,7 @@ END // Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
-IDR_MAINFRAME ICON DISCARDABLE "res\\HelloClient.ico"
+IDR_MAINFRAME ICON "res\\HelloClient.ico"
/////////////////////////////////////////////////////////////////////////////
//
@@ -72,29 +72,25 @@ IDR_MAINFRAME ICON DISCARDABLE "res\\HelloClient.ico" //
IDD_HELLOCLIENT_DIALOG DIALOGEX 0, 0, 234, 97
-STYLE DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION |
- WS_SYSMENU
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Ice Hello Client"
-FONT 8, "MS Shell Dlg"
+FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
- LTEXT "Mode",IDC_MODELABEL,7,18,19,8
- COMBOBOX IDC_MODE,28,16,109,70,CBS_DROPDOWNLIST | WS_TABSTOP
- CONTROL "Secure",IDC_SECURE,"Button",BS_AUTOCHECKBOX |
- WS_TABSTOP,155,14,38,10
- CONTROL "Timeout",IDC_TIMEOUT,"Button",BS_AUTOCHECKBOX |
- WS_TABSTOP,155,26,41,10
- DEFPUSHBUTTON "Say Hello",IDC_INVOKE,7,56,68,14
- PUSHBUTTON "Flush Batch",IDC_FLUSH,83,56,68,14
- PUSHBUTTON "Shutdown Server",IDC_SHUTDOWN,159,56,68,14
- LTEXT "",IDC_STATUSBAR,0,84,234,12,SS_CENTERIMAGE |
- SS_ENDELLIPSIS,WS_EX_STATICEDGE
- CONTROL "Delay",IDC_DELAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,
- 155,38,34,10
+ LTEXT "Mode",IDC_MODELABEL,7,35,19,8
+ COMBOBOX IDC_MODE,41,33,109,70,CBS_DROPDOWNLIST | WS_TABSTOP
+ CONTROL "Secure",IDC_SECURE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,165,15,38,10
+ CONTROL "Timeout",IDC_TIMEOUT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,165,27,41,10
+ DEFPUSHBUTTON "Say Hello",IDC_INVOKE,7,57,68,14
+ PUSHBUTTON "Flush Batch",IDC_FLUSH,83,57,68,14
+ PUSHBUTTON "Shutdown Server",IDC_SHUTDOWN,159,57,68,14
+ LTEXT "",IDC_STATUSBAR,7,81,220,12,SS_CENTERIMAGE | SS_ENDELLIPSIS,WS_EX_STATICEDGE
+ CONTROL "Delay",IDC_DELAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,165,39,34,10
+ EDITTEXT IDC_HOST,41,16,109,14,ES_AUTOHSCROLL
+ LTEXT "Hostname",IDC_HOSTLABEL,7,17,31,8
END
-#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
@@ -117,14 +113,14 @@ BEGIN BEGIN
BLOCK "040904e4"
BEGIN
- VALUE "CompanyName", "ZeroC, Inc.\0"
- VALUE "FileDescription", "Ice Hello Client\0"
- VALUE "FileVersion", "1.0.0.1\0"
- VALUE "InternalName", "HelloClient.exe\0"
- VALUE "LegalCopyright", "Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.\0"
- VALUE "OriginalFilename", "HelloClient.exe\0"
- VALUE "ProductName", "Ice\0"
- VALUE "ProductVersion", "1.0.0.1\0"
+ VALUE "CompanyName", "ZeroC, Inc."
+ VALUE "FileDescription", "Ice Hello Client"
+ VALUE "FileVersion", "1.0.0.1"
+ VALUE "InternalName", "HelloClient.exe"
+ VALUE "LegalCopyright", "Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved."
+ VALUE "OriginalFilename", "HelloClient.exe"
+ VALUE "ProductName", "Ice"
+ VALUE "ProductVersion", "1.0.0.1"
END
END
BLOCK "VarFileInfo"
@@ -133,8 +129,6 @@ BEGIN END
END
-#endif // !_MAC
-
/////////////////////////////////////////////////////////////////////////////
//
@@ -142,14 +136,14 @@ END //
#ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO MOVEABLE PURE
+GUIDELINES DESIGNINFO
BEGIN
IDD_HELLOCLIENT_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 227
TOPMARGIN, 7
- BOTTOMMARGIN, 90
+ BOTTOMMARGIN, 93
END
END
#endif // APSTUDIO_INVOKED
diff --git a/cpp/demo/Ice/MFC/client/HelloClientDlg.cpp b/cpp/demo/Ice/MFC/client/HelloClientDlg.cpp index 8677ccc2393..2531ffbd229 100644 --- a/cpp/demo/Ice/MFC/client/HelloClientDlg.cpp +++ b/cpp/demo/Ice/MFC/client/HelloClientDlg.cpp @@ -15,9 +15,101 @@ #define new DEBUG_NEW #endif +#define WM_AMI_EXCEPTION (WM_USER + 1) +#define WM_AMI_SAY_HELLO_RESPONSE (WM_USER + 2) +#define WM_AMI_SAY_HELLO_SENT (WM_USER + 3) +#define WM_AMI_FLUSH_BATCH_REQUESTS_SENT (WM_USER + 4) +#define WM_AMI_SHUTDOWN_SENT (WM_USER + 5) + using namespace std; using namespace Demo; +class SayHelloCB : public AMI_Hello_sayHello, public Ice::AMISentCallback +{ +public: + + SayHelloCB(CHelloClientDlg* dialog) : _dialog(dialog) + { + } + + virtual void + ice_sent() + { + _dialog->PostMessage(WM_AMI_SAY_HELLO_SENT, 0, 0); + } + + virtual void + ice_response() + { + _dialog->PostMessage(WM_AMI_SAY_HELLO_RESPONSE, 0, 0); + } + + virtual void + ice_exception(const Ice::Exception& ex) + { + _dialog->PostMessage(WM_AMI_EXCEPTION, 0, reinterpret_cast<LONG>(ex.ice_clone())); + } + +private: + + CHelloClientDlg* _dialog; +}; + +class FlushBatchRequestsCB : public Ice::AMI_Object_ice_flushBatchRequests, public Ice::AMISentCallback +{ +public: + + FlushBatchRequestsCB(CHelloClientDlg* dialog) : _dialog(dialog) + { + } + + virtual void + ice_sent() + { + _dialog->PostMessage(WM_AMI_FLUSH_BATCH_REQUESTS_SENT, 0, 0); + } + + virtual void + ice_exception(const Ice::Exception& ex) + { + _dialog->PostMessage(WM_AMI_EXCEPTION, 0, reinterpret_cast<LONG>(ex.ice_clone())); + } + +private: + + CHelloClientDlg* _dialog; +}; + +class ShutdownCB : public AMI_Hello_shutdown, public Ice::AMISentCallback +{ +public: + + ShutdownCB(CHelloClientDlg* dialog) : _dialog(dialog) + { + } + + virtual void + ice_sent() + { + _dialog->PostMessage(WM_AMI_SHUTDOWN_SENT, 0, 0); + } + + virtual void + ice_response() + { + } + + virtual void + ice_exception(const Ice::Exception& ex) + { + _dialog->PostMessage(WM_AMI_EXCEPTION, 0, reinterpret_cast<LONG>(ex.ice_clone())); + } + +private: + + CHelloClientDlg* _dialog; +}; + CHelloClientDlg::CHelloClientDlg(const Ice::CommunicatorPtr& communicator, CWnd* pParent /*=NULL*/) : CDialog(CHelloClientDlg::IDD, pParent), _communicator(communicator), _currentMode(0), _useSecure(false), _useTimeout(false) @@ -38,6 +130,11 @@ BEGIN_MESSAGE_MAP(CHelloClientDlg, CDialog) ON_BN_CLICKED(IDC_INVOKE, OnSayHello) ON_BN_CLICKED(IDC_FLUSH, OnFlush) ON_BN_CLICKED(IDC_SHUTDOWN, OnShutdown) + ON_MESSAGE(WM_AMI_EXCEPTION, OnAMIException) + ON_MESSAGE(WM_AMI_SAY_HELLO_RESPONSE, OnAMISayHelloResponse) + ON_MESSAGE(WM_AMI_SAY_HELLO_SENT, OnAMISayHelloSent) + ON_MESSAGE(WM_AMI_FLUSH_BATCH_REQUESTS_SENT, OnAMIFlushBatchRequestsSent) + ON_MESSAGE(WM_AMI_SHUTDOWN_SENT, OnAMIShutdownSent) END_MESSAGE_MAP() BOOL @@ -53,6 +150,7 @@ CHelloClientDlg::OnInitDialog() // // Retrieve the controls. // + _host = (CEdit*)GetDlgItem(IDC_HOST); _mode = (CComboBox*)GetDlgItem(IDC_MODE); _secure = (CButton*)GetDlgItem(IDC_SECURE); _timeout = (CButton*)GetDlgItem(IDC_TIMEOUT); @@ -67,14 +165,29 @@ CHelloClientDlg::OnInitDialog() // // Create the proxy. // - Ice::ObjectPrx obj = _communicator->propertyToProxy("Hello.Proxy"); - _proxy = HelloPrx::uncheckedCast(obj); - _currentProxy = _proxy; + updateProxy(); + _host->SetWindowText(CString(_hostname.c_str())); _status->SetWindowText(CString(" Ready")); return TRUE; // return TRUE unless you set the focus to a control } +void +CHelloClientDlg::OnClose() +{ + // + // Destroy the communicator. If AMI calls are still in progress they will be + // interrupted with an Ice::CommunicatorDestroyedException. + // + try + { + _communicator->destroy(); + } + catch(const IceUtil::Exception&) + { + } +} + // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. @@ -119,14 +232,24 @@ CHelloClientDlg::OnSayHello() try { updateProxy(); - _currentProxy->sayHello(_delay->GetCheck() == BST_CHECKED ? 2500 : 0); - if(_currentProxy->ice_isBatchOneway() || _currentProxy->ice_isBatchDatagram()) + if(!_currentProxy->ice_isBatchOneway() && !_currentProxy->ice_isBatchDatagram()) { - _status->SetWindowText(CString(" Queued batch request")); + if(_currentProxy->sayHello_async(new SayHelloCB(this), _delay->GetCheck() == BST_CHECKED ? 2500 : 0)) + { + if(_currentProxy->ice_isTwoway()) + { + _status->SetWindowText(CString(" Waiting for response")); + } + } + else + { + _status->SetWindowText(CString(" Sending request")); + } } else { - _status->SetWindowText(CString(" Sent request")); + _currentProxy->sayHello(_delay->GetCheck() == BST_CHECKED ? 2500 : 0); + _status->SetWindowText(CString(" Queued batch request")); } } catch(const IceUtil::Exception& ex) @@ -140,8 +263,15 @@ CHelloClientDlg::OnFlush() { try { - _communicator->flushBatchRequests(); - _status->SetWindowText(CString(" Flushed batch requests")); + updateProxy(); + if(_currentProxy->ice_flushBatchRequests_async(new FlushBatchRequestsCB(this))) + { + _status->SetWindowText(CString(" Flushed batch requests")); + } + else + { + _status->SetWindowText(CString(" Flushing batch requests")); + } } catch(const IceUtil::Exception& ex) { @@ -155,14 +285,21 @@ CHelloClientDlg::OnShutdown() try { updateProxy(); - _currentProxy->shutdown(); - if(_currentProxy->ice_isBatchOneway() || _currentProxy->ice_isBatchDatagram()) + if(!_currentProxy->ice_isBatchOneway() && !_currentProxy->ice_isBatchDatagram()) { - _status->SetWindowText(CString(" Queued shutdown request")); + if(_currentProxy->shutdown_async(new ShutdownCB(this))) + { + _status->SetWindowText(CString(" Sent shutdown request")); + } + else + { + _status->SetWindowText(CString(" Sending shutdown request")); + } } else { - _status->SetWindowText(CString(" Sent shutdown request")); + _currentProxy->shutdown(); + _status->SetWindowText(CString(" Queued shutdown request")); } } catch(const IceUtil::Exception& ex) @@ -171,6 +308,53 @@ CHelloClientDlg::OnShutdown() } } +LRESULT +CHelloClientDlg::OnAMIException(WPARAM, LPARAM lParam) +{ + Ice::Exception* ex = reinterpret_cast<Ice::Exception*>(lParam); + if(!dynamic_cast<Ice::CommunicatorDestroyedException*>(ex)) + { + handleException(*ex); + } + delete ex; + return 0; +} + +LRESULT +CHelloClientDlg::OnAMISayHelloSent(WPARAM, LPARAM) +{ + if(_currentProxy->ice_isTwoway()) + { + _status->SetWindowText(CString(" Waiting for response")); + } + else + { + _status->SetWindowText(CString(" Ready")); + } + return 0; +} + +LRESULT +CHelloClientDlg::OnAMISayHelloResponse(WPARAM, LPARAM) +{ + _status->SetWindowText(CString(" Ready")); + return 0; +} + +LRESULT +CHelloClientDlg::OnAMIFlushBatchRequestsSent(WPARAM, LPARAM) +{ + _status->SetWindowText(CString(" Flushed batch requests")); + return 0; +} + +LRESULT +CHelloClientDlg::OnAMIShutdownSent(WPARAM, LPARAM) +{ + _status->SetWindowText(CString(" Sent shutdown request")); + return 0; +} + void CHelloClientDlg::updateProxy() { @@ -178,12 +362,41 @@ CHelloClientDlg::updateProxy() bool secure = _secure->GetCheck() == BST_CHECKED; bool timeout = _timeout->GetCheck() == BST_CHECKED; - if(mode == _currentMode && secure == _useSecure && timeout == _useTimeout) + CString h; + _host->GetWindowText(h); + string hostname = (LPCTSTR)h; + + if(_currentProxy && + hostname == _hostname && + mode == _currentMode && + secure == _useSecure && + timeout == _useTimeout) { return; } - Ice::ObjectPrx proxy; + if(!_proxy) + { + _proxy = HelloPrx::uncheckedCast(_communicator->stringToProxy("hello:tcp -p 10000:udp -p 10000:ssl -p 10001")); + _hostname = "localhost"; + } + else if(hostname != _hostname) + { + try + { + _proxy = HelloPrx::uncheckedCast(_communicator->stringToProxy(string("hello") + + ":tcp -p 10000 -h " + hostname + + ":udp -p 10000 -h " + hostname + + ":ssl -p 10001 -h " + hostname)); + _hostname = hostname; + } + catch(const Ice::EndpointParseException&) + { + AfxMessageBox(CString("The provided hostname is invalid."), MB_OK|MB_ICONEXCLAMATION); + } + } + + Ice::ObjectPrx proxy = _proxy; switch(mode) { case 0: @@ -214,14 +427,7 @@ CHelloClientDlg::updateProxy() proxy = proxy->ice_timeout(-1); } - if(proxy->ice_isTwoway()) - { - _currentProxy = HelloPrx::checkedCast(proxy); - } - else - { - _currentProxy = HelloPrx::uncheckedCast(proxy); - } + _currentProxy = HelloPrx::uncheckedCast(proxy); _currentMode = mode; _useSecure = secure; _useTimeout = timeout; @@ -236,8 +442,7 @@ CHelloClientDlg::handleException(const IceUtil::Exception& e) } catch(const Ice::NoEndpointException&) { - AfxMessageBox(CString("The proxy does not support the current configuration"), - MB_OK|MB_ICONEXCLAMATION); + AfxMessageBox(CString("The proxy does not support the current configuration"), MB_OK|MB_ICONEXCLAMATION); } catch(const IceUtil::Exception& ex) { diff --git a/cpp/demo/Ice/MFC/client/HelloClientDlg.h b/cpp/demo/Ice/MFC/client/HelloClientDlg.h index 4935e1b72da..4ef7b2835fb 100644 --- a/cpp/demo/Ice/MFC/client/HelloClientDlg.h +++ b/cpp/demo/Ice/MFC/client/HelloClientDlg.h @@ -18,15 +18,19 @@ class CHelloClientDlg : public CDialog
{
public:
+ CHelloClientDlg(const Ice::CommunicatorPtr&, CWnd* = NULL);
enum { IDD = IDD_HELLOCLIENT_DIALOG };
protected:
+ virtual void DoDataExchange(CDataExchange*); // DDX/DDV support
protected:
+ Ice::CommunicatorPtr _communicator;
+ CEdit* _host;
CComboBox* _mode;
CButton* _secure;
CButton* _timeout;
@@ -35,17 +39,24 @@ protected: Demo::HelloPrx _proxy;
Demo::HelloPrx _currentProxy;
int _currentMode;
+ std::string _hostname;
bool _useSecure;
bool _useTimeout;
HICON _hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
+ afx_msg void OnClose();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnSayHello();
afx_msg void OnFlush();
afx_msg void OnShutdown();
+ afx_msg LRESULT OnAMIException(WPARAM, LPARAM);
+ afx_msg LRESULT OnAMISayHelloResponse(WPARAM, LPARAM);
+ afx_msg LRESULT OnAMISayHelloSent(WPARAM, LPARAM);
+ afx_msg LRESULT OnAMIFlushBatchRequestsSent(WPARAM, LPARAM);
+ afx_msg LRESULT OnAMIShutdownSent(WPARAM, LPARAM);
DECLARE_MESSAGE_MAP()
void updateProxy();
diff --git a/cpp/demo/Ice/MFC/client/Resource.h b/cpp/demo/Ice/MFC/client/Resource.h index a4ac959eb20..0e779e87501 100644 --- a/cpp/demo/Ice/MFC/client/Resource.h +++ b/cpp/demo/Ice/MFC/client/Resource.h @@ -1,5 +1,5 @@ //{{NO_DEPENDENCIES}}
-// Microsoft Developer Studio generated include file.
+// Microsoft Visual C++ generated include file.
// Used by HelloClient.rc
//
#define IDD_HELLOCLIENT_DIALOG 101
@@ -13,6 +13,9 @@ #define IDC_SHUTDOWN 1006
#define IDC_STATUSBAR 1007
#define IDC_DELAY 1008
+#define IDC_HOST 1009
+#define IDC_HOSTNAME 1010
+#define IDC_HOSTLABEL 1010
// Next default values for new objects
//
@@ -20,7 +23,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32771
-#define _APS_NEXT_CONTROL_VALUE 1008
+#define _APS_NEXT_CONTROL_VALUE 1010
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/cpp/demo/Ice/MFC/client/config b/cpp/demo/Ice/MFC/client/config index 0aceb3fc121..80829f230be 100644 --- a/cpp/demo/Ice/MFC/client/config +++ b/cpp/demo/Ice/MFC/client/config @@ -1,10 +1,4 @@ # -# The client reads this property to create the reference to the -# "hello" object in the server. -# -Hello.Proxy=hello:tcp -p 10000:udp -p 10000:ssl -p 10001 - -# # Warn about connection exceptions # Ice.Warn.Connections=1 |