glibmm 2.80.0
|
ApplicationCommandLine - A command-line invocation of an application. More...
#include <giomm/applicationcommandline.h>
Public Member Functions | |
ApplicationCommandLine (ApplicationCommandLine &&src) noexcept | |
ApplicationCommandLine & | operator= (ApplicationCommandLine &&src) noexcept |
~ApplicationCommandLine () noexcept override | |
GApplicationCommandLine * | gobj () |
Provides access to the underlying C GObject. | |
const GApplicationCommandLine * | gobj () const |
Provides access to the underlying C GObject. | |
GApplicationCommandLine * | gobj_copy () |
Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. | |
char ** | get_arguments (int &argc) const |
Gets the list of arguments that was passed on the command line. | |
Glib::RefPtr< Glib::VariantDict > | get_options_dict () |
Gets the options that were passed to Glib::application_command_line(). | |
Glib::RefPtr< const Glib::VariantDict > | get_options_dict () const |
Gets the options that were passed to Glib::application_command_line(). | |
Glib::RefPtr< InputStream > | get_stdin () |
Gets the stdin of the invoking process. | |
Glib::RefPtr< const InputStream > | get_stdin () const |
Gets the stdin of the invoking process. | |
std::string | get_cwd () const |
Gets the working directory of the command line invocation. | |
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 nullptr -terminated list of strings in the form 'NAME=VALUE'. | |
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(). | |
bool | is_remote () const |
Determines if cmdline represents a remote invocation. | |
Glib::Variant< std::map< Glib::ustring, Glib::VariantBase > > | get_platform_data () const |
Gets the platform data associated with the invocation of cmdline. | |
void | set_exit_status (int exit_status) |
Sets the exit status that will be used when the invoking process exits. | |
int | get_exit_status () const |
Gets the exit status of cmdline. | |
void | print (const Glib::ustring & message) |
Prints a message using the stdout print handler in the invoking process. | |
void | printerr (const Glib::ustring & message) |
Prints a message using the stderr print handler in the invoking process. | |
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. | |
void | done () |
Signals that command line processing is completed. | |
Public Member Functions inherited from Glib::Object | |
Object (const Object &)=delete | |
Object & | operator= (const Object &)=delete |
Object (Object &&src) noexcept | |
Object & | operator= (Object &&src) noexcept |
void * | get_data (const QueryQuark & key) |
void | set_data (const Quark & key, void *data) |
void | set_data_with_c_callback (const Quark & key, void *data, GDestroyNotify notify) |
void | set_data (const Quark & key, void *data, DestroyNotify notify) |
Prefer set_data_with_c_callback() with a callback with C linkage. | |
void | remove_data (const QueryQuark &quark) |
void * | steal_data (const QueryQuark &quark) |
Public Member Functions inherited from Glib::ObjectBase | |
ObjectBase (const ObjectBase &)=delete | |
ObjectBase & | operator= (const ObjectBase &)=delete |
void | set_property_value (const Glib::ustring & property_name, const Glib::ValueBase & value) |
You probably want to use a specific property_*() accessor method instead. | |
void | get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const |
You probably want to use a specific property_*() accessor method instead. | |
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. | |
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. | |
template<class PropertyType > | |
PropertyType | get_property (const Glib::ustring & property_name) const |
You probably want to use a specific property_*() accessor method instead. | |
sigc::connection | 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. | |
sigc::connection | connect_property_changed (const Glib::ustring & property_name, sigc::slot< void()> &&slot) |
You can use the signal_changed() signal of the property proxy instead. | |
void | freeze_notify () |
Increases the freeze count on object. | |
void | thaw_notify () |
Reverts the effect of a previous call to freeze_notify(). | |
virtual void | reference () const |
Increment the reference count for this object. | |
virtual void | unreference () const |
Decrement the reference count for this object. | |
GObject * | gobj () |
Provides access to the underlying C GObject. | |
const GObject * | gobj () const |
Provides access to the underlying C GObject. | |
GObject * | gobj_copy () const |
Give a ref-ed copy to someone. Use for direct struct access. | |
Static Public Member Functions | |
static GType | get_type () |
Get the GType for this class, for use with the underlying GObject type system. | |
Protected Member Functions | |
ApplicationCommandLine () | |
Protected Member Functions inherited from Glib::Object | |
Object () | |
Object (const Glib::ConstructParams &construct_params) | |
Object (GObject *castitem) | |
~Object () noexcept override | |
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. | |
ObjectBase (const char *custom_type_name) | |
A derived constructor always overrides this choice. | |
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. | |
ObjectBase (ObjectBase &&src) noexcept | |
ObjectBase & | operator= (ObjectBase &&src) noexcept |
virtual | ~ObjectBase () noexcept=0 |
void | initialize (GObject *castitem) |
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper) |
Related Symbols | |
(Note that these are not member symbols.) | |
Glib::RefPtr< Gio::ApplicationCommandLine > | wrap (GApplicationCommandLine *object, bool take_copy=false) |
A Glib::wrap() method for this object. | |
Related Symbols inherited from Glib::Object | |
Glib::RefPtr< Glib::Object > | wrap (GObject *object, bool take_copy=false) |
Additional Inherited Members | |
Public Types inherited from Glib::Object | |
using | DestroyNotify = void(*)(gpointer data) |
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.
|
noexcept |
|
overridenoexcept |
|
protected |
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.
arg | An argument from cmdline. |
void Gio::ApplicationCommandLine::done | ( | ) |
Signals that command line processing is completed.
For remote invocation, it causes the invoking process to terminate.
For local invocation, it does nothing.
This method should be called in the Gio::Application::signal_command_line() handler, after the exit status is set and all messages are printed.
After this call, g_application_command_line_set_exit_status() has no effect. Subsequent calls to this method are no-ops.
This method is automatically called when the ApplicationCommandLine object is disposed — so you can omit the call in non-garbage collected languages.
Gets the list of arguments that was passed on the command line.
The strings in the array may contain non-UTF-8 data on UNIX (such as filenames or arguments given in the system locale) but are always in UTF-8 on Windows.
If you wish to use the return value with Glib::OptionContext, you must use Glib::OptionContext::parse(char**& argv).
The return value is nullptr-terminated and should be freed using g_strfreev().
[out] | argc | The length of the arguments array. |
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 nullptr
.
The return value should not be modified or freed and is valid for as long as cmdline exists.
nullptr
. 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 nullptr
-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 Gio::Application::Flags::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.
nullptr
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.
Glib::RefPtr< Glib::VariantDict > Gio::ApplicationCommandLine::get_options_dict | ( | ) |
Gets the options that were passed to Glib::application_command_line().
If you did not override local_command_line() then these are the same options that were parsed according to the OptionEntrys added to the application with g_application_add_main_option_entries() and possibly modified from your GApplication::handle-local-options handler.
If no options were sent then an empty dictionary is returned so that you don't need to check for nullptr
.
The data has been passed via an untrusted external process, so the types of all values must be checked before being used.
Glib::RefPtr< const Glib::VariantDict > Gio::ApplicationCommandLine::get_options_dict | ( | ) | const |
Gets the options that were passed to Glib::application_command_line().
If you did not override local_command_line() then these are the same options that were parsed according to the OptionEntrys added to the application with g_application_add_main_option_entries() and possibly modified from your GApplication::handle-local-options handler.
If no options were sent then an empty dictionary is returned so that you don't need to check for nullptr
.
The data has been passed via an untrusted external process, so the types of all values must be checked before being used.
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.
It comes from an untrusted external process and hence the types of all values must be validated before being used.
For local invocation, it will be nullptr
.
nullptr
. 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 D-Bus daemon capable of passing file descriptors. If stdin is not available then nullptr
will be returned. In the future, support may be expanded to other platforms.
You must only call this function once per commandline invocation.
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 D-Bus daemon capable of passing file descriptors. If stdin is not available then nullptr
will be returned. In the future, support may be expanded to other platforms.
You must only call this function once per commandline invocation.
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 Gio::Application::Flags::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.
name | The environment variable to get. |
nullptr
if unset or unsent.
|
inline |
Provides access to the underlying C GObject.
|
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.
true
if the invocation was remote.
|
noexcept |
void Gio::ApplicationCommandLine::print | ( | const Glib::ustring & | message | ) |
void Gio::ApplicationCommandLine::printerr | ( | const Glib::ustring & | message | ) |
Prints a message 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.
message | The text to print. |
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.
This method is a no-op if g_application_command_line_done() has been called.
exit_status | The exit status. |
|
related |
A Glib::wrap() method for this object.
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. |