summaryrefslogtreecommitdiff
path: root/Ivy/IvySynchroWnd.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Ivy/IvySynchroWnd.cxx')
-rw-r--r--Ivy/IvySynchroWnd.cxx139
1 files changed, 112 insertions, 27 deletions
diff --git a/Ivy/IvySynchroWnd.cxx b/Ivy/IvySynchroWnd.cxx
index 2c84ad5..374538c 100644
--- a/Ivy/IvySynchroWnd.cxx
+++ b/Ivy/IvySynchroWnd.cxx
@@ -2,15 +2,10 @@
//
#include "IvyStdAfx.h"
-
-
#include "IvySynchroWnd.h"
-
#define WM_IVY_CB WM_USER + 1001
-
-IvySynchroWnd* IvySynchronousCallback::m_synchro = NULL;
IvySynchroWnd* IvySynchroWnd::m_synchro = NULL;
/////////////////////////////////////////////////////////////////////////////
@@ -19,22 +14,22 @@ IvySynchroWnd* IvySynchroWnd::m_synchro = NULL;
IvySynchroWnd::IvySynchroWnd()
{
m_hWnd = NULL;
- m_synchro = this;
+ //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.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.
@@ -59,7 +54,16 @@ IvySynchroWnd::IvySynchroWnd()
IvySynchroWnd::~IvySynchroWnd()
{
}
-
+void IvySynchroWnd::Init(bool synchronous)
+{
+ if ( synchronous && m_synchro == NULL )
+ m_synchro = new IvySynchroWnd();
+}
+void IvySynchroWnd::Finish()
+{
+ if ( m_synchro == NULL )
+ delete m_synchro;
+}
LRESULT CALLBACK IvySynchroWnd::WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
@@ -102,12 +106,57 @@ LRESULT IvySynchroWnd::OnIvyCB(WPARAM wParam, LPARAM lParam)
}
void IvySynchroWnd::PostIvyCB( IvySynchronousCallback *cb )
{
+ BOOL doPost = FALSE;
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 );
+ doPost = callbacklist.empty();
+ callbacklist.push_back( cb );
LeaveCriticalSection( &m_CritSection );
+ if ( doPost )
+ ASSERT(PostMessage(m_hWnd, WM_IVY_CB, 0, 0 ));
+ // give a change to process messages
+ SwitchToThread();
+
}
+BOOL CALLBACK MyQuitWindows( HWND hwnd, LPARAM lParam )
+{
+ BOOL *posted = (BOOL*)lParam;
+ DWORD dwTheardId;
+ DWORD pid;
+ DWORD mypid = GetCurrentProcessId();
+ dwTheardId = ::GetWindowThreadProcessId( hwnd,&pid);
+ if ( pid == mypid )
+ {
+ // give a change to User for closing application safely, save file etc...
+ *posted = PostMessage( hwnd, WM_CLOSE, 0,0 );
+ }
+ return TRUE;
+}
+
+void IvySynchroWnd::PostQuit()
+{
+ BOOL posted = FALSE;
+ BOOL canceled = FALSE;
+ EnumWindows(MyQuitWindows, (LPARAM)&posted );
+ // give a change to process messages
+ if ( !SwitchToThread() )
+ {
+ Sleep( 200 );
+ }
+ if ( !posted )
+ {
+ PostQuitMessage( -1 );
+ // give a change to process messages
+ if ( !SwitchToThread() )
+ {
+ Sleep( 100 );
+ }
+ // ultimate close
+ exit(-1);
+ }
+}
+
+
+ //exit(-1);
//
//
IvySynchronousMessageCallback::IvySynchronousMessageCallback( IvyMessageCallback *cb )
@@ -128,7 +177,6 @@ IvySynchronousMessageCallback::~IvySynchronousMessageCallback()
}
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;
@@ -142,12 +190,17 @@ void IvySynchronousMessageCallback::OnMessage(IvyApplication *app, int argc, con
param->argv[i] = _strdup( argv[i]);
#endif
}
-// TRACE( "IvySynchronousMessageCallback::OnMessage msg count %d\n",wParam);
- m_synchro->PostIvyCB( param );
+#ifdef IVY_DEBUG
+ TRACE( "IvySynchronousMessageCallback::OnMessage Push callback %s argc=%d\n",typeid( *target).name(), argc);
+#endif
+ IvySynchroWnd::m_synchro->PostIvyCB( param );
}
void IvySynchronousMessageCallback::CallCallback()
{
+#ifdef IVY_DEBUG
+ TRACE( "IvySynchronousMessageCallback::OnMessage Real callback %s argc=%d\n",typeid( *target).name(), argc);
+#endif
target->OnMessage( app, argc, (const char **) argv );
for( int i = 0; i < argc ; i++ )
delete argv[i];
@@ -165,7 +218,7 @@ void IvySynchronousApplicationCallback::OnApplicationConnected( IvyApplication *
IvySynchronousApplicationCallback *param = new IvySynchronousApplicationCallback(target);
param->type = CONNECTED_CB;
param->app = app;
- m_synchro->PostIvyCB( param );
+ IvySynchroWnd::m_synchro->PostIvyCB( param );
}
void IvySynchronousApplicationCallback::OnApplicationDisconnected( IvyApplication *app)
@@ -174,7 +227,7 @@ void IvySynchronousApplicationCallback::OnApplicationDisconnected( IvyApplicati
IvySynchronousApplicationCallback *param = new IvySynchronousApplicationCallback(target);
param->type = DISCONNECTED_CB;
param->app = app;
- m_synchro->PostIvyCB( param );
+ IvySynchroWnd::m_synchro->PostIvyCB( param );
}
void IvySynchronousApplicationCallback::CallCallback()
{
@@ -203,7 +256,7 @@ void IvySynchronousBindingCallback::OnAddBind( IvyApplication *app, int id, cons
param->app = app;
param->id = id;
param->regexp = _strdup(regexp);
- m_synchro->PostIvyCB( param );
+ IvySynchroWnd::m_synchro->PostIvyCB( param );
}
void IvySynchronousBindingCallback::OnRemoveBind( IvyApplication *app, int id, const char *regexp)
@@ -214,7 +267,7 @@ void IvySynchronousBindingCallback::OnRemoveBind( IvyApplication *app, int id,
param->app = app;
param->id = id;
param->regexp = _strdup(regexp);
- m_synchro->PostIvyCB( param );
+ IvySynchroWnd::m_synchro->PostIvyCB( param );
}
void IvySynchronousBindingCallback::OnFilterBind( IvyApplication *app, int id, const char *regexp)
{
@@ -224,7 +277,7 @@ void IvySynchronousBindingCallback::OnFilterBind( IvyApplication *app, int id,
param->app = app;
param->id = id;
param->regexp = _strdup(regexp);
- m_synchro->PostIvyCB( param );
+ IvySynchroWnd::m_synchro->PostIvyCB( param );
}
void IvySynchronousBindingCallback::CallCallback()
{
@@ -244,4 +297,36 @@ void IvySynchronousBindingCallback::CallCallback()
}
}
delete regexp;
+}
+
+IvySynchronousDieCallback::IvySynchronousDieCallback( IvyDieCallback *cb )
+{
+ target = cb;
+}
+bool IvySynchronousDieCallback::OnDie(IvyApplication *app, int id, const char *arg )
+{
+ static int msg_count = 0;
+ // duplicate on the Message Queue
+ IvySynchronousDieCallback *param = new IvySynchronousDieCallback(target);
+ param->app = app;
+ param->id = id;
+
+#ifdef UNDER_CE
+ param->arg = _strdup( argv);
+#else
+ param->arg = _strdup( arg);
+#endif
+
+// TRACE( "IvySynchronousMessageCallback::OnMessage msg count %d\n",wParam);
+ IvySynchroWnd::m_synchro->PostIvyCB( param );
+ return FALSE; // do not exit now wait for Quit on MessageQueue
+}
+void IvySynchronousDieCallback::CallCallback()
+{
+ // duplicate on the Message Queue
+ if ( !target ) return;
+ if ( target->OnDie ( app, id, arg ) )
+ {
+ IvySynchroWnd::m_synchro->PostQuit();
+ }
} \ No newline at end of file