/// <summary> /// Force the namespace namespace_ to be loaded if it isn't already. /// </summary> /// <param name="typelibDir">Private directory where to find the requested typelib.</param> /// <param name="namespace">Namespace.</param> /// <param name="version">Version of namespace, may be <c>null</c> for latest.</param> /// <param name="flags">Flags.</param> /// <exception cref="ArgumentNullException">If <paramref name="typelibDir"/> /// or <paramref name="namespace"/> is <c>null<c/>.</exception> /// <exception cref="GErrorException">On failure.</exception> /// <remarks> /// If <paramref name="namespace"/> is not loaded, this function will /// search for a ".typelib" file within the private directory only. In /// addition, a version <paramref name="version"/> of namespace may be /// specified. If <paramref name="version"/> is not specified, the latest /// will be used. /// </remarks> public static void RequirePrivate(string typelibDir, string @namespace, string version = null, RepositoryLoadFlags flags = default(RepositoryLoadFlags)) { if (typelibDir == null) { throw new ArgumentNullException("typelibDir"); } if (@namespace == null) { throw new ArgumentNullException("namespace"); } IntPtr native_typelib_dir = GMarshal.StringToUtf8Ptr(typelibDir); IntPtr native_namespace = GMarshal.StringToUtf8Ptr(@namespace); IntPtr native_version = GMarshal.StringToUtf8Ptr(version); IntPtr error_; g_irepository_require_private(IntPtr.Zero, native_typelib_dir, native_namespace, native_version, (int)flags, out error_); GMarshal.Free(native_typelib_dir); GMarshal.Free(native_namespace); GMarshal.Free(native_version); if (error_ != IntPtr.Zero) { var error = new Error(error_, Runtime.Transfer.Full); throw new GErrorException(error); } }
static Module() { // Initialize the platform-specific "constants". Suffix should end // up being the same as G_MODULE_SUFFIX in C code. var emptyName = GMarshal.StringToUtf8Ptr(string.Empty); var path_ = g_module_build_path(IntPtr.Zero, emptyName); var path = GMarshal.Utf8PtrToString(path_, true); GMarshal.Free(emptyName); var parts = path.Split('.'); Prefix = parts[0]; Suffix = parts[1]; // Hack to detect macOS if (File.Exists("/usr/lib/libSystem.dylib")) { LibrarySuffix = "dylib"; } else { LibrarySuffix = Suffix; } }
public static string FormatFields(LogLevelFlags logLevel, IDictionary <string, string> fields, bool useColor = false) { if (fields == null) { throw new ArgumentNullException(nameof(fields)); } var fields_ = new LogField[fields.Count]; var i = 0; foreach (var item in fields) { fields_[i].Key = GMarshal.StringToUtf8Ptr(item.Key); fields_[i].Value = GMarshal.StringToUtf8Ptr(item.Value); fields_[i].Length = new IntPtr(-1); i++; } try { return(FormatFields(logLevel, fields_, useColor)); } finally { foreach (var item in fields_) { GMarshal.Free(item.Key); GMarshal.Free(item.Value); } } }
static IntPtr New (string name, string nick, string blurb, ParamFlags flags) { if (name == null) { throw new ArgumentNullException (nameof (name)); } if (nick == null) { throw new ArgumentNullException (nameof (nick)); } if (blurb == null) { throw new ArgumentNullException (nameof (blurb)); } var namePtr = GMarshal.StringToUtf8Ptr (name); var nickPtr = GMarshal.StringToUtf8Ptr (nick); var blurbPtr = GMarshal.StringToUtf8Ptr (blurb); var ret = g_param_spec_pointer (namePtr, nickPtr, blurbPtr, flags); // Any strings that have the cooresponding static flag set must not // be freed because they are passed to g_intern_static_string(). if (!flags.HasFlag (ParamFlags.StaticName)) { GMarshal.Free (namePtr); } if (!flags.HasFlag (ParamFlags.StaticNick)) { GMarshal.Free (nickPtr); } if (!flags.HasFlag (ParamFlags.StaticBlurb)) { GMarshal.Free (blurbPtr); } return ret; }
/// <summary> /// Gets the <see cref="Quark"/> identifying the given string. If the string does /// not currently have an associated <see cref="Quark"/>, a new <see cref="Quark"/> is created. /// </summary> /// <param name="string"> /// A string /// </param> /// <returns> /// The <see cref="Quark"/> identifying the string, or <see cref="Zero"/> if <paramref name="string"/> is <c>null</c>. /// </returns> public static Quark FromString(string @string) { var string_ = GMarshal.StringToUtf8Ptr(@string); var ret = g_quark_from_string(string_); GMarshal.Free(string_); return(ret); }
static int GetNInfos(string @namespace) { var native_namespace = GMarshal.StringToUtf8Ptr(@namespace); var ret = g_irepository_get_n_infos(IntPtr.Zero, native_namespace); GMarshal.Free(native_namespace); return(ret); }
public VFuncInfo FindVFuncUsingInterfaces(string name, ObjectInfo implementor) { IntPtr native_name = GMarshal.StringToUtf8Ptr(name); IntPtr raw_ret = g_object_info_find_vfunc_using_interfaces(Handle, native_name, implementor == null ? IntPtr.Zero : implementor.Handle); var ret = MarshalPtr <VFuncInfo> (raw_ret); GMarshal.Free(native_name); return(ret); }
internal static string GetVersion(string @namespace) { IntPtr native_namespace = GMarshal.StringToUtf8Ptr(@namespace); IntPtr raw_ret = g_irepository_get_version(IntPtr.Zero, native_namespace); string ret = GMarshal.Utf8PtrToString(raw_ret); GMarshal.Free(native_namespace); return(ret); }
internal static GISharp.GIRepository.BaseInfo GetInfo(string @namespace, int index) { IntPtr native_namespace = GMarshal.StringToUtf8Ptr(@namespace); IntPtr raw_ret = g_irepository_get_info(IntPtr.Zero, native_namespace, index); GISharp.GIRepository.BaseInfo ret = BaseInfo.MarshalPtr <BaseInfo> (raw_ret); GMarshal.Free(native_namespace); return(ret); }
internal static string[] GetImmediateDependencies(string @namespace) { var native_namespace = GMarshal.StringToUtf8Ptr(@namespace); var raw_ret = g_irepository_get_immediate_dependencies(IntPtr.Zero, native_namespace); var ret = GMarshal.GStrvPtrToStringArray(raw_ret, freePtr: true, freeElements: true); GMarshal.Free(native_namespace); return(ret); }
/// <summary> /// The default log handler set up by GLib; <see cref="SetHandler"/> /// allows to install an alternate default log handler. /// This is used if no log handler has been set for the particular log /// domain and log level combination. It outputs the message to stderr /// or stdout and if the log level is fatal it calls abort(). It automatically /// prints a new-line character after the message, so one does not need to be /// manually included in <paramref name="message"/>. /// </summary> /// <remarks> /// The behavior of this log handler can be influenced by a number of /// environment variables: /// /// - `G_MESSAGES_PREFIXED`: A :-separated list of log levels for which /// messages should be prefixed by the program name and PID of the /// aplication. /// /// - `G_MESSAGES_DEBUG`: A space-separated list of log domains for /// which debug and informational messages are printed. By default /// these messages are not printed. /// /// stderr is used for levels <see cref="LogLevelFlags.Error"/>, <see cref="LogLevelFlags.Critical"/>, /// <see cref="LogLevelFlags.Warning"/> and <see cref="LogLevelFlags.Message"/>. stdout is used for /// the rest. /// /// This has no effect if structured logging is enabled; see /// [Using Structured Logging][using-structured-logging]. /// </remarks> /// <param name="logDomain"> /// the log domain of the message, or <c>null</c> for the /// default "" application domain /// </param> /// <param name="logLevel"> /// the level of the message /// </param> /// <param name="message"> /// the message /// </param> public static void DefaultHandler(string logDomain, LogLevelFlags logLevel, string message) { var logDomain_ = GMarshal.StringToUtf8Ptr(logDomain); var message_ = GMarshal.StringToUtf8Ptr(message); g_log_default_handler(logDomain_, logLevel, message_, IntPtr.Zero); GMarshal.Free(logDomain_); GMarshal.Free(message_); }
public FunctionInfo FindMethod(string name) { IntPtr native_name = GMarshal.StringToUtf8Ptr(name); IntPtr raw_ret = g_object_info_find_method(Handle, native_name); var ret = MarshalPtr <FunctionInfo> (raw_ret); GMarshal.Free(native_name); return(ret); }
/// <summary> /// Retrieve an arbitrary attribute associated with this node. /// </summary> /// <returns>The attribute or <c>null</c> if no such attribute exists.</returns> /// <param name="name">Name.</param> public string GetAttribute(string name) { IntPtr native_name = GMarshal.StringToUtf8Ptr(name); IntPtr raw_ret = g_base_info_get_attribute(Handle, native_name); string ret = GMarshal.Utf8PtrToString(raw_ret); GMarshal.Free(native_name); return(ret); }
internal static string[] GetVersions(string @namespace) { IntPtr native_namespace = GMarshal.StringToUtf8Ptr(@namespace); IntPtr raw_ret = g_irepository_enumerate_versions(IntPtr.Zero, native_namespace); var ret = GMarshal.GListToStringArray(raw_ret, freePtr: true); GMarshal.Free(native_namespace); return(ret); }
public SignalInfo FindSignal(string name) { IntPtr native_name = GMarshal.StringToUtf8Ptr(name); IntPtr raw_ret = g_object_info_find_signal(Handle, native_name); var ret = MarshalPtr <SignalInfo> (raw_ret); GMarshal.Free(native_name); return(ret); }
public VFuncInfo FindVFunc(string name) { IntPtr native_name = GMarshal.StringToUtf8Ptr(name); IntPtr raw_ret = g_object_info_find_vfunc(Handle, native_name); var ret = MarshalPtr <VFuncInfo> (raw_ret); GMarshal.Free(native_name); return(ret); }
static void Log_(string logDomain, LogLevelFlags logLevel, string format, params object[] args) { var logDomain_ = GMarshal.StringToUtf8Ptr(logDomain); var format_ = GMarshal.StringToUtf8Ptr(string.Format(format, args)); g_log(logDomain_, logLevel, format_); GMarshal.Free(logDomain_); GMarshal.Free(format_); }
public static GType RegisterStatic(string typeName, FlagsValue[] values) { GType.AssertGTypeName(typeName); var typeName_ = GMarshal.StringToUtf8Ptr(typeName); var values_ = GMarshal.CArrayToPtr <FlagsValue> (values, nullTerminated: true); var ret = g_flags_register_static(typeName_, values_); // values are never freed for the liftime of the program return(ret); }
/// <summary> /// Prepends directory to the typelib search path. /// </summary> /// <param name="directory">Directory name to prepend to the typelib search path.</param> /// <seealso cref="PrependLibraryPath"/> public static void PrependSearchPath(string directory) { if (directory == null) { throw new ArgumentNullException("directory"); } IntPtr native_directory = GMarshal.StringToUtf8Ptr(directory); g_irepository_prepend_search_path(native_directory); GMarshal.Free(native_directory); }
internal static GISharp.GIRepository.BaseInfo FindByName(string @namespace, string name) { IntPtr native_namespace = GMarshal.StringToUtf8Ptr(@namespace); IntPtr native_name = GMarshal.StringToUtf8Ptr(name); IntPtr raw_ret = g_irepository_find_by_name(IntPtr.Zero, native_namespace, native_name); GISharp.GIRepository.BaseInfo ret = BaseInfo.MarshalPtr <BaseInfo> (raw_ret); GMarshal.Free(native_namespace); GMarshal.Free(native_name); return(ret); }
/// <summary> /// Removes the log handler. /// </summary> /// <remarks> /// This has no effect if structured logging is enabled; see /// [Using Structured Logging][using-structured-logging]. /// </remarks> /// <param name="logDomain"> /// the log domain /// </param> /// <param name="handlerId"> /// the id of the handler, which was returned /// in <see cref="SetHandler"/> /// </param> public static void RemoveHandler(string logDomain, uint handlerId) { if (logDomain == null) { throw new ArgumentNullException(nameof(logDomain)); } var logDomain_ = GMarshal.StringToUtf8Ptr(logDomain); g_log_remove_handler(logDomain_, handlerId); GMarshal.Free(logDomain_); }
public static GType GetDummyGType() { if (_dummyGType == GType.Invalid) { _dummyGType = g_type_register_static_simple(GType.Object, GMarshal.StringToUtf8Ptr(dummyTypeName), new UIntPtr(256), IntPtr.Zero, new UIntPtr(32), IntPtr.Zero, 0); } return(_dummyGType); }
/// <summary> /// Sets the log levels which are fatal in the given domain. /// <see cref="LogLevelFlags.Error"/> is always fatal. /// </summary> /// <remarks> /// This has no effect on structured log messages (using g_log_structured() or /// g_log_structured_array()). To change the fatal behaviour for specific log /// messages, programs must install a custom log writer function using /// g_log_set_writer_func(). See /// [Using Structured Logging][using-structured-logging]. /// </remarks> /// <param name="logDomain"> /// the log domain /// </param> /// <param name="fatalMask"> /// the new fatal mask /// </param> /// <returns> /// the old fatal mask for the log domain /// </returns> public static LogLevelFlags SetFatalMask(string logDomain, LogLevelFlags fatalMask) { if (logDomain == null) { throw new ArgumentNullException(nameof(logDomain)); } var logDomain_ = GMarshal.StringToUtf8Ptr(logDomain); var ret = g_log_set_fatal_mask(logDomain_, fatalMask); GMarshal.Free(logDomain_); return(ret); }
/// <summary> /// Prepends <paramref name="directory"/> to the search path that is used /// to search shared libraries referenced by imported namespaces. /// </summary> /// <param name="directory">A single directory to scan for shared libraries.</param> /// <remarks> /// Multiple calls to this function all contribute to the final list of /// paths. The list of paths is unique and shared for all GIRepository /// instances across the process, but it doesn't affect namespaces imported /// before the call. /// /// If the library is not found in the directories configured in this way, /// loading will fall back to the system library path (ie. LD_LIBRARY_PATH /// and DT_RPATH in ELF systems). See the documentation of your dynamic /// linker for full details. /// </remarks> public static void PrependLibraryPath(string directory) { if (directory == null) { throw new ArgumentNullException("directory"); } // TODO: Marshal as filename, not UTF8 IntPtr native_directory = GMarshal.StringToUtf8Ptr(directory); g_irepository_prepend_library_path(native_directory); GMarshal.Free(native_directory); }
static IntPtr NewLiteral(Quark domain, int code, string message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var messagePtr = GMarshal.StringToUtf8Ptr(message); var ret = g_error_new_literal(domain, code, messagePtr); GMarshal.Free(messagePtr); return(ret); }
public static void Dump(string arg) { IntPtr native_arg = GMarshal.StringToUtf8Ptr(arg); IntPtr error_ = IntPtr.Zero; g_irepository_dump(native_arg, out error_); GMarshal.Free(native_arg); if (error_ != IntPtr.Zero) { var error = new Error(error_, Runtime.Transfer.Full); throw new GErrorException(error); } }
/// <summary> /// Looks up the <see cref="ParamSpec"/> for a property of a class. /// </summary> /// <param name="propertyName"> /// the name of the property to look up /// </param> /// <returns> /// the <see cref="ParamSpec"/> for the property, or /// <c>null</c> if the class doesn't have a property of that name /// </returns> /// <exception cref="ArgumentNullException"> /// Throw when <paramref name="propertyName"/> is <c>null</c> /// </exception> public ParamSpec FindProperty(string propertyName) { if (propertyName == null) { throw new ArgumentNullException(nameof(propertyName)); } var propertyName_ = GMarshal.StringToUtf8Ptr(propertyName); var ret_ = g_object_class_find_property(Handle, propertyName_); var ret = ParamSpec.GetInstance(ret_, Transfer.None); GMarshal.Free(propertyName_); return(ret); }
public static uint SetHandler(string logDomain, LogLevelFlags logLevels, LogFunc logFunc) { if (logFunc == null) { throw new ArgumentNullException(nameof(logFunc)); } var logDomain_ = GMarshal.StringToUtf8Ptr(logDomain); var(logFunc_, destroy_, userData_) = UnmanagedLogFuncFactory.CreateNotifyDelegate(logFunc); var ret = g_log_set_handler_full(logDomain_, logLevels, logFunc_, userData_, destroy_); GMarshal.Free(logDomain_); return(ret); }
public object GetProperty(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } var namePtr = GMarshal.StringToUtf8Ptr(name); Value value; g_object_get_property(Handle, namePtr, out value); GMarshal.Free(namePtr); return(value.Get()); }
bool walk_ancestors); // gboolean public ParamSpec Lookup(string paramName, GType ownerType, bool walkAncestors) { AssertNotDisposed(); if (paramName == null) { throw new ArgumentNullException(nameof(paramName)); } var paramNamePtr = GMarshal.StringToUtf8Ptr(paramName); var retPtr = g_param_spec_pool_lookup(Handle, paramNamePtr, ownerType, walkAncestors); GMarshal.Free(paramNamePtr); var ret = ParamSpec.GetInstance(retPtr, Transfer.None); return(ret); }