[MERGED] openbsc[master]: CTRL: remove boilerplate

Max gerrit-no-reply at lists.osmocom.org
Wed Jan 25 11:52:45 UTC 2017


Max has submitted this change and it was merged.

Change subject: CTRL: remove boilerplate
......................................................................


CTRL: remove boilerplate

Use CTRL_CMD_DEFINE_RO(), CTRL_CMD_DEFINE_WO() and
CTRL_CMD_DEFINE_WO_NOVRF() where appropriate to get rid of boilerplate
code.

Change-Id: I5bcea0b4f4b8f535bef2b423f2013b8b4a218b5b
---
M openbsc/src/libbsc/bsc_ctrl_commands.c
M openbsc/src/libmsc/ctrl_commands.c
M openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
M openbsc/tests/ctrl_test_runner.py
4 files changed, 13 insertions(+), 105 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/openbsc/src/libbsc/bsc_ctrl_commands.c b/openbsc/src/libbsc/bsc_ctrl_commands.c
index 7e84797..14e8d71 100644
--- a/openbsc/src/libbsc/bsc_ctrl_commands.c
+++ b/openbsc/src/libbsc/bsc_ctrl_commands.c
@@ -70,17 +70,6 @@
 CTRL_CMD_VTY_STRING(net_short_name, "short-name", struct gsm_network, name_short);
 CTRL_CMD_VTY_STRING(net_long_name, "long-name", struct gsm_network, name_long);
 
-static int verify_net_apply_config(struct ctrl_cmd *cmd, const char *v, void *d)
-{
-	return 0;
-}
-
-static int get_net_apply_config(struct ctrl_cmd *cmd, void *data)
-{
-	cmd->reply = "Write only attribute";
-	return CTRL_CMD_ERROR;
-}
-
 static int set_net_apply_config(struct ctrl_cmd *cmd, void *data)
 {
 	struct gsm_network *net = cmd->node;
@@ -107,7 +96,7 @@
 	return CTRL_CMD_REPLY;
 }
 
-CTRL_CMD_DEFINE(net_apply_config, "apply-configuration");
+CTRL_CMD_DEFINE_WO_NOVRF(net_apply_config, "apply-configuration");
 
 static int verify_net_mcc_mnc_apply(struct ctrl_cmd *cmd, const char *value, void *d)
 {
@@ -124,12 +113,6 @@
 	if (!mcc || !mnc)
 		return 1;
 	return 0;
-}
-
-static int get_net_mcc_mnc_apply(struct ctrl_cmd *cmd, void *data)
-{
-	cmd->reply = "Write only attribute";
-	return CTRL_CMD_ERROR;
 }
 
 static int set_net_mcc_mnc_apply(struct ctrl_cmd *cmd, void *data)
@@ -165,22 +148,11 @@
 	cmd->reply = "OOM";
 	return CTRL_CMD_ERROR;
 }
-CTRL_CMD_DEFINE(net_mcc_mnc_apply, "mcc-mnc-apply");
+CTRL_CMD_DEFINE_WO(net_mcc_mnc_apply, "mcc-mnc-apply");
 
 /* BTS related commands below */
 CTRL_CMD_DEFINE_RANGE(bts_lac, "location-area-code", struct gsm_bts, location_area_code, 0, 65535);
 CTRL_CMD_DEFINE_RANGE(bts_ci, "cell-identity", struct gsm_bts, cell_identity, 0, 65535);
-
-static int verify_bts_apply_config(struct ctrl_cmd *cmd, const char *v, void *d)
-{
-	return 0;
-}
-
-static int get_bts_apply_config(struct ctrl_cmd *cmd, void *data)
-{
-	cmd->reply = "Write only attribute";
-	return CTRL_CMD_ERROR;
-}
 
 static int set_bts_apply_config(struct ctrl_cmd *cmd, void *data)
 {
@@ -196,18 +168,7 @@
 	return CTRL_CMD_REPLY;
 }
 
