Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / binaryurp / source / writer.hxx
blobe2061502a015bc373940e52147a4656d07cc40bb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <deque>
25 #include <mutex>
26 #include <vector>
28 #include <osl/conditn.hxx>
29 #include <rtl/byteseq.hxx>
30 #include <rtl/ref.hxx>
31 #include <rtl/ustring.hxx>
32 #include <salhelper/thread.hxx>
33 #include <typelib/typedescription.hxx>
34 #include <uno/dispatcher.hxx>
36 #include "binaryany.hxx"
37 #include "marshal.hxx"
38 #include "writerstate.hxx"
40 namespace binaryurp { class Bridge; }
42 namespace binaryurp {
44 class Writer: public salhelper::Thread
46 public:
47 explicit Writer(rtl::Reference< Bridge > const & bridge);
49 // Only called from Bridge::reader_ thread, and only before Bridge::writer_
50 // thread is unblocked:
51 void sendDirectRequest(
52 rtl::ByteSequence const & tid, OUString const & oid,
53 com::sun::star::uno::TypeDescription const & type,
54 com::sun::star::uno::TypeDescription const & member,
55 std::vector< BinaryAny > const & inArguments);
57 // Only called from Bridge::reader_ thread, and only before Bridge::writer_
58 // thread is unblocked:
59 void sendDirectReply(
60 rtl::ByteSequence const & tid,
61 com::sun::star::uno::TypeDescription const & member,
62 bool exception, BinaryAny const & returnValue,
63 std::vector< BinaryAny > const & outArguments);
65 void queueRequest(
66 rtl::ByteSequence const & tid, OUString const & oid,
67 com::sun::star::uno::TypeDescription const & type,
68 com::sun::star::uno::TypeDescription const & member,
69 std::vector< BinaryAny >&& inArguments);
71 void queueReply(
72 rtl::ByteSequence const & tid,
73 com::sun::star::uno::TypeDescription const & member, bool setter,
74 bool exception, BinaryAny const & returnValue,
75 std::vector< BinaryAny >&& outArguments,
76 bool setCurrentContextMode);
78 void unblock();
80 void stop();
82 private:
83 virtual ~Writer() override;
85 virtual void execute() override;
87 void sendRequest(
88 rtl::ByteSequence const & tid, OUString const & oid,
89 com::sun::star::uno::TypeDescription const & type,
90 com::sun::star::uno::TypeDescription const & member,
91 std::vector< BinaryAny > const & inArguments, bool currentContextMode,
92 com::sun::star::uno::UnoInterfaceReference const & currentContext);
94 void sendReply(
95 rtl::ByteSequence const & tid,
96 com::sun::star::uno::TypeDescription const & member, bool setter,
97 bool exception, BinaryAny const & returnValue,
98 std::vector< BinaryAny > const & outArguments);
100 void sendMessage(std::vector< unsigned char > const & buffer);
102 struct Item {
103 Item();
105 // Request:
106 Item(
107 rtl::ByteSequence theTid, OUString theOid,
108 com::sun::star::uno::TypeDescription theType,
109 com::sun::star::uno::TypeDescription theMember,
110 std::vector< BinaryAny >&& inArguments,
111 com::sun::star::uno::UnoInterfaceReference theCurrentContext);
113 // Reply:
114 Item(
115 rtl::ByteSequence theTid,
116 com::sun::star::uno::TypeDescription theMember,
117 bool theSetter, bool theException, BinaryAny theReturnValue,
118 std::vector< BinaryAny >&& outArguments,
119 bool theSetCurrentContextMode);
121 rtl::ByteSequence tid; // request + reply
122 OUString oid; // request
123 com::sun::star::uno::TypeDescription type; // request
124 com::sun::star::uno::TypeDescription member; // request + reply
125 com::sun::star::uno::UnoInterfaceReference currentContext; // request
126 BinaryAny returnValue; // reply
127 std::vector< BinaryAny > arguments; // request: inArguments; reply: outArguments
128 bool request;
129 bool setter; // reply
130 bool exception; // reply
131 bool setCurrentContextMode; // reply
134 rtl::Reference< Bridge > bridge_;
135 WriterState state_;
136 Marshal marshal_;
137 com::sun::star::uno::TypeDescription lastType_;
138 OUString lastOid_;
139 rtl::ByteSequence lastTid_;
140 osl::Condition unblocked_;
141 osl::Condition items_;
143 std::mutex mutex_;
144 std::deque< Item > queue_;
145 bool stop_;
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */