fixeria has submitted this change. ( 
https://gerrit.osmocom.org/c/osmocom-bb/+/30098 )

Change subject: trxcon: move trxcon_inst_{alloc,free}() to a separate file
......................................................................

trxcon: move trxcon_inst_{alloc,free}() to a separate file

Both functions are going to be part of the upcoming libtrxcon.

Change-Id: I98963a1da927581597f7a170239dfb8a87cba842
Related: OS#5599
---
M src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
M src/host/trxcon/src/Makefile.am
A src/host/trxcon/src/trxcon_inst.c
M src/host/trxcon/src/trxcon_main.c
4 files changed, 83 insertions(+), 53 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved



diff --git a/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h 
b/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
index fbbd9e6..b8d3150 100644
--- a/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
+++ b/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
@@ -30,5 +30,5 @@
        } l1p;
 };

-struct trxcon_inst *trxcon_inst_alloc(void *ctx, unsigned int id);
+struct trxcon_inst *trxcon_inst_alloc(void *ctx, unsigned int id, uint32_t 
fn_advance);
 void trxcon_inst_free(struct trxcon_inst *trxcon);
diff --git a/src/host/trxcon/src/Makefile.am b/src/host/trxcon/src/Makefile.am
index 1ec4d76..e0dc337 100644
--- a/src/host/trxcon/src/Makefile.am
+++ b/src/host/trxcon/src/Makefile.am
@@ -43,6 +43,7 @@
        trx_if.c \
        logging.c \
        trxcon_fsm.c \
+       trxcon_inst.c \
        trxcon_main.c \
        $(NULL)

diff --git a/src/host/trxcon/src/trxcon_inst.c 
b/src/host/trxcon/src/trxcon_inst.c
new file mode 100644
index 0000000..c3a85da
--- /dev/null
+++ b/src/host/trxcon/src/trxcon_inst.c
@@ -0,0 +1,70 @@
+/*
+ * OsmocomBB <-> SDR connection bridge
+ *
+ * (C) 2022 by sysmocom - s.f.m.c. GmbH <[email protected]>
+ * Author: Vadim Yanitskiy <[email protected]>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <stdint.h>
+
+#include <osmocom/core/fsm.h>
+#include <osmocom/core/talloc.h>
+
+#include <osmocom/bb/trxcon/trxcon.h>
+#include <osmocom/bb/trxcon/trxcon_fsm.h>
+#include <osmocom/bb/l1sched/l1sched.h>
+
+struct trxcon_inst *trxcon_inst_alloc(void *ctx, unsigned int id, uint32_t 
fn_advance)
+{
+       struct trxcon_inst *trxcon;
+       struct osmo_fsm_inst *fi;
+
+       fi = osmo_fsm_inst_alloc(&trxcon_fsm_def, ctx, NULL, LOGL_DEBUG, NULL);
+       OSMO_ASSERT(fi != NULL);
+
+       trxcon = talloc_zero(fi, struct trxcon_inst);
+       OSMO_ASSERT(trxcon != NULL);
+
+       fi->priv = trxcon;
+       trxcon->fi = fi;
+
+       osmo_fsm_inst_update_id_f(fi, "%u", id);
+       trxcon->id = id;
+
+       /* Logging context to be used by both l1ctl and l1sched modules */
+       trxcon->log_prefix = talloc_asprintf(trxcon, "%s: ", 
osmo_fsm_inst_name(fi));
+
+       /* Init scheduler */
+       const struct l1sched_cfg sched_cfg = {
+               .fn_advance = fn_advance,
+               .log_prefix = trxcon->log_prefix,
+       };
+
+       trxcon->sched = l1sched_alloc(trxcon, &sched_cfg, trxcon);
+       if (trxcon->sched == NULL) {
+               trxcon_inst_free(trxcon);
+               return NULL;
+       }
+
+       return trxcon;
+}
+
+void trxcon_inst_free(struct trxcon_inst *trxcon)
+{
+       if (trxcon == NULL || trxcon->fi == NULL)
+               return;
+       osmo_fsm_inst_term(trxcon->fi, OSMO_FSM_TERM_REQUEST, NULL);
+}
diff --git a/src/host/trxcon/src/trxcon_main.c 
b/src/host/trxcon/src/trxcon_main.c
index 60e8d6d..6b0e1fb 100644
--- a/src/host/trxcon/src/trxcon_main.c
+++ b/src/host/trxcon/src/trxcon_main.c
@@ -336,25 +336,19 @@
        return rc;
 }

