summaryrefslogtreecommitdiff
path: root/Ivy/IvySynchroWnd.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Ivy/IvySynchroWnd.cxx')
-rw-r--r--Ivy/IvySynchroWnd.cxx243
1 files changed, 243 insertions, 0 deletions
diff --git a/Ivy/IvySynchroWnd.cxx b/Ivy/IvySynchroWnd.cxx
new file mode 100644
index 0000000..2109a61
--- /dev/null
+++ b/Ivy/IvySynchroWnd.cxx
@@ -0,0 +1,243 @@
+// SynchroWnd.cpp : implementation file
+//
+
+#include "IvyStdAfx.h"
+
+
+#include "IvySynchroWnd.h"
+
+
+#define WM_IVY_CB WM_USER + 1001
+
+
+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 = TEXT("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, TEXT("IvySynchroClass"), TEXT("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();
+ }
+ InitializeCriticalSection( &m_CritSection );
+
+}
+IvySynchroWnd::~IvySynchroWnd()
+{
+}
+
+
+LRESULT CALLBACK IvySynchroWnd::WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
+{
+ switch ( uMsg )
+ {
+ case WM_IVY_CB:
+ m_synchro->OnIvyCB( wParam, lParam );
+ break;
+ //
+ // Process other messages.
+ //
+
+ default:
+ return DefWindowProc(hwnd, uMsg, wParam, lParam);
+ }
+ return 0;
+}
+
+
+
+
+/////////////////////////////////////////////////////////////////////////////
+// IvySynchroWnd message handlers
+
+
+LRESULT IvySynchroWnd::OnIvyCB(WPARAM wParam, LPARAM lParam)
+{
+ IvySynchronousCallbackList::iterator iter;
+ EnterCriticalSection( &m_CritSection );
+
+ for ( iter = callbacklist.begin(); iter != callbacklist.end(); )
+ {
+ IvySynchronousCallback *param = *iter++;
+ param->CallCallback();
+ delete param;
+ }
+ callbacklist.clear();
+ LeaveCriticalSection( &m_CritSection );
+ return 0L;
+}
+void IvySynchroWnd::PostIvyCB( IvySynchronousCallback *cb )
+{
+ EnterCriticalSection( &m_CritSection );
+ if ( m_synchro->callbacklist.empty() )
+ ASSERT(PostMessage(m_synchro->m_hWnd, WM_IVY_CB, 0, 0 ));
+ m_synchro->callbacklist.push_back( cb );
+ LeaveCriticalSection( &m_CritSection );
+}
+//
+//
+IvySynchronousMessageCallback::IvySynchronousMessageCallback( IvyMessageCallback *cb )
+{
+ target = cb;
+ app = 0;
+ argc = 0;
+ argv = 0;
+}
+IvySynchronousMessageCallback::~IvySynchronousMessageCallback()
+{
+ //delete target;
+ for( int i = 0; i < argc ; i++ )
+ {
+ delete argv[i];
+ }
+ if ( argv ) delete argv;
+}
+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++ )
+ {
+#ifdef UNDER_CE
+ param->argv[i] = _strdup( argv[i]);
+#else
+ param->argv[i] = _strdup( argv[i]);
+#endif
+ }
+// TRACE( "IvySynchronousMessageCallback::OnMessage msg count %d\n",wParam);
+ m_synchro->PostIvyCB( param );
+
+}
+void IvySynchronousMessageCallback::CallCallback()
+{
+ target->OnMessage( app, argc, (const char **) argv );
+ for( int i = 0; i < argc ; i++ )
+ delete argv[i];
+ delete argv;
+}
+
+
+IvySynchronousApplicationCallback::IvySynchronousApplicationCallback( IvyApplicationCallback *cb )
+{
+ target = cb;
+}
+void IvySynchronousApplicationCallback::OnApplicationConnected( IvyApplication *app)
+{
+ // duplicate on the Message Queue
+ IvySynchronousApplicationCallback *param = new IvySynchronousApplicationCallback(target);
+ param->type = CONNECTED_CB;
+ param->app = app;
+ m_synchro->PostIvyCB( param );
+}
+
+void IvySynchronousApplicationCallback::OnApplicationDisconnected( IvyApplication *app)
+{
+ // duplicate on the Message Queue
+ IvySynchronousApplicationCallback *param = new IvySynchronousApplicationCallback(target);
+ param->type = DISCONNECTED_CB;
+ param->app = app;
+ m_synchro->PostIvyCB( param );
+}
+void IvySynchronousApplicationCallback::CallCallback()
+{
+ switch ( type )
+ {
+ case CONNECTED_CB:
+ target->OnApplicationConnected( app );
+ break;
+ case DISCONNECTED_CB:
+ target->OnApplicationDisconnected( app );
+ break;
+ }
+}
+
+
+IvySynchronousBindingCallback::IvySynchronousBindingCallback( IvyBindingCallback *cb )
+{
+ target = cb;
+}
+void IvySynchronousBindingCallback::OnAddBind( IvyApplication *app, int id, const char *regexp)
+{
+ // duplicate on the Message Queue
+ IvySynchronousBindingCallback *param = new IvySynchronousBindingCallback(target);
+ param->type = ADD_CB;
+ param->app = app;
+ param->id = id;
+ param->regexp = _strdup(regexp);
+ m_synchro->PostIvyCB( param );
+}
+
+void IvySynchronousBindingCallback::OnRemoveBind( IvyApplication *app, int id, const char *regexp)
+{
+ // duplicate on the Message Queue
+ IvySynchronousBindingCallback *param = new IvySynchronousBindingCallback(target);
+ param->type = REMOVE_CB;
+ param->app = app;
+ param->id = id;
+ param->regexp = _strdup(regexp);
+ m_synchro->PostIvyCB( param );
+}
+void IvySynchronousBindingCallback::OnFilterBind( IvyApplication *app, int id, const char *regexp)
+{
+ // duplicate on the Message Queue
+ IvySynchronousBindingCallback *param = new IvySynchronousBindingCallback(target);
+ param->type = FILTER_CB;
+ param->app = app;
+ param->id = id;
+ param->regexp = _strdup(regexp);
+ m_synchro->PostIvyCB( param );
+}
+void IvySynchronousBindingCallback::CallCallback()
+{
+ switch ( type )
+ {
+ case ADD_CB:
+ target->OnAddBind( app, id, regexp );
+ break;
+ case REMOVE_CB:
+ target->OnRemoveBind( app, id, regexp );
+ break;
+ case FILTER_CB:
+ target->OnFilterBind( app, id, regexp );
+ break;
+ }
+ delete regexp;
+} \ No newline at end of file