Gio::ApplicationCommandLine Class Reference

ApplicationCommandLine - A command-line invocation of an application. More...

`#include <giomm/applicationcommandline.h>`

Inheritance diagram for Gio::ApplicationCommandLine:
[legend]

## Public Member Functions

virtual | ~ApplicationCommandLine ()
GApplicationCommandLine* | gobj ()
| Provides access to the underlying C GObject. More...
const GApplicationCommandLine* | gobj () const
| Provides access to the underlying C GObject. More...
GApplicationCommandLine* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
char** | get_arguments (int& argc) const
| Gets the list of arguments that was passed on the command line. More...
Glib::RefPtr< InputStream > | get_stdin ()
| Gets the stdin of the invoking process. More...
Glib::RefPtr< const InputStream > | get_stdin () const
| Gets the stdin of the invoking process. More...
std::string | get_cwd () const
| Gets the working directory of the command line invocation. More...
std::vector< std::string > | get_environ () const
| Gets the contents of the 'environ' variable of the command line invocation, as would be returned by Glib::get_environ(), ie as a `0`-terminated list of strings in the form 'NAME=VALUE'. More...
std::string | getenv (const Glib::ustring& name) const
| Gets the value of a particular environment variable of the command line invocation, as would be returned by Glib::getenv(). More...
bool | is_remote () const
| Determines if cmdline represents a remote invocation. More...
Glib::Variant< std::map < Glib::ustring, Glib::VariantBase > > | get_platform_data () const
| Gets the platform data associated with the invocation of cmdline. More...
void | set_exit_status (int exit_status)
| Sets the exit status that will be used when the invoking process exits. More...
int | get_exit_status () const
| Gets the exit status of cmdline. More...
void | print (const Glib::ustring& message)
| Formats a message and prints it using the stdout print handler in the invoking process. More...
void | printerr (const Glib::ustring& message)
| Formats a message and prints it using the stderr print handler in the invoking process. More...
Glib::RefPtr< File > | create_file_for_arg (const Glib::ustring&arg) const
| Creates a File corresponding to a filename that was given as part of the invocation of cmdline. More...
Public Member Functions inherited from Glib::Object
void* | get_data (const QueryQuark& key)
void | set_data (const Quark& key, void* data)
void | set_data (const Quark& key, void* data, DestroyNotify notify)
void | remove_data (const QueryQuark& quark)
void* | steal_data (const QueryQuark& quark)
Public Member Functions inherited from Glib::ObjectBase
void | set_property_value (const Glib::ustring& property_name, const Glib::ValueBase& value)
| You probably want to use a specific property_*() accessor method instead. More...
void | get_property_value (const Glib::ustring& property_name, Glib::ValueBase& value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | set_property (const Glib::ustring& property_name, const PropertyType& value)
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | get_property (const Glib::ustring& property_name, PropertyType& value) const
| You probably want to use a specific property_*() accessor method instead. More...
void | connect_property_changed (const Glib::ustring& property_name, const sigc::slot< void >& slot)
| You can use the signal_changed() signal of the property proxy instead, but this is necessary when using the reduced API. More...
sigc::connection | connect_property_changed_with_return (const Glib::ustring& property_name, const sigc::slot< void >& slot)
| You can use the signal_changed() signal of the property proxy instead, but this is necessary when using the reduced API. More...
void | freeze_notify ()
| Increases the freeze count on object. More...
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify(). More...
virtual void | reference () const
| Increment the reference count for this object. More...
virtual void | unreference () const
| Decrement the reference count for this object. More...
GObject* | gobj ()
| Provides access to the underlying C GObject. More...
const GObject* | gobj () const
| Provides access to the underlying C GObject. More...
GObject* | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access. More...

## Static Public Member Functions

static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...

## Protected Member Functions

| ApplicationCommandLine ()
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams& construct_params)
| Object (GObject* castitem)
virtual | ~Object ()
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
| ObjectBase (const char* custom_type_name)
| A derived constructor always overrides this choice. More...
| ObjectBase (const std::type_info& custom_type_info)
| This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
virtual | ~ObjectBase ()=0
void | initialize (GObject* castitem)

## Related Functions

