Skip to content

Commit

Permalink
api: Promote idhash supplemental API to core
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Jan 5, 2025
1 parent 7cdba96 commit a40b421
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 114 deletions.
3 changes: 0 additions & 3 deletions docs/ref/api/id_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ include file to list of includes.
## ID Map Structure

```c
#include <nng/nng.h>
#include <nng/supplemental/util/idhash.h>

typedef struct nng_id_map_s nng_id_map;
```

Expand Down
1 change: 1 addition & 0 deletions docs/ref/migrate/nng1.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Simply remove any references to them.
- `nng/protocol/survey0/respond.h`
- `nng/protocol/survey0/survey.h`
- `nng/supplemental/tls/tls.h`
- `nng/supplemental/util/idhash.h`
- `nng/supplemental/util/platform.h`
- `nng/transport/inproc/inproc.h`
- `nng/transport/ipc/ipc.h`
Expand Down
14 changes: 14 additions & 0 deletions include/nng/nng.h
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,20 @@ NNG_DECL const char *nng_tls_engine_description(void);
// nng_tls_engine_fips_mode returns true if the engine is in FIPS 140 mode.
NNG_DECL bool nng_tls_engine_fips_mode(void);

// Public ID map support.
typedef struct nng_id_map_s nng_id_map;

#define NNG_MAP_RANDOM 1

NNG_DECL int nng_id_map_alloc(
nng_id_map **map, uint64_t lo, uint64_t hi, int flags);
NNG_DECL void nng_id_map_free(nng_id_map *map);
NNG_DECL void *nng_id_get(nng_id_map *, uint64_t);
NNG_DECL int nng_id_set(nng_id_map *, uint64_t, void *);
NNG_DECL int nng_id_alloc(nng_id_map *, uint64_t *, void *);
NNG_DECL int nng_id_remove(nng_id_map *, uint64_t);
NNG_DECL bool nng_id_visit(nng_id_map *, uint64_t *, void **, uint32_t *);

// Protocol specific values. These were formerly located in protocol specific
// headers, but we are bringing them here for ease of use.

Expand Down
36 changes: 0 additions & 36 deletions include/nng/supplemental/util/idhash.h

This file was deleted.

3 changes: 2 additions & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2024 Staysail Systems, Inc. <[email protected]>
# Copyright 2025 Staysail Systems, Inc. <[email protected]>
#
# This software is supplied under the terms of the MIT License, a
# copy of which should be located in the distribution where this
Expand Down Expand Up @@ -84,6 +84,7 @@ nng_test(aio_test)
nng_test(buf_size_test)
nng_test(errors_test)
nng_test(id_test)
nng_test(idhash_test)
nng_test(init_test)
nng_test(list_test)
nng_test(log_test)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
Expand All @@ -9,8 +9,6 @@

#include <nuts.h>

#include <nng/supplemental/util/idhash.h>

void
test_id_basic(void)
{
Expand Down
55 changes: 55 additions & 0 deletions src/nng.c
Original file line number Diff line number Diff line change
Expand Up @@ -2179,3 +2179,58 @@ nng_udp_multicast_membership(nng_udp *udp, nng_sockaddr *sa, bool join)
return (
nni_plat_udp_multicast_membership((nni_plat_udp *) udp, sa, join));
}

struct nng_id_map_s {
nni_id_map m;
};

int
nng_id_map_alloc(nng_id_map **map, uint64_t lo, uint64_t hi, int flags)
{
nng_id_map *m;

if ((m = NNI_ALLOC_STRUCT(m)) == NULL) {
return (NNG_ENOMEM);

Check warning on line 2193 in src/nng.c

View check run for this annotation

Codecov / codecov/patch

src/nng.c#L2193

Added line #L2193 was not covered by tests
}
nni_id_map_init(
&m->m, lo, hi, (flags & NNG_MAP_RANDOM) ? true : false);
*map = m;
return (0);
}

void
nng_id_map_free(nng_id_map *map)
{
nni_id_map_fini(&map->m);
NNI_FREE_STRUCT(map);
}

void *
nng_id_get(nng_id_map *map, uint64_t id)
{
return (nni_id_get(&map->m, id));
}

int
nng_id_set(nng_id_map *map, uint64_t id, void *val)
{
return (nni_id_set(&map->m, id, val));
}

int
nng_id_remove(nng_id_map *map, uint64_t id)
{
return (nni_id_remove(&map->m, id));
}

int
nng_id_alloc(nng_id_map *map, uint64_t *id, void *val)
{
return (nni_id_alloc(&map->m, id, val));
}

bool
nng_id_visit(nng_id_map *map, uint64_t *id, void **valp, uint32_t *cursor)
{
return (nni_id_visit(&map->m, id, valp, cursor));
}
4 changes: 1 addition & 3 deletions src/supplemental/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
# found online at https://opensource.org/licenses/MIT.
#

nng_sources(idhash.c options.c)
nng_sources(options.c)
nng_headers(
nng/supplemental/util/idhash.h
nng/supplemental/util/options.h)
nng_test(idhash_test)
nng_test(options_test)
68 changes: 0 additions & 68 deletions src/supplemental/util/idhash.c

This file was deleted.

0 comments on commit a40b421

Please sign in to comment.