Compare commits

...

10 Commits
1.0.5 ... 1.0.7

Author SHA1 Message Date
Slava Monich
306d08112b Version 1.0.7 2018-09-23 22:49:16 +03:00
Slava Monich
b489becf51 Merge pull request #5 from monich/forward
Add gbinder_remote_request_copy_to_local() and gbinder_remote_reply_copy_to_local()
2018-09-23 22:44:27 +03:00
Slava Monich
8a27829af3 [gbinder] Make sure RPC protocol matches servicemanager type
This makes it easier to use non-standard binder device name.
2018-09-22 12:15:20 +03:00
Slava Monich
d67b73502e [unit] Added test for gbinder_remote_reply_copy_to_local() 2018-09-22 12:15:20 +03:00
Slava Monich
4ecf3ae24d [gbinder] Added gbinder_remote_reply_copy_to_local(). JB#42956 2018-09-22 12:15:20 +03:00
Slava Monich
d0542e759d [unit] Added test for gbinder_remote_request_copy_to_local() 2018-09-22 12:15:20 +03:00
Slava Monich
ffa44ac5b3 [gbinder] Added gbinder_remote_request_copy_to_local(). JB#42956
This function could be useful for proxy services, as an easy way to
forward an incoming request. To complete the picture, we should also
have gbinder_remote_reply_copy_to_local() for forwarding replies.
2018-09-22 12:15:20 +03:00
Slava Monich
6509e5dac8 Version 1.0.6 2018-09-21 21:16:29 +03:00
Slava Monich
6b956c0d3c Merge pull request #6 from monich/ref_count
Fix GBinderServiceManager lifecycle management
2018-09-21 21:14:01 +03:00
Slava Monich
3b10a08bad [gbinder] Fixed GBinderServiceManager lifecycle management. Fixes JB#43018
Dispose callback is invoked with refcount 1
2018-09-21 20:27:40 +03:00
42 changed files with 899 additions and 283 deletions

View File

@@ -24,7 +24,7 @@ all: debug release pkgconfig
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_RELEASE = 5
VERSION_RELEASE = 7
# Version for pkg-config
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)

14
debian/changelog vendored
View File

@@ -1,3 +1,17 @@
libgbinder (1.0.7) unstable; urgency=low
* Added gbinder_remote_request_copy_to_local()
* Added gbinder_remote_reply_copy_to_local()
* Make sure RPC protocol matches servicemanager type
-- Slava Monich <slava.monich@jolla.com> Sun, 23 Sep 2018 22:47:16 +0300
libgbinder (1.0.6) unstable; urgency=low
* Fixed GBinderServiceManager lifecycle management
-- Slava Monich <slava.monich@jolla.com> Fri, 21 Sep 2018 21:15:28 +0300
libgbinder (1.0.5) unstable; urgency=low
* Added double and float support

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -50,6 +50,11 @@ gbinder_remote_reply_init_reader(
GBinderRemoteReply* reply,
GBinderReader* reader);
GBinderLocalReply*
gbinder_remote_reply_copy_to_local(
GBinderRemoteReply* reply) /* since 1.0.6 */
G_GNUC_WARN_UNUSED_RESULT;
/* Convenience function to decode replies with just one data item */
gboolean

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -62,6 +62,11 @@ uid_t
gbinder_remote_request_sender_euid(
GBinderRemoteRequest* req); /* since 1.0.2 */
GBinderLocalRequest*
gbinder_remote_request_copy_to_local(
GBinderRemoteRequest* req) /* since 1.0.6 */
G_GNUC_WARN_UNUSED_RESULT;
/* Convenience function to decode requests with just one data item */
gboolean

View File

