| /* |
| <:copyright-BRCM:2016:DUAL/GPL:standard |
| |
| Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| All Rights Reserved |
| |
| Unless you and Broadcom execute a separate written software license |
| agreement governing use of this software, this software is licensed |
| to you under the terms of the GNU General Public License version 2 |
| (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| with the following added to such license: |
| |
| As a special exception, the copyright holders of this software give |
| you permission to link this software with independent modules, and |
| to copy and distribute the resulting executable under terms of your |
| choice, provided that you also meet, for each linked independent |
| module, the terms and conditions of the license of that module. |
| An independent module is a module which is not derived from this |
| software. The special exception does not apply to any modifications |
| of the software. |
| |
| Not withstanding the above, under no circumstances may you combine |
| this software in any way with any other Broadcom software provided |
| under a license other than the GPL, without Broadcom's express prior |
| written consent. |
| |
| :> |
| */ |
| |
| /* |
| * bcmolt_dev_selector.c |
| * Set / get current device for all CLI commands |
| */ |
| #include <bcmos_system.h> |
| #include <bcmcli.h> |
| #include <bcmolt_dev_selector.h> |
| |
| /* Current device. External variable */ |
| |
| /* Device change callback registration structure */ |
| typedef struct dev_sel_subscriber dev_sel_subscriber; |
| struct dev_sel_subscriber |
| { |
| F_current_device_change_ind cb; /* Subscriber's callback */ |
| STAILQ_ENTRY(dev_sel_subscriber) next; |
| }; |
| |
| static STAILQ_HEAD(dev_sel_subscriber_list, dev_sel_subscriber) subscriber_list; |
| |
| /* Get/set the current device CLI handler |
| */ |
| static bcmos_errno _dev_sel_device_handler(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| { |
| /* If current device was set - notify all subscribers. |
| * Do not check if it changed here. Sometimes it is good to be able |
| * to refresh. |
| */ |
| if (nparms) |
| { |
| dev_sel_subscriber *subs; |
| |
| current_device = parm[0].value.number; |
| |
| /* Notify all subscribers */ |
| STAILQ_FOREACH(subs, &subscriber_list, next) |
| { |
| subs->cb(session, current_device); |
| } |
| } |
| |
| bcmcli_session_print(session, "Current device: %ld\n", (long)current_device); |
| |
| return BCM_ERR_OK; |
| } |
| |
| |
| /* Register for current device change notification. |
| * Multiple clients can register. |
| */ |
| bcmos_errno bcmolt_dev_sel_ind_register(F_current_device_change_ind cb) |
| { |
| dev_sel_subscriber *subs = bcmos_calloc(sizeof(dev_sel_subscriber)); |
| |
| if (!subs) |
| return BCM_ERR_NOMEM; |
| |
| subs->cb = cb; |
| STAILQ_INSERT_TAIL(&subscriber_list, subs, next); |
| |
| return BCM_ERR_OK; |
| } |
| |
| /* Initialize device selector module */ |
| bcmos_errno bcmolt_dev_sel_init(bcmcli_entry *parent_dir) |
| { |
| STAILQ_INIT(&subscriber_list); |
| |
| /* Get/set current device */ |
| BCMCLI_MAKE_CMD(parent_dir, "device", "Get/Set the current device", _dev_sel_device_handler, |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, |
| 0, BCMTR_MAX_OLTS-1)); |
| |
| return BCM_ERR_OK; |
| } |
| |
| |