LCOV - code coverage report
Current view: top level - binaryurp/source - bridge.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 3 3 100.0 %
Date: 2015-06-13 12:38:46 Functions: 3 3 100.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             : #ifndef INCLUDED_BINARYURP_SOURCE_BRIDGE_HXX
      21             : #define INCLUDED_BINARYURP_SOURCE_BRIDGE_HXX
      22             : 
      23             : #include "sal/config.h"
      24             : 
      25             : #include <cstddef>
      26             : #include <list>
      27             : #include <map>
      28             : #include <vector>
      29             : 
      30             : #include "com/sun/star/bridge/XBridge.hpp"
      31             : #include "com/sun/star/lang/XComponent.hpp"
      32             : #include "com/sun/star/uno/Reference.hxx"
      33             : #include "com/sun/star/uno/RuntimeException.hpp"
      34             : #include "cppuhelper/implbase2.hxx"
      35             : #include "osl/conditn.hxx"
      36             : #include "osl/mutex.hxx"
      37             : #include "rtl/ref.hxx"
      38             : #include "rtl/ustring.hxx"
      39             : #include "sal/types.h"
      40             : #include "uno/environment.hxx"
      41             : #include "uno/mapping.hxx"
      42             : #include "uno/threadpool.h"
      43             : 
      44             : #include "outgoingrequest.hxx"
      45             : #include "outgoingrequests.hxx"
      46             : #include "writer.hxx"
      47             : 
      48             : namespace binaryurp {
      49             :     class BinaryAny;
      50             :     class BridgeFactory;
      51             :     class Proxy;
      52             :     class Reader;
      53             : }
      54             : namespace com { namespace sun { namespace star {
      55             :     namespace bridge { class XInstanceProvider; }
      56             :     namespace connection { class XConnection; }
      57             :     namespace lang { class XEventListener; }
      58             :     namespace uno {
      59             :         class Any;
      60             :         class TypeDescription;
      61             :         class UnoInterfaceReference;
      62             :         class XInterface;
      63             :     }
      64             : } } }
      65             : namespace rtl { class ByteSequence; }
      66             : 
      67             : namespace binaryurp {
      68             : 
      69             : class Bridge:
      70             :     public cppu::WeakImplHelper2<
      71             :         com::sun::star::bridge::XBridge, com::sun::star::lang::XComponent >
      72             : {
      73             : public:
      74             :     Bridge(
      75             :         rtl::Reference< BridgeFactory > const & factory,
      76             :         OUString const & name,
      77             :         com::sun::star::uno::Reference<
      78             :             com::sun::star::connection::XConnection > const & connection,
      79             :         com::sun::star::uno::Reference<
      80             :             com::sun::star::bridge::XInstanceProvider > const & provider);
      81             : 
      82             :     void start();
      83             : 
      84             :     // Internally waits for all incoming and outgoing remote calls to terminate,
      85             :     // so must not be called from within such a call; when final is true, also
      86             :     // joins all remaining threads (reader, writer, and worker threads from the
      87             :     // thread pool), so must not be called with final set to true from such a
      88             :     // thread:
      89             :     void terminate(bool final);
      90             : 
      91             :     com::sun::star::uno::Reference< com::sun::star::connection::XConnection >
      92      219480 :     getConnection() const { return connection_;}
      93             : 
      94             :     com::sun::star::uno::Reference< com::sun::star::bridge::XInstanceProvider >
      95          96 :     getProvider() const { return provider_;}
      96             : 
      97          98 :     com::sun::star::uno::Mapping & getCppToBinaryMapping() { return cppToBinaryMapping_;}
      98             : 
      99             :     BinaryAny mapCppToBinaryAny(com::sun::star::uno::Any const & cppAny);
     100             : 
     101             :     uno_ThreadPool getThreadPool();
     102             : 
     103             :     rtl::Reference< Writer > getWriter();
     104             : 
     105             :     com::sun::star::uno::UnoInterfaceReference registerIncomingInterface(
     106             :         OUString const & oid,
     107             :         com::sun::star::uno::TypeDescription const & type);
     108             : 
     109             :     OUString registerOutgoingInterface(
     110             :         com::sun::star::uno::UnoInterfaceReference const & object,
     111             :         com::sun::star::uno::TypeDescription const & type);
     112             : 
     113             :     com::sun::star::uno::UnoInterfaceReference findStub(
     114             :         OUString const & oid,
     115             :         com::sun::star::uno::TypeDescription const & type);
     116             : 
     117             :     void releaseStub(
     118             :         OUString const & oid,
     119             :         com::sun::star::uno::TypeDescription const & type);
     120             : 
     121             :     void resurrectProxy(Proxy & proxy);
     122             : 
     123             :     void revokeProxy(Proxy & proxy);
     124             : 
     125             :     void freeProxy(Proxy & proxy);
     126             : 
     127             :     void incrementCalls(bool normalCall) throw ();
     128             : 
     129             :     void decrementCalls();
     130             : 
     131             :     void incrementActiveCalls() throw ();
     132             : 
     133             :     void decrementActiveCalls() throw ();
     134             : 
     135             :     bool makeCall(
     136             :         OUString const & oid,
     137             :         com::sun::star::uno::TypeDescription const & member, bool setter,
     138             :         std::vector< BinaryAny > const & inArguments, BinaryAny * returnValue,
     139             :         std::vector< BinaryAny > * outArguments);
     140             : 
     141             :     // Only called from reader_ thread:
     142             :     void sendRequestChangeRequest();
     143             : 
     144             :     // Only called from reader_ thread:
     145             :     void handleRequestChangeReply(
     146             :         bool exception, BinaryAny const & returnValue);
     147             : 
     148             :     // Only called from reader_ thread:
     149             :     void handleCommitChangeReply(bool exception, BinaryAny const & returnValue);
     150             : 
     151             :     // Only called from reader_ thread:
     152             :     void handleRequestChangeRequest(
     153             :         rtl::ByteSequence const & tid,
     154             :         std::vector< BinaryAny > const & inArguments);
     155             : 
     156             :     // Only called from reader_ thread:
     157             :     void handleCommitChangeRequest(
     158             :         rtl::ByteSequence const & tid,
     159             :         std::vector< BinaryAny > const & inArguments);
     160             : 
     161             :     OutgoingRequest lastOutgoingRequest(rtl::ByteSequence const & tid);
     162             : 
     163             :     bool isProtocolPropertiesRequest(
     164             :         OUString const & oid,
     165             :         com::sun::star::uno::TypeDescription const & type) const;
     166             : 
     167             :     void setCurrentContextMode();
     168             : 
     169             :     bool isCurrentContextMode();
     170             : 
     171             : private:
     172             :     Bridge(const Bridge&) SAL_DELETED_FUNCTION;
     173             :     Bridge& operator=(const Bridge&) SAL_DELETED_FUNCTION;
     174             : 
     175             :     virtual ~Bridge();
     176             : 
     177             :     virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
     178             :     SAL_CALL getInstance(OUString const & sInstanceName)
     179             :         throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     180             : 
     181             :     virtual OUString SAL_CALL getName()
     182             :         throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     183             : 
     184             :     virtual OUString SAL_CALL getDescription()
     185             :         throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     186             : 
     187             :     virtual void SAL_CALL dispose()
     188             :         throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     189             : 
     190             :     virtual void SAL_CALL addEventListener(
     191             :         com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >
     192             :             const & xListener)
     193             :         throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     194             : 
     195             :     virtual void SAL_CALL removeEventListener(
     196             :         com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >
     197             :             const & aListener)
     198             :         throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     199             : 
     200             :     // Only called from reader_ thread:
     201             :     void sendCommitChangeRequest();
     202             : 
     203             :     // Only called from reader_ thread:
     204             :     void sendProtPropRequest(
     205             :         OutgoingRequest::Kind kind,
     206             :         std::vector< BinaryAny > const & inArguments);
     207             : 
     208             :     void makeReleaseCall(
     209             :         OUString const & oid,
     210             :         com::sun::star::uno::TypeDescription const & type);
     211             : 
     212             :     void sendRequest(
     213             :         rtl::ByteSequence const & tid, OUString const & oid,
     214             :         com::sun::star::uno::TypeDescription const & type,
     215             :         com::sun::star::uno::TypeDescription const & member,
     216             :         std::vector< BinaryAny > const & inArguments);
     217             : 
     218             :     void throwException(bool exception, BinaryAny const & value);
     219             : 
     220             :     com::sun::star::uno::Any mapBinaryToCppAny(BinaryAny const & binaryAny);
     221             : 
     222             :     bool becameUnused() const;
     223             : 
     224             :     void terminateWhenUnused(bool unused);
     225             : 
     226             :     // Must only be called with mutex_ locked:
     227             :     void checkDisposed();
     228             : 
     229             :     typedef
     230             :         std::list<
     231             :             com::sun::star::uno::Reference<
     232             :                 com::sun::star::lang::XEventListener > >
     233             :         Listeners;
     234             : 
     235             :     struct SubStub;
     236             : 
     237             :     typedef std::map< com::sun::star::uno::TypeDescription, SubStub > Stub;
     238             : 
     239             :     typedef std::map< OUString, Stub > Stubs;
     240             : 
     241             :     enum State { STATE_INITIAL, STATE_STARTED, STATE_TERMINATED, STATE_FINAL };
     242             : 
     243             :     enum Mode {
     244             :         MODE_REQUESTED, MODE_REPLY_MINUS1, MODE_REPLY_0, MODE_REPLY_1,
     245             :         MODE_WAIT, MODE_NORMAL, MODE_NORMAL_WAIT };
     246             : 
     247             :     rtl::Reference< BridgeFactory > factory_;
     248             :     OUString name_;
     249             :     com::sun::star::uno::Reference< com::sun::star::connection::XConnection >
     250             :         connection_;
     251             :     com::sun::star::uno::Reference< com::sun::star::bridge::XInstanceProvider >
     252             :         provider_;
     253             :     com::sun::star::uno::Environment binaryUno_;
     254             :     com::sun::star::uno::Mapping cppToBinaryMapping_;
     255             :     com::sun::star::uno::Mapping binaryToCppMapping_;
     256             :     rtl::ByteSequence protPropTid_;
     257             :     OUString protPropOid_;
     258             :     com::sun::star::uno::TypeDescription protPropType_;
     259             :     com::sun::star::uno::TypeDescription protPropRequest_;
     260             :     com::sun::star::uno::TypeDescription protPropCommit_;
     261             :     OutgoingRequests outgoingRequests_;
     262             :     osl::Condition passive_;
     263             :         // to guarantee that passive_ is eventually set (to avoid deadlock, see
     264             :         // dispose), activeCalls_ only counts those calls for which it can be
     265             :         // guaranteed that incrementActiveCalls is indeed followed by
     266             :         // decrementActiveCalls, without an intervening exception
     267             :     osl::Condition terminated_;
     268             : 
     269             :     osl::Mutex mutex_;
     270             :     State state_;
     271             :     Listeners listeners_;
     272             :     uno_ThreadPool threadPool_;
     273             :     rtl::Reference< Writer > writer_;
     274             :     rtl::Reference< Reader > reader_;
     275             :     bool currentContextMode_;
     276             :     Stubs stubs_;
     277             :     std::size_t proxies_;
     278             :     std::size_t calls_;
     279             :     bool normalCall_;
     280             :     std::size_t activeCalls_;
     281             : 
     282             :     // Only accessed from reader_ thread:
     283             :     Mode mode_;
     284             :     sal_Int32 random_;
     285             : };
     286             : 
     287             : }
     288             : 
     289             : #endif
     290             : 
     291             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11