diff options
author | Damian Hobson-Garcia <dhobsong@igel.co.jp> | 2022-04-14 15:22:07 +0900 |
---|---|---|
committer | Damian Hobson-Garcia <dhobsong@igel.co.jp> | 2022-04-20 10:58:39 +0900 |
commit | 84bd108e702b753bc1f7b232c94baa5b84295b5f (patch) | |
tree | 357059fc81eda2867112cd06327702f1428095eb | |
parent | 6a12fcc3821e913ca799ff8981d9415d0a251836 (diff) |
Refactor connector in lease config
A connector within a lease configuration can have
more attributes than just a name. Refactor it into
a connector configuation that can store additional
properties.
Bug-AGL: SPEC-3815
Change-Id: Ied4c767bba914eb64b9e82c600e10162d0232c65
Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
-rw-r--r-- | drm-lease-manager/drm-lease.h | 8 | ||||
-rw-r--r-- | drm-lease-manager/lease-config.c | 28 | ||||
-rw-r--r-- | drm-lease-manager/lease-manager.c | 7 | ||||
-rw-r--r-- | drm-lease-manager/test/lease-config-test.c | 12 | ||||
-rw-r--r-- | drm-lease-manager/test/lease-manager-test.c | 8 |
5 files changed, 37 insertions, 26 deletions
diff --git a/drm-lease-manager/drm-lease.h b/drm-lease-manager/drm-lease.h index 76f0bd7..2de4fa4 100644 --- a/drm-lease-manager/drm-lease.h +++ b/drm-lease-manager/drm-lease.h @@ -22,14 +22,18 @@ struct lease_handle { void *user_data; }; +struct connector_config { + char *name; +}; + struct lease_config { char *lease_name; int ncids; uint32_t *connector_ids; - int cnames; - char **connector_names; + int nconnectors; + struct connector_config *connectors; }; #endif diff --git a/drm-lease-manager/lease-config.c b/drm-lease-manager/lease-config.c index abb7fc1..e246445 100644 --- a/drm-lease-manager/lease-config.c +++ b/drm-lease-manager/lease-config.c @@ -23,24 +23,26 @@ #define CONFIG_ERROR(x, ...) ERROR_LOG("%s: " x, filename, ##__VA_ARGS__) -static bool populate_connector_names(struct lease_config *config, - toml_array_t *conns) +static bool populate_connector_config(struct lease_config *config, + toml_array_t *conns) { - int cnames = toml_array_nelem(conns); - config->connector_names = calloc(cnames, sizeof(char *)); - if (!config->connector_names) { + int nconnectors = toml_array_nelem(conns); + config->connectors = calloc(nconnectors, sizeof(*config->connectors)); + if (!config->connectors) { DEBUG_LOG("Memory allocation failed: %s\n", strerror(errno)); return false; } - config->cnames = cnames; + config->nconnectors = nconnectors; - for (int i = 0; i < config->cnames; i++) { + for (int i = 0; i < config->nconnectors; i++) { toml_datum_t conn = toml_string_at(conns, i); if (!conn.ok) { + ERROR_LOG("Invalid connector in lease %s: idx:%d\n", + config->lease_name, i); return false; } - config->connector_names[i] = conn.u.s; + config->connectors[i].name = conn.u.s; } return true; } @@ -90,8 +92,8 @@ int parse_config(char *filename, struct lease_config **parsed_config) config[i].lease_name = name.u.s; toml_array_t *conns = toml_array_in(lease, "connectors"); - if (conns && !populate_connector_names(&config[i], conns)) { - CONFIG_ERROR("Non string connector name in lease: %s\n", + if (conns && !populate_connector_config(&config[i], conns)) { + CONFIG_ERROR("Error configuring lease: %s\n", config[i].lease_name); goto err_free_config; } @@ -113,9 +115,9 @@ void release_config(int num_leases, struct lease_config *config) for (int i = 0; i < num_leases; i++) { struct lease_config *c = &config[i]; free(c->lease_name); - for (int j = 0; j < c->cnames; j++) - free(c->connector_names[j]); - free(c->connector_names); + for (int j = 0; j < c->nconnectors; j++) + free(c->connectors[j].name); + free(c->connectors); } free(config); } diff --git a/drm-lease-manager/lease-manager.c b/drm-lease-manager/lease-manager.c index 291594c..177a241 100644 --- a/drm-lease-manager/lease-manager.c +++ b/drm-lease-manager/lease-manager.c @@ -343,7 +343,8 @@ static struct lease *lease_create(struct lm *lm, goto err; } - int nconnectors = config->cnames > 0 ? config->cnames : config->ncids; + int nconnectors = + config->nconnectors > 0 ? config->nconnectors : config->ncids; int nobjects = lm->drm_plane_resource->count_planes + nconnectors * DRM_OBJECTS_PER_CONNECTOR; @@ -356,8 +357,8 @@ static struct lease *lease_create(struct lm *lm, for (int i = 0; i < nconnectors; i++) { uint32_t cid; - if (config->cnames > 0) { - char *connector_name = config->connector_names[i]; + if (config->nconnectors > 0) { + char *connector_name = config->connectors[i].name; if (!drm_find_connector(lm, connector_name, &cid)) { WARN_LOG("Lease: %s, " diff --git a/drm-lease-manager/test/lease-config-test.c b/drm-lease-manager/test/lease-config-test.c index fa5edcd..65bd32a 100644 --- a/drm-lease-manager/test/lease-config-test.c +++ b/drm-lease-manager/test/lease-config-test.c @@ -61,14 +61,14 @@ START_TEST(parse_leases) ck_assert_ptr_ne(config, NULL); ck_assert_str_eq(config[0].lease_name, "lease 1"); - ck_assert_int_eq(config[0].cnames, 3); - ck_assert_str_eq(config[0].connector_names[0], "1"); - ck_assert_str_eq(config[0].connector_names[1], "b"); - ck_assert_str_eq(config[0].connector_names[2], "gamma"); + ck_assert_int_eq(config[0].nconnectors, 3); + ck_assert_str_eq(config[0].connectors[0].name, "1"); + ck_assert_str_eq(config[0].connectors[1].name, "b"); + ck_assert_str_eq(config[0].connectors[2].name, "gamma"); ck_assert_str_eq(config[1].lease_name, "lease 2"); - ck_assert_int_eq(config[1].cnames, 1); - ck_assert_str_eq(config[1].connector_names[0], "connector 3"); + ck_assert_int_eq(config[1].nconnectors, 1); + ck_assert_str_eq(config[1].connectors[0].name, "connector 3"); release_config(nconfigs, config); } diff --git a/drm-lease-manager/test/lease-manager-test.c b/drm-lease-manager/test/lease-manager-test.c index f6524ab..b32cd05 100644 --- a/drm-lease-manager/test/lease-manager-test.c +++ b/drm-lease-manager/test/lease-manager-test.c @@ -508,8 +508,12 @@ START_TEST(named_connector_config) struct lease_config lconfig = { .lease_name = "Lease Config Test 1", - .cnames = 2, - .connector_names = (char *[]){"HDMI-A-1", "VGA-3"}, + .nconnectors = 2, + .connectors = + (struct connector_config[]){ + {.name = "HDMI-A-1"}, + {.name = "VGA-3"}, + }, }; struct lease_handle **handles = create_leases(lease_cnt, &lconfig); |