Exemple #1
0
        /// <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);
            }
        }
Exemple #2
0
        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);
                }
            }
        }
Exemple #3
0
        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;
            }
        }
        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;
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        /// <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);
        }
Exemple #7
0
        /// <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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        /// <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_);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        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);
        }
Exemple #15
0
        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);
        }
Exemple #16
0
        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);
        }
Exemple #17
0
        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_);
        }
Exemple #18
0
        /// <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);
        }
Exemple #19
0
        /// <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_);
        }
Exemple #20
0
        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);
        }
Exemple #21
0
        /// <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);
        }
Exemple #22
0
        /// <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);
        }
Exemple #23
0
        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);
        }
Exemple #24
0
        public void InstallProperties(ParamSpec[] pspecs)
        {
            if (pspecs == null)
            {
                throw new ArgumentNullException(nameof(pspecs));
            }
            var pspecs_  = GMarshal.OpaqueCArrayToPtr <ParamSpec> (pspecs, false);
            var nPspecs_ = (uint)(pspecs == null ? 0 : pspecs.Length);

            g_object_class_install_properties(Handle, nPspecs_, pspecs_);
            GMarshal.Free(pspecs_);
        }
Exemple #25
0
        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);
            }
        }
Exemple #26
0
        /// <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);
        }
Exemple #27
0
        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);
        }
Exemple #28
0
        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());
        }
Exemple #29
0
        /// <summary>
        /// Check whether a particular namespace (and optionally, a specific
        /// version thereof) is currently loaded.
        /// </summary>
        /// <returns><c>true</c> if is registered the specified <c>namespace-version</c>
        /// was loaded; otherwise, <c>false</c>.</returns>
        /// <param name="namespace">Namespace of interest.</param>
        /// <param name="version">Requred version or <c>null</c> for latest.</param>
        public static bool IsRegistered(string @namespace, string version = null)
        {
            if (@namespace == null)
            {
                throw new ArgumentNullException("namespace");
            }
            IntPtr native_namespace = GMarshal.StringToUtf8Ptr(@namespace);
            IntPtr native_version   = GMarshal.StringToUtf8Ptr(version);
            bool   raw_ret          = g_irepository_is_registered(IntPtr.Zero, native_namespace, native_version);
            bool   ret = raw_ret;

            GMarshal.Free(native_namespace);
            GMarshal.Free(native_version);
            return(ret);
        }
Exemple #30
0
            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);
        }