Exemplo n.º 1
0
/**
 * Object-to-Config function. 
 * Creates a config-node (and subnodes) from a LedSetup model
 * @param c the current preferences context
 * @param n a freshly created prefs node that this function should fill with properties of obj
 * @param obj object of this class where preferences should be generated from
 * @result NFT_SUCCESS if everything went fine, NFT_FAILURE otherwise
 * @note you shouldn't call this function directly
 * It's used by nft_prefs_obj_to_node() etc. 
 */
static NftResult _prefs_from_setup(NftPrefs * p, NftPrefsNode * n, void *obj,
                                   void *userptr)
{
        if(!p || !n || !obj)
                NFT_LOG_NULL(NFT_FAILURE);

        /* "Setup" object */
        LedSetup *s = obj;

        /* process all "hardware" objects */
        LedHardware *h;
        for(h = led_setup_get_hardware(s); h;
            h = led_hardware_list_get_next(h))
        {
                /* generate prefs for each hardware node */
                NftPrefsNode *node;
                if(!
                   (node =
                    nft_prefs_obj_to_node(p, LED_HARDWARE_NAME, h, NULL)))
                        return NFT_FAILURE;

                /* add hardware to this setup */
                if(!(nft_prefs_node_add_child(n, node)))
                        return NFT_FAILURE;

        }

        return NFT_SUCCESS;
}
Exemplo n.º 2
0
/**
 * Object-to-Config function. 
 * Creates a config-node (and subnodes) from a LedHardware model
 * @param c the current preferences context
 * @param n a freshly created prefs node that this function should fill with properties of obj
 * @param obj object of this class where preferences should be generated from
 * @result NFT_SUCCESS if everything went fine, NFT_FAILURE otherwise
 * @note you shouldn't call this function directly
 * It's used by nft_prefs_obj_to_node() etc. 
 */
static NftResult _prefs_from_chain(NftPrefs * p, NftPrefsNode * n, void *obj,
                                   void *userptr)
{
        if(!p || !n || !obj)
                NFT_LOG_NULL(NFT_FAILURE);


        /* chain to generate preferences from */
        LedChain *c = obj;


        /* amount of LEDs in this chain - ledcount */
        if(!nft_prefs_node_prop_int_set(n, LED_CHAIN_PROP_LEDCOUNT,
                                        led_chain_get_ledcount(c)))
                return NFT_FAILURE;

        /* pixel-format of this chain */
        if(!nft_prefs_node_prop_string_set(n, LED_CHAIN_PROP_FORMAT,
                                           (char *) led_pixel_format_to_string
                                           (led_chain_get_format(c))))
                return NFT_FAILURE;


        /* add all LEDs in this chain */
        LedCount i;
        for(i = 0; i < led_chain_get_ledcount(c); i++)
        {
                /* generate prefs node from LED */
                NftPrefsNode *node;
                if(!
                   (node = led_prefs_led_to_node(p, led_chain_get_nth(c, i))))
                        return NFT_FAILURE;

                /* add node as child of this node */
                if(!nft_prefs_node_add_child(n, node))
                        return NFT_FAILURE;
        }


        return NFT_SUCCESS;
}
Exemplo n.º 3
0
/**
 * Object-to-Config function.
 * Creates a config-node (and subnodes) from a LedHardware model
 * @param c the current preferences context
 * @param n a freshly created prefs node that this function should fill with properties of obj
 * @param obj object of this class where preferences should be generated from
 * @result NFT_SUCCESS if everything went fine, NFT_FAILURE otherwise
 * @note you shouldn't call this function directly
 * It's used by nft_prefs_obj_to_node() etc.
 */
