LCOV - code coverage report
Current view: top level - toolkit/source/awt - asynccallback.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 19 28 67.9 %
Date: 2014-11-03 Functions: 11 14 78.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/config.h>
      21             : 
      22             : #include <boost/noncopyable.hpp>
      23             : #include "vcl/svapp.hxx"
      24             : #include "osl/mutex.hxx"
      25             : #include "cppuhelper/factory.hxx"
      26             : #include "cppuhelper/implementationentry.hxx"
      27             : #include "cppuhelper/implbase2.hxx"
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : #include "com/sun/star/lang/XServiceInfo.hpp"
      30             : #include <com/sun/star/uno/XComponentContext.hpp>
      31             : #include "com/sun/star/awt/XRequestCallback.hpp"
      32             : 
      33             : /// anonymous implementation namespace
      34             : namespace {
      35             : 
      36             : class AsyncCallback:
      37             :     public ::cppu::WeakImplHelper2<
      38             :         css::lang::XServiceInfo,
      39             :         css::awt::XRequestCallback>,
      40             :     private boost::noncopyable
      41             : {
      42             : public:
      43           4 :     AsyncCallback() {}
      44             : 
      45             :     // ::com::sun::star::lang::XServiceInfo:
      46             :     virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      47             :     virtual sal_Bool SAL_CALL supportsService(const OUString & ServiceName) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      48             :     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      49             : 
      50             :     // ::com::sun::star::awt::XRequestCallback:
      51             :     virtual void SAL_CALL addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const ::com::sun::star::uno::Any & aData) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      52             : 
      53             : private:
      54             : 
      55           2 :     struct CallbackData
      56             :     {
      57           2 :         CallbackData( const css::uno::Reference< css::awt::XCallback >& rCallback, const css::uno::Any& rAny ) :
      58           2 :             xCallback( rCallback ), aData( rAny ) {}
      59             : 
      60             :         css::uno::Reference< css::awt::XCallback > xCallback;
      61             :         css::uno::Any                              aData;
      62             :     };
      63             : 
      64             :     DECL_STATIC_LINK( AsyncCallback, Notify_Impl, CallbackData* );
      65             : 
      66           8 :     virtual ~AsyncCallback() {}
      67             : };
      68             : 
      69             : // com.sun.star.uno.XServiceInfo:
      70           0 : OUString SAL_CALL AsyncCallback::getImplementationName() throw (css::uno::RuntimeException, std::exception)
      71             : {
      72           0 :     return OUString("com.sun.star.awt.comp.AsyncCallback");
      73             : }
      74             : 
      75           0 : sal_Bool SAL_CALL AsyncCallback::supportsService(OUString const & serviceName) throw (css::uno::RuntimeException, std::exception)
      76             : {
      77           0 :     return cppu::supportsService(this, serviceName);
      78             : }
      79             : 
      80           0 : css::uno::Sequence< OUString > SAL_CALL AsyncCallback::getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception)
      81             : {
      82           0 :     css::uno::Sequence< OUString > s(1);
      83           0 :     s[0] = "com.sun.star.awt.AsyncCallback";
      84           0 :     return s;
      85             : }
      86             : 
      87             : // ::com::sun::star::awt::XRequestCallback:
      88           2 : void SAL_CALL AsyncCallback::addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const ::com::sun::star::uno::Any & aData) throw (css::uno::RuntimeException, std::exception)
      89             : {
      90           2 :     if ( Application::IsInMain() )
      91             :     {
      92           2 :         SolarMutexGuard aSolarGuard;
      93             : 
      94           2 :         CallbackData* pCallbackData = new CallbackData( xCallback, aData );
      95           2 :         Application::PostUserEvent( STATIC_LINK( this, AsyncCallback, Notify_Impl ), pCallbackData );
      96             :     }
      97           2 : }
      98             : 
      99             : // private asynchronous link to call reference to the callback object
     100           4 : IMPL_STATIC_LINK_NOINSTANCE( AsyncCallback, Notify_Impl, CallbackData*, pCallbackData )
     101             : {
     102             :     try
     103             :     {
     104             :         // Asynchronous execution
     105             :         // Check pointer and reference before!
     106           2 :         if ( pCallbackData && pCallbackData->xCallback.is() )
     107           2 :             pCallbackData->xCallback->notify( pCallbackData->aData );
     108             :     }
     109           0 :     catch ( css::uno::Exception& )
     110             :     {
     111             :     }
     112             : 
     113           2 :     delete pCallbackData;
     114           2 :     return 0;
     115             : }
     116             : 
     117             : } // closing anonymous implementation namespace
     118             : 
     119             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     120           4 : com_sun_star_awt_comp_AsyncCallback_get_implementation(
     121             :     css::uno::XComponentContext *,
     122             :     css::uno::Sequence<css::uno::Any> const &)
     123             : {
     124           4 :     return cppu::acquire(new AsyncCallback());
     125        1227 : }
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10