LCOV - code coverage report
Current view: top level - libreoffice/toolkit/source/awt - asynccallback.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 40 0.0 %
Date: 2012-12-27 Functions: 0 14 0.0 %
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             : ::rtl::OUString SAL_CALL _getImplementationName();
      36             : css::uno::Sequence< ::rtl::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 ::rtl::OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException);
      56             :     virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException);
      57             :     virtual css::uno::Sequence< ::rtl::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           0 :     struct CallbackData
      65             :     {
      66           0 :         CallbackData( const css::uno::Reference< css::awt::XCallback >& rCallback, const css::uno::Any& rAny ) :
      67           0 :             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           0 :     virtual ~AsyncCallback() {}
      79             : 
      80             :     css::uno::Reference< css::uno::XComponentContext > m_xContext;
      81             : };
      82             : 
      83           0 : AsyncCallback::AsyncCallback(css::uno::Reference< css::uno::XComponentContext > const & context) :
      84           0 :     m_xContext(context)
      85           0 : {}
      86             : 
      87             : // com.sun.star.uno.XServiceInfo:
      88           0 : ::rtl::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(::rtl::OUString const & serviceName) throw (css::uno::RuntimeException)
      94             : {
      95           0 :     const css::uno::Sequence< ::rtl::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< ::rtl::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           0 : 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           0 :     if ( Application::IsInMain() )
     112             :     {
     113           0 :         SolarMutexGuard aSolarGuard;
     114             : 
     115           0 :         CallbackData* pCallbackData = new CallbackData( xCallback, aData );
     116           0 :         Application::PostUserEvent( STATIC_LINK( this, AsyncCallback, Notify_Impl ), pCallbackData );
     117             :     }
     118           0 : }
     119             : 
     120             : // private asynchronous link to call reference to the callback object
     121           0 : IMPL_STATIC_LINK_NOINSTANCE( AsyncCallback, Notify_Impl, CallbackData*, pCallbackData )
     122             : {
     123             :     try
     124             :     {
     125             :         // Asynchronous execution
     126             :         // Check pointer and reference before!
     127           0 :         if ( pCallbackData && pCallbackData->xCallback.is() )
     128           0 :             pCallbackData->xCallback->notify( pCallbackData->aData );
     129             :     }
     130           0 :     catch ( css::uno::Exception& )
     131             :     {
     132             :     }
     133             : 
     134           0 :     delete pCallbackData;
     135           0 :     return 0;
     136             : }
     137             : 
     138             : } // closing anonymous implementation namespace
     139             : 
     140             : 
     141             : 
     142             : // component helper namespace
     143             : namespace comp_AsyncCallback {
     144             : 
     145           0 : ::rtl::OUString SAL_CALL _getImplementationName() {
     146             :     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     147           0 :         "com.sun.star.awt.comp.AsyncCallback"));
     148             : }
     149             : 
     150           0 : css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames()
     151             : {
     152           0 :     css::uno::Sequence< ::rtl::OUString > s(1);
     153           0 :     s[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
     154           0 :         "com.sun.star.awt.AsyncCallback"));
     155           0 :     return s;
     156             : }
     157             : 
     158           0 : css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
     159             :     const css::uno::Reference< css::uno::XComponentContext > & context)
     160             :         SAL_THROW((css::uno::Exception))
     161             : {
     162           0 :     return static_cast< ::cppu::OWeakObject * >(new AsyncCallback(context));
     163             : }
     164             : 
     165             : } // closing component helper namespace
     166             : 
     167             : static ::cppu::ImplementationEntry const entries[] = {
     168             :     { &comp_AsyncCallback::_create,
     169             :       &comp_AsyncCallback::_getImplementationName,
     170             :       &comp_AsyncCallback::_getSupportedServiceNames,
     171             :       &::cppu::createSingleComponentFactory, 0, 0 },
     172             :     { 0, 0, 0, 0, 0, 0 }
     173             : };
     174             : 
     175           0 : void * SAL_CALL comp_AsyncCallback_component_getFactory(
     176             :     const char * implName, void * serviceManager, void * registryKey)
     177             : {
     178             :     return ::cppu::component_getFactoryHelper(
     179           0 :         implName, serviceManager, registryKey, entries);
     180             : }
     181             : 
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10