static NftResult _prefs_from_hardware(NftPrefs * p, NftPrefsNode * n,
                                      void *obj, void *userptr)
{
        if(!p || !n || !obj)
                NFT_LOG_NULL(NFT_FAILURE);

        /* hardware "object" */
        LedHardware *h = obj;



        /* name of hardware */
        if(!nft_prefs_node_prop_string_set(n, LED_HARDWARE_PROP_NAME,
                                           (char *) led_hardware_get_name(h)))
                return NFT_FAILURE;


        /* plugin family of hardware */
        if(!nft_prefs_node_prop_string_set(n, LED_HARDWARE_PROP_PLUGIN,
                                           (char
                                            *) led_hardware_plugin_get_family
                                           (h)))
                return NFT_FAILURE;


        /* id of hardware */
        if(!nft_prefs_node_prop_string_set(n, LED_HARDWARE_PROP_ID,
                                           (char *) led_hardware_get_id(h)))
                return NFT_FAILURE;


        /* LED stride */
        if(!nft_prefs_node_prop_int_set(n, LED_HARDWARE_PROP_STRIDE,
                                        led_hardware_get_stride(h)))
                return NFT_FAILURE;

        /* handle custom plugin properties */
        int i, a = led_hardware_plugin_prop_get_count(h);
        for(i = 0; i < a; i++)
        {
                LedPluginCustomProp *prop;
                if(!(prop = led_hardware_plugin_prop_get_nth(h, i)))
                {
                        NFT_LOG(L_ERROR,
                                "Could not get property %d (but %d registered). This is a bug!",
                                i, a);
                        break;
                }

                /* create new node for property */
                NftPrefsNode *pnode;
                if(!
                   (pnode = nft_prefs_node_alloc(LED_HARDWARE_PROPERTY_NAME)))
                {
                        NFT_LOG(L_ERROR, "Failed to create new node.");
                        return NFT_FAILURE;
                }

                /* name of property */
                if(!nft_prefs_node_prop_string_set
                   (pnode, LED_HARDWARE_PROPERTY_PROP_NAME,
                    (char *) led_hardware_plugin_prop_get_name(prop)))
                        return NFT_FAILURE;

                /* handle various types of properties */
                switch (led_hardware_plugin_prop_get_type(prop))
                {
                        case LED_HW_CUSTOM_PROP_STRING:
                        {
                                /* save type */
                                if(!nft_prefs_node_prop_string_set
                                   (pnode, LED_HARDWARE_PROPERTY_PROP_TYPE,
                                    "string"))
                                        return NFT_FAILURE;

                                /* get string */
                                char *string;
                                if(!led_hardware_plugin_prop_get_string(h,
                                                                        led_hardware_plugin_prop_get_name
                                                                        (prop),
                                                                        &string))
                                        return NFT_FAILURE;

                                /* save value */
                                if(!nft_prefs_node_prop_string_set
                                   (pnode, LED_HARDWARE_PROPERTY_PROP_VALUE,
                                    string))
                                        return NFT_FAILURE;

                                break;
                        }

                        case LED_HW_CUSTOM_PROP_INT:
                        {
                                /* save type */
                                if(!nft_prefs_node_prop_string_set
                                   (pnode, LED_HARDWARE_PROPERTY_PROP_TYPE,
                                    "int"))
                                        return NFT_FAILURE;

                                /* get integer */
                                int integer;
                                if(!led_hardware_plugin_prop_get_int(h,
                                                                     led_hardware_plugin_prop_get_name
                                                                     (prop),
                                                                     &integer))
                                        return NFT_FAILURE;

                                /* convert to string */
                                char *string;
                                if(!(string = alloca(64)))
                                {
                                        NFT_LOG_PERROR("alloca");
                                        return NFT_FAILURE;
                                }
                                snprintf(string, 64, "%d", integer);

                                /* save value */
                                if(!nft_prefs_node_prop_string_set
                                   (pnode, LED_HARDWARE_PROPERTY_PROP_VALUE,
                                    string))
                                        return NFT_FAILURE;
                                break;
                        }

                        case LED_HW_CUSTOM_PROP_FLOAT:
                        {
                                /* save type */
                                if(!nft_prefs_node_prop_string_set
                                   (pnode, LED_HARDWARE_PROPERTY_PROP_TYPE,
                                    "float"))
                                        return NFT_FAILURE;

                                /* get float */
                                float fp;
                                if(!led_hardware_plugin_prop_get_float(h,
                                                                       led_hardware_plugin_prop_get_name
                                                                       (prop),
                                                                       &fp))
                                        return NFT_FAILURE;

                                /* convert to string */
                                char *string;
                                if(!(string = alloca(64)))
                                {
                                        NFT_LOG_PERROR("alloca");
                                        return NFT_FAILURE;
                                }
                                snprintf(string, 64, "%f", fp);

                                /* save value */
                                if(!nft_prefs_node_prop_string_set
                                   (pnode, LED_HARDWARE_PROPERTY_PROP_VALUE,
                                    string))
                                        return NFT_FAILURE;

                                break;
                        }

                                /* unsupported type */
                        default:
                        {
                                NFT_LOG(L_WARNING,
                                        "Property \"%s\" is of unsupported type. Ignoring",
                                        led_hardware_plugin_prop_get_name
                                        (prop));
                                continue;
                        }
                }

                /* add node as child of this node */
                nft_prefs_node_add_child(n, pnode);

        }

        /* chain of this hardware */
        LedChain *c;
        if((c = led_hardware_get_chain(h)))
        {
                /* generate prefs node from chain */
                NftPrefsNode *node;
                if(!(node = led_prefs_chain_to_node(p, c)))
                        return NFT_FAILURE;

                /* add node as child of this node */
                nft_prefs_node_add_child(n, node);
        }

        /* tiles of this hardware */
        LedTile *t;
        for(t = led_hardware_get_tile(h); t; t = led_tile_list_get_next(t))
        {
                NftPrefsNode *node;
                if(!(node = led_prefs_tile_to_node(p, t)))
                        return NFT_FAILURE;

                /* add node as child of this node */
                nft_prefs_node_add_child(n, node);
        }


        /* all OK */
        return NFT_SUCCESS;
}