-CTRL_CMD_DEFINE(bts_apply_config, "apply-configuration");
-
-static int verify_bts_si(struct ctrl_cmd *cmd, const char *v, void *d)
-{
-    return 0;
-}
-
-static int get_bts_si(struct ctrl_cmd *cmd, void *data)
-{
-	cmd->reply = "Write only attribute";
-	return CTRL_CMD_ERROR;
-}
+CTRL_CMD_DEFINE_WO_NOVRF(bts_apply_config, "apply-configuration");
 
 static int set_bts_si(struct ctrl_cmd *cmd, void *data)
 {
@@ -223,12 +184,7 @@
 	cmd->reply = "Generated new System Information";
 	return CTRL_CMD_REPLY;
 }
-CTRL_CMD_DEFINE(bts_si, "send-new-system-informations");
-
-static int verify_bts_chan_load(struct ctrl_cmd *cmd, const char *v, void *d)
-{
-	return 0;
-}
+CTRL_CMD_DEFINE_WO_NOVRF(bts_si, "send-new-system-informations");
 
 static int get_bts_chan_load(struct ctrl_cmd *cmd, void *data)
 {
@@ -271,23 +227,7 @@
 	return CTRL_CMD_ERROR;
 }
 
-static int set_bts_chan_load(struct ctrl_cmd *cmd, void *data)
-{
-	cmd->reply = "Read only attribute";
-	return CTRL_CMD_ERROR;
-}
-CTRL_CMD_DEFINE(bts_chan_load, "channel-load");
-
-static int verify_bts_oml_conn(struct ctrl_cmd *cmd, const char *value, void *_data)
-{
-	struct gsm_bts *bts = cmd->node;
-
-	if (!is_ipaccess_bts(bts)) {
-		cmd->reply = "";
-		return -1;
-	}
-	return 0;
-}
+CTRL_CMD_DEFINE_RO(bts_chan_load, "channel-load");
 
 static int get_bts_oml_conn(struct ctrl_cmd *cmd, void *data)
 {
@@ -297,12 +237,7 @@
 	return CTRL_CMD_REPLY;
 }
 
-static int set_bts_oml_conn(struct ctrl_cmd *cmd, void *data)
-{
-	cmd->reply = "Read only attribute";
-	return CTRL_CMD_ERROR;
-}
-CTRL_CMD_DEFINE(bts_oml_conn, "oml-connection-state");
+CTRL_CMD_DEFINE_RO(bts_oml_conn, "oml-connection-state");
 
 static int verify_bts_gprs_mode(struct ctrl_cmd *cmd, const char *value, void *_data)
 {
diff --git a/openbsc/src/libmsc/ctrl_commands.c b/openbsc/src/libmsc/ctrl_commands.c
index d153247..a56d122 100644
--- a/openbsc/src/libmsc/ctrl_commands.c
+++ b/openbsc/src/libmsc/ctrl_commands.c
@@ -75,12 +75,6 @@
 	return rc;
 }
 
-static int get_subscriber_modify(struct ctrl_cmd *cmd, void *data)
-{
-	cmd->reply = "Set only attribute";
-	return CTRL_CMD_ERROR;
-}
-
 static int set_subscriber_modify(struct ctrl_cmd *cmd, void *data)
 {
 	struct gsm_network *net = cmd->node;
@@ -157,18 +151,7 @@
 	return CTRL_CMD_ERROR;
 }
 
-CTRL_CMD_DEFINE(subscriber_modify, "subscriber-modify-v1");
-
-static int verify_subscriber_delete(struct ctrl_cmd *cmd, const char *v, void *d)
-{
-	return 0;
-}
-
-static int get_subscriber_delete(struct ctrl_cmd *cmd, void *data)
-{
-	cmd->reply = "Set only attribute";
-	return CTRL_CMD_ERROR;
-}
+CTRL_CMD_DEFINE_WO(subscriber_modify, "subscriber-modify-v1");
 
 static int set_subscriber_delete(struct ctrl_cmd *cmd, void *data)
 {
@@ -199,7 +182,7 @@
 	cmd->reply = was_used ? "Removed active subscriber" : "Removed";
 	return CTRL_CMD_REPLY;
 }
