- Session thread ID is initialized automatically, no explicit call to GetSessionThread() is needed
- SalomeApp_EventFilter moved to Event library and can be reused in any SALOME-based application that uses SALOME_Event
- Some diagnostic output added to SALOME_Event
DEFINES += EVENT_EXPORTS
HEADERS = Event.h
-HEADERS += SALOME_Event.h
+HEADERS += SALOME_Event.h
+HEADERS += SALOME_EventFilter.h
-SOURCES = SALOME_Event.cxx
+SOURCES = SALOME_Event.cxx
+SOURCES += SALOME_EventFilter.cxx
includes.files = $$HEADERS
includes.path = ../../include
salomeinclude_HEADERS = \
Event.h \
- SALOME_Event.h
+ SALOME_Event.h \
+ SALOME_EventFilter.h
-dist_libEvent_la_SOURCES = SALOME_Event.cxx
+dist_libEvent_la_SOURCES = \
+ SALOME_Event.cxx \
+ SALOME_EventFilter.cxx
libEvent_la_CPPFLAGS = $(QT_INCLUDES)
libEvent_la_LDFLAGS = $(QT_MT_LIBS)
static pthread_t myThread;
#endif
+/*!
+ \class InitEvent
+ \brief Helper event class responsible for initializing SALOME_Event
+ mechanism by the main thread ID
+ */
+class InitEvent : public SALOME_Event
+{
+public:
+ InitEvent();
+ virtual ~InitEvent();
+ virtual void Execute();
+};
+
+/*!
+ \brief Constructor, initializes the event mechanism by the current thread ID.
+ It is asssumed to be the main thread ID, so be careful!
+*/
+InitEvent::InitEvent()
+{
+ GetSessionThread();
+}
+
+/*!
+ \brief Destructor, does nothing.
+*/
+InitEvent::~InitEvent()
+{
+}
+
+/*!
+ \brief Nothing to be executed for this kind of event.
+*/
+void InitEvent::Execute()
+{
+}
+
+// NOTE: Here the SALOME event mechanism is initalized by the
+// current thread ID that is always assumed to be the main thread ID.
+// This should be revised as soon as the application library is no longer
+// linked against the Event library (i.e. this static object is not created or created
+// outside the main thread).
+static InitEvent myInitEvent;
+
/*!
\class SALOME_CustomEvent
\brief Generic event class for user-defined events
delete mySemaphore;
}
+/*!
+ \brief This method should be called by the main GUI thread
+ in order to execute the code specific for this event and finally
+ to inform the calling thread that the event
+ has been processed waking it up with help of the semaphore .
+ */
+void SALOME_Event::ExecutePostedEvent()
+{
+ // Diagnose incorrect usage of SALOME_Event API
+ if ( !IsSessionThread() ){
+ qWarning( "SALOME_Event::ExecutePostedEvent() is called from a secondary thread that might mean an error in application logic!" );
+ }
+ // Actual execution specific for particular kind of event
+ Execute();
+ // Signal the calling thread that the event has been processed
+ processed();
+}
+
/*!
\brief Post the event and wait for its completion.
+ process() should be called from a secondary thread only.
\sa processed()
*/
void SALOME_Event::process()
{
+ // Diagnose incorrect usage of SALOME_Event API
+ if ( IsSessionThread() ){
+ qWarning( "SALOME_Event::process() is called from the main GUI thread that might mean an error in application logic!" );
+ }
+
QApplication::postEvent( qApp, new SALOME_CustomEvent( SALOME_EVENT, (void*)this ) );
mySemaphore->acquire( 1 );
}
SALOME_Event();
virtual ~SALOME_Event();
+ void ExecutePostedEvent();
virtual void Execute() = 0;
static bool IsSessionThread();
friend class SalomeApp_EventFilter;
static void GetSessionThread();
- friend int main(int, char **);
private:
QSemaphore* mySemaphore; //!< internal semaphore
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "SALOME_EventFilter.h"
+#include "SALOME_Event.h"
+
+#include <QApplication>
+
+SALOME_EventFilter* SALOME_EventFilter::myFilter = NULL;
+
+/*!Constructor.*/
+SALOME_EventFilter::SALOME_EventFilter()
+: QObject()
+{
+ /* VSR 13/01/03 : installing global event filter for the application */
+ qApp->installEventFilter( this );
+}
+
+/*!Destructor.*/
+SALOME_EventFilter::~SALOME_EventFilter()
+{
+ qApp->removeEventFilter( this );
+}
+
+/*!
+ Custom event filter
+*/
+bool SALOME_EventFilter::eventFilter( QObject* o, QEvent* e )
+{
+ if ( e->type() == SALOME_EVENT )
+ {
+ SALOME_Event* aSE = (SALOME_Event*)((SALOME_CustomEvent*)e)->data();
+ processEvent(aSE);
+ ((SALOME_CustomEvent*)e)->setData( 0 );
+ return true;
+ }
+ return QObject::eventFilter( o, e );
+}
+
+/*!Process event.*/
+void SALOME_EventFilter::processEvent( SALOME_Event* theEvent )
+{
+ if(theEvent)
+ theEvent->ExecutePostedEvent();
+}
+
+/*!Create new instance of SALOME_EventFilter*/
+void SALOME_EventFilter::Init()
+{
+ if( myFilter==NULL )
+ myFilter = new SALOME_EventFilter();
+}
+
+/*!Destroy filter.*/
+void SALOME_EventFilter::Destroy()
+{
+ if( myFilter )
+ {
+ delete myFilter;
+ myFilter = NULL;
+ }
+}
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#ifndef SALOME_EVENTFILTER_H
+#define SALOME_EVENTFILTER_H
+
+#include "Event.h"
+#include <QObject>
+
+#if defined WIN32
+#pragma warning( disable: 4251 )
+#endif
+
+class SALOME_Event;
+
+/*!
+ Event filter class for QApplication object that handles custom events posted by SALOME_Event objects.
+ It assumes that such custom events are alwys posted, not sent.
+ This event filter can be installed by any application that intends to use SALOME_Event mechanism asynchronously.
+ This class replaced SalomeApp_EventFilter.
+*/
+class EVENT_EXPORT SALOME_EventFilter: public QObject
+{
+public:
+ static void Init();
+ static void Destroy();
+
+protected:
+ SALOME_EventFilter();
+ virtual ~SALOME_EventFilter();
+
+private:
+ /*! global event filter for qapplication */
+ virtual bool eventFilter( QObject* o, QEvent* e );
+ void processEvent( SALOME_Event* );
+
+private:
+ static SALOME_EventFilter* myFilter;
+};
+
+#if defined WIN32
+#pragma warning( default: 4251 )
+#endif
+
+#endif
SalomeApp_Module.h \
SalomeApp_Study.h \
SalomeApp_ExceptionHandler.h \
- SalomeApp_EventFilter.h \
SalomeApp_PyInterp.h \
SalomeApp_Tools.h \
SalomeApp_ImportOperation.h \
SalomeApp_LoadStudiesDlg.cxx \
SalomeApp_Study.cxx \
SalomeApp_ExceptionHandler.cxx \
- SalomeApp_EventFilter.cxx \
SalomeApp_PyInterp.cxx \
SalomeApp_Tools.cxx \
SalomeApp_ImportOperation.cxx \
../SVTK/libSVTK.la ../SOCC/libSOCC.la ../PyInterp/libPyInterp.la \
../PyConsole/libPyConsole.la ../LogWindow/libLogWindow.la \
../LightApp/libLightApp.la ../TOOLSGUI/libToolsGUI.la ../Session/libSalomeSession.la \
- ../CASCatch/libCASCatch.la $(CAS_KERNEL)
+ ../Event/libEvent.la ../CASCatch/libCASCatch.la $(CAS_KERNEL)
HEADERS += SalomeApp_Module.h
HEADERS += SalomeApp_Study.h
HEADERS += SalomeApp_ExceptionHandler.h
-HEADERS += SalomeApp_EventFilter.h
HEADERS += SalomeApp_Tools.h
HEADERS += SalomeApp_ImportOperation.h
HEADERS += SalomeApp_Filter.h
SOURCES += SalomeApp_LoadStudiesDlg.cxx
SOURCES += SalomeApp_Study.cxx
SOURCES += SalomeApp_ExceptionHandler.cxx
-SOURCES += SalomeApp_EventFilter.cxx
SOURCES += SalomeApp_PyInterp.cxx
SOURCES += SalomeApp_Tools.cxx
SOURCES += SalomeApp_ImportOperation.cxx
#include "SalomeApp_Study.h"
#include "SalomeApp_DataModel.h"
#include "SalomeApp_DataObject.h"
-#include "SalomeApp_EventFilter.h"
#include "SalomeApp_VisualState.h"
#include "SalomeApp_StudyPropertiesDlg.h"
#include "SalomeApp_LoadStudiesDlg.h"
#include <QtxTreeView.h>
+#include <SALOME_EventFilter.h>
+
// temporary commented
//#include <OB_ListItem.h>
SalomeApp_Application::~SalomeApp_Application()
{
// Do not destroy. It's a singleton !
- //SalomeApp_EventFilter::Destroy();
+ //SALOME_EventFilter::Destroy();
}
/*!Start application.*/
{
LightApp_Application::start();
- SalomeApp_EventFilter::Init();
+ SALOME_EventFilter::Init();
static bool isFirst = true;
if ( isFirst ) {
+++ /dev/null
-// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-
-#include "SalomeApp_EventFilter.h"
-#include <SALOME_Event.h>
-
-#include <QApplication>
-
-SalomeApp_EventFilter* SalomeApp_EventFilter::myFilter = NULL;
-
-/*!Constructor.*/
-SalomeApp_EventFilter::SalomeApp_EventFilter()
-: QObject()
-{
- /* VSR 13/01/03 : installing global event filter for the application */
- qApp->installEventFilter( this );
-}
-
-/*!Destructor.*/
-SalomeApp_EventFilter::~SalomeApp_EventFilter()
-{
- qApp->removeEventFilter( this );
-}
-
-/*!
- Custom event filter
-*/
-bool SalomeApp_EventFilter::eventFilter( QObject* o, QEvent* e )
-{
- if ( e->type() == SALOME_EVENT )
- {
- SALOME_Event* aSE = (SALOME_Event*)((SALOME_CustomEvent*)e)->data();
- processEvent(aSE);
- ((SALOME_CustomEvent*)e)->setData( 0 );
- return true;
- }
- return QObject::eventFilter( o, e );
-}
-
-/*!Process event.*/
-void SalomeApp_EventFilter::processEvent( SALOME_Event* theEvent )
-{
- if(theEvent){
- theEvent->Execute();
- // Signal the calling thread that the event has been processed
- theEvent->processed();
- }
-}
-
-/*!Create new instance of SalomeApp_EventFilter*/
-void SalomeApp_EventFilter::Init()
-{
- if( myFilter==NULL )
- myFilter = new SalomeApp_EventFilter();
-}
-
-/*!Destroy filter.*/
-void SalomeApp_EventFilter::Destroy()
-{
- if( myFilter )
- {
- delete myFilter;
- myFilter = NULL;
- }
-}
+++ /dev/null
-// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-#ifndef SALOMEAPP_EVENTFILTER_H
-#define SALOMEAPP_EVENTFILTER_H
-
-#include "SalomeApp.h"
-#include <QObject>
-
-#if defined WIN32
-#pragma warning( disable: 4251 )
-#endif
-
-class SALOME_Event;
-
-/*!
- Class provide event filter.
-*/
-class SALOMEAPP_EXPORT SalomeApp_EventFilter: public QObject
-{
-public:
- static void Init();
- static void Destroy();
-
-protected:
- SalomeApp_EventFilter();
- virtual ~SalomeApp_EventFilter();
-
-private:
- /*! global event filter for qapplication */
- virtual bool eventFilter( QObject* o, QEvent* e );
- void processEvent( SALOME_Event* );
-
-private:
- static SalomeApp_EventFilter* myFilter;
-};
-
-#if defined WIN32
-#pragma warning( default: 4251 )
-#endif
-
-#endif
int orbArgc = 1;
orb = init( orbArgc, argv );
- // ...install SALOME thread event handler
- SALOME_Event::GetSessionThread();
-
CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
poa = PortableServer::POA::_narrow( obj );