1*3638366cSAndrew Rist /************************************************************** 2*3638366cSAndrew Rist * 3*3638366cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*3638366cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*3638366cSAndrew Rist * distributed with this work for additional information 6*3638366cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*3638366cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*3638366cSAndrew Rist * "License"); you may not use this file except in compliance 9*3638366cSAndrew Rist * with the License. You may obtain a copy of the License at 10*3638366cSAndrew Rist * 11*3638366cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*3638366cSAndrew Rist * 13*3638366cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*3638366cSAndrew Rist * software distributed under the License is distributed on an 15*3638366cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*3638366cSAndrew Rist * KIND, either express or implied. See the License for the 17*3638366cSAndrew Rist * specific language governing permissions and limitations 18*3638366cSAndrew Rist * under the License. 19*3638366cSAndrew Rist * 20*3638366cSAndrew Rist *************************************************************/ 21*3638366cSAndrew Rist 22*3638366cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef INCLUDED_BINARYURP_SOURCE_WRITER_HXX 25cdf0e10cSrcweir #define INCLUDED_BINARYURP_SOURCE_WRITER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "sal/config.h" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <cstddef> 30cdf0e10cSrcweir #include <deque> 31cdf0e10cSrcweir #include <vector> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include "boost/noncopyable.hpp" 34cdf0e10cSrcweir #include "osl/conditn.hxx" 35cdf0e10cSrcweir #include "osl/mutex.hxx" 36cdf0e10cSrcweir #include "osl/thread.hxx" 37cdf0e10cSrcweir #include "rtl/byteseq.hxx" 38cdf0e10cSrcweir #include "rtl/ref.hxx" 39cdf0e10cSrcweir #include "rtl/ustring.hxx" 40cdf0e10cSrcweir #include "sal/types.h" 41cdf0e10cSrcweir #include "salhelper/simplereferenceobject.hxx" 42cdf0e10cSrcweir #include "typelib/typedescription.hxx" 43cdf0e10cSrcweir #include "uno/dispatcher.hxx" 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include "binaryany.hxx" 46cdf0e10cSrcweir #include "marshal.hxx" 47cdf0e10cSrcweir #include "writerstate.hxx" 48cdf0e10cSrcweir 49cdf0e10cSrcweir namespace binaryurp { class Bridge; } 50cdf0e10cSrcweir 51cdf0e10cSrcweir namespace binaryurp { 52cdf0e10cSrcweir 53cdf0e10cSrcweir class Writer: 54cdf0e10cSrcweir public osl::Thread, public salhelper::SimpleReferenceObject, 55cdf0e10cSrcweir private boost::noncopyable 56cdf0e10cSrcweir { 57cdf0e10cSrcweir public: operator new(std::size_t size)58cdf0e10cSrcweir static void * operator new(std::size_t size) 59cdf0e10cSrcweir { return Thread::operator new(size); } 60cdf0e10cSrcweir operator delete(void * pointer)61cdf0e10cSrcweir static void operator delete(void * pointer) 62cdf0e10cSrcweir { Thread::operator delete(pointer); } 63cdf0e10cSrcweir 64cdf0e10cSrcweir explicit Writer(rtl::Reference< Bridge > const & bridge); 65cdf0e10cSrcweir 66cdf0e10cSrcweir // Only called from Bridge::reader_ thread, and only before Bridge::writer_ 67cdf0e10cSrcweir // thread is unblocked: 68cdf0e10cSrcweir void sendDirectRequest( 69cdf0e10cSrcweir rtl::ByteSequence const & tid, rtl::OUString const & oid, 70cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & type, 71cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & member, 72cdf0e10cSrcweir std::vector< BinaryAny > const & inArguments); 73cdf0e10cSrcweir 74cdf0e10cSrcweir // Only called from Bridge::reader_ thread, and only before Bridge::writer_ 75cdf0e10cSrcweir // thread is unblocked: 76cdf0e10cSrcweir void sendDirectReply( 77cdf0e10cSrcweir rtl::ByteSequence const & tid, 78cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & member, 79cdf0e10cSrcweir bool exception, BinaryAny const & returnValue, 80cdf0e10cSrcweir std::vector< BinaryAny > const & outArguments); 81cdf0e10cSrcweir 82cdf0e10cSrcweir void queueRequest( 83cdf0e10cSrcweir rtl::ByteSequence const & tid, rtl::OUString const & oid, 84cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & type, 85cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & member, 86cdf0e10cSrcweir std::vector< BinaryAny > const & inArguments); 87cdf0e10cSrcweir 88cdf0e10cSrcweir void queueReply( 89cdf0e10cSrcweir rtl::ByteSequence const & tid, 90cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & member, bool setter, 91cdf0e10cSrcweir bool exception, BinaryAny const & returnValue, 92cdf0e10cSrcweir std::vector< BinaryAny > const & outArguments, 93cdf0e10cSrcweir bool setCurrentContextMode); 94cdf0e10cSrcweir 95cdf0e10cSrcweir void unblock(); 96cdf0e10cSrcweir 97cdf0e10cSrcweir void stop(); 98cdf0e10cSrcweir 99cdf0e10cSrcweir private: 100cdf0e10cSrcweir virtual ~Writer(); 101cdf0e10cSrcweir 102cdf0e10cSrcweir virtual void SAL_CALL run(); 103cdf0e10cSrcweir 104cdf0e10cSrcweir virtual void SAL_CALL onTerminated(); 105cdf0e10cSrcweir 106cdf0e10cSrcweir void sendRequest( 107cdf0e10cSrcweir rtl::ByteSequence const & tid, rtl::OUString const & oid, 108cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & type, 109cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & member, 110cdf0e10cSrcweir std::vector< BinaryAny > const & inArguments, bool currentContextMode, 111cdf0e10cSrcweir com::sun::star::uno::UnoInterfaceReference const & currentContext); 112cdf0e10cSrcweir 113cdf0e10cSrcweir void sendReply( 114cdf0e10cSrcweir rtl::ByteSequence const & tid, 115cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & member, bool setter, 116cdf0e10cSrcweir bool exception, BinaryAny const & returnValue, 117cdf0e10cSrcweir std::vector< BinaryAny > const & outArguments); 118cdf0e10cSrcweir 119cdf0e10cSrcweir void sendMessage(std::vector< unsigned char > const & buffer); 120cdf0e10cSrcweir 121cdf0e10cSrcweir struct Item { 122cdf0e10cSrcweir Item(); 123cdf0e10cSrcweir 124cdf0e10cSrcweir // Request: 125cdf0e10cSrcweir Item( 126cdf0e10cSrcweir rtl::ByteSequence const & theTid, rtl::OUString const & theOid, 127cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & theType, 128cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & theMember, 129cdf0e10cSrcweir std::vector< BinaryAny > const & inArguments, 130cdf0e10cSrcweir com::sun::star::uno::UnoInterfaceReference const & 131cdf0e10cSrcweir theCurrentContext); 132cdf0e10cSrcweir 133cdf0e10cSrcweir // Reply: 134cdf0e10cSrcweir Item( 135cdf0e10cSrcweir rtl::ByteSequence const & theTid, 136cdf0e10cSrcweir com::sun::star::uno::TypeDescription const & theMember, 137cdf0e10cSrcweir bool theSetter, bool theException, BinaryAny const & theReturnValue, 138cdf0e10cSrcweir std::vector< BinaryAny > const & outArguments, 139cdf0e10cSrcweir bool theSetCurrentContextMode); 140cdf0e10cSrcweir 141cdf0e10cSrcweir bool request; 142cdf0e10cSrcweir 143cdf0e10cSrcweir rtl::ByteSequence tid; // request + reply 144cdf0e10cSrcweir 145cdf0e10cSrcweir rtl::OUString oid; // request 146cdf0e10cSrcweir 147cdf0e10cSrcweir com::sun::star::uno::TypeDescription type; // request 148cdf0e10cSrcweir 149cdf0e10cSrcweir com::sun::star::uno::TypeDescription member; // request + reply 150cdf0e10cSrcweir 151cdf0e10cSrcweir bool setter; // reply 152cdf0e10cSrcweir 153cdf0e10cSrcweir std::vector< BinaryAny > arguments; 154cdf0e10cSrcweir // request: inArguments; reply: outArguments 155cdf0e10cSrcweir 156cdf0e10cSrcweir bool exception; // reply 157cdf0e10cSrcweir 158cdf0e10cSrcweir BinaryAny returnValue; // reply 159cdf0e10cSrcweir 160cdf0e10cSrcweir com::sun::star::uno::UnoInterfaceReference currentContext; // request 161cdf0e10cSrcweir 162cdf0e10cSrcweir bool setCurrentContextMode; // reply 163cdf0e10cSrcweir }; 164cdf0e10cSrcweir 165cdf0e10cSrcweir rtl::Reference< Bridge > bridge_; 166cdf0e10cSrcweir WriterState state_; 167cdf0e10cSrcweir Marshal marshal_; 168cdf0e10cSrcweir com::sun::star::uno::TypeDescription lastType_; 169cdf0e10cSrcweir rtl::OUString lastOid_; 170cdf0e10cSrcweir rtl::ByteSequence lastTid_; 171cdf0e10cSrcweir osl::Condition unblocked_; 172cdf0e10cSrcweir osl::Condition items_; 173cdf0e10cSrcweir 174cdf0e10cSrcweir osl::Mutex mutex_; 175cdf0e10cSrcweir std::deque< Item > queue_; 176cdf0e10cSrcweir bool stop_; 177cdf0e10cSrcweir }; 178cdf0e10cSrcweir 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir #endif 182