-struct trxcon_inst *trxcon_inst_alloc(void *ctx, unsigned int id)
+static void l1ctl_conn_accept_cb(struct l1ctl_client *l1c)
 {
        struct trxcon_inst *trxcon;
-       struct osmo_fsm_inst *fi;

-       fi = osmo_fsm_inst_alloc(&trxcon_fsm_def, ctx, NULL, LOGL_DEBUG, NULL);
-       OSMO_ASSERT(fi != NULL);
+       trxcon = trxcon_inst_alloc(l1c, l1c->id, app_data.trx_fn_advance);
+       if (trxcon == NULL) {
+               l1ctl_client_conn_close(l1c);
+               return;
+       }

-       trxcon = talloc_zero(fi, struct trxcon_inst);
-       OSMO_ASSERT(trxcon != NULL);
-
-       fi->priv = trxcon;
-       trxcon->fi = fi;
-
-       osmo_fsm_inst_update_id_f(fi, "%u", id);
-       trxcon->id = id;
-
-       /* Logging context to be used by both l1ctl and l1sched modules */
-       trxcon->log_prefix = talloc_asprintf(trxcon, "%s: ", 
osmo_fsm_inst_name(fi));
+       l1c->log_prefix = talloc_strdup(l1c, trxcon->log_prefix);
+       l1c->priv = trxcon->fi;
+       trxcon->l2if = l1c;

        const struct trx_if_params phyif_params = {
                .local_host = app_data.trx_bind_ip,
@@ -370,45 +364,10 @@
        /* Init transceiver interface */
        trxcon->phyif = trx_if_open(&phyif_params);
        if (trxcon->phyif == NULL) {
-               trxcon_inst_free(trxcon);
-               return NULL;
-       }
-
-       /* Init scheduler */
-       const struct l1sched_cfg sched_cfg = {
-               .fn_advance = app_data.trx_fn_advance,
-               .log_prefix = trxcon->log_prefix,
-       };
-
-       trxcon->sched = l1sched_alloc(trxcon, &sched_cfg, trxcon);
-       if (trxcon->sched == NULL) {
-               trxcon_inst_free(trxcon);
-               return NULL;
-       }
-
-       return trxcon;
-}
-
-void trxcon_inst_free(struct trxcon_inst *trxcon)
-{
-       if (trxcon == NULL || trxcon->fi == NULL)
-               return;
-       osmo_fsm_inst_term(trxcon->fi, OSMO_FSM_TERM_REQUEST, NULL);
-}
-
-static void l1ctl_conn_accept_cb(struct l1ctl_client *l1c)
-{
-       struct trxcon_inst *trxcon;
-
-       trxcon = trxcon_inst_alloc(l1c, l1c->id);
-       if (trxcon == NULL) {
-               l1ctl_client_conn_close(l1c);
+               /* TRXCON_EV_PHYIF_FAILURE triggers l1ctl_client_conn_close() */
+               osmo_fsm_inst_dispatch(trxcon->fi, TRXCON_EV_PHYIF_FAILURE, 
NULL);
                return;
        }
-
-       l1c->log_prefix = talloc_strdup(l1c, trxcon->log_prefix);
-       l1c->priv = trxcon->fi;
-       trxcon->l2if = l1c;
 }

 static void l1ctl_conn_close_cb(struct l1ctl_client *l1c)

--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30098
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I98963a1da927581597f7a170239dfb8a87cba842
Gerrit-Change-Number: 30098
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to