summaryrefslogtreecommitdiff
path: root/Ivy
diff options
context:
space:
mode:
Diffstat (limited to 'Ivy')
-rw-r--r--Ivy/IvySynchroWnd.cxx158
1 files changed, 158 insertions, 0 deletions
diff --git a/Ivy/IvySynchroWnd.cxx b/Ivy/IvySynchroWnd.cxx
new file mode 100644
index 0000000..297c64e
--- /dev/null
+++ b/Ivy/IvySynchroWnd.cxx
@@ -0,0 +1,158 @@
+// SynchroWnd.cpp : implementation file
+//
+
+#include "stdafx.h"
+
+#include "IvySynchroWnd.h"
+
+
+#define WM_MESSAGE_CB WM_USER + 1001
+#define WM_APPCONNECTED_CB WM_USER + 1002
+#define WM_APPDISCONNECTED_CB WM_USER + 1003
+
+IvySynchroWnd* IvySynchronousCallback::m_synchro = NULL;
+IvySynchroWnd* IvySynchroWnd::m_synchro = NULL;
+
+/////////////////////////////////////////////////////////////////////////////
+// IvySynchroWnd
+
+IvySynchroWnd::IvySynchroWnd()
+{
+ m_hWnd = NULL;
+ m_synchro = this;
+
+ WNDCLASS wc;
+
+ // Fill in the window class structure with parameters
+ // that describe the main window.
+
+ wc.style = 0; // noredraw if size changes
+ wc.lpfnWndProc = WindowProc; // points to window procedure
+ wc.cbClsExtra = 0; // no extra class memory
+ wc.cbWndExtra = 0; // no extra window memory
+ wc.hInstance = 0; // handle to instance
+ wc.hIcon = NULL; // predefined app. icon
+ wc.hCursor = NULL; // predefined arrow
+ wc.hbrBackground = 0; // white background brush
+ wc.lpszMenuName = NULL; // no menu
+ wc.lpszClassName = "IvySynchroClass"; // name of window class
+
+ // Register the window class.
+
+ if ( ! RegisterClass(&wc) )
+ {
+ TRACE("Warning: unable to create Ivy Synchro notify window!\n");
+ //AfxThrowResourceException();
+ }
+
+ // Create the syncrho window.
+ m_hWnd = CreateWindowEx(0, "IvySynchroClass","Ivy Synchro Notification Sink",
+ WS_OVERLAPPED, 0, 0, 0, 0, NULL , NULL, NULL, NULL);
+ if (!m_hWnd)
+ {
+ TRACE("Warning: unable to create Ivy Synchro notify window!\n");
+ //AfxThrowResourceException();
+ }
+
+}
+IvySynchroWnd::~IvySynchroWnd()
+{
+}
+
+
+LRESULT CALLBACK IvySynchroWnd::WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
+{
+ switch ( uMsg )
+ {
+ case WM_MESSAGE_CB:
+ m_synchro->OnMessageCB( wParam, lParam );
+ break;
+ case WM_APPCONNECTED_CB:
+ m_synchro->OnApplicationConnectedCB( wParam, lParam );
+ break;
+ case WM_APPDISCONNECTED_CB:
+ m_synchro->OnApplicationDisconnectedCB( wParam, lParam );
+ break;
+
+ //
+ // Process other messages.
+ //
+
+ default:
+ return DefWindowProc(hwnd, uMsg, wParam, lParam);
+ }
+ return 0;
+}
+
+
+
+
+/////////////////////////////////////////////////////////////////////////////
+// IvySynchroWnd message handlers
+
+
+LRESULT IvySynchroWnd::OnMessageCB(WPARAM wParam, LPARAM lParam)
+{
+ IvySynchronousMessageCallback *param = ( IvySynchronousMessageCallback * ) lParam;
+// TRACE( "IvySynchroWnd::OnMessageCB msg count %d\n",wParam);
+ param->target->OnMessage( param->app, param->argc, (const char **) param->argv );
+ for( int i = 0; i < param->argc ; i++ )
+ free( param->argv[i] ); // allocated with strdup
+ delete param->argv; // allocated with new
+ delete param;
+ return 0L;
+}
+LRESULT IvySynchroWnd::OnApplicationConnectedCB(WPARAM wParam, LPARAM lParam)
+{
+ IvySynchronousApplicationCallback *param = ( IvySynchronousApplicationCallback * ) lParam;
+// TRACE( "IvySynchroWnd::OnSynchroNotify End Synchro\n");
+ param->target->OnApplicationConnected( param->app );
+ delete param;
+ return 0L;
+}
+LRESULT IvySynchroWnd::OnApplicationDisconnectedCB(WPARAM wParam, LPARAM lParam)
+{
+ IvySynchronousApplicationCallback *param = ( IvySynchronousApplicationCallback * ) lParam;
+// TRACE( "IvySynchroWnd::OnSynchroNotify End Synchro\n");
+ param->target->OnApplicationDisconnected( param->app );
+ delete param;
+ return 0L;
+}
+//
+//
+IvySynchronousMessageCallback::IvySynchronousMessageCallback( IvyMessageCallback *cb )
+{
+ target = cb;
+}
+void IvySynchronousMessageCallback::OnMessage(IvyApplication *app, int argc, const char **argv )
+{
+ static int msg_count = 0;
+ // duplicate on the Message Queue
+ IvySynchronousMessageCallback *param = new IvySynchronousMessageCallback(target);
+ param->app = app;
+ param->argc = argc;
+ param->argv = new char*[argc];
+ for( int i = 0; i < argc ; i++ )
+ param->argv[i] = strdup( argv[i]);
+// TRACE( "IvySynchronousMessageCallback::OnMessage msg count %d\n",wParam);
+ assert(PostMessage(m_synchro->m_hWnd, WM_MESSAGE_CB, msg_count++, (LPARAM)param ));
+
+}
+IvySynchronousApplicationCallback::IvySynchronousApplicationCallback( IvyApplicationCallback *cb )
+{
+ target = cb;
+}
+void IvySynchronousApplicationCallback::OnApplicationConnected( IvyApplication *app)
+{
+ // duplicate on the Message Queue
+ IvySynchronousApplicationCallback *param = new IvySynchronousApplicationCallback(target);
+ param->app = app;
+ assert(PostMessage(m_synchro->m_hWnd, WM_APPCONNECTED_CB, 0, (LPARAM)param ));
+}
+void IvySynchronousApplicationCallback::OnApplicationDisconnected( IvyApplication *app)
+{
+ // duplicate on the Message Queue
+ IvySynchronousApplicationCallback *param = new IvySynchronousApplicationCallback(target);
+ param->app = app;
+ assert(PostMessage(m_synchro->m_hWnd, WM_APPDISCONNECTED_CB, 0, (LPARAM)param ));
+}