
/* This file is generated by glib-mkenums, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */

#include "mm-huawei-enums-types.h"
/* enumerations from "/build/modemmanager/src/build/../ModemManager/plugins/huawei/mm-modem-helpers-huawei.h" */
static const GEnumValue mm_huawei_port_mode_values[] = {
    { MM_HUAWEI_PORT_MODE_NONE, "MM_HUAWEI_PORT_MODE_NONE", "none" },
    { MM_HUAWEI_PORT_MODE_PCUI, "MM_HUAWEI_PORT_MODE_PCUI", "pcui" },
    { MM_HUAWEI_PORT_MODE_MODEM, "MM_HUAWEI_PORT_MODE_MODEM", "modem" },
    { MM_HUAWEI_PORT_MODE_DIAG, "MM_HUAWEI_PORT_MODE_DIAG", "diag" },
    { MM_HUAWEI_PORT_MODE_GPS, "MM_HUAWEI_PORT_MODE_GPS", "gps" },
    { MM_HUAWEI_PORT_MODE_NET, "MM_HUAWEI_PORT_MODE_NET", "net" },
    { MM_HUAWEI_PORT_MODE_CDROM, "MM_HUAWEI_PORT_MODE_CDROM", "cdrom" },
    { MM_HUAWEI_PORT_MODE_SD, "MM_HUAWEI_PORT_MODE_SD", "sd" },
    { MM_HUAWEI_PORT_MODE_BT, "MM_HUAWEI_PORT_MODE_BT", "bt" },
    { MM_HUAWEI_PORT_MODE_SHELL, "MM_HUAWEI_PORT_MODE_SHELL", "shell" },
    { 0, NULL, NULL }
};

/* Define type-specific symbols */
#undef __MM_IS_ENUM__
#undef __MM_IS_FLAGS__
#define __MM_IS_ENUM__

GType
mm_huawei_port_mode_get_type (void)
{
    static gsize g_define_type_id_initialized = 0;

    if (g_once_init_enter (&g_define_type_id_initialized)) {
        GType g_define_type_id =
            g_enum_register_static (g_intern_static_string ("MMHuaweiPortMode"),
                                      mm_huawei_port_mode_values);
        g_once_init_leave (&g_define_type_id_initialized, g_define_type_id);
    }

    return g_define_type_id_initialized;
}

/**
 * mm_huawei_port_mode_get_string:
 * @val: a MMHuaweiPortMode.
 *
 * Gets the nickname string for the #MMHuaweiPortMode specified at @val.
 *
 * Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value.
 */
#if defined __MM_IS_ENUM__
const gchar *
mm_huawei_port_mode_get_string (MMHuaweiPortMode val)
{
    guint i;

    for (i = 0; mm_huawei_port_mode_values[i].value_nick; i++) {
        if ((gint)val == mm_huawei_port_mode_values[i].value)
            return mm_huawei_port_mode_values[i].value_nick;
    }

    return NULL;
}
#endif /* __MM_IS_ENUM_ */

/**
 * mm_huawei_port_mode_build_string_from_mask:
 * @mask: bitmask of MMHuaweiPortMode values.
 *
 * Builds a string containing a comma-separated list of nicknames for
 * each #MMHuaweiPortMode in @mask.
 *
 * Returns: (transfer full): a string with the list of nicknames, or %NULL if none given. The returned value should be freed with g_free().
 */
#if defined __MM_IS_FLAGS__
gchar *
mm_huawei_port_mode_build_string_from_mask (MMHuaweiPortMode mask)
{
    guint i;
    gboolean first = TRUE;
    GString *str = NULL;

    for (i = 0; mm_huawei_port_mode_values[i].value_nick; i++) {
        /* We also look for exact matches */
        if (mask == mm_huawei_port_mode_values[i].value) {
            if (str)
                g_string_free (str, TRUE);
            return g_strdup (mm_huawei_port_mode_values[i].value_nick);
        }

        /* Build list with single-bit masks */
        if (mask & mm_huawei_port_mode_values[i].value) {
            guint c;
            gulong number = mm_huawei_port_mode_values[i].value;

            for (c = 0; number; c++)
                number &= number - 1;

            if (c == 1) {
                if (!str)
                    str = g_string_new ("");
                g_string_append_printf (str, "%s%s",
                                        first ? "" : ", ",
                                        mm_huawei_port_mode_values[i].value_nick);
                if (first)
                    first = FALSE;
            }
        }
    }

    return (str ? g_string_free (str, FALSE) : NULL);
}
#endif /* __MM_IS_FLAGS__ */

/* Generated data ends here */

