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

Generated by: LCOV version 1.10