-CTRL_CMD_DEFINE(subscriber_delete, "subscriber-delete-v1");
+CTRL_CMD_DEFINE_WO_NOVRF(subscriber_delete, "subscriber-delete-v1");
 
 static int verify_subscriber_list(struct ctrl_cmd *cmd, const char *value, void *d)
 {
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
index ec4243e..057a583 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_ctrl.c
@@ -446,11 +446,7 @@
 	return 0;
 }
 
-CTRL_CMD_DEFINE(net_save_cmd, "net 0 save-configuration");
-static int verify_net_save_cmd(struct ctrl_cmd *cmd, const char *v, void *d)
-{
-	return 0;
-}
+CTRL_CMD_DEFINE_WO_NOVRF(net_save_cmd, "net 0 save-configuration");
 
 static int set_net_save_cmd(struct ctrl_cmd *cmd, void *data)
 {
@@ -462,12 +458,6 @@
 	}
 
 	return CTRL_CMD_REPLY;
-}
-
-static int get_net_save_cmd(struct ctrl_cmd *cmd, void *data)
-{
-	cmd->reply = "Write only attribute";
-	return CTRL_CMD_ERROR;
 }
 
 struct ctrl_handle *bsc_nat_controlif_setup(struct bsc_nat *nat,
diff --git a/openbsc/tests/ctrl_test_runner.py b/openbsc/tests/ctrl_test_runner.py
index 4fd831f..9050c09 100644
--- a/openbsc/tests/ctrl_test_runner.py
+++ b/openbsc/tests/ctrl_test_runner.py
@@ -219,7 +219,7 @@
     def testBtsGenerateSystemInformation(self):
         r = self.do_get('bts.0.send-new-system-informations')
         self.assertEquals(r['mtype'], 'ERROR')
-        self.assertEquals(r['error'], 'Write only attribute')
+        self.assertEquals(r['error'], 'Write Only attribute')
 
         # No RSL links so it will fail
         r = self.do_set('bts.0.send-new-system-informations', '1')
@@ -229,7 +229,7 @@
     def testBtsChannelLoad(self):
         r = self.do_set('bts.0.channel-load', '1')
         self.assertEquals(r['mtype'], 'ERROR')
-        self.assertEquals(r['error'], 'Read only attribute')
+        self.assertEquals(r['error'], 'Read Only attribute')
 
         # No RSL link so everything is 0
         r = self.do_get('bts.0.channel-load')
@@ -243,7 +243,7 @@
         """Check OML state. It will not be connected"""
         r = self.do_set('bts.0.oml-connection-state', '1')
         self.assertEquals(r['mtype'], 'ERROR')
-        self.assertEquals(r['error'], 'Read only attribute')
+        self.assertEquals(r['error'], 'Read Only attribute')
 
         # No RSL link so everything is 0
         r = self.do_get('bts.0.oml-connection-state')
@@ -531,7 +531,7 @@
     def testApplyConfiguration(self):
         r = self.do_get('bts.0.apply-configuration')
         self.assertEquals(r['mtype'], 'ERROR')
-        self.assertEquals(r['error'], 'Write only attribute')
+        self.assertEquals(r['error'], 'Write Only attribute')
 
         r = self.do_set('bts.0.apply-configuration', '1')
         self.assertEquals(r['mtype'], 'SET_REPLY')

-- 
To view, visit https://gerrit.osmocom.org/1576
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5bcea0b4f4b8f535bef2b423f2013b8b4a218b5b
Gerrit-PatchSet: 5
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>


More information about the gerrit-log mailing list