@@ -1,5 +1,5 @@
Name: libgbinder
Version: 1.0.5
Version: 1.0.7
Release: 0
Summary: Binder client library
Group: Development/Libraries

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -36,12 +36,12 @@
#include <gutil_macros.h>
typedef struct gbinder_buffer_memory {
struct gbinder_buffer_memory {
gint refcount;
void* buffer;
gsize size;
GBinderDriver* driver;
} GBinderBufferMemory;
};
typedef struct gbinder_buffer_priv {
GBinderBuffer pub;
@@ -81,7 +81,6 @@ gbinder_buffer_memory_free(
g_slice_free(GBinderBufferMemory, self);
}
static
GBinderBufferMemory*
gbinder_buffer_memory_ref(
GBinderBufferMemory* self)
@@ -93,7 +92,6 @@ gbinder_buffer_memory_ref(
return self;
}
static
void
gbinder_buffer_memory_unref(
GBinderBufferMemory* self)
@@ -155,10 +153,30 @@ gbinder_buffer_new_with_parent(
gsize size)
{
return gbinder_buffer_alloc(parent ?
gbinder_buffer_memory_ref(gbinder_buffer_cast(parent)->memory) : NULL,
gbinder_buffer_memory_ref(gbinder_buffer_memory(parent)) : NULL,
data, size);
}
gconstpointer
gbinder_buffer_data(
GBinderBuffer* self,
gsize* size)
{
GBinderBufferMemory* memory = gbinder_buffer_memory(self);
if (G_LIKELY(memory)) {
if (size) {
*size = memory->size;
}
return memory->buffer;
} else {
if (size) {
*size = 0;
}
return NULL;
}
}
GBinderDriver*
gbinder_buffer_driver(
GBinderBuffer* self)
@@ -173,6 +191,22 @@ gbinder_buffer_driver(
return NULL;
}
const GBinderIo*
gbinder_buffer_io(
GBinderBuffer* buf)
{
GBinderDriver* driver = gbinder_buffer_driver(buf);
return driver ? gbinder_driver_io(driver) : NULL;
}
GBinderBufferMemory*
gbinder_buffer_memory(
GBinderBuffer* self)
{
return G_LIKELY(self) ? gbinder_buffer_cast(self)->memory : NULL;
}
/*
* Local Variables:
* mode: C

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -53,8 +53,26 @@ GBinderDriver*
gbinder_buffer_driver(
GBinderBuffer* buf);
#define gbinder_buffer_io(buf) \
gbinder_driver_io(gbinder_buffer_driver(buf))
GBinderBufferMemory*
gbinder_buffer_memory(
GBinderBuffer* buf);
gconstpointer
gbinder_buffer_data(
GBinderBuffer* buf,
gsize* size);
const GBinderIo*
gbinder_buffer_io(
GBinderBuffer* buf);
GBinderBufferMemory*
gbinder_buffer_memory_ref(
GBinderBufferMemory* mem);
void
gbinder_buffer_memory_unref(
GBinderBufferMemory* mem);
#endif /* GBINDER_BUFFER_PRIVATE_H */

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -31,6 +31,7 @@
*/
#include "gbinder_servicemanager_p.h"
#include "gbinder_rpc_protocol.h"
#include "gbinder_log.h"
#include <gbinder_client.h>
@@ -165,6 +166,7 @@ gbinder_defaultservicemanager_class_init(
klass->handle = DEFAULTSERVICEMANAGER_HANDLE;
klass->iface = DEFAULTSERVICEMANAGER_IFACE;
klass->default_device = GBINDER_DEFAULT_BINDER;
klass->rpc_protocol = &gbinder_rpc_protocol_binder;
klass->list = gbinder_defaultservicemanager_list;
klass->get_service = gbinder_defaultservicemanager_get_service;

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -672,7 +672,8 @@ gbinder_driver_txstatus(
GBinderDriver*
gbinder_driver_new(
const char* dev)
const char* dev,
const GBinderRpcProtocol* protocol)
{
const int fd = gbinder_system_open(dev, O_RDWR | O_CLOEXEC);
if (fd >= 0) {
@@ -711,8 +712,10 @@ gbinder_driver_new(
GERR("%s failed to set max threads (%u): %s", dev,
max_threads, strerror(errno));
}
/* Choose the protocol based on the device name */
self->protocol = gbinder_rpc_protocol_for_device(dev);
/* Choose the protocol based on the device name
* if none is explicitely specified */
self->protocol = protocol ? protocol :
gbinder_rpc_protocol_for_device(dev);
return self;
} else {
GERR("%s failed to mmap: %s", dev, strerror(errno));

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -39,7 +39,8 @@ struct pollfd;
GBinderDriver*
gbinder_driver_new(
const char* dev);
const char* dev,
const GBinderRpcProtocol* protocol);
GBinderDriver*
gbinder_driver_ref(

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -31,6 +31,7 @@
*/
#include "gbinder_servicemanager_p.h"
#include "gbinder_rpc_protocol.h"
#include "gbinder_log.h"
#include <gbinder_client.h>
@@ -184,6 +185,7 @@ gbinder_hwservicemanager_class_init(
klass->handle = HWSERVICEMANAGER_HANDLE;
klass->iface = HWSERVICEMANAGER_IFACE;
klass->default_device = GBINDER_DEFAULT_HWBINDER;
klass->rpc_protocol = &gbinder_rpc_protocol_hwbinder;
klass->list = gbinder_hwservicemanager_list;
klass->get_service = gbinder_hwservicemanager_get_service;

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -90,6 +90,21 @@ GBINDER_IO_FN(write_read)(
return ret;
}
/* Returns size of the object's extra data */
static
gsize
GBINDER_IO_FN(object_data_size)(
const void* obj)
{
const struct binder_buffer_object* buf = obj;
if (buf && buf->hdr.type == BINDER_TYPE_PTR) {
return buf->length;
} else {
return 0;
}
}
/* Writes pointer to the buffer */
static
guint
@@ -445,6 +460,8 @@ const GBinderIo GBINDER_IO_PREFIX = {
.failed_reply = BR_FAILED_REPLY
},
.object_data_size = GBINDER_IO_FN(object_data_size),
/* Encoders */
.encode_pointer = GBINDER_IO_FN(encode_pointer),
.encode_local_object = GBINDER_IO_FN(encode_local_object),

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -118,6 +118,9 @@ struct gbinder_io {
guint failed_reply;
} br;
/* Size of the object's extra data */
gsize (*object_data_size)(const void* obj);
/* Writes pointer to the buffer. The destination buffer must have
* at least GBINDER_IO_MAX_POINTER_SIZE bytes available. The
* actual size is returned. */

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -981,7 +981,8 @@ gbinder_ipc_tx_proc(
GBinderIpc*
gbinder_ipc_new(
const char* dev)
const char* dev,
const GBinderRpcProtocol* protocol)
{
GBinderIpc* self = NULL;
@@ -994,7 +995,7 @@ gbinder_ipc_new(
if (self) {
gbinder_ipc_ref(self);
} else {
GBinderDriver* driver = gbinder_driver_new(dev);
GBinderDriver* driver = gbinder_driver_new(dev, protocol);
if (driver) {
GBinderIpcPriv* priv;

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -70,7 +70,8 @@ void
GBinderIpc*
gbinder_ipc_new(
const char* dev);
const char* dev,
const GBinderRpcProtocol* protocol);
GBinderIpc*
gbinder_ipc_ref(

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -33,6 +33,7 @@
#include "gbinder_local_reply_p.h"
#include "gbinder_output_data.h"
#include "gbinder_writer_p.h"
#include "gbinder_buffer_p.h"
#include "gbinder_log.h"
#include <gutil_intarray.h>
@@ -92,6 +93,20 @@ gbinder_local_reply_new(
return NULL;
}
GBinderLocalReply*
gbinder_local_reply_new_from_data(
GBinderBuffer* buffer,
void** objects)
{
const GBinderIo* io = gbinder_buffer_io(buffer);
GBinderLocalReply* self = gbinder_local_reply_new(io);
if (self) {
gbinder_writer_data_set_contents(&self->data, buffer, objects);
}
return self;
}
static
void
gbinder_local_reply_free(

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -45,6 +45,11 @@ GBinderOutputData*
gbinder_local_reply_data(
GBinderLocalReply* reply);
GBinderLocalReply*
gbinder_local_reply_new_from_data(
GBinderBuffer* buffer,
void** objects);
#endif /* GBINDER_LOCAL_REPLY_PRIVATE_H */
/*

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -33,6 +33,8 @@
#include "gbinder_local_request_p.h"
#include "gbinder_output_data.h"
#include "gbinder_writer_p.h"
#include "gbinder_buffer_p.h"
#include "gbinder_io.h"
#include "gbinder_log.h"
#include <gutil_intarray.h>
@@ -42,6 +44,7 @@ struct gbinder_local_request {
gint refcount;
GBinderWriterData data;
GBinderOutputData out;
GBinderBufferMemory* memory;
};
GBINDER_INLINE_FUNC
@@ -101,6 +104,20 @@ gbinder_local_request_new(
return NULL;
}
GBinderLocalRequest*
gbinder_local_request_new_from_data(
GBinderBuffer* buffer,
void** objects)
{
GBinderLocalRequest* self = gbinder_local_request_new
(gbinder_buffer_io(buffer), NULL);
if (self) {
gbinder_writer_data_set_contents(&self->data, buffer, objects);
}
return self;
}
static
void
gbinder_local_request_free(
@@ -111,6 +128,7 @@ gbinder_local_request_free(
g_byte_array_free(data->bytes, TRUE);
gutil_int_array_free(data->offsets, TRUE);
gbinder_cleanup_free(data->cleanup);
gbinder_buffer_memory_unref(self->memory);
g_slice_free(GBinderLocalRequest, self);
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -46,6 +46,11 @@ GBinderOutputData*
gbinder_local_request_data(
GBinderLocalRequest* req);
GBinderLocalRequest*
gbinder_local_request_new_from_data(
GBinderBuffer* buffer,
void** objects);
#endif /* GBINDER_LOCAL_REQUEST_PRIVATE_H */
/*

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -31,6 +31,7 @@
*/
#include "gbinder_remote_reply_p.h"
#include "gbinder_local_reply_p.h"
#include "gbinder_reader_p.h"
#include "gbinder_object_registry.h"
#include "gbinder_buffer.h"
@@ -117,6 +118,18 @@ gbinder_remote_reply_is_empty(
return !self || !self->data.buffer || !self->data.buffer->size;
}
GBinderLocalReply*
gbinder_remote_reply_copy_to_local(
GBinderRemoteReply* self)
{
if (G_LIKELY(self)) {
GBinderReaderData* d = &self->data;
return gbinder_local_reply_new_from_data(d->buffer, d->objects);
}
return NULL;
}
static
inline
void

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -33,6 +33,7 @@
#include "gbinder_remote_request_p.h"
#include "gbinder_reader_p.h"
#include "gbinder_rpc_protocol.h"
#include "gbinder_local_request_p.h"
#include "gbinder_object_registry.h"
#include "gbinder_buffer.h"
#include "gbinder_log.h"
@@ -68,6 +69,18 @@ gbinder_remote_request_new(
return self;
}
GBinderLocalRequest*
gbinder_remote_request_copy_to_local(
GBinderRemoteRequest* self)
{
if (G_LIKELY(self)) {
GBinderReaderData* d = &self->data;
return gbinder_local_request_new_from_data(d->buffer, d->objects);
}
return NULL;
}
static
void
gbinder_remote_request_free(

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -109,22 +109,22 @@ gbinder_rpc_protocol_hwbinder_read_rpc_header(
* Interface
*==========================================================================*/
const GBinderRpcProtocol gbinder_rpc_protocol_binder = {
.read_rpc_header = gbinder_rpc_protocol_binder_read_rpc_header,
.write_rpc_header = gbinder_rpc_protocol_binder_write_rpc_header
};
const GBinderRpcProtocol gbinder_rpc_protocol_hwbinder = {
.read_rpc_header = gbinder_rpc_protocol_hwbinder_read_rpc_header,
.write_rpc_header = gbinder_rpc_protocol_hwbinder_write_rpc_header
};
const GBinderRpcProtocol*
gbinder_rpc_protocol_for_device(
const char* dev)
{
static const GBinderRpcProtocol protocol_binder = {
.read_rpc_header = gbinder_rpc_protocol_binder_read_rpc_header,
.write_rpc_header = gbinder_rpc_protocol_binder_write_rpc_header
};
static const GBinderRpcProtocol protocol_hwbinder = {
.read_rpc_header = gbinder_rpc_protocol_hwbinder_read_rpc_header,
.write_rpc_header = gbinder_rpc_protocol_hwbinder_write_rpc_header
};
return (dev && !strcmp(dev, GBINDER_DEFAULT_HWBINDER)) ?
&protocol_hwbinder : &protocol_binder;
&gbinder_rpc_protocol_hwbinder : &gbinder_rpc_protocol_binder;
}
/*

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,10 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -45,6 +46,10 @@ struct gbinder_rpc_protocol {
void (*write_rpc_header)(GBinderWriter* writer, const char* iface);
};
extern const GBinderRpcProtocol gbinder_rpc_protocol_binder;
extern const GBinderRpcProtocol gbinder_rpc_protocol_hwbinder;
/* Returns one of the above based on the device name */
const GBinderRpcProtocol*
gbinder_rpc_protocol_for_device(
const char* dev);

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -93,7 +93,7 @@ gbinder_servicemanager_new_with_type(
GBinderIpc* ipc;
if (!dev) dev = klass->default_device;
ipc = gbinder_ipc_new(dev);
ipc = gbinder_ipc_new(dev, klass->rpc_protocol);
if (ipc) {
GBinderRemoteObject* object = gbinder_ipc_get_remote_object
(ipc, klass->handle);
@@ -475,7 +475,7 @@ gbinder_servicemanager_dispose(
* gbinder_servicemanager_finalize() will not be called
* this time around.
*/
if (klass->table && object->ref_count == 0) {
if (klass->table && g_atomic_int_get(&object->ref_count) <= 1) {
g_hash_table_remove(klass->table, self->dev);
if (g_hash_table_size(klass->table) == 0) {
g_hash_table_unref(klass->table);

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -54,6 +54,7 @@ typedef struct gbinder_servicemanager_class {
guint32 handle;
const char* iface;
const char* default_device;
const GBinderRpcProtocol* rpc_protocol;
/* Methods (synchronous) */
char** (*list)(GBinderServiceManager* self);

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -35,6 +35,7 @@
#include <gbinder_types.h>
typedef struct gbinder_buffer_memory GBinderBufferMemory;
typedef struct gbinder_cleanup GBinderCleanup;
typedef struct gbinder_driver GBinderDriver;
typedef struct gbinder_handler GBinderHandler;

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -31,6 +31,7 @@
*/
#include "gbinder_writer_p.h"
#include "gbinder_buffer_p.h"
#include "gbinder_io.h"
#include "gbinder_log.h"
@@ -51,6 +52,53 @@ GBINDER_INLINE_FUNC GBinderWriterPriv* gbinder_writer_cast(GBinderWriter* pub)
GBINDER_INLINE_FUNC GBinderWriterData* gbinder_writer_data(GBinderWriter* pub)
{ return G_LIKELY(pub) ? gbinder_writer_cast(pub)->data : NULL; }
static
void
gbinder_writer_data_memory_cleanup(
gpointer memory)
{
gbinder_buffer_memory_unref(memory);
}
void
gbinder_writer_data_set_contents(
GBinderWriterData* data,
GBinderBuffer* buffer,
void** objects)
{
gsize bufsize;
const guint8* bufdata = gbinder_buffer_data(buffer, &bufsize);
const GBinderIo* io = gbinder_buffer_io(buffer);
GBinderBufferMemory* mem = gbinder_buffer_memory(buffer);
GASSERT(data->io == io);
g_byte_array_set_size(data->bytes, 0);
gutil_int_array_set_count(data->offsets, 0);
data->buffers_size = 0;
g_byte_array_append(data->bytes, bufdata, bufsize);
if (mem) {
data->cleanup = gbinder_cleanup_add(data->cleanup,
gbinder_writer_data_memory_cleanup,
gbinder_buffer_memory_ref(mem));
}
if (objects && *objects) {
if (!data->offsets) {
data->offsets = gutil_int_array_new();
}
while (*objects) {
const guint8* obj = *objects++;
gsize offset = obj - bufdata;
gsize objsize = io->object_data_size(obj);
GASSERT(offset > 0 && offset < bufsize);
gutil_int_array_append(data->offsets, (int)offset);
/* Size of each buffer has to be 8-byte aligned */
data->buffers_size += G_ALIGN8(objsize);
}
}
}
static
void
gbinder_writer_data_record_offset(

View File

@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -50,6 +50,12 @@ gbinder_writer_init(
GBinderWriter* writer,
GBinderWriterData* data);
void
gbinder_writer_data_set_contents(
GBinderWriterData* data,
GBinderBuffer* buffer,
void** objects);
void
gbinder_writer_data_append_bool(
GBinderWriterData* data,

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -32,7 +32,9 @@
#include "gbinder_system.h"
#define GLOG_MODULE_NAME test_binder_log
#include <gutil_log.h>
GLOG_MODULE_DEFINE2("test_binder", gutil_log_default);
#include <unistd.h>
#include <fcntl.h>
@@ -61,6 +63,7 @@ typedef struct test_binder_node {
char* path;
int refcount;
const TestBinderIo* io;
GHashTable* destroy_map;
} TestBinderNode;
typedef struct test_binder {
@@ -123,6 +126,25 @@ typedef struct binder_pre_cookie_64 {
#define BR_DEAD_BINDER_64 _IOR('r', 15, guint64)
#define BR_FAILED_REPLY _IO('r', 17)
static
void
test_io_free_buffer(
TestBinder* binder,
void* ptr)
{
if (ptr) {
TestBinderNode* node = binder->node;
GDestroyNotify destroy = g_hash_table_lookup(node->destroy_map, ptr);
if (destroy) {
g_hash_table_remove(node->destroy_map, ptr);
destroy(ptr);
} else {
g_free(ptr);
}
}
}
static
int
test_io_handle_write_read_64(
@@ -151,7 +173,8 @@ test_io_handle_write_read_64(
/* Is there anything special about transactions and replies? */
break;
case BC_FREE_BUFFER_64:
g_free((void*)(gsize)(*(guint64*)write_ptr));
test_io_free_buffer(binder,
GSIZE_TO_POINTER(*(guint64*)write_ptr));
break;
case BC_INCREFS:
case BC_ACQUIRE:
@@ -219,6 +242,7 @@ test_binder_node_unref(
node->refcount--;
if (!node->refcount) {
g_hash_table_remove(test_node_map, node->path);
g_hash_table_destroy(node->destroy_map);
g_free(node->path);
g_free(node);
}
@@ -228,24 +252,57 @@ test_binder_node_unref(
}
}
static
TestBinder*
test_binder_from_fd(
int fd)
{
TestBinder* binder = NULL;
GASSERT(test_fd_map);
if (test_fd_map) {
binder = g_hash_table_lookup(test_fd_map, GINT_TO_POINTER(fd));
GASSERT(binder);
}
return binder;
}
static
void
test_io_destroy_none(
gpointer data)
{
GDEBUG("Not freeing %p", data);
}
void
test_binder_set_destroy(
int fd,
gpointer ptr,
GDestroyNotify destroy)
{
TestBinder* binder = test_binder_from_fd(fd);
if (binder) {
TestBinderNode* node = binder->node;
g_hash_table_replace(node->destroy_map, ptr,
destroy ? destroy : test_io_destroy_none);
}
}
static
gboolean
test_binder_push_data(
int fd,
const void* data)
{
GASSERT(test_fd_map);
if (test_fd_map) {
gpointer key = GINT_TO_POINTER(fd);
TestBinder* binder = g_hash_table_lookup(test_fd_map, key);
TestBinder* binder = test_binder_from_fd(fd);
GASSERT(binder);
if (binder) {
const guint32* cmd = data;
const int len = sizeof(*cmd) + _IOC_SIZE(*cmd);
if (binder) {
const guint32* cmd = data;
const int len = sizeof(*cmd) + _IOC_SIZE(*cmd);
return write(binder->private_fd, data, len) == len;
}
return write(binder->private_fd, data, len) == len;
}
return FALSE;
}
@@ -440,6 +497,7 @@ gbinder_system_open(
node->path = g_strdup(path);
node->refcount = 1;
node->io = &test_io_64;
node->destroy_map = g_hash_table_new(g_direct_hash, g_direct_equal);
if (!test_node_map) {
test_node_map = g_hash_table_new(g_str_hash, g_str_equal);
}
@@ -466,24 +524,19 @@ int
gbinder_system_close(
int fd)
{
GASSERT(test_fd_map);
if (test_fd_map) {
gpointer key = GINT_TO_POINTER(fd);
TestBinder* binder = g_hash_table_lookup(test_fd_map, key);
TestBinder* binder = test_binder_from_fd(fd);
GASSERT(binder);
if (binder) {
g_hash_table_remove(test_fd_map, key);
if (!g_hash_table_size(test_fd_map)) {
g_hash_table_unref(test_fd_map);
test_fd_map = NULL;
}
test_binder_node_unref(binder->node);
close(binder->public_fd);
close(binder->private_fd);
g_free(binder);
return 0;
if (binder) {
g_hash_table_remove(test_fd_map, GINT_TO_POINTER(fd));
if (!g_hash_table_size(test_fd_map)) {
g_hash_table_unref(test_fd_map);
test_fd_map = NULL;
}
test_binder_node_unref(binder->node);
close(binder->public_fd);
close(binder->private_fd);
g_free(binder);
return 0;
}
errno = EBADF;
return -1;
@@ -495,27 +548,21 @@ gbinder_system_ioctl(
int request,
void* data)
{
GASSERT(test_fd_map);
if (test_fd_map) {
gpointer key = GINT_TO_POINTER(fd);
TestBinder* binder = g_hash_table_lookup(test_fd_map, key);
TestBinder* binder = test_binder_from_fd(fd);
if (binder) {
const TestBinderIo* io = binder->node->io;
GASSERT(binder);
if (binder) {
const TestBinderIo* io = binder->node->io;
switch (request) {
case BINDER_VERSION:
return test_binder_ioctl_version(binder, data);
case BINDER_SET_MAX_THREADS:
return 0;
default:
if (request == io->write_read_request) {
return io->handle_write_read(binder, data);
} else {
errno = EINVAL;
return -1;
}
switch (request) {
case BINDER_VERSION:
return test_binder_ioctl_version(binder, data);
case BINDER_SET_MAX_THREADS:
return 0;
default:
if (request == io->write_read_request) {
return io->handle_write_read(binder, data);
} else {
errno = EINVAL;
return -1;
}
}
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -95,6 +95,12 @@ test_binder_br_reply_status(
int fd,
gint32 status);
void
test_binder_set_destroy(
int fd,
gpointer ptr,
GDestroyNotify destroy);
#endif /* TEST_BINDER_H */
/*

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -46,9 +46,10 @@ void
test_null(
void)
{
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderBuffer* buf = gbinder_buffer_new(NULL, NULL, 0);
GBinderBuffer* buf2;
gsize size = 1;
gbinder_buffer_free(buf);
@@ -66,6 +67,10 @@ test_null(
gbinder_buffer_free(NULL);
g_assert(!gbinder_buffer_driver(NULL));
g_assert(!gbinder_buffer_io(NULL));
g_assert(!gbinder_buffer_data(NULL, NULL));
g_assert(!gbinder_buffer_data(NULL, &size));
g_assert(!size);
gbinder_driver_unref(driver);
}
@@ -80,12 +85,20 @@ test_parent(
{
static const guint8 data[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
void* ptr = g_memdup(data, sizeof(data));
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
gsize size = 0;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderBuffer* parent = gbinder_buffer_new(driver, ptr, sizeof(data));
GBinderBuffer* buf = gbinder_buffer_new_with_parent
(parent, ptr, sizeof(data));
g_assert(gbinder_buffer_driver(buf) == driver);
g_assert(gbinder_buffer_io(buf));
g_assert(gbinder_buffer_io(buf) == gbinder_driver_io(driver));
g_assert(gbinder_buffer_memory(buf));
g_assert(gbinder_buffer_data(buf, NULL) == ptr);
g_assert(gbinder_buffer_data(buf, &size) == ptr);
g_assert(size == sizeof(data));
gbinder_buffer_free(buf);
gbinder_buffer_free(parent);
gbinder_driver_unref(driver);

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -54,7 +54,7 @@ test_client_new(
guint handle,
const char* iface)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
GBinderRemoteObject* obj = gbinder_object_registry_get_remote(reg, handle);
GBinderClient* client = gbinder_client_new(obj, iface);
@@ -95,7 +95,7 @@ void
test_basic(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
GBinderRemoteObject* obj = gbinder_object_registry_get_remote(reg, 0);
GBinderClient* client = gbinder_client_new(obj, "foo");

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -56,8 +56,8 @@ test_basic(
GBinderDriver* driver;
const char* dev = GBINDER_DEFAULT_BINDER;
g_assert(!gbinder_driver_new(""));
driver = gbinder_driver_new(dev);
g_assert(!gbinder_driver_new("", NULL));
driver = gbinder_driver_new(dev, NULL);
g_assert(driver);
g_assert(!g_strcmp0(dev, gbinder_driver_dev(driver)));
g_assert(gbinder_driver_ref(driver) == driver);
@@ -86,7 +86,7 @@ void
test_noop(
void)
{
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
const int fd = gbinder_driver_fd(driver);
g_assert(driver);
@@ -116,7 +116,7 @@ test_local_request(
0x00, 0x00, 0x00, 0x00
};
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderLocalRequest* req = gbinder_driver_local_request_new(driver, iface);
GBinderOutputData* data = gbinder_local_request_data(req);

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -91,8 +91,8 @@ void
test_basic(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc2 = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderIpc* ipc2 = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER, NULL);
g_assert(ipc);
g_assert(ipc2);
@@ -101,14 +101,14 @@ test_basic(
gbinder_ipc_unref(ipc2);
/* Second gbinder_ipc_new returns the same (default) object */
g_assert(gbinder_ipc_new(NULL) == ipc);
g_assert(gbinder_ipc_new("") == ipc);
g_assert(gbinder_ipc_new(NULL, NULL) == ipc);
g_assert(gbinder_ipc_new("", NULL) == ipc);
gbinder_ipc_unref(ipc);
gbinder_ipc_unref(ipc);
gbinder_ipc_unref(ipc);
/* Invalid path */
g_assert(!gbinder_ipc_new("invalid path"));
g_assert(!gbinder_ipc_new("invalid path", NULL));
}
/*==========================================================================*
@@ -120,7 +120,7 @@ void
test_sync_oneway(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(ipc->driver);
const int fd = gbinder_driver_fd(ipc->driver);
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
@@ -141,7 +141,7 @@ void
test_sync_reply_ok_status(
int* status)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(ipc->driver);
const int fd = gbinder_driver_fd(ipc->driver);
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
@@ -196,7 +196,7 @@ void
test_sync_reply_error(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(ipc->driver);
const int fd = gbinder_driver_fd(ipc->driver);
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
@@ -253,7 +253,7 @@ void
test_transact_ok(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(ipc->driver);
const int fd = gbinder_driver_fd(ipc->driver);
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
@@ -310,7 +310,7 @@ void
test_transact_dead(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(ipc->driver);
const int fd = gbinder_driver_fd(ipc->driver);
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
@@ -356,7 +356,7 @@ void
test_transact_failed(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(ipc->driver);
const int fd = gbinder_driver_fd(ipc->driver);
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
@@ -404,7 +404,7 @@ void
test_transact_status(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(ipc->driver);
const int fd = gbinder_driver_fd(ipc->driver);
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
@@ -445,7 +445,7 @@ void
test_transact_custom(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
gulong id = gbinder_ipc_transact_custom(ipc, NULL,
test_transact_custom_done, NULL, loop);
@@ -475,7 +475,7 @@ void
test_transact_custom2(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
gulong id = gbinder_ipc_transact_custom(ipc, NULL, NULL,
test_transact_custom_destroy, loop);
@@ -522,7 +522,7 @@ void
test_transact_cancel(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
gulong id = gbinder_ipc_transact_custom(ipc, test_transact_cancel_exec,
test_transact_cancel_done, test_transact_cancel_destroy, loop);
@@ -566,7 +566,7 @@ void
test_transact_cancel2(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
/* Reusing test_transact_cancel_done and test_transact_cancel_destroy */
gulong id = gbinder_ipc_transact_custom(ipc, test_transact_cancel2_exec,
@@ -629,7 +629,7 @@ void
test_transact_incoming(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(ipc->driver);
const int fd = gbinder_driver_fd(ipc->driver);
const char* dev = gbinder_driver_dev(ipc->driver);
@@ -690,7 +690,7 @@ void
test_transact_status_reply(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(ipc->driver);
const int fd = gbinder_driver_fd(ipc->driver);
const char* dev = gbinder_driver_dev(ipc->driver);

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -149,7 +149,7 @@ void
test_basic(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
GBinderLocalObject* foo;
GBinderLocalObject* bar;
@@ -201,7 +201,7 @@ test_get_descriptor(
int status = INT_MAX;
const char* dev = GBINDER_DEFAULT_HWBINDER;
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
GBinderIpc* ipc = gbinder_ipc_new(dev);
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
GBinderLocalObject* obj =
@@ -256,7 +256,7 @@ test_descriptor_chain(
int status = INT_MAX;
const char* dev = GBINDER_DEFAULT_HWBINDER;
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
GBinderIpc* ipc = gbinder_ipc_new(dev);
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
GBinderLocalObject* obj =
@@ -323,7 +323,7 @@ test_custom_iface(
int count = 0, status = INT_MAX;
const char* dev = GBINDER_DEFAULT_HWBINDER;
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
GBinderIpc* ipc = gbinder_ipc_new(dev);
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
GBinderLocalObject* obj = gbinder_ipc_new_local_object(ipc, custom_iface,
@@ -428,7 +428,7 @@ test_reply_status(
int count = 0, status = 0;
const char* dev = GBINDER_DEFAULT_HWBINDER;
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
GBinderIpc* ipc = gbinder_ipc_new(dev);
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
GBinderLocalObject* obj = gbinder_ipc_new_local_object(ipc, custom_iface,
@@ -468,7 +468,7 @@ void
test_increfs(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderLocalObject* obj = gbinder_ipc_new_local_object
(ipc, NULL, NULL, NULL);
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
@@ -510,7 +510,7 @@ void
test_decrefs(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderLocalObject* obj = gbinder_ipc_new_local_object
(ipc, NULL, NULL, NULL);
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
@@ -552,7 +552,7 @@ void
test_acquire(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderLocalObject* obj = gbinder_ipc_new_local_object
(ipc, NULL, NULL, NULL);
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
@@ -594,7 +594,7 @@ void
test_release(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderLocalObject* obj = gbinder_ipc_new_local_object
(ipc, NULL, NULL, NULL);
GMainLoop* loop = g_main_loop_new(NULL, FALSE);

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -31,10 +31,13 @@
*/
#include "test_common.h"
#include "test_binder.h"
#include "gbinder_local_object.h"
#include "gbinder_local_reply_p.h"
#include "gbinder_output_data.h"
#include "gbinder_buffer_p.h"
#include "gbinder_driver.h"
#include "gbinder_writer.h"
#include "gbinder_io.h"
#include "gbinder_ipc.h"
@@ -56,6 +59,17 @@ test_int_inc(
(*((int*)data))++;
}
static
GBinderBuffer*
test_buffer_from_bytes(
GBinderDriver* driver,
const GByteArray* bytes)
{
/* Prevent double free */
test_binder_set_destroy(gbinder_driver_fd(driver), bytes->data, NULL);
return gbinder_buffer_new(driver, bytes->data, bytes->len);
}
/*==========================================================================*
* null
*==========================================================================*/
@@ -74,6 +88,7 @@ test_null(
gbinder_local_reply_init_writer(NULL, NULL);
gbinder_local_reply_init_writer(NULL, &writer);
g_assert(!gbinder_local_reply_data(NULL));
g_assert(!gbinder_local_reply_new_from_data(NULL, NULL));
gbinder_local_reply_cleanup(NULL, NULL, &count);
gbinder_local_reply_cleanup(NULL, test_int_inc, &count);
@@ -384,7 +399,7 @@ test_local_object(
GBinderLocalReply* reply;
GBinderOutputData* data;
GUtilIntArray* offsets;
GBinderIpc* ipc = gbinder_ipc_new(NULL);
GBinderIpc* ipc = gbinder_ipc_new(NULL, NULL);
GBinderLocalObject* obj =
gbinder_ipc_new_local_object(ipc, "foo", NULL, NULL);
@@ -438,6 +453,47 @@ test_remote_object(
gbinder_local_reply_unref(reply);
}
/*==========================================================================*
* remote_reply
*==========================================================================*/
static
void
test_remote_reply(
void)
{
/* The size of the string gets aligned at 4-byte boundary */
static const char input[] = "test";
static const guint8 output[] = { 't', 'e', 's', 't', 0, 0, 0, 0 };
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(driver);
GBinderLocalReply* req = gbinder_local_reply_new(io);
GBinderLocalReply* req2;
GBinderOutputData* data2;
const GByteArray* bytes;
const GByteArray* bytes2;
GBinderBuffer* buffer;
gbinder_local_reply_append_string8(req, input);
bytes = gbinder_local_reply_data(req)->bytes;
/* Copy flat structures (no binder objects) */
buffer = test_buffer_from_bytes(driver, bytes);
req2 = gbinder_local_reply_new_from_data(buffer, NULL);
gbinder_buffer_free(buffer);
data2 = gbinder_local_reply_data(req2);
bytes2 = data2->bytes;
g_assert(!gbinder_output_data_offsets(data2));
g_assert(!gbinder_output_data_buffers_size(data2));
g_assert(bytes2->len == sizeof(output));
g_assert(!memcmp(bytes2->data, output, bytes2->len));
gbinder_local_reply_unref(req2);
gbinder_local_reply_unref(req);
gbinder_driver_unref(driver);
}
/*==========================================================================*
* Common
*==========================================================================*/
@@ -460,6 +516,7 @@ int main(int argc, char* argv[])
g_test_add_func(TEST_PREFIX "hidl_string_vec", test_hidl_string_vec);
g_test_add_func(TEST_PREFIX "local_object", test_local_object);
g_test_add_func(TEST_PREFIX "remote_object", test_remote_object);
g_test_add_func(TEST_PREFIX "remote_reply", test_remote_reply);
test_init(&test_opt, argc, argv);
return g_test_run();
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -31,9 +31,12 @@
*/
#include "test_common.h"
#include "test_binder.h"
#include "gbinder_local_request_p.h"
#include "gbinder_output_data.h"
#include "gbinder_buffer_p.h"
#include "gbinder_driver.h"
#include "gbinder_writer.h"
#include "gbinder_io.h"
@@ -54,6 +57,17 @@ test_int_inc(
(*((int*)data))++;
}
static
GBinderBuffer*
test_buffer_from_bytes(
GBinderDriver* driver,
const GByteArray* bytes)
{
/* Prevent double free */
test_binder_set_destroy(gbinder_driver_fd(driver), bytes->data, NULL);
return gbinder_buffer_new(driver, bytes->data, bytes->len);
}
/*==========================================================================*
* null
*==========================================================================*/
@@ -68,6 +82,7 @@ test_null(
g_assert(!gbinder_local_request_new(NULL, NULL));
g_assert(!gbinder_local_request_ref(NULL));
g_assert(!gbinder_local_request_new_from_data(NULL, NULL));
gbinder_local_request_unref(NULL);
gbinder_local_request_init_writer(NULL, NULL);
gbinder_local_request_init_writer(NULL, &writer);
@@ -436,6 +451,125 @@ test_remote_object(
gbinder_local_request_unref(req);
}
/*==========================================================================*
* remote_request
*==========================================================================*/
static
void
test_remote_request(
void)
{
/* The size of the string gets aligned at 4-byte boundary */
static const char input[] = "test";
static const guint8 output[] = { 't', 'e', 's', 't', 0, 0, 0, 0 };
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(driver);
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
GBinderLocalRequest* req2;
GBinderOutputData* data2;
const GByteArray* bytes;
const GByteArray* bytes2;
GBinderBuffer* buffer;
void* no_obj = NULL;
gbinder_local_request_append_string8(req, input);
bytes = gbinder_local_request_data(req)->bytes;
/* Copy flat structures (no binder objects) */
buffer = test_buffer_from_bytes(driver, bytes);
req2 = gbinder_local_request_new_from_data(buffer, NULL);
gbinder_buffer_free(buffer);
data2 = gbinder_local_request_data(req2);
bytes2 = data2->bytes;
g_assert(!gbinder_output_data_offsets(data2));
g_assert(!gbinder_output_data_buffers_size(data2));
g_assert(bytes2->len == sizeof(output));
g_assert(!memcmp(bytes2->data, output, bytes2->len));
gbinder_local_request_unref(req2);
/* Same thing but with non-NULL (albeit empty) array of objects */
buffer = test_buffer_from_bytes(driver, bytes);
req2 = gbinder_local_request_new_from_data(buffer, &no_obj);
gbinder_buffer_free(buffer);
data2 = gbinder_local_request_data(req2);
bytes2 = data2->bytes;
g_assert(!gbinder_output_data_offsets(data2));
g_assert(!gbinder_output_data_buffers_size(data2));
g_assert(bytes2->len == sizeof(output));
g_assert(!memcmp(bytes2->data, output, bytes2->len));
gbinder_local_request_unref(req2);
gbinder_local_request_unref(req);
gbinder_driver_unref(driver);
}
/*==========================================================================*
* remote_request_obj
*==========================================================================*/
static
void
test_remote_request_obj_validate_data(
GBinderOutputData* data)
{
const GByteArray* bytes = data->bytes;
GUtilIntArray* offsets = gbinder_output_data_offsets(data);
offsets = gbinder_output_data_offsets(data);
g_assert(offsets);
g_assert(offsets->count == 3);
g_assert(offsets->data[0] == 4);
g_assert(offsets->data[1] == 4 + BUFFER_OBJECT_SIZE_64);
g_assert(offsets->data[2] == 4 + 2*BUFFER_OBJECT_SIZE_64);
g_assert(bytes->len == 4 + 2*BUFFER_OBJECT_SIZE_64 + BINDER_OBJECT_SIZE_64);
/* HidlString + the contents (2 bytes) aligned at 8-byte boundary */
g_assert(gbinder_output_data_buffers_size(data) == (sizeof(HidlString)+8));
}
static
void
test_remote_request_obj(
void)
{
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
const GBinderIo* io = gbinder_driver_io(driver);
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
GBinderLocalRequest* req2;
GBinderOutputData* data;
GUtilIntArray* offsets;
GBinderBuffer* buffer;
const GByteArray* bytes;
void** objects;
guint i;
gbinder_local_request_append_int32(req, 1);
gbinder_local_request_append_hidl_string(req, "2");
gbinder_local_request_append_local_object(req, NULL);
data = gbinder_local_request_data(req);
test_remote_request_obj_validate_data(data);
bytes = data->bytes;
offsets = gbinder_output_data_offsets(data);
objects = g_new0(void*, offsets->count + 1);
for (i = 0; i < offsets->count; i++) {
objects[i] = bytes->data + offsets->data[i];
}
buffer = test_buffer_from_bytes(driver, data->bytes);
req2 = gbinder_local_request_new_from_data(buffer, objects);
gbinder_buffer_free(buffer);
g_free(objects);
test_remote_request_obj_validate_data(gbinder_local_request_data(req2));
gbinder_local_request_unref(req);
gbinder_local_request_unref(req2);
gbinder_driver_unref(driver);
}
/*==========================================================================*
* Common
*==========================================================================*/
@@ -459,6 +593,8 @@ int main(int argc, char* argv[])
g_test_add_func(TEST_PREFIX "hidl_string_vec", test_hidl_string_vec);
g_test_add_func(TEST_PREFIX "local_object", test_local_object);
g_test_add_func(TEST_PREFIX "remote_object", test_remote_object);
g_test_add_func(TEST_PREFIX "remote_request", test_remote_request);
g_test_add_func(TEST_PREFIX "remote_request_obj", test_remote_request_obj);
test_init(&test_opt, argc, argv);
return g_test_run();
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -74,20 +74,20 @@ static const TestHeaderData test_header_tests[] = {
};
/*==========================================================================*
* default
* device
*==========================================================================*/
static
void
test_default(
test_device(
void)
{
const GBinderRpcProtocol* p1 = gbinder_rpc_protocol_for_device(NULL);
const GBinderRpcProtocol* p2 = gbinder_rpc_protocol_for_device
(GBINDER_DEFAULT_BINDER);
g_assert(p1);
g_assert(p1 == p2);
g_assert(gbinder_rpc_protocol_for_device(NULL) ==
&gbinder_rpc_protocol_binder);
g_assert(gbinder_rpc_protocol_for_device(GBINDER_DEFAULT_BINDER) ==
&gbinder_rpc_protocol_binder);
g_assert(gbinder_rpc_protocol_for_device(GBINDER_DEFAULT_HWBINDER) ==
&gbinder_rpc_protocol_hwbinder);
}
/*==========================================================================*
@@ -140,7 +140,7 @@ test_read_header(
gconstpointer test_data)
{
const TestHeaderData* test = test_data;
GBinderDriver* driver = gbinder_driver_new(test->dev);
GBinderDriver* driver = gbinder_driver_new(test->dev, NULL);
GBinderRemoteRequest* req = gbinder_remote_request_new(NULL,
gbinder_rpc_protocol_for_device(test->dev), 0, 0);
@@ -162,7 +162,7 @@ int main(int argc, char* argv[])
guint i;
g_test_init(&argc, &argv, NULL);
g_test_add_func(TEST_PREFIX "default", test_default);
g_test_add_func(TEST_PREFIX "device", test_device);
g_test_add_func(TEST_PREFIX "no_header", test_no_header);
for (i = 0; i < G_N_ELEMENTS(test_header_tests); i++) {

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -97,7 +97,7 @@ test_byte(
{
const guint8 in = 42;
guint8 out = 0;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderReader reader;
GBinderReaderData data;
@@ -131,7 +131,7 @@ test_bool(
const guint8 in_true[4] = { 0x01, 0xff, 0xff, 0xff };
const guint8 in_false[4] = { 0x00, 0xff, 0xff, 0xff };
gboolean out = FALSE;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderReader reader;
GBinderReaderData data;
@@ -180,7 +180,7 @@ test_int32(
const guint32 in = 42;
guint32 out1 = 0;
gint32 out2 = 0;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderReader reader;
GBinderReaderData data;
@@ -219,7 +219,7 @@ test_int64(
const guint64 in = 42;
guint64 out1 = 0;
gint64 out2 = 0;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderReader reader;
GBinderReaderData data;
@@ -258,7 +258,7 @@ test_float(
const gfloat in = 42;
gfloat out1 = 0;
gfloat out2 = 0;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderReader reader;
GBinderReaderData data;
@@ -297,7 +297,7 @@ test_double(
const gdouble in = 42;
gdouble out1 = 0;
gdouble out2 = 0;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderReader reader;
GBinderReaderData data;
@@ -361,7 +361,7 @@ test_string8(
gconstpointer test_data)
{
const TestStringData* test = test_data;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderReader reader;
GBinderReaderData data;
const char* str;
@@ -425,7 +425,7 @@ void
test_string16_null(
void)
{
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderReader reader;
GBinderReaderData data;
char dummy;
@@ -464,7 +464,7 @@ test_string16(
gconstpointer test_data)
{
const TestStringData* test = test_data;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderReader reader;
GBinderReaderData data;
const gboolean valid = (test->out != NULL);
@@ -547,7 +547,7 @@ test_hidl_string_err(
gconstpointer test_data)
{
const TestHidlStringErr* test = test_data;
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderBuffer* buf = gbinder_buffer_new(ipc->driver,
g_memdup(test->in, test->in_size), test->in_size);
GBinderReaderData data;
@@ -589,7 +589,7 @@ test_object(
TEST_INT32_BYTES(BINDER_TYPE_HANDLE), TEST_INT32_BYTES(0),
TEST_INT64_BYTES(1 /* handle*/), TEST_INT64_BYTES(0)
};
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER, NULL);
GBinderBuffer* buf = gbinder_buffer_new(ipc->driver,
g_memdup(input, sizeof(input)), sizeof(input));
GBinderRemoteObject* obj = NULL;
@@ -647,7 +647,7 @@ test_object_invalid(
TEST_INT32_BYTES(42 /* invalid type */), TEST_INT32_BYTES(0),
TEST_INT64_BYTES(1 /* handle*/), TEST_INT64_BYTES(0)
};
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER, NULL);
GBinderBuffer* buf = gbinder_buffer_new(ipc->driver,
g_memdup(input, sizeof(input)), sizeof(input));
GBinderRemoteObject* obj = NULL;
@@ -681,7 +681,7 @@ test_vec(
void)
{
/* Using 64-bit I/O */
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER, NULL);
GBinderReaderData data;
GBinderReader reader;
BinderObject64 obj;

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -67,7 +67,7 @@ void
test_basic(
void)
{
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
GBinderRemoteObject* obj1 = gbinder_object_registry_get_remote(reg, 1);
GBinderRemoteObject* obj2 = gbinder_object_registry_get_remote(reg, 2);
@@ -108,7 +108,7 @@ test_dead(
{
const guint handle = 1;
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER);
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderRemoteObject* obj = gbinder_ipc_get_remote_object(ipc, handle);
gulong id = gbinder_remote_object_add_death_handler
(obj, test_dead_done, loop);

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -35,10 +35,17 @@
#include "gbinder_buffer_p.h"
#include "gbinder_driver.h"
#include "gbinder_reader.h"
#include "gbinder_local_reply_p.h"
#include "gbinder_remote_reply_p.h"
#include "gbinder_output_data.h"
#include <gutil_intarray.h>
static TestOpt test_opt;
#define BINDER_TYPE_BINDER GBINDER_FOURCC('s', 'b', '*', 0x85)
#define BINDER_OBJECT_SIZE_64 (GBINDER_MAX_BINDER_OBJECT_SIZE)
/*==========================================================================*
* null
*==========================================================================*/
@@ -56,6 +63,7 @@ test_null(
gbinder_remote_reply_init_reader(NULL, &reader);
g_assert(gbinder_reader_at_end(&reader));
g_assert(gbinder_remote_reply_is_empty(NULL));
g_assert(!gbinder_remote_reply_copy_to_local(NULL));
g_assert(!gbinder_remote_reply_read_int32(NULL, NULL));
g_assert(!gbinder_remote_reply_read_uint32(NULL, NULL));
g_assert(!gbinder_remote_reply_read_int64(NULL, NULL));
@@ -74,7 +82,7 @@ void
test_empty(
void)
{
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderRemoteReply* reply = gbinder_remote_reply_new(NULL);
gbinder_remote_reply_set_data
@@ -120,7 +128,7 @@ test_int32(
};
guint32 out1 = 0;
gint32 out2 = 0;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderRemoteReply* reply = gbinder_remote_reply_new(NULL);
gbinder_remote_reply_set_data(reply, gbinder_buffer_new(driver,
@@ -151,7 +159,7 @@ test_int64(
};
guint64 out1 = 0;
gint64 out2 = 0;
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderRemoteReply* reply = gbinder_remote_reply_new(NULL);
gbinder_remote_reply_set_data(reply, gbinder_buffer_new(driver,
@@ -180,7 +188,7 @@ test_string8(
static const guint8 reply_data [] = {
'b', 'a', 'r', 0x00
};
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderRemoteReply* reply = gbinder_remote_reply_new(NULL);
gbinder_remote_reply_set_data(reply, gbinder_buffer_new(driver,
@@ -208,7 +216,7 @@ test_string16(
TEST_INT16_BYTES('b'), TEST_INT16_BYTES('a'),
TEST_INT16_BYTES('r'), 0x00, 0x00
};
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER);
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
GBinderRemoteReply* reply = gbinder_remote_reply_new(NULL);
char* str;
@@ -225,6 +233,55 @@ test_string16(
gbinder_driver_unref(driver);
}
/*==========================================================================*
* to_local
*==========================================================================*/
static
void
test_to_local(
void)
{
static const guint8 reply_data [] = {
/* 32-bit integer */
TEST_INT32_BYTES(42),
/* 64-bit NULL flat_binder_object */
TEST_INT32_BYTES(BINDER_TYPE_BINDER), /* hdr.type */
TEST_INT32_BYTES(0x17f), /* flags */
TEST_INT64_BYTES(0), /* handle */
TEST_INT64_BYTES(0) /* cookie */
};
const char* dev = GBINDER_DEFAULT_BINDER;
GBinderDriver* driver = gbinder_driver_new(dev, NULL);
GBinderRemoteReply* req = gbinder_remote_reply_new(NULL);
GBinderLocalReply* req2;
GBinderOutputData* data;
const GByteArray* bytes;
GUtilIntArray* offsets;
guint8* req_data = g_memdup(reply_data, sizeof(reply_data));
void** objects = g_new0(void*, 2);
/* Skip the 32-bit integer */
objects[0] = req_data + 4;
gbinder_remote_reply_set_data(req, gbinder_buffer_new(driver, req_data,
sizeof(reply_data)), objects);
/* Convert to GBinderLocalReply */
req2 = gbinder_remote_reply_copy_to_local(req);
data = gbinder_local_reply_data(req2);
offsets = gbinder_output_data_offsets(data);
bytes = data->bytes;
g_assert(offsets);
g_assert(offsets->count == 1);
g_assert(offsets->data[0] == 4);
g_assert(!gbinder_output_data_buffers_size(data));
g_assert(bytes->len == sizeof(reply_data));
gbinder_remote_reply_unref(req);
gbinder_local_reply_unref(req2);
gbinder_driver_unref(driver);
}
/*==========================================================================*
* Common
*==========================================================================*/
@@ -241,6 +298,7 @@ int main(int argc, char* argv[])
g_test_add_func(TEST_PREFIX "int64", test_int64);
g_test_add_func(TEST_PREFIX "string8", test_string8);
g_test_add_func(TEST_PREFIX "string16", test_string16);
g_test_add_func(TEST_PREFIX "to_local", test_to_local);
test_init(&test_opt, argc, argv);
return g_test_run();
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Jolla Ltd nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -37,6 +37,11 @@
#include "gbinder_reader.h"
#include "gbinder_remote_request_p.h"
#include "gbinder_rpc_protocol.h"
#include "gbinder_local_request_p.h"
#include "gbinder_output_data.h"
#include "gbinder_io.h"
#include <gutil_intarray.h>
static TestOpt test_opt;
@@ -50,6 +55,9 @@ static TestOpt test_opt;
TEST_INT16_BYTES('f'), TEST_INT16_BYTES('o'), \
TEST_INT16_BYTES('o'), 0x00, 0x00
#define BINDER_TYPE_BINDER GBINDER_FOURCC('s', 'b', '*', 0x85)
#define BINDER_OBJECT_SIZE_64 (GBINDER_MAX_BINDER_OBJECT_SIZE)
/*==========================================================================*
* null
*==========================================================================*/
@@ -67,6 +75,7 @@ test_null(
gbinder_remote_request_init_reader(NULL, &reader);
g_assert(gbinder_reader_at_end(&reader));
g_assert(!gbinder_remote_request_interface(NULL));
g_assert(!gbinder_remote_request_copy_to_local(NULL));
g_assert(gbinder_remote_request_sender_pid(NULL) == (pid_t)(-1));
g_assert(gbinder_remote_request_sender_euid(NULL) == (uid_t)(-1));
g_assert(!gbinder_remote_request_read_int32(NULL, NULL));
@@ -116,7 +125,7 @@ test_int32(
guint32 out1 = 0;
gint32 out2 = 0;
const char* dev = GBINDER_DEFAULT_BINDER;
GBinderDriver* driver = gbinder_driver_new(dev);
GBinderDriver* driver = gbinder_driver_new(dev, NULL);
GBinderRemoteRequest* req = gbinder_remote_request_new(NULL,
gbinder_rpc_protocol_for_device(dev), 0, 0);
@@ -150,7 +159,7 @@ test_int64(
guint64 out1 = 0;
gint64 out2 = 0;
const char* dev = GBINDER_DEFAULT_BINDER;
GBinderDriver* driver = gbinder_driver_new(dev);
GBinderDriver* driver = gbinder_driver_new(dev, NULL);
GBinderRemoteRequest* req = gbinder_remote_request_new(NULL,
gbinder_rpc_protocol_for_device(dev), 0, 0);
@@ -182,7 +191,7 @@ test_string8(
'b', 'a', 'r', 0x00
};
const char* dev = GBINDER_DEFAULT_BINDER;
GBinderDriver* driver = gbinder_driver_new(dev);
GBinderDriver* driver = gbinder_driver_new(dev, NULL);
GBinderRemoteRequest* req = gbinder_remote_request_new(NULL,
gbinder_rpc_protocol_for_device(dev), 0, 0);
@@ -213,7 +222,7 @@ test_string16(
TEST_INT16_BYTES('r'), 0x00, 0x00
};
const char* dev = GBINDER_DEFAULT_BINDER;
GBinderDriver* driver = gbinder_driver_new(dev);
GBinderDriver* driver = gbinder_driver_new(dev, NULL);
GBinderRemoteRequest* req = gbinder_remote_request_new(NULL,
gbinder_rpc_protocol_for_device(dev), 0, 0);
char* str;
@@ -231,6 +240,59 @@ test_string16(
gbinder_driver_unref(driver);
}
/*==========================================================================*
* to_local
*==========================================================================*/
static
void
test_to_local(
void)
{
static const guint8 request_data [] = {
TEST_RPC_HEADER,
/* 32-bit integer */
TEST_INT32_BYTES(42),
/* 64-bit NULL flat_binder_object */
TEST_INT32_BYTES(BINDER_TYPE_BINDER), /* hdr.type */
TEST_INT32_BYTES(0x17f), /* flags */
TEST_INT64_BYTES(0), /* handle */
TEST_INT64_BYTES(0) /* cookie */
};
const char* dev = GBINDER_DEFAULT_BINDER;
GBinderDriver* driver = gbinder_driver_new(dev, NULL);
GBinderRemoteRequest* req = gbinder_remote_request_new(NULL,
gbinder_rpc_protocol_for_device(dev), 0, 0);
GBinderLocalRequest* req2;
GBinderOutputData* data;
const GByteArray* bytes;
GUtilIntArray* offsets;
guint8* req_data = g_memdup(request_data, sizeof(request_data));
void** objects = g_new0(void*, 2);
/* Skip the 32-bit integer */
objects[0] = req_data + 4;
gbinder_remote_request_set_data(req, gbinder_buffer_new(driver, req_data,
sizeof(request_data)), objects);
g_assert(!g_strcmp0(gbinder_remote_request_interface(req), TEST_RPC_IFACE));
/* Convert to GBinderLocalRequest */
req2 = gbinder_remote_request_copy_to_local(req);
data = gbinder_local_request_data(req2);
offsets = gbinder_output_data_offsets(data);
bytes = data->bytes;
g_assert(offsets);
g_assert(offsets->count == 1);
g_assert(offsets->data[0] == 4);
g_assert(!gbinder_output_data_buffers_size(data));
g_assert(bytes->len == sizeof(request_data));
gbinder_remote_request_unref(req);
gbinder_local_request_unref(req2);
gbinder_driver_unref(driver);
}
/*==========================================================================*
* Common
*==========================================================================*/
@@ -246,6 +308,7 @@ int main(int argc, char* argv[])
g_test_add_func(TEST_PREFIX "int64", test_int64);
g_test_add_func(TEST_PREFIX "string8", test_string8);
g_test_add_func(TEST_PREFIX "string16", test_string16);
g_test_add_func(TEST_PREFIX "to_local", test_to_local);
test_init(&test_opt, argc, argv);
return g_test_run();
}