LCOV - code coverage report
Current view: top level - toolkit/source/awt - asynccallback.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 29 40 72.5 %
Date: 2012-08-25 Functions: 11 14 78.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 17 44 38.6 %

           Branch data     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                 :            : 
      21                 :            : #include "vcl/svapp.hxx"
      22                 :            : #include "osl/mutex.hxx"
      23                 :            : #include "sal/config.h"
      24                 :            : #include "cppuhelper/factory.hxx"
      25                 :            : #include "cppuhelper/implementationentry.hxx"
      26                 :            : #include "cppuhelper/implbase2.hxx"
      27                 :            : #include "com/sun/star/lang/XServiceInfo.hpp"
      28                 :            : #include "com/sun/star/awt/XRequestCallback.hpp"
      29                 :            : 
      30                 :            : 
      31                 :            : // component helper namespace
      32                 :            : namespace comp_AsyncCallback {
      33                 :            : 
      34                 :            : namespace css = ::com::sun::star;
      35                 :            : 
      36                 :            : // component and service helper functions:
      37                 :            : ::rtl::OUString SAL_CALL _getImplementationName();
      38                 :            : css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames();
      39                 :            : css::uno::Reference< css::uno::XInterface > SAL_CALL _create( css::uno::Reference< css::uno::XComponentContext > const & context );
      40                 :            : 
      41                 :            : } // closing component helper namespace
      42                 :            : 
      43                 :            : 
      44                 :            : 
      45                 :            : /// anonymous implementation namespace
      46                 :            : namespace {
      47                 :            : 
      48                 :            : namespace css = ::com::sun::star;
      49                 :            : 
      50                 :            : class AsyncCallback:
      51                 :            :     public ::cppu::WeakImplHelper2<
      52                 :            :         css::lang::XServiceInfo,
      53                 :            :         css::awt::XRequestCallback>
      54                 :            : {
      55                 :            : public:
      56                 :            :     explicit AsyncCallback(css::uno::Reference< css::uno::XComponentContext > const & context);
      57                 :            : 
      58                 :            :     // ::com::sun::star::lang::XServiceInfo:
      59                 :            :     virtual ::rtl::OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException);
      60                 :            :     virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException);
      61                 :            :     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException);
      62                 :            : 
      63                 :            :     // ::com::sun::star::awt::XRequestCallback:
      64                 :            :     virtual void SAL_CALL addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const ::com::sun::star::uno::Any & aData) throw (css::uno::RuntimeException);
      65                 :            : 
      66                 :            : private:
      67                 :            : 
      68                 :          2 :     struct CallbackData
      69                 :            :     {
      70                 :          2 :         CallbackData( const css::uno::Reference< css::awt::XCallback >& rCallback, const css::uno::Any& rAny ) :
      71                 :          2 :             xCallback( rCallback ), aData( rAny ) {}
      72                 :            : 
      73                 :            :         css::uno::Reference< css::awt::XCallback > xCallback;
      74                 :            :         css::uno::Any                              aData;
      75                 :            :     };
      76                 :            : 
      77                 :            :     DECL_STATIC_LINK( AsyncCallback, Notify_Impl, CallbackData* );
      78                 :            : 
      79                 :            :     AsyncCallback(AsyncCallback &); // not defined
      80                 :            :     void operator =(AsyncCallback &); // not defined
      81                 :            : 
      82         [ -  + ]:          4 :     virtual ~AsyncCallback() {}
      83                 :            : 
      84                 :            :     css::uno::Reference< css::uno::XComponentContext > m_xContext;
      85                 :            : };
      86                 :            : 
      87                 :          2 : AsyncCallback::AsyncCallback(css::uno::Reference< css::uno::XComponentContext > const & context) :
      88                 :          2 :     m_xContext(context)
      89                 :          2 : {}
      90                 :            : 
      91                 :            : // com.sun.star.uno.XServiceInfo:
      92                 :          0 : ::rtl::OUString SAL_CALL AsyncCallback::getImplementationName() throw (css::uno::RuntimeException)
      93                 :            : {
      94                 :          0 :     return comp_AsyncCallback::_getImplementationName();
      95                 :            : }
      96                 :            : 
      97                 :          0 : ::sal_Bool SAL_CALL AsyncCallback::supportsService(::rtl::OUString const & serviceName) throw (css::uno::RuntimeException)
      98                 :            : {
      99         [ #  # ]:          0 :     const css::uno::Sequence< ::rtl::OUString > serviceNames = comp_AsyncCallback::_getSupportedServiceNames();
     100         [ #  # ]:          0 :     for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
     101         [ #  # ]:          0 :         if (serviceNames[i] == serviceName)
     102                 :          0 :             return sal_True;
     103                 :            :     }
     104         [ #  # ]:          0 :     return sal_False;
     105                 :            : }
     106                 :            : 
     107                 :          0 : css::uno::Sequence< ::rtl::OUString > SAL_CALL AsyncCallback::getSupportedServiceNames() throw (css::uno::RuntimeException)
     108                 :            : {
     109                 :          0 :     return comp_AsyncCallback::_getSupportedServiceNames();
     110                 :            : }
     111                 :            : 
     112                 :            : // ::com::sun::star::awt::XRequestCallback:
     113                 :          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)
     114                 :            : {
     115         [ +  - ]:          2 :     if ( Application::IsInMain() )
     116                 :            :     {
     117         [ +  - ]:          2 :         SolarMutexGuard aSolarGuard;
     118                 :            : 
     119 [ +  - ][ +  - ]:          2 :         CallbackData* pCallbackData = new CallbackData( xCallback, aData );
     120 [ +  - ][ +  - ]:          2 :         Application::PostUserEvent( STATIC_LINK( this, AsyncCallback, Notify_Impl ), pCallbackData );
                 [ +  - ]
     121                 :            :     }
     122                 :          2 : }
     123                 :            : 
     124                 :            : // private asynchronous link to call reference to the callback object
     125                 :          2 : IMPL_STATIC_LINK_NOINSTANCE( AsyncCallback, Notify_Impl, CallbackData*, pCallbackData )
     126                 :            : {
     127                 :            :     try
     128                 :            :     {
     129                 :            :         // Asynchronous execution
     130                 :            :         // Check pointer and reference before!
     131 [ +  - ][ +  - ]:          2 :         if ( pCallbackData && pCallbackData->xCallback.is() )
                 [ +  - ]
     132 [ +  - ][ +  - ]:          2 :             pCallbackData->xCallback->notify( pCallbackData->aData );
     133                 :            :     }
     134                 :          0 :     catch ( css::uno::Exception& )
     135                 :            :     {
     136                 :            :     }
     137                 :            : 
     138         [ +  - ]:          2 :     delete pCallbackData;
     139         [ #  # ]:          2 :     return 0;
     140                 :            : }
     141                 :            : 
     142                 :            : } // closing anonymous implementation namespace
     143                 :            : 
     144                 :            : 
     145                 :            : 
     146                 :            : // component helper namespace
     147                 :            : namespace comp_AsyncCallback {
     148                 :            : 
     149                 :          2 : ::rtl::OUString SAL_CALL _getImplementationName() {
     150                 :            :     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     151                 :          2 :         "com.sun.star.awt.comp.AsyncCallback"));
     152                 :            : }
     153                 :            : 
     154                 :          2 : css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames()
     155                 :            : {
     156                 :          2 :     css::uno::Sequence< ::rtl::OUString > s(1);
     157         [ +  - ]:          2 :     s[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     158         [ +  - ]:          4 :         "com.sun.star.awt.AsyncCallback"));
     159                 :          2 :     return s;
     160                 :            : }
     161                 :            : 
     162                 :          2 : css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
     163                 :            :     const css::uno::Reference< css::uno::XComponentContext > & context)
     164                 :            :         SAL_THROW((css::uno::Exception))
     165                 :            : {
     166         [ +  - ]:          2 :     return static_cast< ::cppu::OWeakObject * >(new AsyncCallback(context));
     167                 :            : }
     168                 :            : 
     169                 :            : } // closing component helper namespace
     170                 :            : 
     171                 :            : static ::cppu::ImplementationEntry const entries[] = {
     172                 :            :     { &comp_AsyncCallback::_create,
     173                 :            :       &comp_AsyncCallback::_getImplementationName,
     174                 :            :       &comp_AsyncCallback::_getSupportedServiceNames,
     175                 :            :       &::cppu::createSingleComponentFactory, 0, 0 },
     176                 :            :     { 0, 0, 0, 0, 0, 0 }
     177                 :            : };
     178                 :            : 
     179                 :          2 : void * SAL_CALL comp_AsyncCallback_component_getFactory(
     180                 :            :     const char * implName, void * serviceManager, void * registryKey)
     181                 :            : {
     182                 :            :     return ::cppu::component_getFactoryHelper(
     183                 :          2 :         implName, serviceManager, registryKey, entries);
     184                 :            : }
     185                 :            : 
     186                 :            : 
     187                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10