Debian Codegraph @

vcl/unx/gtk3_kde5/filepicker_ipc_commands.hxx

raw
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 #pragma once
21
22 #include <cstdint>
23 #include <iostream>
24 #include <vector>
25
26 #include <sal/types.h>
27 #include <com/sun/star/uno/Sequence.hxx>
28
29 // #define DEBUG_FILEPICKER_IPC
30
31 class QString;
32
33 enum class Commands : uint16_t
34 {
35 SetTitle,
36 SetWinId,
37 Execute,
38 SetMultiSelectionMode,
39 SetDefaultName,
40 SetDisplayDirectory,
41 GetDisplayDirectory,
42 GetSelectedFiles,
43 AppendFilter,
44 SetCurrentFilter,
45 GetCurrentFilter,
46 SetValue,
47 GetValue,
48 EnableControl,
49 SetLabel,
50 GetLabel,
51 AddCheckBox,
52 Initialize,
53 Quit,
54 EnablePickFolderMode,
55 };
56
57 inline std::vector<char> readIpcStringArg(std::istream& stream)
58 {
59 uint32_t length = 0;
60 stream >> length;
61 stream.ignore(); // skip space separator
62 std::vector<char> buffer(length, '\0');
63 stream.read(buffer.data(), length);
64 return buffer;
65 }
66
67 void readIpcArg(std::istream& stream, OUString& string);
68 void readIpcArg(std::istream& stream, QString& string);
69 void readIpcArg(std::istream& stream, css::uno::Sequence<OUString>& seq);
70
71 inline void readIpcArg(std::istream& stream, Commands& value)
72 {
73 uint16_t v = 0;
74 stream >> v;
75 stream.ignore(); // skip space
76 value = static_cast<Commands>(v);
77 }
78
79 void readIpcArg(std::istream&, sal_Bool) = delete;
80
81 inline void readIpcArg(std::istream& stream, bool& value)
82 {
83 stream >> value;
84 stream.ignore(); // skip space
85 }
86
87 inline void readIpcArg(std::istream& stream, sal_Int16& value)
88 {
89 stream >> value;
90 stream.ignore(); // skip space
91 }
92
93 inline void readIpcArg(std::istream& stream, sal_uIntPtr& value)
94 {
95 stream >> value;
96 stream.ignore(); // skip space
97 }
98
99 #if SAL_TYPES_SIZEOFPOINTER == 4
100 inline void readIpcArg(std::istream& stream, uint64_t& value)
101 {
102 stream >> value;
103 stream.ignore(); // skip space
104 }
105 #endif
106
107 inline void readIpcArgs(std::istream& /*stream*/)
108 {
109 // end of arguments, nothing to do
110 }
111
112 template <typename T, typename... Args>
113 inline void readIpcArgs(std::istream& stream, T& arg, Args&... args)
114 {
115 readIpcArg(stream, arg);
116 readIpcArgs(stream, args...);
117 }
118
119 void sendIpcArg(std::ostream& stream, const OUString& string);
120 void sendIpcArg(std::ostream& stream, const QString& string);
121
122 inline void sendIpcStringArg(std::ostream& stream, uint32_t length, const char* string)
123 {
124 stream << length << ' ';
125 stream.write(string, length);
126 stream << ' ';
127 }
128
129 inline void sendIpcArg(std::ostream& stream, Commands value)
130 {
131 stream << static_cast<uint16_t>(value) << ' ';
132 }
133
134 void sendIpcArg(std::ostream&, sal_Bool) = delete;
135
136 inline void sendIpcArg(std::ostream& stream, bool value) { stream << value << ' '; }
137
138 inline void sendIpcArg(std::ostream& stream, sal_Int16 value) { stream << value << ' '; }
139
140 inline void sendIpcArg(std::ostream& stream, sal_uIntPtr value) { stream << value << ' '; }
141
142 #if SAL_TYPES_SIZEOFPOINTER == 4
143 inline void sendIpcArg(std::ostream& stream, uint64_t value) { stream << value << ' '; }
144 #endif
145
146 inline void sendIpcArgsImpl(std::ostream& stream)
147 {
148 // end of arguments, flush stream
149 stream << std::endl;
150 }
151
152 template <typename T, typename... Args>
153 inline void sendIpcArgsImpl(std::ostream& stream, const T& arg, const Args&... args)
154 {
155 sendIpcArg(stream, arg);
156 sendIpcArgsImpl(stream, args...);
157 }
158
159 template <typename T, typename... Args>
160 inline void sendIpcArgs(std::ostream& stream, const T& arg, const Args&... args)
161 {
162 sendIpcArgsImpl(stream, arg, args...);
163 #ifdef DEBUG_FILEPICKER_IPC
164 std::cerr << "IPC MSG: ";
165 sendIpcArgsImpl(std::cerr, arg, args...);
166 #endif
167 }
168
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */