diff options
author | fcolin | 2007-02-01 13:03:04 +0000 |
---|---|---|
committer | fcolin | 2007-02-01 13:03:04 +0000 |
commit | 282cd689421f7d9a458978e1e05af54d28e9bd7a (patch) | |
tree | 44de2cbba6ea5cac8bb4871342b107b7db38150d /Bus/Ivy/IvySynchroWnd.cxx | |
parent | 71e551449be7df68e5b6a10640c3e0d5a6974710 (diff) | |
download | ivy-cplusplus-282cd689421f7d9a458978e1e05af54d28e9bd7a.zip ivy-cplusplus-282cd689421f7d9a458978e1e05af54d28e9bd7a.tar.gz ivy-cplusplus-282cd689421f7d9a458978e1e05af54d28e9bd7a.tar.bz2 ivy-cplusplus-282cd689421f7d9a458978e1e05af54d28e9bd7a.tar.xz |
Utilisateur : Fcolin Date : 21/07/00 Heure : 10:48 Archivé dans $/Ivy Commentaire: separation file cb de la file de message windows (vss 3)
Diffstat (limited to 'Bus/Ivy/IvySynchroWnd.cxx')
-rw-r--r-- | Bus/Ivy/IvySynchroWnd.cxx | 85 |
1 files changed, 49 insertions, 36 deletions
diff --git a/Bus/Ivy/IvySynchroWnd.cxx b/Bus/Ivy/IvySynchroWnd.cxx index 5e7189c..80b2622 100644 --- a/Bus/Ivy/IvySynchroWnd.cxx +++ b/Bus/Ivy/IvySynchroWnd.cxx @@ -6,9 +6,8 @@ #include "IvySynchroWnd.h"
-#define WM_MESSAGE_CB WM_USER + 1001
-#define WM_APPCONNECTED_CB WM_USER + 1002
-#define WM_APPDISCONNECTED_CB WM_USER + 1003
+#define WM_IVY_CB WM_USER + 1001
+
IvySynchroWnd* IvySynchronousCallback::m_synchro = NULL;
IvySynchroWnd* IvySynchroWnd::m_synchro = NULL;
@@ -53,6 +52,7 @@ IvySynchroWnd::IvySynchroWnd() TRACE("Warning: unable to create Ivy Synchro notify window!\n");
//AfxThrowResourceException();
}
+ InitializeCriticalSection( &m_CritSection );
}
IvySynchroWnd::~IvySynchroWnd()
@@ -64,16 +64,9 @@ LRESULT CALLBACK IvySynchroWnd::WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam {
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 );
+ case WM_IVY_CB:
+ m_synchro->OnIvyCB( wParam, lParam );
break;
-
//
// Process other messages.
//
@@ -91,32 +84,28 @@ LRESULT CALLBACK IvySynchroWnd::WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam // IvySynchroWnd message handlers
-LRESULT IvySynchroWnd::OnMessageCB(WPARAM wParam, LPARAM lParam)
+LRESULT IvySynchroWnd::OnIvyCB(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
+ std::list<IvySynchronousCallback*>::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;
}
-LRESULT IvySynchroWnd::OnApplicationConnectedCB(WPARAM wParam, LPARAM lParam)
+void IvySynchroWnd::PostIvyCB( IvySynchronousCallback *cb )
{
- 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;
+ EnterCriticalSection( &m_CritSection );
+ if ( !m_synchro->callbacklist.size() )
+ assert(PostMessage(m_synchro->m_hWnd, WM_IVY_CB, 0, 0 ));
+ m_synchro->callbacklist.push_back( cb );
+ LeaveCriticalSection( &m_CritSection );
}
//
//
@@ -139,9 +128,18 @@ void IvySynchronousMessageCallback::OnMessage(IvyApplication *app, int argc, con 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 ));
+ m_synchro->PostIvyCB( param );
}
+void IvySynchronousMessageCallback::CallCallback()
+{
+ target->OnMessage( app, argc, (const char **) argv );
+ for( int i = 0; i < argc ; i++ )
+ free( argv[i] ); // allocated with strdup
+ delete argv; // allocated with new
+}
+
+
IvySynchronousApplicationCallback::IvySynchronousApplicationCallback( IvyApplicationCallback *cb )
{
target = cb;
@@ -150,13 +148,28 @@ void IvySynchronousApplicationCallback::OnApplicationConnected( IvyApplication * {
// duplicate on the Message Queue
IvySynchronousApplicationCallback *param = new IvySynchronousApplicationCallback(target);
+ param->type = CONNECTED_CB;
param->app = app;
- assert(PostMessage(m_synchro->m_hWnd, WM_APPCONNECTED_CB, 0, (LPARAM)param ));
+ 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;
- assert(PostMessage(m_synchro->m_hWnd, WM_APPDISCONNECTED_CB, 0, (LPARAM)param ));
+ m_synchro->PostIvyCB( param );
}
+void IvySynchronousApplicationCallback::CallCallback()
+{
+ switch ( type )
+ {
+ case CONNECTED_CB:
+ target->OnApplicationConnected( app );
+ break;
+ case DISCONNECTED_CB:
+ target->OnApplicationDisconnected( app );
+ break;
+ }
+}
\ No newline at end of file |