(Note that these are not member functions.)
Glib::RefPtr < Gio::ApplicationCommandLine > | wrap (GApplicationCommandLine* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...
Related Functions inherited from Glib::Object
Glib::RefPtr< Glib::Object > | wrap (GObject* object, bool take_copy=false)

## Additional Inherited Members

Public Types inherited from Glib::Object
typedef void(* | DestroyNotify )(gpointer data)

## Detailed Description

ApplicationCommandLine - A command-line invocation of an application.

ApplicationCommandLine represents a command-line invocation of an application. It is created by Application and emitted in the "command-line" signal and virtual function.

The class contains the list of arguments that the program was invoked with. It is also possible to query if the commandline invocation was local (ie: the current process is running in direct response to the invocation) or remote (ie: some other process forwarded the commandline to this process).

The ApplicationCommandLine object can provide the argc and argv parameters for use with the Glib::OptionContext command-line parsing API, with the get_arguments() method.

The exit status of the originally-invoked process may be set and messages can be printed to stdout or stderr of that process. The lifecycle of the originally-invoked process is tied to the lifecycle of this object (ie: the process exits when the last reference is dropped).

The main use for ApplicationCommandline (and the "command-line" signal) is 'Emacs server' like use cases: You can set the EDITOR environment variable to have e.g. git use your favourite editor to edit commit messages, and if you already have an instance of the editor running, the editing will happen in the running instance, instead of opening a new one. An important aspect of this use case is that the process that gets started by git does not return until the editing is done.

Since glibmm 2.32:

## Constructor & Destructor Documentation

virtual Gio::ApplicationCommandLine::~ApplicationCommandLine | ( |  | ) |

virtual

Gio::ApplicationCommandLine::ApplicationCommandLine | ( |  | ) |

protected

## Member Function Documentation

Glib::RefPtr<File> Gio::ApplicationCommandLine::create_file_for_arg | ( | const Glib::ustring& | arg | ) | const

Creates a File corresponding to a filename that was given as part of the invocation of cmdline.

This differs from g_file_new_for_commandline_arg() in that it resolves relative pathnames using the current working directory of the invoking process rather than the local process.

Since glibmm 2.36:

Parameters

  arg | An argument from cmdline.

Returns
  A new File.

char** Gio::ApplicationCommandLine::get_arguments | ( | int & | argc | ) | const

Gets the list of arguments that was passed on the command line.

The strings in the array may contain non-utf8 data.

The return value is `0`-terminated and should be freed using Glib::strfreev().

Since glibmm 2.28:

Parameters

  argc | The length of the arguments array, or `0`.

Returns
  The string array containing the arguments (the argv).

std::string Gio::ApplicationCommandLine::get_cwd | ( |  | ) | const

Gets the working directory of the command line invocation.

The string may contain non-utf8 data.

It is possible that the remote application did not send a working directory, so this may be `0`.

The return value should not be modified or freed and is valid for as long as cmdline exists.

Since glibmm 2.28:

Returns
  The current directory, or `0`.

std::vector<std::string> Gio::ApplicationCommandLine::get_environ | ( |  | ) | const

Gets the contents of the 'environ' variable of the command line invocation, as would be returned by Glib::get_environ(), ie as a `0`-terminated list of strings in the form 'NAME=VALUE'.

The strings may contain non-utf8 data.

The remote application usually does not send an environment. Use APPLICATION_SEND_ENVIRONMENT to affect that. Even with this flag set it is possible that the environment is still not available (due to invocation messages from other applications).

The return value should not be modified or freed and is valid for as long as cmdline exists.

See g_application_command_line_getenv() if you are only interested in the value of a single environment variable.

Since glibmm 2.28:

Returns
  The environment strings, or `0` if they were not sent.

int Gio::ApplicationCommandLine::get_exit_status | ( |  | ) | const

Gets the exit status of cmdline.

See g_application_command_line_set_exit_status() for more information.

Since glibmm 2.28:

Returns
  The exit status.

Glib::Variant< std::map<Glib::ustring, Glib::VariantBase> > Gio::ApplicationCommandLine::get_platform_data | ( |  | ) | const

Gets the platform data associated with the invocation of cmdline.

This is a Variant dictionary containing information about the context in which the invocation occurred. It typically contains information like the current working directory and the startup notification ID.

For local invocation, it will be `0`.

Since glibmm 2.28:

Returns
  The platform data, or `0`.

Glib::RefPtr<InputStream> Gio::ApplicationCommandLine::get_stdin | ( |  | ) |

Gets the stdin of the invoking process.

The InputStream can be used to read data passed to the standard input of the invoking process. This doesn't work on all platforms. Presently, it is only available on UNIX when using a DBus daemon capable of passing file descriptors. If stdin is not available then `0` will be returned. In the future, support may be expanded to other platforms.

You must only call this function once per commandline invocation.

Since glibmm 2.34:

Returns
  A InputStream for stdin.

Glib::RefPtr<const InputStream> Gio::ApplicationCommandLine::get_stdin | ( |  | ) | const

Gets the stdin of the invoking process.

The InputStream can be used to read data passed to the standard input of the invoking process. This doesn't work on all platforms. Presently, it is only available on UNIX when using a DBus daemon capable of passing file descriptors. If stdin is not available then `0` will be returned. In the future, support may be expanded to other platforms.

You must only call this function once per commandline invocation.

Since glibmm 2.34:

Returns
  A InputStream for stdin.

static GType Gio::ApplicationCommandLine::get_type | ( |  | ) |

static

Get the GType for this class, for use with the underlying GObject type system.

std::string Gio::ApplicationCommandLine::getenv | ( | const Glib::ustring& | name | ) | const

Gets the value of a particular environment variable of the command line invocation, as would be returned by Glib::getenv().

The strings may contain non-utf8 data.

The remote application usually does not send an environment. Use APPLICATION_SEND_ENVIRONMENT to affect that. Even with this flag set it is possible that the environment is still not available (due to invocation messages from other applications).

The return value should not be modified or freed and is valid for as long as cmdline exists.

Since glibmm 2.28:

Parameters

  name | The environment variable to get.

Returns
  The value of the variable, or `0` if unset or unsent.

GApplicationCommandLine* Gio::ApplicationCommandLine::gobj | ( |  | ) |

inline

Provides access to the underlying C GObject.

const GApplicationCommandLine* Gio::ApplicationCommandLine::gobj | ( |  | ) | const

inline

Provides access to the underlying C GObject.

GApplicationCommandLine* Gio::ApplicationCommandLine::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

bool Gio::ApplicationCommandLine::is_remote | ( |  | ) | const

Determines if cmdline represents a remote invocation.

Since glibmm 2.28:

Returns
  `true` if the invocation was remote.

void Gio::ApplicationCommandLine::print | ( | const Glib::ustring& | message | ) |

Formats a message and prints it using the stdout print handler in the invoking process.

If this is a local invocation then this is exactly equivalent to g_print(). If this is remote then this is equivalent to calling g_print() in the invoking process.

Parameters

  message | The text to print.

void Gio::ApplicationCommandLine::printerr | ( | const Glib::ustring& | message | ) |

Formats a message and prints it using the stderr print handler in the invoking process.

If this is a local invocation then this is exactly equivalent to g_printerr(). If this is remote then this is equivalent to calling g_printerr() in the invoking process.

Parameters

  message | The text to print.

void Gio::ApplicationCommandLine::set_exit_status | ( | int | exit_status | ) |

Sets the exit status that will be used when the invoking process exits.

The return value of the Application::signal_command_line() signal is passed to this function when the handler returns. This is the usual way of setting the exit status.

In the event that you want the remote invocation to continue running and want to decide on the exit status in the future, you can use this call. For the case of a remote invocation, the remote process will typically exit when the last reference is dropped on cmdline. The exit status of the remote process will be equal to the last value that was set with this function.

In the case that the commandline invocation is local, the situation is slightly more complicated. If the commandline invocation results in the mainloop running (ie: because the use-count of the application increased to a non-zero value) then the application is considered to have been 'successful' in a certain sense, and the exit status is always zero. If the application use count is zero, though, the exit status of the local ApplicationCommandLine is used.

Since glibmm 2.28:

Parameters

  exit_status | The exit status.

## Friends And Related Function Documentation

Glib::RefPtr< Gio::ApplicationCommandLine > wrap | ( | GApplicationCommandLine * | object,
|  | bool | take_copy = `false`
| ) |  |

related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.