1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2011 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef INCLUDED_BINARYURP_SOURCE_WRITER_HXX 29 #define INCLUDED_BINARYURP_SOURCE_WRITER_HXX 30 31 #include "sal/config.h" 32 33 #include <cstddef> 34 #include <deque> 35 #include <vector> 36 37 #include "boost/noncopyable.hpp" 38 #include "osl/conditn.hxx" 39 #include "osl/mutex.hxx" 40 #include "osl/thread.hxx" 41 #include "rtl/byteseq.hxx" 42 #include "rtl/ref.hxx" 43 #include "rtl/ustring.hxx" 44 #include "sal/types.h" 45 #include "salhelper/simplereferenceobject.hxx" 46 #include "typelib/typedescription.hxx" 47 #include "uno/dispatcher.hxx" 48 49 #include "binaryany.hxx" 50 #include "marshal.hxx" 51 #include "writerstate.hxx" 52 53 namespace binaryurp { class Bridge; } 54 55 namespace binaryurp { 56 57 class Writer: 58 public osl::Thread, public salhelper::SimpleReferenceObject, 59 private boost::noncopyable 60 { 61 public: 62 static void * operator new(std::size_t size) 63 { return Thread::operator new(size); } 64 65 static void operator delete(void * pointer) 66 { Thread::operator delete(pointer); } 67 68 explicit Writer(rtl::Reference< Bridge > const & bridge); 69 70 // Only called from Bridge::reader_ thread, and only before Bridge::writer_ 71 // thread is unblocked: 72 void sendDirectRequest( 73 rtl::ByteSequence const & tid, rtl::OUString const & oid, 74 com::sun::star::uno::TypeDescription const & type, 75 com::sun::star::uno::TypeDescription const & member, 76 std::vector< BinaryAny > const & inArguments); 77 78 // Only called from Bridge::reader_ thread, and only before Bridge::writer_ 79 // thread is unblocked: 80 void sendDirectReply( 81 rtl::ByteSequence const & tid, 82 com::sun::star::uno::TypeDescription const & member, 83 bool exception, BinaryAny const & returnValue, 84 std::vector< BinaryAny > const & outArguments); 85 86 void queueRequest( 87 rtl::ByteSequence const & tid, rtl::OUString const & oid, 88 com::sun::star::uno::TypeDescription const & type, 89 com::sun::star::uno::TypeDescription const & member, 90 std::vector< BinaryAny > const & inArguments); 91 92 void queueReply( 93 rtl::ByteSequence const & tid, 94 com::sun::star::uno::TypeDescription const & member, bool setter, 95 bool exception, BinaryAny const & returnValue, 96 std::vector< BinaryAny > const & outArguments, 97 bool setCurrentContextMode); 98 99 void unblock(); 100 101 void stop(); 102 103 private: 104 virtual ~Writer(); 105 106 virtual void SAL_CALL run(); 107 108 virtual void SAL_CALL onTerminated(); 109 110 void sendRequest( 111 rtl::ByteSequence const & tid, rtl::OUString const & oid, 112 com::sun::star::uno::TypeDescription const & type, 113 com::sun::star::uno::TypeDescription const & member, 114 std::vector< BinaryAny > const & inArguments, bool currentContextMode, 115 com::sun::star::uno::UnoInterfaceReference const & currentContext); 116 117 void sendReply( 118 rtl::ByteSequence const & tid, 119 com::sun::star::uno::TypeDescription const & member, bool setter, 120 bool exception, BinaryAny const & returnValue, 121 std::vector< BinaryAny > const & outArguments); 122 123 void sendMessage(std::vector< unsigned char > const & buffer); 124 125 struct Item { 126 Item(); 127 128 // Request: 129 Item( 130 rtl::ByteSequence const & theTid, rtl::OUString const & theOid, 131 com::sun::star::uno::TypeDescription const & theType, 132 com::sun::star::uno::TypeDescription const & theMember, 133 std::vector< BinaryAny > const & inArguments, 134 com::sun::star::uno::UnoInterfaceReference const & 135 theCurrentContext); 136 137 // Reply: 138 Item( 139 rtl::ByteSequence const & theTid, 140 com::sun::star::uno::TypeDescription const & theMember, 141 bool theSetter, bool theException, BinaryAny const & theReturnValue, 142 std::vector< BinaryAny > const & outArguments, 143 bool theSetCurrentContextMode); 144 145 bool request; 146 147 rtl::ByteSequence tid; // request + reply 148 149 rtl::OUString oid; // request 150 151 com::sun::star::uno::TypeDescription type; // request 152 153 com::sun::star::uno::TypeDescription member; // request + reply 154 155 bool setter; // reply 156 157 std::vector< BinaryAny > arguments; 158 // request: inArguments; reply: outArguments 159 160 bool exception; // reply 161 162 BinaryAny returnValue; // reply 163 164 com::sun::star::uno::UnoInterfaceReference currentContext; // request 165 166 bool setCurrentContextMode; // reply 167 }; 168 169 rtl::Reference< Bridge > bridge_; 170 WriterState state_; 171 Marshal marshal_; 172 com::sun::star::uno::TypeDescription lastType_; 173 rtl::OUString lastOid_; 174 rtl::ByteSequence lastTid_; 175 osl::Condition unblocked_; 176 osl::Condition items_; 177 178 osl::Mutex mutex_; 179 std::deque< Item > queue_; 180 bool stop_; 181 }; 182 183 } 184 185 #endif 186