[gbinder] Added gbinder_client_rpc_header(). JB#55014

Mostly for logging purposes.
This commit is contained in:
Slava Monich
2021-11-17 17:24:51 +02:00
parent d439bd467a
commit 7b319ba822
3 changed files with 43 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018-2020 Jolla Ltd.
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018-2021 Jolla Ltd.
* Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -78,6 +78,11 @@ gbinder_client_interface2(
GBinderClient* client,
guint32 code); /* since 1.0.42 */
GBytes*
gbinder_client_rpc_header(
GBinderClient* client,
guint32 code); /* since 1.1.14 */
GBinderLocalRequest*
gbinder_client_new_request(
GBinderClient* client);

View File

@@ -351,6 +351,22 @@ gbinder_client_interface2(
return NULL;
}
GBytes*
gbinder_client_rpc_header(
GBinderClient* self,
guint32 code) /* since 1.1.14 */
{
if (G_LIKELY(self)) {
const GBinderClientIfaceRange* r =
gbinder_client_find_range(gbinder_client_cast(self), code);
if (r) {
return r->rpc_header;
}
}
return NULL;
}
GBinderLocalRequest*
gbinder_client_new_request(
GBinderClient* self)

View File

@@ -41,6 +41,7 @@
#include "gbinder_output_data.h"
#include "gbinder_remote_object_p.h"
#include "gbinder_remote_reply.h"
#include "gbinder_writer.h"
#include <gutil_log.h>
@@ -79,6 +80,7 @@ test_null(
g_assert(!gbinder_client_ref(NULL));
g_assert(!gbinder_client_interface(NULL));
g_assert(!gbinder_client_interface2(NULL, 0));
g_assert(!gbinder_client_rpc_header(NULL, 0));
gbinder_client_unref(NULL);
g_assert(!gbinder_client_new_request(NULL));
g_assert(!gbinder_client_new_request2(NULL, 0));
@@ -131,6 +133,11 @@ test_interfaces(
};
GBinderClient* client = gbinder_client_new2(obj, ifaces,
G_N_ELEMENTS(ifaces));
GBinderWriter writer;
GBinderLocalRequest* req;
GBytes* rpc_header;
gsize len;
const void* hdr;
g_assert(client);
g_assert_cmpstr(gbinder_client_interface(client), == ,"11");
@@ -138,12 +145,25 @@ test_interfaces(
g_assert_cmpstr(gbinder_client_interface2(client, 22), == ,"22");
g_assert_cmpstr(gbinder_client_interface2(client, 33), == ,"33");
g_assert(!gbinder_client_interface2(client, 34));
g_assert(!gbinder_client_rpc_header(client, 34));
g_assert(!gbinder_client_new_request2(client, 34));
/* Those fail to allocate default request for out-of-range codes: */
g_assert(!gbinder_client_transact_sync_reply(client, 34, NULL, NULL));
g_assert_cmpint(gbinder_client_transact_sync_oneway(client, 34, NULL),
== ,-EINVAL);
g_assert(!gbinder_client_transact(client, 34, 0, NULL, NULL, NULL, NULL));
/* Check the RPC header */
rpc_header = gbinder_client_rpc_header(client, 33);
req = gbinder_client_new_request2(client, 33);
g_assert(rpc_header);
g_assert(req);
gbinder_local_request_init_writer(req, &writer);
hdr = gbinder_writer_get_data(&writer, &len);
g_assert(hdr);
g_assert_cmpuint(len, == ,g_bytes_get_size(rpc_header));
g_assert(!memcmp(hdr, g_bytes_get_data(rpc_header, NULL), len));
gbinder_local_request_unref(req);
gbinder_client_unref(client);
/* Client with no interface info */