"Fossies" - the Fresh Open Source Software Archive 
Member "glibmm-2.76.0/untracked/gio/giomm/applicationcommandline.h" (12 Mar 2023, 15316 Bytes) of package /linux/misc/glibmm-2.76.0.tar.xz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "applicationcommandline.h" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
2.74.1_vs_2.76.0.
1 // Generated by gmmproc 2.76.0 -- DO NOT MODIFY!
2 #ifndef _GIOMM_APPLICATIONCOMMANDLINE_H
3 #define _GIOMM_APPLICATIONCOMMANDLINE_H
4
5
6 #include <glibmm/ustring.h>
7 #include <sigc++/sigc++.h>
8
9 /* Copyright (C) 2010 Jonathon Jongsma <jonathon@quotidian.org>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25 #include <giomm/file.h>
26 #include <giomm/inputstream.h>
27 #include <glibmm/object.h>
28 #include <glibmm/variant.h>
29 #include <glibmm/variantdict.h>
30
31
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 using GApplicationCommandLine = struct _GApplicationCommandLine;
34 using GApplicationCommandLineClass = struct _GApplicationCommandLineClass;
35 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
36
37
38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 namespace Gio
40 { class GIOMM_API ApplicationCommandLine_Class; } // namespace Gio
41 #endif //DOXYGEN_SHOULD_SKIP_THIS
42
43 namespace Gio
44 {
45
46 /** ApplicationCommandLine - A command-line invocation of an application.
47 * ApplicationCommandLine represents a command-line invocation of an
48 * application. It is created by Application and emitted in the "command-line"
49 * signal and virtual function.
50 *
51 * The class contains the list of arguments that the program was invoked with.
52 * It is also possible to query if the commandline invocation was local (ie:
53 * the current process is running in direct response to the invocation) or
54 * remote (ie: some other process forwarded the commandline to this process).
55 *
56 * The ApplicationCommandLine object can provide the argc and argv parameters
57 * for use with the Glib::OptionContext command-line parsing API, with the
58 * get_arguments() method.
59 *
60 * The exit status of the originally-invoked process may be set and messages
61 * can be printed to stdout or stderr of that process. The lifecycle of the
62 * originally-invoked process is tied to the lifecycle of this object (ie: the
63 * process exits when the last reference is dropped).
64 *
65 * The main use for ApplicationCommandline (and the "command-line" signal) is
66 * 'Emacs server' like use cases: You can set the EDITOR environment variable
67 * to have e.g. git use your favourite editor to edit commit messages, and if
68 * you already have an instance of the editor running, the editing will happen
69 * in the running instance, instead of opening a new one. An important aspect
70 * of this use case is that the process that gets started by git does not
71 * return until the editing is done.
72 * @newin{2,32}
73 */
74
75 class GIOMM_API ApplicationCommandLine : public Glib::Object
76 {
77
78 #ifndef DOXYGEN_SHOULD_SKIP_THIS
79
80 public:
81 using CppObjectType = ApplicationCommandLine;
82 using CppClassType = ApplicationCommandLine_Class;
83 using BaseObjectType = GApplicationCommandLine;
84 using BaseClassType = GApplicationCommandLineClass;
85
86 // noncopyable
87 ApplicationCommandLine(const ApplicationCommandLine&) = delete;
88 ApplicationCommandLine& operator=(const ApplicationCommandLine&) = delete;
89
90 private: friend class ApplicationCommandLine_Class;
91 static CppClassType applicationcommandline_class_;
92
93 protected:
94 explicit ApplicationCommandLine(const Glib::ConstructParams& construct_params);
95 explicit ApplicationCommandLine(GApplicationCommandLine* castitem);
96
97 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
98
99 public:
100
101 ApplicationCommandLine(ApplicationCommandLine&& src) noexcept;
102 ApplicationCommandLine& operator=(ApplicationCommandLine&& src) noexcept;
103
104 ~ApplicationCommandLine() noexcept override;
105
106 /** Get the GType for this class, for use with the underlying GObject type system.
107 */
108 static GType get_type() G_GNUC_CONST;
109
110 #ifndef DOXYGEN_SHOULD_SKIP_THIS
111
112
113 static GType get_base_type() G_GNUC_CONST;
114 #endif
115
116 ///Provides access to the underlying C GObject.
117 GApplicationCommandLine* gobj() { return reinterpret_cast<GApplicationCommandLine*>(gobject_); }
118
119 ///Provides access to the underlying C GObject.
120 const GApplicationCommandLine* gobj() const { return reinterpret_cast<GApplicationCommandLine*>(gobject_); }
121
122 ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
123 GApplicationCommandLine* gobj_copy();
124
125 private:
126
127
128 protected:
129 ApplicationCommandLine();
130
131 public:
132
133
134 /** Gets the list of arguments that was passed on the command line.
135 *
136 * The strings in the array may contain non-UTF-8 data on UNIX (such as
137 * filenames or arguments given in the system locale) but are always in
138 * UTF-8 on Windows.
139 *
140 * If you wish to use the return value with Glib::OptionContext, you must
141 * use Glib::OptionContext::parse(char**& argv).
142 *
143 * The return value is nullptr-terminated and should be freed using
144 * g_strfreev().
145 *
146 * @newin{2,28}
147 *
148 * @param[out] argc The length of the arguments array.
149 * @return The string array containing the arguments (the argv).
150 */
151 char** get_arguments(int& argc) const;
152
153 //TODO: Wrap the GVariantDict*. See also Application's handle-local-options signal.
154
155 /** Gets the options that were passed to Glib::application_command_line().
156 *
157 * If you did not override local_command_line() then these are the same
158 * options that were parsed according to the OptionEntrys added to the
159 * application with g_application_add_main_option_entries() and possibly
160 * modified from your GApplication::handle-local-options handler.
161 *
162 * If no options were sent then an empty dictionary is returned so that
163 * you don't need to check for <tt>nullptr</tt>.
164 *
165 * The data has been passed via an untrusted external process, so the types of
166 * all values must be checked before being used.
167 *
168 * @newin{2,40}
169 *
170 * @return A VariantDict with the options.
171 */
172 Glib::RefPtr<Glib::VariantDict> get_options_dict();
173
174 /** Gets the options that were passed to Glib::application_command_line().
175 *
176 * If you did not override local_command_line() then these are the same
177 * options that were parsed according to the OptionEntrys added to the
178 * application with g_application_add_main_option_entries() and possibly
179 * modified from your GApplication::handle-local-options handler.
180 *
181 * If no options were sent then an empty dictionary is returned so that
182 * you don't need to check for <tt>nullptr</tt>.
183 *
184 * The data has been passed via an untrusted external process, so the types of
185 * all values must be checked before being used.
186 *
187 * @newin{2,40}
188 *
189 * @return A VariantDict with the options.
190 */
191 Glib::RefPtr<const Glib::VariantDict> get_options_dict() const;
192
193
194 /** Gets the stdin of the invoking process.
195 *
196 * The InputStream can be used to read data passed to the standard
197 * input of the invoking process.
198 * This doesn't work on all platforms. Presently, it is only available
199 * on UNIX when using a D-Bus daemon capable of passing file descriptors.
200 * If stdin is not available then <tt>nullptr</tt> will be returned. In the
201 * future, support may be expanded to other platforms.
202 *
203 * You must only call this function once per commandline invocation.
204 *
205 * @newin{2,34}
206 *
207 * @return A InputStream for stdin.
208 */
209 Glib::RefPtr<InputStream> get_stdin();
210
211 /** Gets the stdin of the invoking process.
212 *
213 * The InputStream can be used to read data passed to the standard
214 * input of the invoking process.
215 * This doesn't work on all platforms. Presently, it is only available
216 * on UNIX when using a D-Bus daemon capable of passing file descriptors.
217 * If stdin is not available then <tt>nullptr</tt> will be returned. In the
218 * future, support may be expanded to other platforms.
219 *
220 * You must only call this function once per commandline invocation.
221 *
222 * @newin{2,34}
223 *
224 * @return A InputStream for stdin.
225 */
226 Glib::RefPtr<const InputStream> get_stdin() const;
227
228
229 //We use std::string instead of ustring because the C documentation says that it may be non-UTF-8 data:
230
231 /** Gets the working directory of the command line invocation.
232 * The string may contain non-utf8 data.
233 *
234 * It is possible that the remote application did not send a working
235 * directory, so this may be <tt>nullptr</tt>.
236 *
237 * The return value should not be modified or freed and is valid for as
238 * long as @a cmdline exists.
239 *
240 * @newin{2,28}
241 *
242 * @return The current directory, or <tt>nullptr</tt>.
243 */
244 std::string get_cwd() const;
245
246 //We use std::string instead of ustring because the C documentation says that it may be non-UTF-8 data:
247
248
249 /** Gets the contents of the 'environ' variable of the command line
250 * invocation, as would be returned by Glib::get_environ(), ie as a
251 * <tt>nullptr</tt>-terminated list of strings in the form 'NAME=VALUE'.
252 * The strings may contain non-utf8 data.
253 *
254 * The remote application usually does not send an environment. Use
255 * Gio::Application::Flags::SEND_ENVIRONMENT to affect that. Even with this flag
256 * set it is possible that the environment is still not available (due
257 * to invocation messages from other applications).
258 *
259 * The return value should not be modified or freed and is valid for as
260 * long as @a cmdline exists.
261 *
262 * See g_application_command_line_getenv() if you are only interested
263 * in the value of a single environment variable.
264 *
265 * @newin{2,28}
266 *
267 * @return The environment strings, or <tt>nullptr</tt> if they were not sent.
268 */
269 std::vector<std::string> get_environ() const;
270
271 //We use std::string instead of ustring because the C documentation says that it may be non-UTF-8 data:
272
273 /** Gets the value of a particular environment variable of the command
274 * line invocation, as would be returned by Glib::getenv(). The strings may
275 * contain non-utf8 data.
276 *
277 * The remote application usually does not send an environment. Use
278 * Gio::Application::Flags::SEND_ENVIRONMENT to affect that. Even with this flag
279 * set it is possible that the environment is still not available (due
280 * to invocation messages from other applications).
281 *
282 * The return value should not be modified or freed and is valid for as
283 * long as @a cmdline exists.
284 *
285 * @newin{2,28}
286 *
287 * @param name The environment variable to get.
288 * @return The value of the variable, or <tt>nullptr</tt> if unset or unsent.
289 */
290 std::string getenv(const Glib::ustring& name) const;
291
292
293 /** Determines if @a cmdline represents a remote invocation.
294 *
295 * @newin{2,28}
296 *
297 * @return <tt>true</tt> if the invocation was remote.
298 */
299 bool is_remote() const;
300
301
302 /** Gets the platform data associated with the invocation of @a cmdline.
303 *
304 * This is a Variant dictionary containing information about the
305 * context in which the invocation occurred. It typically contains
306 * information like the current working directory and the startup
307 * notification ID.
308 *
309 * It comes from an untrusted external process and hence the types of all
310 * values must be validated before being used.
311 *
312 * For local invocation, it will be <tt>nullptr</tt>.
313 *
314 * @newin{2,28}
315 *
316 * @return The platform data, or <tt>nullptr</tt>.
317 */
318 Glib::Variant< std::map<Glib::ustring, Glib::VariantBase> > get_platform_data() const;
319
320
321 /** Sets the exit status that will be used when the invoking process
322 * exits.
323 *
324 * The return value of the Application::signal_command_line() signal is
325 * passed to this function when the handler returns. This is the usual
326 * way of setting the exit status.
327 *
328 * In the event that you want the remote invocation to continue running
329 * and want to decide on the exit status in the future, you can use this
330 * call. For the case of a remote invocation, the remote process will
331 * typically exit when the last reference is dropped on @a cmdline. The
332 * exit status of the remote process will be equal to the last value
333 * that was set with this function.
334 *
335 * In the case that the commandline invocation is local, the situation
336 * is slightly more complicated. If the commandline invocation results
337 * in the mainloop running (ie: because the use-count of the application
338 * increased to a non-zero value) then the application is considered to
339 * have been 'successful' in a certain sense, and the exit status is
340 * always zero. If the application use count is zero, though, the exit
341 * status of the local ApplicationCommandLine is used.
342 *
343 * @newin{2,28}
344 *
345 * @param exit_status The exit status.
346 */
347 void set_exit_status(int exit_status);
348
349 /** Gets the exit status of @a cmdline. See
350 * g_application_command_line_set_exit_status() for more information.
351 *
352 * @newin{2,28}
353 *
354 * @return The exit status.
355 */
356 int get_exit_status() const;
357
358 /** Formats a message and prints it using the stdout print handler in the invoking process.
359 * If this is a local invocation then this is exactly equivalent to g_print().
360 * If this is remote then this is equivalent to calling g_print() in the invoking process.
361 *
362 * @param message The text to print.
363 */
364 void print(const Glib::ustring& message);
365
366
367 /** Formats a message and prints it using the stderr print handler in the invoking process.
368 * If this is a local invocation then this is exactly equivalent to g_printerr().
369 * If this is remote then this is equivalent to calling g_printerr() in the invoking process.
370 *
371 * @param message The text to print.
372 */
373 void printerr(const Glib::ustring& message);
374
375
376 /** Creates a File corresponding to a filename that was given as part
377 * of the invocation of @a cmdline.
378 *
379 * This differs from g_file_new_for_commandline_arg() in that it
380 * resolves relative pathnames using the current working directory of
381 * the invoking process rather than the local process.
382 *
383 * @newin{2,36}
384 *
385 * @param arg An argument from @a cmdline.
386 * @return A new File.
387 */
388 Glib::RefPtr<File> create_file_for_arg(const Glib::ustring& arg) const;
389
390
391 public:
392
393 public:
394 //C++ methods used to invoke GTK+ virtual functions:
395
396 protected:
397 //GTK+ Virtual Functions (override these to change behaviour):
398
399 //Default Signal Handlers::
400
401
402 };
403
404
405 } // namespace Gio
406
407
408 namespace Glib
409 {
410 /** A Glib::wrap() method for this object.
411 *
412 * @param object The C instance.
413 * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
414 * @result A C++ instance that wraps this C instance.
415 *
416 * @relates Gio::ApplicationCommandLine
417 */
418 GIOMM_API
419 Glib::RefPtr<Gio::ApplicationCommandLine> wrap(GApplicationCommandLine* object, bool take_copy = false);
420 }
421
422
423 #endif /* _GIOMM_APPLICATIONCOMMANDLINE_H */
424