37#include <com/sun/star/frame/XSessionManagerClient.hpp> 
   38#include <com/sun/star/lang/XMultiServiceFactory.hpp> 
   39#include <com/sun/star/lang/XServiceInfo.hpp> 
   40#include <com/sun/star/frame/XSessionManagerListener2.hpp> 
   56    public cppu::WeakComponentImplHelper < XSessionManagerClient, css::lang::XServiceInfo >
 
   60        css::uno::Reference< XSessionManagerListener >      
m_xListener;
 
   61        bool                                        m_bInteractionRequested;
 
   62        bool                                        m_bInteractionDone;
 
   65        explicit Listener( css::uno::Reference< XSessionManagerListener > xListener )
 
   67                  m_bInteractionRequested( false ),
 
   68                  m_bInteractionDone( false ),
 
   74    std::unique_ptr< SalSession >                   m_xSession;
 
   75    bool                                            m_bInteractionRequested;
 
   76    bool                                            m_bInteractionGranted;
 
   77    bool                                            m_bInteractionDone;
 
   80    static void SalSessionEventProc( 
void* pData, 
SalSessionEvent* pEvent );
 
   82    virtual ~VCLSession()
 override {}
 
   84    virtual void SAL_CALL addSessionManagerListener( 
const css::uno::Reference< XSessionManagerListener >& xListener ) 
override;
 
   85    virtual void SAL_CALL removeSessionManagerListener( 
const css::uno::Reference< XSessionManagerListener>& xListener ) 
override;
 
   86    virtual void SAL_CALL queryInteraction( 
const css::uno::Reference< XSessionManagerListener >& xListener ) 
override;
 
   87    virtual void SAL_CALL interactionDone( 
const css::uno::Reference< XSessionManagerListener >& xListener ) 
override;
 
   88    virtual void SAL_CALL saveDone( 
const css::uno::Reference< XSessionManagerListener >& xListener ) 
override;
 
   89    virtual sal_Bool SAL_CALL cancelShutdown() 
override;
 
   92        return "com.sun.star.frame.VCLSessionManagerClient";
 
  100        return {
"com.sun.star.frame.SessionManagerClient"};
 
  103    void SAL_CALL disposing() 
override;
 
  105    void callSaveRequested( 
bool bShutdown );
 
  106    void callShutdownCancelled();
 
  107    void callInteractionGranted( 
bool bGranted );
 
  116VCLSession::VCLSession()
 
  117        : WeakComponentImplHelper( 
m_aMutex ),
 
  118          m_xSession( 
ImplGetSVData()->mpDefInst->CreateSalSession() ),
 
  119          m_bInteractionRequested( false ),
 
  120          m_bInteractionGranted( false ),
 
  121          m_bInteractionDone( false ),
 
  124    SAL_INFO(
"vcl.se", 
"VCLSession::VCLSession" );
 
  127        m_xSession->SetCallback( SalSessionEventProc, 
this );
 
  130void VCLSession::callSaveRequested( 
bool bShutdown )
 
  132    SAL_INFO(
"vcl.se", 
"VCLSession::callSaveRequested" );
 
  136        osl::MutexGuard aGuard( m_aMutex );
 
  139            listener.m_bSaveDone = listener.m_bInteractionRequested = listener.m_bInteractionDone = 
false;
 
  146        m_bInteractionDone = 
false;
 
  149        m_bInteractionRequested = m_bInteractionGranted = !m_xSession;
 
  154        SAL_INFO(
"vcl.se.debug", 
"  aListeners.empty() = " << (
aListeners.empty() ? 
"true" : 
"false") <<
 
  155                                 ", bShutdown = " << (bShutdown ? 
"true" : 
"false"));
 
  159                m_xSession->saveDone();
 
  165    for (
auto const & listener: aListeners)
 
  166        listener.m_xListener->doSave( bShutdown, 
false );
 
  169void VCLSession::callInteractionGranted( 
bool bInteractionGranted )
 
  171    SAL_INFO(
"vcl.se", 
"VCLSession::callInteractionGranted" );
 
  175        osl::MutexGuard aGuard( m_aMutex );
 
  178            if( listener.m_bInteractionRequested )
 
  181        m_bInteractionGranted = bInteractionGranted;
 
  186        SAL_INFO(
"vcl.se.debug", 
"  aListeners.empty() = " << (
aListeners.empty() ? 
"true" : 
"false") <<
 
  187                                 ", bInteractionGranted = " << (bInteractionGranted ? 
"true" : 
"false"));
 
  191                m_xSession->interactionDone();
 
  197    for (
auto const & listener: aListeners)
 
  198        listener.m_xListener->approveInteraction( bInteractionGranted );
 
  201void VCLSession::callShutdownCancelled()
 
  203    SAL_INFO(
"vcl.se", 
"VCLSession::callShutdownCancelled");
 
  207        osl::MutexGuard aGuard( m_aMutex );
 
  211        m_bInteractionRequested = m_bInteractionDone = m_bInteractionGranted = 
false;
 
  215    for (
auto const & listener: aListeners)
 
  216        listener.m_xListener->shutdownCanceled();
 
  219void VCLSession::callQuit()
 
  221    SAL_INFO(
"vcl.se", 
"VCLSession::callQuit");
 
  225        osl::MutexGuard aGuard( m_aMutex );
 
  229        m_bInteractionRequested = m_bInteractionDone = m_bInteractionGranted = 
false;
 
  233    for (
auto const & listener: aListeners)
 
  235        css::uno::Reference< XSessionManagerListener2 > xListener2( listener.m_xListener, UNO_QUERY );
 
  236        if( xListener2.is() )
 
  237            xListener2->doQuit();
 
  241void VCLSession::SalSessionEventProc( 
void* pData, 
SalSessionEvent* pEvent )
 
  243    SAL_INFO(
"vcl.se", 
"VCLSession::SalSessionEventProc");
 
  245    VCLSession * pThis = 
static_cast< VCLSession * 
>( 
pData );
 
  250            SAL_INFO(
"vcl.se.debug", 
"  EventProcType = Interaction");
 
  257            SAL_INFO(
"vcl.se.debug", 
"  EventProcType = SaveRequest");
 
  263            SAL_INFO(
"vcl.se.debug", 
"  EventProcType = ShutdownCancel");
 
  264            pThis->callShutdownCancelled();
 
  267            SAL_INFO(
"vcl.se.debug", 
"  EventProcType = Quit");
 
  273void SAL_CALL VCLSession::addSessionManagerListener( 
const css::uno::Reference<XSessionManagerListener>& xListener )
 
  275    SAL_INFO(
"vcl.se", 
"VCLSession::addSessionManagerListener" );
 
  277    osl::MutexGuard aGuard( m_aMutex );
 
  283void SAL_CALL VCLSession::removeSessionManagerListener( 
const css::uno::Reference<XSessionManagerListener>& xListener )
 
  285    SAL_INFO(
"vcl.se", 
"VCLSession::removeSessionManagerListener" );
 
  287    osl::MutexGuard aGuard( m_aMutex );
 
  294void SAL_CALL VCLSession::queryInteraction( 
const css::uno::Reference<XSessionManagerListener>& xListener )
 
  296    SAL_INFO(
"vcl.se", 
"VCLSession::queryInteraction");
 
  298    SAL_INFO(
"vcl.se.debug", 
"  m_bInteractionGranted = " << (m_bInteractionGranted ? 
"true" : 
"false") <<
 
  299                             ", m_bInteractionRequested = "<< (m_bInteractionRequested ? 
"true" : 
"false"));
 
  300    if( m_bInteractionGranted )
 
  302        if( m_bInteractionDone )
 
  303            xListener->approveInteraction( 
false );
 
  305            xListener->approveInteraction( 
true );
 
  309    osl::MutexGuard aGuard( m_aMutex );
 
  310    if( ! m_bInteractionRequested )
 
  312        m_xSession->queryInteraction();
 
  313        m_bInteractionRequested = 
true;
 
  317        if( listener.m_xListener == xListener )
 
  319            SAL_INFO(
"vcl.se.debug", 
"  listener.m_xListener == xListener");
 
  320            listener.m_bInteractionRequested = 
true;
 
  321            listener.m_bInteractionDone      = 
false;
 
  326void SAL_CALL VCLSession::interactionDone( 
const css::uno::Reference< XSessionManagerListener >& xListener )
 
  328    SAL_INFO(
"vcl.se", 
"VCLSession::interactionDone");
 
  330    osl::MutexGuard aGuard( m_aMutex );
 
  331    int nRequested = 0, nDone = 0;
 
  334        if( listener.m_bInteractionRequested )
 
  337            if( xListener == listener.m_xListener )
 
  338                listener.m_bInteractionDone = 
true;
 
  340        if( listener.m_bInteractionDone )
 
  344    SAL_INFO(
"vcl.se.debug", 
"  nDone = " << nDone <<
 
  345                             ", nRequested =" << nRequested);
 
  346    if( nDone == nRequested && nDone > 0 )
 
  348        m_bInteractionDone = 
true;
 
  350            m_xSession->interactionDone();
 
  354void SAL_CALL VCLSession::saveDone( 
const css::uno::Reference< XSessionManagerListener >& xListener )
 
  356    SAL_INFO(
"vcl.se", 
"VCLSession::saveDone");
 
  358    osl::MutexGuard aGuard( m_aMutex );
 
  360    bool bSaveDone = 
true;
 
  363        if( listener.m_xListener == xListener )
 
  364            listener.m_bSaveDone = 
true;
 
  365        if( ! listener.m_bSaveDone )
 
  369    SAL_INFO(
"vcl.se.debug", 
"  bSaveDone = " << (bSaveDone ? 
"true" : 
"false"));
 
  371    if( bSaveDone && !m_bSaveDone )
 
  375            m_xSession->saveDone();
 
  379sal_Bool SAL_CALL VCLSession::cancelShutdown()
 
  381    SAL_INFO(
"vcl.se", 
"VCLSession::cancelShutdown");
 
  383    return m_xSession && m_xSession->cancelShutdown();
 
  386void VCLSession::disposing() {
 
  387    SAL_INFO(
"vcl.se", 
"VCLSession::disposing");
 
  389    std::vector<Listener> vector;
 
  391        osl::MutexGuard g(m_aMutex);
 
  394    css::lang::EventObject src(getXWeak());
 
  395    for (
auto const & listener: vector) {
 
  397            listener.m_xListener->disposing(src);
 
  398            SAL_INFO(
"vcl.se.debug", 
"  call Listener disposing");
 
  399        } 
catch (css::uno::RuntimeException &) {
 
  407extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
 
  409    css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> 
const&)
 
  411    return cppu::acquire(
new VCLSession);
 
A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex ...
 
#define TOOLS_WARN_EXCEPTION(area, stream)
 
std::vector< Reference< css::datatransfer::clipboard::XClipboardListener > > m_aListeners
 
#define SAL_WARN_IF(condition, area, stream)
 
#define SAL_INFO(area, stream)
 
std::unique_ptr< sal_Int32[]> pData
 
css::uno::Sequence< OUString > getSupportedServiceNames()
 
OUString getImplementationName()
 
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
 
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_frame_VCLSessionManagerClient_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
 
SalSessionEventType m_eType
 
bool m_bInteractionGranted
 
ImplSVData * ImplGetSVData()