From patchwork Thu May 15 09:24:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Holger Freyther X-Patchwork-Id: 349141 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [IPv6:2001:780:45:1d:225:90ff:fe52:c662]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 610AA1400DD for ; Thu, 15 May 2014 19:25:48 +1000 (EST) Received: from localhost ([127.0.0.1] helo=ganesha.gnumonks.org) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1Wkruz-0004mH-3M; Thu, 15 May 2014 11:25:37 +0200 Received: from mail.sysmocom.de ([2a01:4f8:191:444c::2:4]) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1Wkrtq-0004VT-02 for openbsc@lists.osmocom.org; Thu, 15 May 2014 11:24:30 +0200 Received: from sangmingze-mail.local (24-134-58-61-dynip.superkabel.de [24.134.58.61]) by mail.sysmocom.de (Postfix) with ESMTPSA id D183D58062 for ; Thu, 15 May 2014 09:24:25 +0000 (UTC) Received: from localhost.home ([127.0.0.1] helo=xiaoyu.home) by sangmingze-mail.local with esmtp (Exim 4.82) (envelope-from ) id 1Wkrtu-0004xo-0o for openbsc@lists.osmocom.org; Thu, 15 May 2014 11:24:30 +0200 From: Holger Freyther To: openbsc@lists.osmocom.org Subject: [PATCH] ctrl: Introduce a macro for read-only attributes and use it Date: Thu, 15 May 2014 11:24:28 +0200 Message-Id: <1400145868-19050-1-git-send-email-holger@freyther.de> X-Mailer: git-send-email 1.9.1 X-Spam-Score: 0.0 (/) X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: openbsc-bounces@lists.osmocom.org Errors-To: openbsc-bounces@lists.osmocom.org From: Holger Hans Peter Freyther Certain attributes are read-only. Add a macro to make it more easy to define those. --- openbsc/include/openbsc/control_cmd.h | 20 ++++++++++++++++++ openbsc/src/osmo-bsc/osmo_bsc_ctrl.c | 38 +++-------------------------------- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/openbsc/include/openbsc/control_cmd.h b/openbsc/include/openbsc/control_cmd.h index 8aede15..df5ae23 100644 --- a/openbsc/include/openbsc/control_cmd.h +++ b/openbsc/include/openbsc/control_cmd.h @@ -172,6 +172,26 @@ static struct ctrl_cmd_element cmd_##cmdname = { \ .verify = &verify_##cmdname, \ } +#define CTRL_CMD_DEFINE_RO(cmdname, cmdstr) \ +static int get_##cmdname(struct ctrl_cmd *cmd, void *data); \ +static inline int set_##cmdname(struct ctrl_cmd *cmd, void *data) \ +{ \ + cmd->reply = "Read Only attribute"; \ + return CTRL_CMD_ERROR; \ +} \ +static inline int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *data) \ +{ \ + cmd->reply = "Read Only attribute"; \ + return 1; \ +} \ +static struct ctrl_cmd_element cmd_##cmdname = { \ + .name = cmdstr, \ + .param = NULL, \ + .get = &get_##cmdname, \ + .set = &set_##cmdname, \ + .verify = &verify_##cmdname, \ +} + struct gsm_network; #endif /* _CONTROL_CMD_H */ diff --git a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c index e32218d..d3593de 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_ctrl.c @@ -58,7 +58,7 @@ void osmo_bsc_send_trap(struct ctrl_cmd *cmd, struct bsc_msc_connection *msc_con talloc_free(trap); } -CTRL_CMD_DEFINE(msc_connection_status, "msc_connection_status"); +CTRL_CMD_DEFINE_RO(msc_connection_status, "msc_connection_status"); static int msc_connection_status = 0; static int get_msc_connection_status(struct ctrl_cmd *cmd, void *data) @@ -70,17 +70,6 @@ static int get_msc_connection_status(struct ctrl_cmd *cmd, void *data) return CTRL_CMD_REPLY; } -static int set_msc_connection_status(struct ctrl_cmd *cmd, void *data) -{ - return CTRL_CMD_ERROR; -} - -static int verify_msc_connection_status(struct ctrl_cmd *cmd, const char *value, void *data) -{ - cmd->reply = "Read-only property"; - return 1; -} - static int msc_connection_status_trap_cb(unsigned int subsys, unsigned int signal, void *handler_data, void *signal_data) { struct ctrl_cmd *cmd; @@ -114,7 +103,7 @@ static int msc_connection_status_trap_cb(unsigned int subsys, unsigned int signa return 0; } -CTRL_CMD_DEFINE(bts_connection_status, "bts_connection_status"); +CTRL_CMD_DEFINE_RO(bts_connection_status, "bts_connection_status"); static int bts_connection_status = 0; static int get_bts_connection_status(struct ctrl_cmd *cmd, void *data) @@ -126,17 +115,6 @@ static int get_bts_connection_status(struct ctrl_cmd *cmd, void *data) return CTRL_CMD_REPLY; } -static int set_bts_connection_status(struct ctrl_cmd *cmd, void *data) -{ - return CTRL_CMD_ERROR; -} - -static int verify_bts_connection_status(struct ctrl_cmd *cmd, const char *value, void *data) -{ - cmd->reply = "Read-only property"; - return 1; -} - static int bts_connection_status_trap_cb(unsigned int subsys, unsigned int signal, void *handler_data, void *signal_data) { struct ctrl_cmd *cmd; @@ -496,7 +474,7 @@ err: return 1; } -CTRL_CMD_DEFINE(bts_rf_state, "rf_state"); +CTRL_CMD_DEFINE_RO(bts_rf_state, "rf_state"); static int get_bts_rf_state(struct ctrl_cmd *cmd, void *data) { const char *oper, *admin, *policy; @@ -520,16 +498,6 @@ static int get_bts_rf_state(struct ctrl_cmd *cmd, void *data) return CTRL_CMD_REPLY; } -static int set_bts_rf_state(struct ctrl_cmd *cmd, void *data) -{ - cmd->reply = "set is unimplemented"; - return CTRL_CMD_ERROR; -} - -static int verify_bts_rf_state(struct ctrl_cmd *cmd, const char *value, void *data) -{ - return 0; -} CTRL_CMD_DEFINE(net_rf_lock, "rf_locked"); static int get_net_rf_lock(struct ctrl_cmd *cmd, void *data)