GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add wpcp_get_subscription_count() and wpcp_iterate_subscriptions() · WebProcessControl/libwpcp@749782b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • include
    • wpcp.h
  • src
    • wpcp.c
  • test
    • test_session.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎include/wpcp.h‎

Copy file name to clipboardExpand all lines: include/wpcp.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ typedef void(WPCP_CDECL *wpcp_unsubscribe_cb_t)(void* user, struct wpcp_result_t
110110
typedef void(WPCP_CDECL *wpcp_unsubscribe_ex_cb_t)(void* user, struct wpcp_result_t* result, struct wpcp_subscription_t* subscription, void** context, uint32_t remaining);
111111
typedef void(WPCP_CDECL *wpcp_republish_cb_t)(void* user, struct wpcp_publish_handle_t* publish_handle, struct wpcp_subscription_t* subscription);
112112
typedef void(WPCP_CDECL *wpcp_republish_ex_cb_t)(void* user, struct wpcp_publish_handle_t* publish_handle, struct wpcp_subscription_t* subscription, void** context, uint32_t remaining);
113+
typedef void(WPCP_CDECL *wpcp_iterate_subscriptions_cb_t)(void* user, struct wpcp_subscription_t* subscription, struct wpcp_publish_handle_t* publish_handle);
113114

114115
union wpcp_has_out_message_callback_t {
115116
wpcp_has_out_message_cb_t cb;
@@ -202,6 +203,10 @@ WPCP_EXPORT void wpcp_subscription_set_user(struct wpcp_subscription_t* subscrip
202203

203204
WPCP_EXPORT size_t wpcp_subscription_get_usage_count(struct wpcp_subscription_t* subscription);
204205

206+
WPCP_EXPORT size_t wpcp_get_subscription_count(struct wpcp_t* wpcp);
207+
208+
WPCP_EXPORT void wpcp_iterate_subscriptions(struct wpcp_t* wpcp, void* user, wpcp_iterate_subscriptions_cb_t callback);
209+
205210
WPCP_EXPORT void wpcp_return_read_data(struct wpcp_result_t* result, const struct wpcp_value_t* diagnostic_info, const struct wpcp_value_t* value, double timestamp, uint32_t status, const struct wpcp_key_value_pair_t* additional, uint32_t additional_count);
206211

207212
WPCP_EXPORT void wpcp_return_write_data(struct wpcp_result_t* result, const struct wpcp_value_t* diagnostic_info, bool success);
Collapse file

‎src/wpcp.c‎

Copy file name to clipboardExpand all lines: src/wpcp.c
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,23 @@ static bool wpcp_session_handle_unsubscribe_message(struct wpcp_session_t* sessi
206206
return ret;
207207
}
208208

209+
size_t wpcp_get_subscription_count(struct wpcp_t* wpcp)
210+
{
211+
struct wpcp_internal_t* wpcp_internal = (struct wpcp_internal_t*) wpcp;
212+
return wpcp_internal->subscription_count;
213+
}
214+
215+
void wpcp_iterate_subscriptions(struct wpcp_t* wpcp, void* user, wpcp_iterate_subscriptions_cb_t callback)
216+
{
217+
size_t i;
218+
struct wpcp_internal_t* wpcp_internal = (struct wpcp_internal_t*) wpcp;
219+
220+
for (i = 0; i < wpcp_internal->subscription_count; ++i) {
221+
struct wpcp_subscription_t* subscription = wpcp_internal->subscriptions[i];
222+
callback(user, subscription, &subscription->publish_handle);
223+
}
224+
}
225+
209226
void wpcp_return_unsubscribe(struct wpcp_result_t* result, const struct wpcp_value_t* diagnostic_info, struct wpcp_subscription_t* subscription)
210227
{
211228
if (subscription)
Collapse file

‎test/test_session.c‎

Copy file name to clipboardExpand all lines: test/test_session.c
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,63 @@ START_TEST(subscription_type)
201201
}
202202
END_TEST
203203

204+
START_TEST(get_subscription_count)
205+
{
206+
ck_assert_int_eq(wpcp_get_subscription_count(&g_wpcp_internal.wpcp), 0);
207+
208+
struct wpcp_subscription_t* subsa = wpcp_request_subscription(&g_wpcp_internal, 0, NULL, 0);
209+
ck_assert_int_eq(wpcp_get_subscription_count(&g_wpcp_internal.wpcp), 1);
210+
211+
struct wpcp_subscription_t* subsb = wpcp_request_subscription(&g_wpcp_internal, 1, NULL, 0);
212+
ck_assert_int_eq(wpcp_get_subscription_count(&g_wpcp_internal.wpcp), 2);
213+
214+
wpcp_release_subscription(&g_wpcp_internal, subsb);
215+
ck_assert_int_eq(wpcp_get_subscription_count(&g_wpcp_internal.wpcp), 1);
216+
217+
wpcp_release_subscription(&g_wpcp_internal, subsa);
218+
ck_assert_int_eq(wpcp_get_subscription_count(&g_wpcp_internal.wpcp), 0);
219+
}
220+
END_TEST
221+
222+
struct test_session_iterate_subscriptions_t {
223+
size_t counter;
224+
struct wpcp_subscription_t* subscriptions[2];
225+
};
226+
227+
void test_session_iterate_subscriptions_callback(void* user, struct wpcp_subscription_t* subscription, struct wpcp_publish_handle_t* publish_handle)
228+
{
229+
struct test_session_iterate_subscriptions_t* helper = (struct test_session_iterate_subscriptions_t*) user;
230+
ck_assert_ptr_eq(subscription, helper->subscriptions[helper->counter]);
231+
ck_assert_ptr_eq(publish_handle, &helper->subscriptions[helper->counter++]->publish_handle);
232+
}
233+
234+
START_TEST(iterate_subscriptions)
235+
{
236+
struct test_session_iterate_subscriptions_t helper;
237+
memset(&helper, 0, sizeof(helper));
238+
239+
wpcp_iterate_subscriptions(&g_wpcp_internal.wpcp, &helper, test_session_iterate_subscriptions_callback);
240+
ck_assert_int_eq(helper.counter, 0);
241+
242+
helper.counter = 0;
243+
helper.subscriptions[0] = wpcp_request_subscription(&g_wpcp_internal, 0, NULL, 0);
244+
wpcp_iterate_subscriptions(&g_wpcp_internal.wpcp, &helper, test_session_iterate_subscriptions_callback);
245+
ck_assert_int_eq(helper.counter, 1);
246+
247+
helper.counter = 0;
248+
helper.subscriptions[1] = wpcp_request_subscription(&g_wpcp_internal, 1, NULL, 0);
249+
wpcp_iterate_subscriptions(&g_wpcp_internal.wpcp, &helper, test_session_iterate_subscriptions_callback);
250+
ck_assert_int_eq(helper.counter, 2);
251+
252+
wpcp_release_subscription(&g_wpcp_internal, helper.subscriptions[0]);
253+
wpcp_release_subscription(&g_wpcp_internal, helper.subscriptions[1]);
254+
255+
helper.counter = 0;
256+
wpcp_iterate_subscriptions(&g_wpcp_internal.wpcp, &helper, test_session_iterate_subscriptions_callback);
257+
ck_assert_int_eq(helper.counter, 0);
258+
}
259+
END_TEST
260+
204261
START_TEST(subscription_publish_item)
205262
{
206263
uint32_t id1 = wpcp_session_get_next_free_publish_id(g_session);
@@ -874,6 +931,8 @@ TCase* testcase_session(void)
874931
tcase_add_test (ret, subscription_max_publish_item);
875932
tcase_add_test (ret, subscription_release_publish_item_via_session);
876933
tcase_add_test (ret, subscription_publish_item_malloc_fail);
934+
tcase_add_test (ret, get_subscription_count);
935+
tcase_add_test (ret, iterate_subscriptions);
877936
tcase_add_test (ret, session_out_message);
878937
tcase_add_test (ret, session_out_message_malloc_fail);
879938
tcase_add_test (ret, subscription_publish_item_publish);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.