This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
neels gerrit-no-reply at lists.osmocom.orgneels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hlr/+/16206 )
Change subject: gsup client: add up_down_cb(), add osmo_gsup_client_create3()
......................................................................
gsup client: add up_down_cb(), add osmo_gsup_client_create3()
For the GSUP clients in upcoming D-GSM enabled osmo-hlr, it will be necessary
to trigger an event as soon as a GSUP client connection becomes ready for
communication. Add the osmo_gsup_client->up_down_cb.
Add osmo_gsup_client_create3() pass the up_down_cb in the arguments. Also add
a cb data argument, and groupt the cb and data arguments after the oapc_config
argument. (Usually, we have cb and data arguments last.)
We need the callbacks and data pointer in the osmo_gsup_client_create()
function right before startup, because this function immediately starts up the
connection. Who knows whether callbacks might trigger right away.
Change-Id: I6f181e42b678465bc9945f192559dc57d2083c6d
---
M include/osmocom/gsupclient/gsup_client.h
M src/gsupclient/gsup_client.c
2 files changed, 63 insertions(+), 14 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/06/16206/1
diff --git a/include/osmocom/gsupclient/gsup_client.h b/include/osmocom/gsupclient/gsup_client.h
index 154e3e0..deae4d4 100644
--- a/include/osmocom/gsupclient/gsup_client.h
+++ b/include/osmocom/gsupclient/gsup_client.h
@@ -39,6 +39,8 @@
/* Expects message in msg->l2h */
typedef int (*osmo_gsup_client_read_cb_t)(struct osmo_gsup_client *gsupc, struct msgb *msg);
+typedef bool (*osmo_gsup_client_up_down_cb_t)(struct osmo_gsup_client *gsupc, bool up);
+
struct osmo_gsup_client {
const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */
@@ -54,8 +56,18 @@
int got_ipa_pong;
struct ipaccess_unit *ipa_dev; /* identification information sent to IPA server */
+
+ osmo_gsup_client_up_down_cb_t up_down_cb;
};
+struct osmo_gsup_client *osmo_gsup_client_create3(void *talloc_ctx,
+ struct ipaccess_unit *ipa_dev,
+ const char *ip_addr,
+ unsigned int tcp_port,
+ struct osmo_oap_client_config *oapc_config,
+ osmo_gsup_client_read_cb_t read_cb,
+ osmo_gsup_client_up_down_cb_t up_down_cb,
+ void *data);
struct osmo_gsup_client *osmo_gsup_client_create2(void *talloc_ctx,
struct ipaccess_unit *ipa_dev,
const char *ip_addr,
diff --git a/src/gsupclient/gsup_client.c b/src/gsupclient/gsup_client.c
index 52985c9..d522056 100644
--- a/src/gsupclient/gsup_client.c
+++ b/src/gsupclient/gsup_client.c
@@ -97,6 +97,12 @@
if (gsupc->is_connected)
return;
+ if (gsupc->up_down_cb) {
+ /* When the up_down_cb() returns false, the user asks us not to retry connecting. */
+ if (!gsupc->up_down_cb(gsupc, false))
+ return;
+ }
+
gsup_client_connect(gsupc);
}
@@ -139,9 +145,18 @@
gsup_client_oap_register(gsupc);
osmo_timer_del(&gsupc->connect_timer);
+
+ if (gsupc->up_down_cb)
+ gsupc->up_down_cb(gsupc, true);
} else {
osmo_timer_del(&gsupc->ping_timer);
+ if (gsupc->up_down_cb) {
+ /* When the up_down_cb() returns false, the user asks us not to retry connecting. */
+ if (!gsupc->up_down_cb(gsupc, false))
+ return;
+ }
+
osmo_timer_schedule(&gsupc->connect_timer,
OSMO_GSUP_CLIENT_RECONNECT_INTERVAL, 0);
}
@@ -263,28 +278,39 @@
* Use the provided ipaccess unit as the client-side identifier; ipa_dev should
* be allocated in talloc_ctx talloc_ctx as well.
* \param[in] talloc_ctx talloc context.
- * \param[in] ipa_dev IP access unit which contains client identification information; must be allocated
- * in talloc_ctx as well to ensure it lives throughout the lifetime of the connection.
- * \param[in] ip_addr GSUP server IP address.
- * \param[in] tcp_port GSUP server TCP port.
- * \param[in] read_cb callback for reading from the GSUP connection.
- * \param[in] oapc_config OPA client configuration.
- * \returns a GSUP client connection or NULL on failure.
+ * \param[in] ipa_dev IP access unit which contains client identification information; must be allocated
+ * in talloc_ctx as well to ensure it lives throughout the lifetime of the connection.
+ * \param[in] ip_addr GSUP server IP address to connect to.
+ * \param[in] tcp_port GSUP server TCP port to connect to.
+ * \param[in] oapc_config OPA client configuration, or NULL.
+ * \param[in] read_cb callback for reading from the GSUP connection.
+ * \param[in] up_down_cb Invoked when the GSUP link is ready for communication, and when the link drops.
+ * \param[in] data User data stored in the returned gsupc->data, as context for the callbacks.
+ * \return a GSUP client connection, or NULL on failure.
*/
-struct osmo_gsup_client *osmo_gsup_client_create2(void *talloc_ctx,
+struct osmo_gsup_client *osmo_gsup_client_create3(void *talloc_ctx,
struct ipaccess_unit *ipa_dev,
const char *ip_addr,
unsigned int tcp_port,
+ struct osmo_oap_client_config *oapc_config,
osmo_gsup_client_read_cb_t read_cb,
- struct osmo_oap_client_config *oapc_config)
+ osmo_gsup_client_up_down_cb_t up_down_cb,
+ void *data)
{
struct osmo_gsup_client *gsupc;
int rc;
+ OSMO_ASSERT(ipa_dev->unit_name);
+
gsupc = talloc_zero(talloc_ctx, struct osmo_gsup_client);
OSMO_ASSERT(gsupc);
- gsupc->unit_name = (const char *)ipa_dev->unit_name; /* API backwards compat */
- gsupc->ipa_dev = ipa_dev;
+ *gsupc = (struct osmo_gsup_client){
+ .unit_name = (const char *)ipa_dev->unit_name, /* API backwards compat */
+ .ipa_dev = ipa_dev,
+ .read_cb = read_cb,
+ .up_down_cb = up_down_cb,
+ .data = data,
+ };
/* a NULL oapc_config will mark oap_state disabled. */
rc = osmo_oap_client_init(oapc_config, &gsupc->oap_state);
@@ -309,9 +335,6 @@
if (rc < 0)
goto failed;
-
- gsupc->read_cb = read_cb;
-
return gsupc;
failed:
@@ -319,6 +342,20 @@
return NULL;
}
+/*! Like osmo_gsup_client_create3() but without the up_down_cb and data arguments, and with the oapc_config argument in
+ * a different position.
+ */
+struct osmo_gsup_client *osmo_gsup_client_create2(void *talloc_ctx,
+ struct ipaccess_unit *ipa_dev,
+ const char *ip_addr,
+ unsigned int tcp_port,
+ osmo_gsup_client_read_cb_t read_cb,
+ struct osmo_oap_client_config *oapc_config)
+{
+ return osmo_gsup_client_create3(talloc_ctx, ipa_dev, ip_addr, tcp_port, oapc_config,
+ read_cb, NULL, NULL);
+}
+
/**
* Like osmo_gsup_client_create2() except it expects a unit name instead
* of a full-blown ipacess_unit as the client-side identifier.
--
To view, visit https://gerrit.osmocom.org/c/osmo-hlr/+/16206
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Change-Id: I6f181e42b678465bc9945f192559dc57d2083c6d
Gerrit-Change-Number: 16206
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191125/e9e7dfaf/attachment.htm>