Compare commits
	
		
			68 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					2d878c2391 | ||
| 
						 | 
					6dec867cd3 | ||
| 
						 | 
					d8bd7b9366 | ||
| 
						 | 
					b52e4c6dee | ||
| 
						 | 
					21046af42f | ||
| 
						 | 
					3cbe1d6ac8 | ||
| 
						 | 
					b4b1a99a27 | ||
| 
						 | 
					f5a2d481e3 | ||
| 
						 | 
					da57a15852 | ||
| 
						 | 
					9d0ac624c5 | ||
| 
						 | 
					b8ccc80b87 | ||
| 
						 | 
					27e2dac22e | ||
| 
						 | 
					a4ec4e382d | ||
| 
						 | 
					30df5faf64 | ||
| 
						 | 
					0aa29d8a91 | ||
| 
						 | 
					3ace986e4a | ||
| 
						 | 
					064ab48eee | ||
| 
						 | 
					12c1725ab1 | ||
| 
						 | 
					ba2ddf4163 | ||
| 
						 | 
					3d16384acd | ||
| 
						 | 
					0f73626025 | ||
| 
						 | 
					84fb44e519 | ||
| 
						 | 
					aafe23396a | ||
| 
						 | 
					51f270df67 | ||
| 
						 | 
					e9c404de92 | ||
| 
						 | 
					141bda151b | ||
| 
						 | 
					e952380ce6 | ||
| 
						 | 
					721f5dc469 | ||
| 
						 | 
					434b17eefe | ||
| 
						 | 
					af6a1c84ef | ||
| 
						 | 
					a0ce447a1f | ||
| 
						 | 
					f24145f407 | ||
| 
						 | 
					11c173b2e4 | ||
| 
						 | 
					aff816d10c | ||
| 
						 | 
					e1acaa3bdb | ||
| 
						 | 
					c63743ac51 | ||
| 
						 | 
					6832d9bf46 | ||
| 
						 | 
					4c3ccbc06f | ||
| 
						 | 
					f82596c372 | ||
| 
						 | 
					4921a6ab8d | ||
| 
						 | 
					ef9c242a59 | ||
| 
						 | 
					a83c9937a5 | ||
| 
						 | 
					cfa3ad4d9e | ||
| 
						 | 
					ffc9638ebb | ||
| 
						 | 
					000534654d | ||
| 
						 | 
					68e9358d02 | ||
| 
						 | 
					37e3859f8f | ||
| 
						 | 
					e79b940b0d | ||
| 
						 | 
					d8dfe3f289 | ||
| 
						 | 
					394c286ee5 | ||
| 
						 | 
					307bd6942c | ||
| 
						 | 
					148b53e862 | ||
| 
						 | 
					5c8cb0a013 | ||
| 
						 | 
					4d644e0584 | ||
| 
						 | 
					dce9c8b3d1 | ||
| 
						 | 
					b117ee6404 | ||
| 
						 | 
					c3f783bf7e | ||
| 
						 | 
					4c65a6eded | ||
| 
						 | 
					c382cab922 | ||
| 
						 | 
					199fd4ed61 | ||
| 
						 | 
					f86d62fbf8 | ||
| 
						 | 
					3ea82dc384 | ||
| 
						 | 
					03ae5834ee | ||
| 
						 | 
					e39b5c20ee | ||
| 
						 | 
					d6e131eb6e | ||
| 
						 | 
					1c36b5f142 | ||
| 
						 | 
					827bd0b59f | ||
| 
						 | 
					2dab057652 | 
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							@@ -2,3 +2,4 @@ Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
Matti Lehtimäki <matti.lehtimaki@gmail.com>
 | 
			
		||||
Franz-Josef Haider <franz.haider@jolla.com>
 | 
			
		||||
Juho Hämäläinen <juho.hamalainen@jolla.com>
 | 
			
		||||
Andrew Branson <andrew.branson@jolla.com>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								LICENSE
									
									
									
									
									
								
							@@ -1,5 +1,5 @@
 | 
			
		||||
Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
Copyright (C) 2018-2020 Jolla Ltd.
 | 
			
		||||
Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 | 
			
		||||
You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 | 
			
		||||
@@ -12,9 +12,9 @@ are met:
 | 
			
		||||
  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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								Makefile
									
									
									
									
									
								
							@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
.PHONY: clean all debug release test
 | 
			
		||||
.PHONY: print_debug_so print_release_so
 | 
			
		||||
.PHONY: print_debug_lib print_release_lib
 | 
			
		||||
.PHONY: print_debug_lib print_release_lib print_coverage_lib
 | 
			
		||||
.PHONY: print_debug_link print_release_link
 | 
			
		||||
.PHONY: print_debug_path print_release_path
 | 
			
		||||
 | 
			
		||||
@@ -24,7 +24,7 @@ all: debug release pkgconfig
 | 
			
		||||
 | 
			
		||||
VERSION_MAJOR = 1
 | 
			
		||||
VERSION_MINOR = 0
 | 
			
		||||
VERSION_RELEASE = 20
 | 
			
		||||
VERSION_RELEASE = 35
 | 
			
		||||
 | 
			
		||||
# Version for pkg-config
 | 
			
		||||
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
 | 
			
		||||
@@ -62,6 +62,7 @@ SRC = \
 | 
			
		||||
  gbinder_remote_reply.c \
 | 
			
		||||
  gbinder_remote_request.c \
 | 
			
		||||
  gbinder_rpc_protocol.c \
 | 
			
		||||
  gbinder_servicename.c \
 | 
			
		||||
  gbinder_servicepoll.c \
 | 
			
		||||
  gbinder_writer.c
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										100
									
								
								debian/changelog
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										100
									
								
								debian/changelog
									
									
									
									
										vendored
									
									
								
							@@ -1,6 +1,104 @@
 | 
			
		||||
libgbinder (1.0.35) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Added binder-ping example
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 25 Feb 2020 13:58:19 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.34) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Better cleanup on unload to prevent crashes on exit
 | 
			
		||||
  * Fixed rare memory leak in GBinderServiceManager
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Mon, 16 Dec 2019 12:25:56 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.33) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Reuse loopers
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Fri, 13 Sep 2019 15:57:47 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.32) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Refuse to perform transactions with dead objects
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Fri, 17 May 2019 15:57:30 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.31) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Invalidate handle when remote object dies
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Mon, 13 May 2019 18:05:35 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.30) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Added gbinder_local_object_new()
 | 
			
		||||
  * Added gbinder_remote_object_ipc()
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Wed, 20 Feb 2019 11:59:08 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.29) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Added gbinder_servicemanager_new_local_object2()
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Thu, 14 Feb 2019 18:17:53 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.28) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Set type for local nulls to BINDER_TYPE_WEAK_BINDER
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 29 Jan 2019 02:49:10 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.27) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Fixed outgoing oneway transactions
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Thu, 24 Jan 2019 18:55:16 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.26) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Implement PING and INTERFACE transactions
 | 
			
		||||
  * Add GBinderServiceName API
 | 
			
		||||
  * Added gbinder_reader_read_string16_utf16()
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Wed, 23 Jan 2019 17:43:41 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.25) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Added ServiceManager presence API
 | 
			
		||||
 | 
			
		||||
    gbinder_servicemanager_wait()
 | 
			
		||||
    gbinder_servicemanager_is_present()
 | 
			
		||||
    gbinder_servicemanager_add_presence_handler()
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 22 Jan 2019 16:03:57 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.24) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Revert "Make sure NULL objects are passed as BINDER_TYPE_WEAK_HANDLE"
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Fri, 18 Jan 2019 21:36:32 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.23) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Added gbinder_reader_read_hidl_string_c()
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 15 Jan 2019 15:16:41 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.22) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Added gbinder_client_interface()
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Thu, 10 Jan 2019 14:09:44 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.21) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Added API to overwrite prefix length
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 18 Dec 2018 14:05:14 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.20) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Added API to block incoming requests.
 | 
			
		||||
  * Added API to block incoming requests
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Mon, 17 Dec 2018 16:06:43 +0200
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							@@ -2,13 +2,13 @@ Source: libgbinder
 | 
			
		||||
Section: libs
 | 
			
		||||
Priority: optional
 | 
			
		||||
Maintainer: Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
Build-Depends: debhelper (>= 7), libglib2.0-dev (>= 2.0), libglibutil (>= 1.0.34)
 | 
			
		||||
Build-Depends: debhelper (>= 7), libglib2.0-dev (>= 2.0), libglibutil (>= 1.0.35)
 | 
			
		||||
Standards-Version: 3.8.4
 | 
			
		||||
 | 
			
		||||
Package: libgbinder
 | 
			
		||||
Section: libs
 | 
			
		||||
Architecture: any
 | 
			
		||||
Depends: libglibutil (>= 1.0.34), ${shlibs:Depends}, ${misc:Depends}
 | 
			
		||||
Depends: libglibutil (>= 1.0.35), ${shlibs:Depends}, ${misc:Depends}
 | 
			
		||||
Description: Binder client library
 | 
			
		||||
 | 
			
		||||
Package: libgbinder-dev
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								debian/copyright
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								debian/copyright
									
									
									
									
										vendored
									
									
								
							@@ -1,5 +1,5 @@
 | 
			
		||||
Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
Copyright (C) 2018-2020 Jolla Ltd.
 | 
			
		||||
Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 | 
			
		||||
You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 | 
			
		||||
@@ -12,9 +12,9 @@ are met:
 | 
			
		||||
  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
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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
 | 
			
		||||
@@ -44,6 +44,7 @@
 | 
			
		||||
#include "gbinder_remote_object.h"
 | 
			
		||||
#include "gbinder_remote_reply.h"
 | 
			
		||||
#include "gbinder_remote_request.h"
 | 
			
		||||
#include "gbinder_servicename.h"
 | 
			
		||||
#include "gbinder_servicemanager.h"
 | 
			
		||||
#include "gbinder_writer.h"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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
 | 
			
		||||
@@ -58,6 +58,10 @@ void
 | 
			
		||||
gbinder_client_unref(
 | 
			
		||||
    GBinderClient* client);
 | 
			
		||||
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_client_interface(
 | 
			
		||||
    GBinderClient* client); /* since 1.0.22 */
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_client_new_request(
 | 
			
		||||
    GBinderClient* client);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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,14 @@
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_local_object_new(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderLocalTransactFunc handler,
 | 
			
		||||
    void* user_data) /* Since 1.0.30 */
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT;
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_local_object_ref(
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -125,7 +125,7 @@ gbinder_reader_read_buffer(
 | 
			
		||||
const void*
 | 
			
		||||
gbinder_reader_read_hidl_struct1(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    gsize size); /* since 1.0.9 */
 | 
			
		||||
    gsize size); /* Since 1.0.9 */
 | 
			
		||||
 | 
			
		||||
#define gbinder_reader_read_hidl_struct(reader,type) \
 | 
			
		||||
    ((const type*)gbinder_reader_read_hidl_struct1(reader, sizeof(type)))
 | 
			
		||||
@@ -140,7 +140,7 @@ const void*
 | 
			
		||||
gbinder_reader_read_hidl_vec1(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    gsize* count,
 | 
			
		||||
    guint expected_elemsize); /* since 1.0.9 */
 | 
			
		||||
    guint expected_elemsize); /* Since 1.0.9 */
 | 
			
		||||
 | 
			
		||||
#define gbinder_reader_read_hidl_type_vec(reader,type,count) \
 | 
			
		||||
    ((const type*)gbinder_reader_read_hidl_vec1(reader, count, sizeof(type)))
 | 
			
		||||
@@ -152,6 +152,13 @@ gbinder_reader_read_hidl_string(
 | 
			
		||||
    GBinderReader* reader)
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT;
 | 
			
		||||
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_reader_read_hidl_string_c(
 | 
			
		||||
    GBinderReader* reader); /* Since 1.0.23 */
 | 
			
		||||
 | 
			
		||||
#define gbinder_reader_skip_hidl_string(reader) \
 | 
			
		||||
    (gbinder_reader_read_hidl_string_c(reader) != NULL)
 | 
			
		||||
 | 
			
		||||
char**
 | 
			
		||||
gbinder_reader_read_hidl_string_vec(
 | 
			
		||||
    GBinderReader* reader);
 | 
			
		||||
@@ -177,8 +184,13 @@ gbinder_reader_read_nullable_string16(
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_reader_read_nullable_string16_utf16(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    gunichar2** out,
 | 
			
		||||
    gsize* len); /* since 1.0.17 */
 | 
			
		||||
    const gunichar2** out,
 | 
			
		||||
    gsize* len); /* Since 1.0.17 */
 | 
			
		||||
 | 
			
		||||
const gunichar2*
 | 
			
		||||
gbinder_reader_read_string16_utf16(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    gsize* len); /* Since 1.0.26 */
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_reader_skip_string16(
 | 
			
		||||
@@ -187,7 +199,7 @@ gbinder_reader_skip_string16(
 | 
			
		||||
const void*
 | 
			
		||||
gbinder_reader_read_byte_array(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    gsize* len); /* since 1.0.12 */
 | 
			
		||||
    gsize* len); /* Since 1.0.12 */
 | 
			
		||||
 | 
			
		||||
gsize
 | 
			
		||||
gbinder_reader_bytes_read(
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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
 | 
			
		||||
@@ -51,6 +51,10 @@ void
 | 
			
		||||
gbinder_remote_object_unref(
 | 
			
		||||
    GBinderRemoteObject* obj);
 | 
			
		||||
 | 
			
		||||
GBinderIpc*
 | 
			
		||||
gbinder_remote_object_ipc(
 | 
			
		||||
    GBinderRemoteObject* obj); /* Since 1.0.30 */
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_remote_object_is_dead(
 | 
			
		||||
    GBinderRemoteObject* obj);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -37,6 +37,12 @@
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
void
 | 
			
		||||
(*GBinderServiceManagerFunc)(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
 | 
			
		||||
/* GBinderServiceManagerListFunc callback returns TRUE to keep the services
 | 
			
		||||
 * list, otherwise the caller will deallocate it. */
 | 
			
		||||
typedef
 | 
			
		||||
@@ -87,6 +93,13 @@ gbinder_servicemanager_new_local_object(
 | 
			
		||||
    GBinderLocalTransactFunc handler,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_servicemanager_new_local_object2(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderLocalTransactFunc handler,
 | 
			
		||||
    void* user_data); /* Since 1.0.29 */
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_servicemanager_ref(
 | 
			
		||||
    GBinderServiceManager* sm);
 | 
			
		||||
@@ -95,6 +108,15 @@ void
 | 
			
		||||
gbinder_servicemanager_unref(
 | 
			
		||||
    GBinderServiceManager* sm);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_servicemanager_is_present(
 | 
			
		||||
    GBinderServiceManager* sm); /* Since 1.0.25 */
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_servicemanager_wait(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    long max_wait_ms); /* Since 1.0.25 */
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_servicemanager_list(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
@@ -137,6 +159,12 @@ gbinder_servicemanager_cancel(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    gulong id);
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_servicemanager_add_presence_handler(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    GBinderServiceManagerFunc func,
 | 
			
		||||
    void* user_data); /* Since 1.0.25 */
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_servicemanager_add_registration_handler(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
@@ -149,6 +177,15 @@ gbinder_servicemanager_remove_handler(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    gulong id); /* Since 1.0.13 */
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_remove_handlers(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    gulong* ids,
 | 
			
		||||
    guint count); /* Since 1.0.25 */
 | 
			
		||||
 | 
			
		||||
#define gbinder_servicemanager_remove_all_handlers(r,ids) \
 | 
			
		||||
    gbinder_servicemanager_remove_handlers(sm, ids, G_N_ELEMENTS(ids))
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_SERVICEMANAGER_H */
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										70
									
								
								include/gbinder_servicename.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								include/gbinder_servicename.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,70 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
 * are met:
 | 
			
		||||
 *
 | 
			
		||||
 *   1. Redistributions of source code must retain the above copyright
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer.
 | 
			
		||||
 *   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 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
 | 
			
		||||
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | 
			
		||||
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
 | 
			
		||||
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 | 
			
		||||
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 | 
			
		||||
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
			
		||||
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
			
		||||
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 | 
			
		||||
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 | 
			
		||||
 * THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef GBINDER_SERVICENAME_H
 | 
			
		||||
#define GBINDER_SERVICENAME_H
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types.h"
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
/* Since 1.0.26 */
 | 
			
		||||
 | 
			
		||||
struct gbinder_servicename {
 | 
			
		||||
    const char* name;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
GBinderServiceName*
 | 
			
		||||
gbinder_servicename_new(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    GBinderLocalObject* object,
 | 
			
		||||
    const char* name);
 | 
			
		||||
 | 
			
		||||
GBinderServiceName*
 | 
			
		||||
gbinder_servicename_ref(
 | 
			
		||||
    GBinderServiceName* name);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicename_unref(
 | 
			
		||||
    GBinderServiceName* name);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_SERVICENAME_H */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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
 | 
			
		||||
@@ -61,6 +61,7 @@ G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_buffer GBinderBuffer;
 | 
			
		||||
typedef struct gbinder_client GBinderClient;
 | 
			
		||||
typedef struct gbinder_ipc GBinderIpc;
 | 
			
		||||
typedef struct gbinder_local_object GBinderLocalObject;
 | 
			
		||||
typedef struct gbinder_local_reply GBinderLocalReply;
 | 
			
		||||
typedef struct gbinder_local_request GBinderLocalRequest;
 | 
			
		||||
@@ -68,6 +69,7 @@ typedef struct gbinder_reader GBinderReader;
 | 
			
		||||
typedef struct gbinder_remote_object GBinderRemoteObject;
 | 
			
		||||
typedef struct gbinder_remote_reply GBinderRemoteReply;
 | 
			
		||||
typedef struct gbinder_remote_request GBinderRemoteRequest;
 | 
			
		||||
typedef struct gbinder_servicename GBinderServiceName;
 | 
			
		||||
typedef struct gbinder_servicemanager GBinderServiceManager;
 | 
			
		||||
typedef struct gbinder_writer GBinderWriter;
 | 
			
		||||
typedef struct gbinder_parent GBinderParent;
 | 
			
		||||
 
 | 
			
		||||
@@ -119,6 +119,16 @@ gbinder_writer_append_fd(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    int fd); /* Since 1.0.18 */
 | 
			
		||||
 | 
			
		||||
gsize
 | 
			
		||||
gbinder_writer_bytes_written(
 | 
			
		||||
    GBinderWriter* writer); /* since 1.0.21 */
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_overwrite_int32(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    gsize offset,
 | 
			
		||||
    gint32 value); /* since 1.0.21 */
 | 
			
		||||
 | 
			
		||||
guint
 | 
			
		||||
gbinder_writer_append_buffer_object_with_parent(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,14 @@
 | 
			
		||||
Name: libgbinder
 | 
			
		||||
Version: 1.0.20
 | 
			
		||||
Version: 1.0.35
 | 
			
		||||
Release: 0
 | 
			
		||||
Summary: Binder client library
 | 
			
		||||
Group: Development/Libraries
 | 
			
		||||
License: BSD
 | 
			
		||||
URL: https://github.com/mer-hybris/libgbinder
 | 
			
		||||
Source: %{name}-%{version}.tar.bz2
 | 
			
		||||
Requires: libglibutil >= 1.0.34
 | 
			
		||||
Requires: libglibutil >= 1.0.35
 | 
			
		||||
BuildRequires: pkgconfig(glib-2.0)
 | 
			
		||||
BuildRequires: pkgconfig(libglibutil) >= 1.0.34
 | 
			
		||||
BuildRequires: pkgconfig(libglibutil) >= 1.0.35
 | 
			
		||||
Requires(post): /sbin/ldconfig
 | 
			
		||||
Requires(postun): /sbin/ldconfig
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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
 | 
			
		||||
@@ -176,6 +176,13 @@ gbinder_client_unref(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_client_interface(
 | 
			
		||||
    GBinderClient* self) /* since 1.0.22 */
 | 
			
		||||
{
 | 
			
		||||
    return G_LIKELY(self) ? gbinder_client_cast(self)->iface : NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_client_new_request(
 | 
			
		||||
    GBinderClient* self)
 | 
			
		||||
@@ -198,12 +205,15 @@ gbinder_client_transact_sync_reply(
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderRemoteObject* obj = self->remote;
 | 
			
		||||
 | 
			
		||||
        if (!req) {
 | 
			
		||||
            /* Default empty request (just the header, no parameters) */
 | 
			
		||||
            req = gbinder_client_cast(self)->basic_req;
 | 
			
		||||
        if (G_LIKELY(!obj->dead)) {
 | 
			
		||||
            if (!req) {
 | 
			
		||||
                /* Default empty request (just the header, no parameters) */
 | 
			
		||||
                req = gbinder_client_cast(self)->basic_req;
 | 
			
		||||
            }
 | 
			
		||||
            return gbinder_ipc_transact_sync_reply(obj->ipc, obj->handle,
 | 
			
		||||
                code, req, status);
 | 
			
		||||
        }
 | 
			
		||||
        return gbinder_ipc_transact_sync_reply(obj->ipc, obj->handle,
 | 
			
		||||
            code, req, status);
 | 
			
		||||
        GDEBUG("Refusing to perform transaction with a dead object");
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
@@ -217,15 +227,18 @@ gbinder_client_transact_sync_oneway(
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderRemoteObject* obj = self->remote;
 | 
			
		||||
 | 
			
		||||
        if (!req) {
 | 
			
		||||
            /* Default empty request (just the header, no parameters) */
 | 
			
		||||
            req = gbinder_client_cast(self)->basic_req;
 | 
			
		||||
        if (G_LIKELY(!obj->dead)) {
 | 
			
		||||
            if (!req) {
 | 
			
		||||
                /* Default empty request (just the header, no parameters) */
 | 
			
		||||
                req = gbinder_client_cast(self)->basic_req;
 | 
			
		||||
            }
 | 
			
		||||
            return gbinder_ipc_transact_sync_oneway(obj->ipc, obj->handle,
 | 
			
		||||
                code, req);
 | 
			
		||||
        }
 | 
			
		||||
        return gbinder_ipc_transact_sync_oneway(obj->ipc, obj->handle,
 | 
			
		||||
            code, req);
 | 
			
		||||
    } else {
 | 
			
		||||
        return (-EINVAL);
 | 
			
		||||
        GDEBUG("Refusing to perform transaction with a dead object");
 | 
			
		||||
        return (-ESTALE);
 | 
			
		||||
    }
 | 
			
		||||
    return (-EINVAL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
@@ -240,23 +253,27 @@ gbinder_client_transact(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderRemoteObject* obj = self->remote;
 | 
			
		||||
        GBinderClientTx* tx = g_slice_new0(GBinderClientTx);
 | 
			
		||||
 | 
			
		||||
        tx->client = gbinder_client_ref(self);
 | 
			
		||||
        tx->reply = reply;
 | 
			
		||||
        tx->destroy = destroy;
 | 
			
		||||
        tx->user_data = user_data;
 | 
			
		||||
        if (G_LIKELY(!obj->dead)) {
 | 
			
		||||
            GBinderClientTx* tx = g_slice_new0(GBinderClientTx);
 | 
			
		||||
 | 
			
		||||
        if (!req) {
 | 
			
		||||
            /* Default empty request (just the header, no parameters) */
 | 
			
		||||
            req = gbinder_client_cast(self)->basic_req;
 | 
			
		||||
            tx->client = gbinder_client_ref(self);
 | 
			
		||||
            tx->reply = reply;
 | 
			
		||||
            tx->destroy = destroy;
 | 
			
		||||
            tx->user_data = user_data;
 | 
			
		||||
 | 
			
		||||
            if (!req) {
 | 
			
		||||
                /* Default empty request (just the header, no parameters) */
 | 
			
		||||
                req = gbinder_client_cast(self)->basic_req;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return gbinder_ipc_transact(obj->ipc, obj->handle, code,
 | 
			
		||||
                flags, req, gbinder_client_transact_reply,
 | 
			
		||||
                gbinder_client_transact_destroy, tx);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return gbinder_ipc_transact(obj->ipc, obj->handle, code, flags, req,
 | 
			
		||||
            gbinder_client_transact_reply, gbinder_client_transact_destroy, tx);
 | 
			
		||||
    } else {
 | 
			
		||||
        return 0;
 | 
			
		||||
        GDEBUG("Refusing to perform transaction with a dead object");
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -76,8 +76,6 @@ enum gbinder_defaultservicemanager_calls {
 | 
			
		||||
    LIST_SERVICES_TRANSACTION
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* As a special case, ServiceManager's handle is zero */
 | 
			
		||||
#define DEFAULTSERVICEMANAGER_HANDLE (0)
 | 
			
		||||
#define DEFAULTSERVICEMANAGER_IFACE  "android.os.IServiceManager"
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
@@ -301,7 +299,6 @@ void
 | 
			
		||||
gbinder_defaultservicemanager_class_init(
 | 
			
		||||
    GBinderDefaultServiceManagerClass* klass)
 | 
			
		||||
{
 | 
			
		||||
    klass->handle = DEFAULTSERVICEMANAGER_HANDLE;
 | 
			
		||||
    klass->iface = DEFAULTSERVICEMANAGER_IFACE;
 | 
			
		||||
    klass->default_device = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    klass->rpc_protocol = &gbinder_rpc_protocol_binder;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -288,19 +288,15 @@ gbinder_driver_death_notification(
 | 
			
		||||
    guint32 cmd,
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(obj)) {
 | 
			
		||||
        GBinderIoBuf write;
 | 
			
		||||
        guint8 buf[4 + GBINDER_MAX_DEATH_NOTIFICATION_SIZE];
 | 
			
		||||
        guint32* data = (guint32*)buf;
 | 
			
		||||
    GBinderIoBuf write;
 | 
			
		||||
    guint8 buf[4 + GBINDER_MAX_DEATH_NOTIFICATION_SIZE];
 | 
			
		||||
    guint32* data = (guint32*)buf;
 | 
			
		||||
 | 
			
		||||
        data[0] = cmd;
 | 
			
		||||
        memset(&write, 0, sizeof(write));
 | 
			
		||||
        write.ptr = (uintptr_t)buf;
 | 
			
		||||
        write.size = 4 + self->io->encode_death_notification(data + 1, obj);
 | 
			
		||||
 | 
			
		||||
        return gbinder_driver_write(self, &write) >= 0;
 | 
			
		||||
    }
 | 
			
		||||
    return FALSE;
 | 
			
		||||
    data[0] = cmd;
 | 
			
		||||
    memset(&write, 0, sizeof(write));
 | 
			
		||||
    write.ptr = (uintptr_t)buf;
 | 
			
		||||
    write.size = 4 + self->io->encode_death_notification(data + 1, obj);
 | 
			
		||||
    return gbinder_driver_write(self, &write) >= 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -458,7 +454,7 @@ gbinder_driver_handle_transaction(
 | 
			
		||||
            &status);
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        GWARN("Unhandled transaction 0x%08x", tx.code);
 | 
			
		||||
        GWARN("Unhandled transaction %s 0x%08x", iface, tx.code);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -535,6 +531,7 @@ gbinder_driver_handle_command(
 | 
			
		||||
    } else if (cmd == io->br.transaction) {
 | 
			
		||||
        gbinder_driver_handle_transaction(self, reg, handler, data);
 | 
			
		||||
    } else if (cmd == io->br.dead_binder) {
 | 
			
		||||
        guint8 buf[4 + GBINDER_MAX_PTR_COOKIE_SIZE];
 | 
			
		||||
        guint64 handle = 0;
 | 
			
		||||
        GBinderRemoteObject* obj;
 | 
			
		||||
 | 
			
		||||
@@ -545,6 +542,8 @@ gbinder_driver_handle_command(
 | 
			
		||||
            gbinder_remote_object_handle_death_notification(obj);
 | 
			
		||||
            gbinder_remote_object_unref(obj);
 | 
			
		||||
        }
 | 
			
		||||
        GVERBOSE("< BC_DEAD_BINDER_DONE %llu", (long long unsigned int)handle);
 | 
			
		||||
        gbinder_driver_cmd_data(self, io->bc.dead_binder_done, data, buf);
 | 
			
		||||
    } else if (cmd == io->br.clear_death_notification_done) {
 | 
			
		||||
        GVERBOSE("> BR_CLEAR_DEATH_NOTIFICATION_DONE");
 | 
			
		||||
    } else {
 | 
			
		||||
@@ -812,8 +811,13 @@ gbinder_driver_request_death_notification(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_driver_death_notification
 | 
			
		||||
        (self, self->io->bc.request_death_notification, obj);
 | 
			
		||||
    if (G_LIKELY(obj)) {
 | 
			
		||||
        GVERBOSE("< BC_REQUEST_DEATH_NOTIFICATION 0x%08x", obj->handle);
 | 
			
		||||
        return gbinder_driver_death_notification(self,
 | 
			
		||||
            self->io->bc.request_death_notification, obj);
 | 
			
		||||
    } else {
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
@@ -821,8 +825,13 @@ gbinder_driver_clear_death_notification(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_driver_death_notification
 | 
			
		||||
        (self, self->io->bc.clear_death_notification, obj);
 | 
			
		||||
    if (G_LIKELY(obj)) {
 | 
			
		||||
        GVERBOSE("< BC_CLEAR_DEATH_NOTIFICATION 0x%08x", obj->handle);
 | 
			
		||||
        return gbinder_driver_death_notification(self,
 | 
			
		||||
            self->io->bc.clear_death_notification, obj);
 | 
			
		||||
    } else {
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
@@ -1038,6 +1047,28 @@ gbinder_driver_transact(
 | 
			
		||||
    return txstatus;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_driver_ping(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
{
 | 
			
		||||
    const GBinderRpcProtocol* protocol = self->protocol;
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_local_request_new(self->io, NULL);
 | 
			
		||||
    GBinderRemoteReply* reply = gbinder_remote_reply_new(reg);
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
    int ret;
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_init_writer(req, &writer);
 | 
			
		||||
    protocol->write_ping(&writer);
 | 
			
		||||
    ret = gbinder_driver_transact(self, reg, handle, protocol->ping_tx,
 | 
			
		||||
        req, reply);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    gbinder_remote_reply_unref(reply);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_driver_local_request_new(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -131,6 +131,12 @@ gbinder_driver_transact(
 | 
			
		||||
    GBinderLocalRequest* request,
 | 
			
		||||
    GBinderRemoteReply* reply);
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_driver_ping(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    guint32 handle);
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_driver_local_request_new(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -80,8 +80,6 @@ enum gbinder_hwservicemanager_notifications {
 | 
			
		||||
    ON_REGISTRATION_TRANSACTION = GBINDER_FIRST_CALL_TRANSACTION
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* As a special case, ServiceManager's handle is zero */
 | 
			
		||||
#define HWSERVICEMANAGER_HANDLE (0)
 | 
			
		||||
#define HWSERVICEMANAGER_IFACE  "android.hidl.manager@1.0::IServiceManager"
 | 
			
		||||
#define HWSERVICEMANAGER_NOTIFICATION_IFACE \
 | 
			
		||||
    "android.hidl.manager@1.0::IServiceNotification"
 | 
			
		||||
@@ -378,7 +376,6 @@ void
 | 
			
		||||
gbinder_hwservicemanager_class_init(
 | 
			
		||||
    GBinderHwServiceManagerClass* klass)
 | 
			
		||||
{
 | 
			
		||||
    klass->handle = HWSERVICEMANAGER_HANDLE;
 | 
			
		||||
    klass->iface = HWSERVICEMANAGER_IFACE;
 | 
			
		||||
    klass->default_device = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    klass->rpc_protocol = &gbinder_rpc_protocol_hwbinder;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -128,9 +128,13 @@ GBINDER_IO_FN(encode_local_object)(
 | 
			
		||||
    struct flat_binder_object* dest = out;
 | 
			
		||||
 | 
			
		||||
    memset(dest, 0, sizeof(*dest));
 | 
			
		||||
    dest->hdr.type = obj ? BINDER_TYPE_BINDER : BINDER_TYPE_WEAK_HANDLE;
 | 
			
		||||
    dest->flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
 | 
			
		||||
    dest->binder = (uintptr_t)obj;
 | 
			
		||||
    if (obj) {
 | 
			
		||||
        dest->hdr.type = BINDER_TYPE_BINDER;
 | 
			
		||||
        dest->flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
 | 
			
		||||
        dest->binder = (uintptr_t)obj;
 | 
			
		||||
    } else {
 | 
			
		||||
        dest->hdr.type = BINDER_TYPE_WEAK_BINDER;
 | 
			
		||||
    }
 | 
			
		||||
    return sizeof(*dest);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -409,7 +413,7 @@ guint
 | 
			
		||||
GBINDER_IO_FN(decode_buffer_object)(
 | 
			
		||||
    GBinderBuffer* buf,
 | 
			
		||||
    gsize offset,
 | 
			
		||||
    GBinderBuffer** out)
 | 
			
		||||
    GBinderIoBufferObject* out)
 | 
			
		||||
{
 | 
			
		||||
    const void* data = (guint8*)buf->data + offset;
 | 
			
		||||
    const gsize size = (offset < buf->size) ? (buf->size - offset) : 0;
 | 
			
		||||
@@ -417,12 +421,14 @@ GBINDER_IO_FN(decode_buffer_object)(
 | 
			
		||||
 | 
			
		||||
    if (size >= sizeof(*flat) && flat->hdr.type == BINDER_TYPE_PTR) {
 | 
			
		||||
        if (out) {
 | 
			
		||||
            *out = gbinder_buffer_new_with_parent(buf,
 | 
			
		||||
                (void*)(uintptr_t)flat->buffer, flat->length);
 | 
			
		||||
            out->data = (void*)(uintptr_t)flat->buffer;
 | 
			
		||||
            out->size = (gsize)flat->length;
 | 
			
		||||
            out->parent_offset = (gsize)flat->parent_offset;
 | 
			
		||||
            out->has_parent = (flat->flags & BINDER_BUFFER_FLAG_HAS_PARENT) ?
 | 
			
		||||
                TRUE : FALSE;
 | 
			
		||||
        }
 | 
			
		||||
        return sizeof(*flat);
 | 
			
		||||
    }
 | 
			
		||||
    if (out) *out = NULL;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -43,6 +43,13 @@ typedef struct gbinder_io_buf {
 | 
			
		||||
    gsize consumed;
 | 
			
		||||
} GBinderIoBuf;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_io_buffer_object {
 | 
			
		||||
    void* data;
 | 
			
		||||
    gsize size;
 | 
			
		||||
    gsize parent_offset;
 | 
			
		||||
    gboolean has_parent;
 | 
			
		||||
} GBinderIoBufferObject;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_io_tx_data {
 | 
			
		||||
    int status;
 | 
			
		||||
    guint32 code;
 | 
			
		||||
@@ -165,9 +172,9 @@ struct gbinder_io {
 | 
			
		||||
    void* (*decode_binder_ptr_cookie)(const void* data);
 | 
			
		||||
    guint (*decode_cookie)(const void* data, guint64* cookie);
 | 
			
		||||
    guint (*decode_binder_object)(const void* data, gsize size,
 | 
			
		||||
       GBinderObjectRegistry* reg, GBinderRemoteObject** obj);
 | 
			
		||||
        GBinderObjectRegistry* reg, GBinderRemoteObject** obj);
 | 
			
		||||
    guint (*decode_buffer_object)(GBinderBuffer* buf, gsize offset,
 | 
			
		||||
        GBinderBuffer** out);
 | 
			
		||||
        GBinderIoBufferObject* out);
 | 
			
		||||
    guint (*decode_fd_object)(const void* data, gsize size, int* fd);
 | 
			
		||||
 | 
			
		||||
    /* ioctl wrappers */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -14,8 +14,8 @@
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer in the
 | 
			
		||||
 *      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.
 | 
			
		||||
 *      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
 | 
			
		||||
@@ -87,7 +87,7 @@ static GHashTable* gbinder_ipc_table = NULL;
 | 
			
		||||
static pthread_mutex_t gbinder_ipc_mutex = PTHREAD_MUTEX_INITIALIZER;
 | 
			
		||||
 | 
			
		||||
#define GBINDER_IPC_MAX_TX_THREADS (15)
 | 
			
		||||
#define GBINDER_IPC_MAX_LOOPERS (15)
 | 
			
		||||
#define GBINDER_IPC_MAX_PRIMARY_LOOPERS (5)
 | 
			
		||||
#define GBINDER_IPC_LOOPER_START_TIMEOUT_SEC (2)
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
@@ -173,6 +173,7 @@ typedef struct gbinder_ipc_tx_priv {
 | 
			
		||||
    GBinderIpcTxPrivFunc fn_exec;
 | 
			
		||||
    GBinderIpcTxPrivFunc fn_done;
 | 
			
		||||
    GBinderIpcTxPrivFunc fn_free;
 | 
			
		||||
    GSource* completion;
 | 
			
		||||
} GBinderIpcTxPriv;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_ipc_tx_internal {
 | 
			
		||||
@@ -358,6 +359,48 @@ gbinder_remote_request_complete(
 | 
			
		||||
 * GBinderIpcLooper
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_looper_free(
 | 
			
		||||
    GBinderIpcLooper* looper)
 | 
			
		||||
{
 | 
			
		||||
    if (looper->thread) {
 | 
			
		||||
        g_thread_unref(looper->thread);
 | 
			
		||||
    }
 | 
			
		||||
    close(looper->pipefd[0]);
 | 
			
		||||
    close(looper->pipefd[1]);
 | 
			
		||||
    if (looper->txfd[0] >= 0) {
 | 
			
		||||
        close(looper->txfd[0]);
 | 
			
		||||
        close(looper->txfd[1]);
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_driver_unref(looper->driver);
 | 
			
		||||
    g_free(looper->name);
 | 
			
		||||
    g_cond_clear(&looper->start_cond);
 | 
			
		||||
    g_mutex_clear(&looper->mutex);
 | 
			
		||||
    g_slice_free(GBinderIpcLooper, looper);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderIpcLooper*
 | 
			
		||||
gbinder_ipc_looper_ref(
 | 
			
		||||
    GBinderIpcLooper* looper)
 | 
			
		||||
{
 | 
			
		||||
    GASSERT(looper->refcount > 0);
 | 
			
		||||
    g_atomic_int_inc(&looper->refcount);
 | 
			
		||||
    return looper;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_looper_unref(
 | 
			
		||||
    GBinderIpcLooper* looper)
 | 
			
		||||
{
 | 
			
		||||
    GASSERT(looper->refcount > 0);
 | 
			
		||||
    if (g_atomic_int_dec_and_test(&looper->refcount)) {
 | 
			
		||||
        gbinder_ipc_looper_free(looper);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_ipc_looper_tx_handle(
 | 
			
		||||
@@ -442,6 +485,25 @@ gbinder_ipc_looper_tx_done(
 | 
			
		||||
    gbinder_ipc_looper_tx_unref(data, FALSE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_looper_start(
 | 
			
		||||
    GBinderIpcLooper* looper)
 | 
			
		||||
{
 | 
			
		||||
    if (!g_atomic_int_get(&looper->started)) {
 | 
			
		||||
        /* Lock */
 | 
			
		||||
        g_mutex_lock(&looper->mutex);
 | 
			
		||||
        if (!g_atomic_int_get(&looper->started)) {
 | 
			
		||||
            g_cond_wait_until(&looper->start_cond, &looper->mutex,
 | 
			
		||||
                g_get_monotonic_time() + GBINDER_IPC_LOOPER_START_TIMEOUT_SEC *
 | 
			
		||||
                    G_TIME_SPAN_SECOND);
 | 
			
		||||
            GASSERT(g_atomic_int_get(&looper->started));
 | 
			
		||||
        }
 | 
			
		||||
        g_mutex_unlock(&looper->mutex);
 | 
			
		||||
        /* Unlock */
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_ipc_looper_remove_from_list(
 | 
			
		||||
@@ -488,6 +550,18 @@ gbinder_ipc_looper_remove_blocked(
 | 
			
		||||
        &looper->ipc->priv->blocked_loopers);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
gbinder_ipc_looper_count_primary(
 | 
			
		||||
    GBinderIpcLooper* looper)
 | 
			
		||||
{
 | 
			
		||||
    const GBinderIpcLooper* ptr = looper->ipc->priv->primary_loopers;
 | 
			
		||||
    guint n = 0;
 | 
			
		||||
 | 
			
		||||
    for (n = 0; ptr; ptr = ptr->next) n++;
 | 
			
		||||
    return n;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_ipc_looper_transact(
 | 
			
		||||
@@ -514,12 +588,12 @@ gbinder_ipc_looper_transact(
 | 
			
		||||
        struct pollfd fds[2];
 | 
			
		||||
        guint8 done = 0;
 | 
			
		||||
        GSource* source = g_idle_source_new();
 | 
			
		||||
        gboolean was_blocked = FALSE;
 | 
			
		||||
 | 
			
		||||
        /* Let GBinderLocalObject handle the transaction on the main thread */
 | 
			
		||||
        g_source_set_callback(source, gbinder_ipc_looper_tx_handle,
 | 
			
		||||
            gbinder_ipc_looper_tx_ref(tx), gbinder_ipc_looper_tx_done);
 | 
			
		||||
        g_source_attach(source, priv->context);
 | 
			
		||||
        g_source_unref(source);
 | 
			
		||||
 | 
			
		||||
        /* Wait for either transaction completion or looper shutdown */
 | 
			
		||||
        memset(fds, 0, sizeof(fds));
 | 
			
		||||
@@ -543,29 +617,35 @@ gbinder_ipc_looper_transact(
 | 
			
		||||
                 * moved to the blocked_loopers list.
 | 
			
		||||
                 */
 | 
			
		||||
                GBinderIpcPriv* priv = looper->ipc->priv;
 | 
			
		||||
                GBinderIpcLooper* new_looper = NULL;
 | 
			
		||||
 | 
			
		||||
                /* Lock */
 | 
			
		||||
                g_mutex_lock(&priv->looper_mutex);
 | 
			
		||||
                if (gbinder_ipc_looper_remove_primary(looper)) {
 | 
			
		||||
                    GBinderIpcLooper* new_looper;
 | 
			
		||||
 | 
			
		||||
                    GDEBUG("Primary looper %s is blocked", looper->name);
 | 
			
		||||
                    looper->next = priv->blocked_loopers;
 | 
			
		||||
                    priv->blocked_loopers = looper;
 | 
			
		||||
                    was_blocked = TRUE;
 | 
			
		||||
 | 
			
		||||
                    /* Looper will exit once transaction completes */
 | 
			
		||||
                    g_atomic_int_set(&looper->exit, 1);
 | 
			
		||||
 | 
			
		||||
                    /* Create new primary looper to replace this one */
 | 
			
		||||
                    new_looper = gbinder_ipc_looper_new(ipc);
 | 
			
		||||
                    if (new_looper) {
 | 
			
		||||
                        new_looper->next = priv->primary_loopers;
 | 
			
		||||
                        priv->primary_loopers = new_looper;
 | 
			
		||||
                    /* If there's no more primary loopers left, create one */
 | 
			
		||||
                    if (!priv->primary_loopers) {
 | 
			
		||||
                        new_looper = gbinder_ipc_looper_new(ipc);
 | 
			
		||||
                        if (new_looper) {
 | 
			
		||||
                            /* Will unref it after it gets started */
 | 
			
		||||
                            gbinder_ipc_looper_ref(new_looper);
 | 
			
		||||
                            priv->primary_loopers = new_looper;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                g_mutex_unlock(&priv->looper_mutex);
 | 
			
		||||
                /* Unlock */
 | 
			
		||||
 | 
			
		||||
                if (new_looper) {
 | 
			
		||||
                    /* Wait until it gets started */
 | 
			
		||||
                    gbinder_ipc_looper_start(new_looper);
 | 
			
		||||
                    gbinder_ipc_looper_unref(new_looper);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                /* Block until asynchronous transaction gets completed. */
 | 
			
		||||
                done = 0;
 | 
			
		||||
                memset(fds, 0, sizeof(fds));
 | 
			
		||||
@@ -576,10 +656,12 @@ gbinder_ipc_looper_transact(
 | 
			
		||||
                poll(fds, 2, -1);
 | 
			
		||||
                if ((fds[1].revents & POLLIN) &&
 | 
			
		||||
                    read(fds[1].fd, &done, sizeof(done)) == 1) {
 | 
			
		||||
                    GDEBUG("Looper %s is released", looper->name);
 | 
			
		||||
                    GASSERT(done == TX_DONE);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (done) {
 | 
			
		||||
            GASSERT(done == TX_DONE);
 | 
			
		||||
            reply = gbinder_local_reply_ref(tx->reply);
 | 
			
		||||
@@ -596,53 +678,32 @@ gbinder_ipc_looper_transact(
 | 
			
		||||
        } else {
 | 
			
		||||
            gbinder_ipc_looper_tx_unref(tx, FALSE);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        g_source_destroy(source);
 | 
			
		||||
        g_source_unref(source);
 | 
			
		||||
 | 
			
		||||
        if (was_blocked) {
 | 
			
		||||
            guint n;
 | 
			
		||||
 | 
			
		||||
            g_mutex_lock(&priv->looper_mutex);
 | 
			
		||||
            n = gbinder_ipc_looper_count_primary(looper);
 | 
			
		||||
            if (n >= GBINDER_IPC_MAX_PRIMARY_LOOPERS) {
 | 
			
		||||
                /* Looper will exit once transaction completes */
 | 
			
		||||
                GDEBUG("Too many primary loopers (%u)", n);
 | 
			
		||||
                g_atomic_int_set(&looper->exit, 1);
 | 
			
		||||
            } else {
 | 
			
		||||
                /* Move it back to the primary list */
 | 
			
		||||
                gbinder_ipc_looper_remove_blocked(looper);
 | 
			
		||||
                looper->next = priv->primary_loopers;
 | 
			
		||||
                priv->primary_loopers = looper;
 | 
			
		||||
            }
 | 
			
		||||
            g_mutex_unlock(&priv->looper_mutex);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    *result = status;
 | 
			
		||||
    return reply;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_looper_free(
 | 
			
		||||
    GBinderIpcLooper* looper)
 | 
			
		||||
{
 | 
			
		||||
    if (looper->thread) {
 | 
			
		||||
        g_thread_unref(looper->thread);
 | 
			
		||||
    }
 | 
			
		||||
    close(looper->pipefd[0]);
 | 
			
		||||
    close(looper->pipefd[1]);
 | 
			
		||||
    if (looper->txfd[0] >= 0) {
 | 
			
		||||
        close(looper->txfd[0]);
 | 
			
		||||
        close(looper->txfd[1]);
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_driver_unref(looper->driver);
 | 
			
		||||
    g_free(looper->name);
 | 
			
		||||
    g_cond_clear(&looper->start_cond);
 | 
			
		||||
    g_mutex_clear(&looper->mutex);
 | 
			
		||||
    g_slice_free(GBinderIpcLooper, looper);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderIpcLooper*
 | 
			
		||||
gbinder_ipc_looper_ref(
 | 
			
		||||
    GBinderIpcLooper* looper)
 | 
			
		||||
{
 | 
			
		||||
    GASSERT(looper->refcount > 0);
 | 
			
		||||
    g_atomic_int_inc(&looper->refcount);
 | 
			
		||||
    return looper;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_looper_unref(
 | 
			
		||||
    GBinderIpcLooper* looper)
 | 
			
		||||
{
 | 
			
		||||
    GASSERT(looper->refcount > 0);
 | 
			
		||||
    if (g_atomic_int_dec_and_test(&looper->refcount)) {
 | 
			
		||||
        gbinder_ipc_looper_free(looper);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gpointer
 | 
			
		||||
gbinder_ipc_looper_thread(
 | 
			
		||||
@@ -787,27 +848,21 @@ gbinder_ipc_looper_check(
 | 
			
		||||
 | 
			
		||||
            /* Lock */
 | 
			
		||||
            g_mutex_lock(&priv->looper_mutex);
 | 
			
		||||
            if (!priv->primary_loopers) {
 | 
			
		||||
                priv->primary_loopers = gbinder_ipc_looper_new(self);
 | 
			
		||||
            }
 | 
			
		||||
            looper = priv->primary_loopers;
 | 
			
		||||
            if (!looper) {
 | 
			
		||||
                looper = priv->primary_loopers = gbinder_ipc_looper_new(self);
 | 
			
		||||
            if (looper) {
 | 
			
		||||
                gbinder_ipc_looper_ref(looper);
 | 
			
		||||
            }
 | 
			
		||||
            g_mutex_unlock(&priv->looper_mutex);
 | 
			
		||||
            /* Unlock */
 | 
			
		||||
 | 
			
		||||
            /* We are not ready to accept incoming transactions until
 | 
			
		||||
             * looper has started. We may need to wait a bit. */
 | 
			
		||||
            if (looper && !g_atomic_int_get(&looper->started)) {
 | 
			
		||||
                /* Lock */
 | 
			
		||||
                g_mutex_lock(&looper->mutex);
 | 
			
		||||
                if (!g_atomic_int_get(&looper->started)) {
 | 
			
		||||
                    g_cond_wait_until(&looper->start_cond, &looper->mutex,
 | 
			
		||||
                        g_get_monotonic_time() +
 | 
			
		||||
                        GBINDER_IPC_LOOPER_START_TIMEOUT_SEC *
 | 
			
		||||
                        G_TIME_SPAN_SECOND);
 | 
			
		||||
                    GASSERT(g_atomic_int_get(&looper->started));
 | 
			
		||||
                }
 | 
			
		||||
                g_mutex_unlock(&looper->mutex);
 | 
			
		||||
                /* Unlock */
 | 
			
		||||
            if (looper) {
 | 
			
		||||
                gbinder_ipc_looper_start(looper);
 | 
			
		||||
                gbinder_ipc_looper_unref(looper);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -865,8 +920,39 @@ gbinder_ipc_looper_join(
 | 
			
		||||
 * GBinderObjectRegistry
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_invalidate_remote_handle_locked(
 | 
			
		||||
    GBinderIpcPriv* priv,
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
{
 | 
			
		||||
    /* Caller holds priv->remote_objects_mutex */
 | 
			
		||||
    if (priv->remote_objects) {
 | 
			
		||||
        GVERBOSE_("handle %u", handle);
 | 
			
		||||
        g_hash_table_remove(priv->remote_objects, GINT_TO_POINTER(handle));
 | 
			
		||||
        if (g_hash_table_size(priv->remote_objects) == 0) {
 | 
			
		||||
            g_hash_table_unref(priv->remote_objects);
 | 
			
		||||
            priv->remote_objects = NULL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_invalidate_remote_handle(
 | 
			
		||||
    GBinderIpc* self,
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpcPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    /* Lock */
 | 
			
		||||
    g_mutex_lock(&priv->remote_objects_mutex);
 | 
			
		||||
    gbinder_ipc_invalidate_remote_handle_locked(priv, handle);
 | 
			
		||||
    g_mutex_unlock(&priv->remote_objects_mutex);
 | 
			
		||||
    /* Unlock */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Internal function called by gbinder_object_dispose(). Among other things,
 | 
			
		||||
 * Internal functions called by gbinder_object_dispose(). Among other things,
 | 
			
		||||
 * it means that it doesn't have to check GBinderIpc pointer for NULL.
 | 
			
		||||
 *
 | 
			
		||||
 * Note the following scenario (where object may be either local or remote):
 | 
			
		||||
@@ -914,31 +1000,19 @@ gbinder_ipc_remote_object_disposed(
 | 
			
		||||
 | 
			
		||||
    /* Lock */
 | 
			
		||||
    g_mutex_lock(&priv->remote_objects_mutex);
 | 
			
		||||
    if (obj->object.ref_count == 1 && priv->remote_objects) {
 | 
			
		||||
        void* key = GINT_TO_POINTER(obj->handle);
 | 
			
		||||
 | 
			
		||||
        GVERBOSE_("handle %u", obj->handle);
 | 
			
		||||
        GASSERT(g_hash_table_contains(priv->remote_objects, key));
 | 
			
		||||
        g_hash_table_remove(priv->remote_objects, key);
 | 
			
		||||
        if (g_hash_table_size(priv->remote_objects) == 0) {
 | 
			
		||||
            g_hash_table_unref(priv->remote_objects);
 | 
			
		||||
            priv->remote_objects = NULL;
 | 
			
		||||
        }
 | 
			
		||||
    if (obj->object.ref_count == 1) {
 | 
			
		||||
        gbinder_ipc_invalidate_remote_handle_locked(priv, obj->handle);
 | 
			
		||||
    }
 | 
			
		||||
    g_mutex_unlock(&priv->remote_objects_mutex);
 | 
			
		||||
    /* Unlock */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_ipc_new_local_object(
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_register_local_object(
 | 
			
		||||
    GBinderIpc* self,
 | 
			
		||||
    const char* iface,
 | 
			
		||||
    GBinderLocalTransactFunc txproc,
 | 
			
		||||
    void* data)
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpcPriv* priv = self->priv;
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new
 | 
			
		||||
        (self, iface, txproc, data);
 | 
			
		||||
 | 
			
		||||
    /* Lock */
 | 
			
		||||
    g_mutex_lock(&priv->local_objects_mutex);
 | 
			
		||||
@@ -951,7 +1025,6 @@ gbinder_ipc_new_local_object(
 | 
			
		||||
 | 
			
		||||
    GVERBOSE_("%p", obj);
 | 
			
		||||
    gbinder_ipc_looper_check(self);
 | 
			
		||||
    return obj;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -986,7 +1059,8 @@ static
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_ipc_priv_get_remote_object(
 | 
			
		||||
    GBinderIpcPriv* priv,
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    gboolean maybe_dead)
 | 
			
		||||
{
 | 
			
		||||
    GBinderRemoteObject* obj = NULL;
 | 
			
		||||
    void* key = GINT_TO_POINTER(handle);
 | 
			
		||||
@@ -999,7 +1073,11 @@ gbinder_ipc_priv_get_remote_object(
 | 
			
		||||
    if (obj) {
 | 
			
		||||
        gbinder_remote_object_ref(obj);
 | 
			
		||||
    } else {
 | 
			
		||||
        obj = gbinder_remote_object_new(priv->self, handle);
 | 
			
		||||
        /*
 | 
			
		||||
         * If maybe_dead is TRUE, the caller is supposed to try reanimating
 | 
			
		||||
         * the object on the main thread not holding any global locks.
 | 
			
		||||
         */
 | 
			
		||||
        obj = gbinder_remote_object_new(priv->self, handle, maybe_dead);
 | 
			
		||||
        if (!priv->remote_objects) {
 | 
			
		||||
            priv->remote_objects = g_hash_table_new
 | 
			
		||||
                (g_direct_hash, g_direct_equal);
 | 
			
		||||
@@ -1015,10 +1093,11 @@ gbinder_ipc_priv_get_remote_object(
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_ipc_get_remote_object(
 | 
			
		||||
    GBinderIpc* self,
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    gboolean maybe_dead)
 | 
			
		||||
{
 | 
			
		||||
    /* GBinderServiceManager makes sure that GBinderIpc pointer is not NULL */
 | 
			
		||||
    return gbinder_ipc_priv_get_remote_object(self->priv, handle);
 | 
			
		||||
    return gbinder_ipc_priv_get_remote_object(self->priv, handle, maybe_dead);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBINDER_INLINE_FUNC
 | 
			
		||||
@@ -1070,7 +1149,7 @@ gbinder_ipc_object_registry_get_remote(
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_ipc_priv_get_remote_object
 | 
			
		||||
        (gbinder_ipc_priv_from_object_registry(reg), handle);
 | 
			
		||||
        (gbinder_ipc_priv_from_object_registry(reg), handle, FALSE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -1102,6 +1181,38 @@ gbinder_ipc_tx_get_id(
 | 
			
		||||
    return id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_tx_free(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpcTxPriv* tx = data;
 | 
			
		||||
    GBinderIpcTx* pub = &tx->pub;
 | 
			
		||||
    GBinderIpc* self = pub->ipc;
 | 
			
		||||
    GBinderIpcPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    g_source_unref(tx->completion);
 | 
			
		||||
    g_hash_table_remove(priv->tx_table, GINT_TO_POINTER(pub->id));
 | 
			
		||||
    tx->fn_free(tx);
 | 
			
		||||
 | 
			
		||||
    /* This may actually deallocate GBinderIpc object: */
 | 
			
		||||
    gbinder_ipc_unref(self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_ipc_tx_done(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpcTxPriv* tx = data;
 | 
			
		||||
    GBinderIpcTx* pub = &tx->pub;
 | 
			
		||||
 | 
			
		||||
    if (!pub->cancelled) {
 | 
			
		||||
        tx->fn_done(tx);
 | 
			
		||||
    }
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_tx_pub_init(
 | 
			
		||||
@@ -1115,6 +1226,26 @@ gbinder_ipc_tx_pub_init(
 | 
			
		||||
    tx->user_data = user_data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_tx_priv_init(
 | 
			
		||||
    GBinderIpcTxPriv* priv,
 | 
			
		||||
    GBinderIpc* self,
 | 
			
		||||
    gulong id,
 | 
			
		||||
    void* user_data,
 | 
			
		||||
    GBinderIpcTxPrivFunc fn_exec,
 | 
			
		||||
    GBinderIpcTxPrivFunc fn_done,
 | 
			
		||||
    GBinderIpcTxPrivFunc fn_free)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_ipc_tx_pub_init(&priv->pub, self, id, user_data);
 | 
			
		||||
    priv->fn_exec = fn_exec;
 | 
			
		||||
    priv->fn_done = fn_done;
 | 
			
		||||
    priv->fn_free = fn_free;
 | 
			
		||||
    priv->completion = g_idle_source_new();
 | 
			
		||||
    g_source_set_callback(priv->completion, gbinder_ipc_tx_done, priv,
 | 
			
		||||
        gbinder_ipc_tx_free);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
inline
 | 
			
		||||
GBinderIpcTxInternal*
 | 
			
		||||
@@ -1164,14 +1295,19 @@ gbinder_ipc_tx_internal_exec(
 | 
			
		||||
    GBinderObjectRegistry* reg = &self->priv->object_registry;
 | 
			
		||||
 | 
			
		||||
    /* Perform synchronous transaction */
 | 
			
		||||
    tx->reply = gbinder_remote_reply_new(&self->priv->object_registry);
 | 
			
		||||
    tx->status = gbinder_driver_transact(self->driver, reg,
 | 
			
		||||
        tx->handle, tx->code, tx->req, tx->reply);
 | 
			
		||||
    if (tx->status != GBINDER_STATUS_OK &&
 | 
			
		||||
        gbinder_remote_reply_is_empty(tx->reply)) {
 | 
			
		||||
        /* Drop useless reply */
 | 
			
		||||
        gbinder_remote_reply_unref(tx->reply);
 | 
			
		||||
        tx->reply = NULL;
 | 
			
		||||
    if (tx->flags & GBINDER_TX_FLAG_ONEWAY) {
 | 
			
		||||
        tx->status = gbinder_driver_transact(self->driver, reg, tx->handle,
 | 
			
		||||
            tx->code, tx->req, NULL);
 | 
			
		||||
    } else {
 | 
			
		||||
        tx->reply = gbinder_remote_reply_new(&self->priv->object_registry);
 | 
			
		||||
        tx->status = gbinder_driver_transact(self->driver, reg, tx->handle,
 | 
			
		||||
            tx->code, tx->req, tx->reply);
 | 
			
		||||
        if (tx->status != GBINDER_STATUS_OK &&
 | 
			
		||||
            gbinder_remote_reply_is_empty(tx->reply)) {
 | 
			
		||||
            /* Drop useless reply */
 | 
			
		||||
            gbinder_remote_reply_unref(tx->reply);
 | 
			
		||||
            tx->reply = NULL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -1191,10 +1327,9 @@ gbinder_ipc_tx_internal_new(
 | 
			
		||||
    GBinderIpcTxInternal* tx = g_slice_new0(GBinderIpcTxInternal);
 | 
			
		||||
    GBinderIpcTxPriv* priv = &tx->tx;
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_tx_pub_init(&priv->pub, self, id, user_data);
 | 
			
		||||
    priv->fn_exec = gbinder_ipc_tx_internal_exec;
 | 
			
		||||
    priv->fn_done = gbinder_ipc_tx_internal_done;
 | 
			
		||||
    priv->fn_free = gbinder_ipc_tx_internal_free;
 | 
			
		||||
    gbinder_ipc_tx_priv_init(priv, self, id, user_data,
 | 
			
		||||
        gbinder_ipc_tx_internal_exec, gbinder_ipc_tx_internal_done,
 | 
			
		||||
        gbinder_ipc_tx_internal_free);
 | 
			
		||||
 | 
			
		||||
    tx->code = code;
 | 
			
		||||
    tx->flags = flags;
 | 
			
		||||
@@ -1265,10 +1400,9 @@ gbinder_ipc_tx_custom_new(
 | 
			
		||||
    GBinderIpcTxCustom* tx = g_slice_new0(GBinderIpcTxCustom);
 | 
			
		||||
    GBinderIpcTxPriv* priv = &tx->tx;
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_tx_pub_init(&priv->pub, self, id, user_data);
 | 
			
		||||
    priv->fn_exec = gbinder_ipc_tx_custom_exec;
 | 
			
		||||
    priv->fn_done = gbinder_ipc_tx_custom_done;
 | 
			
		||||
    priv->fn_free = gbinder_ipc_tx_custom_free;
 | 
			
		||||
    gbinder_ipc_tx_priv_init(priv, self, id, user_data,
 | 
			
		||||
        gbinder_ipc_tx_custom_exec, gbinder_ipc_tx_custom_done,
 | 
			
		||||
        gbinder_ipc_tx_custom_free);
 | 
			
		||||
 | 
			
		||||
    tx->fn_custom_exec = exec;
 | 
			
		||||
    tx->fn_custom_done = done;
 | 
			
		||||
@@ -1277,41 +1411,6 @@ gbinder_ipc_tx_custom_new(
 | 
			
		||||
    return priv;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_tx_free(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpcTxPriv* tx = data;
 | 
			
		||||
    GBinderIpcTx* pub = &tx->pub;
 | 
			
		||||
    GBinderIpc* self = pub->ipc;
 | 
			
		||||
    GBinderIpcPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    g_hash_table_remove(priv->tx_table, GINT_TO_POINTER(pub->id));
 | 
			
		||||
    tx->fn_free(tx);
 | 
			
		||||
 | 
			
		||||
    /* This may actually deallocate GBinderIpc object: */
 | 
			
		||||
    gbinder_ipc_unref(self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_ipc_tx_done(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpcTxPriv* tx = data;
 | 
			
		||||
    GBinderIpcTx* pub = &tx->pub;
 | 
			
		||||
    GBinderIpc* self = pub->ipc;
 | 
			
		||||
    GBinderIpcPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    if (g_hash_table_remove(priv->tx_table, GINT_TO_POINTER(tx->pub.id))) {
 | 
			
		||||
        GASSERT(!pub->cancelled);
 | 
			
		||||
        tx->fn_done(tx);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Invoked on a thread from tx_pool */
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
@@ -1322,7 +1421,6 @@ gbinder_ipc_tx_proc(
 | 
			
		||||
    GBinderIpcTxPriv* tx = data;
 | 
			
		||||
    GBinderIpc* self = GBINDER_IPC(object);
 | 
			
		||||
    GBinderIpcPriv* priv = self->priv;
 | 
			
		||||
    GSource* source = g_idle_source_new();
 | 
			
		||||
 | 
			
		||||
    if (!tx->pub.cancelled) {
 | 
			
		||||
        tx->fn_exec(tx);
 | 
			
		||||
@@ -1331,9 +1429,7 @@ gbinder_ipc_tx_proc(
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* The result is handled by the main thread */
 | 
			
		||||
    g_source_set_callback(source, gbinder_ipc_tx_done, tx, gbinder_ipc_tx_free);
 | 
			
		||||
    g_source_attach(source, priv->context);
 | 
			
		||||
    g_source_unref(source);
 | 
			
		||||
    g_source_attach(tx->completion, priv->context);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -1510,7 +1606,6 @@ gbinder_ipc_cancel(
 | 
			
		||||
        GBinderIpcTx* tx = g_hash_table_lookup(priv->tx_table, key);
 | 
			
		||||
 | 
			
		||||
        if (tx) {
 | 
			
		||||
            GVERIFY(g_hash_table_remove(priv->tx_table, key));
 | 
			
		||||
            tx->cancelled = TRUE;
 | 
			
		||||
            GVERBOSE_("%lu", id);
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -1550,14 +1645,44 @@ gbinder_ipc_init(
 | 
			
		||||
    self->pool = gutil_idle_pool_new();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_stop_loopers(
 | 
			
		||||
    GBinderIpc* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpcPriv* priv = self->priv;
 | 
			
		||||
    GBinderIpcLooper* loopers = NULL;
 | 
			
		||||
 | 
			
		||||
    do {
 | 
			
		||||
        GBinderIpcLooper* tmp;
 | 
			
		||||
 | 
			
		||||
        /* Lock */
 | 
			
		||||
        g_mutex_lock(&priv->looper_mutex);
 | 
			
		||||
        loopers = gbinder_ipc_looper_stop_all(gbinder_ipc_looper_stop_all(NULL,
 | 
			
		||||
            priv->primary_loopers), priv->blocked_loopers);
 | 
			
		||||
        priv->blocked_loopers = NULL;
 | 
			
		||||
        priv->primary_loopers = NULL;
 | 
			
		||||
        g_mutex_unlock(&priv->looper_mutex);
 | 
			
		||||
        /* Unlock */
 | 
			
		||||
 | 
			
		||||
        tmp = loopers;
 | 
			
		||||
        while (tmp) {
 | 
			
		||||
            GBinderIpcLooper* looper = tmp;
 | 
			
		||||
 | 
			
		||||
            tmp = looper->next;
 | 
			
		||||
            looper->next = NULL;
 | 
			
		||||
            gbinder_ipc_looper_join(looper);
 | 
			
		||||
            gbinder_ipc_looper_unref(looper);
 | 
			
		||||
        }
 | 
			
		||||
    } while (loopers);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_dispose(
 | 
			
		||||
    GObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* self = GBINDER_IPC(object);
 | 
			
		||||
    GBinderIpcPriv* priv = self->priv;
 | 
			
		||||
    GBinderIpcLooper* loopers = NULL;
 | 
			
		||||
 | 
			
		||||
    GVERBOSE_("%s", self->dev);
 | 
			
		||||
    /* Lock */
 | 
			
		||||
@@ -1576,24 +1701,7 @@ gbinder_ipc_dispose(
 | 
			
		||||
    pthread_mutex_unlock(&gbinder_ipc_mutex);
 | 
			
		||||
    /* Unlock */
 | 
			
		||||
 | 
			
		||||
    /* Lock */
 | 
			
		||||
    g_mutex_lock(&priv->looper_mutex);
 | 
			
		||||
    loopers = gbinder_ipc_looper_stop_all(loopers, priv->primary_loopers);
 | 
			
		||||
    loopers = gbinder_ipc_looper_stop_all(loopers, priv->blocked_loopers);
 | 
			
		||||
    priv->blocked_loopers = NULL;
 | 
			
		||||
    priv->primary_loopers = NULL;
 | 
			
		||||
    g_mutex_unlock(&priv->looper_mutex);
 | 
			
		||||
    /* Unlock */
 | 
			
		||||
 | 
			
		||||
    while (loopers) {
 | 
			
		||||
        GBinderIpcLooper* looper = loopers;
 | 
			
		||||
 | 
			
		||||
        loopers = looper->next;
 | 
			
		||||
        looper->next = NULL;
 | 
			
		||||
        gbinder_ipc_looper_join(looper);
 | 
			
		||||
        gbinder_ipc_looper_unref(looper);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_stop_loopers(self);
 | 
			
		||||
    G_OBJECT_CLASS(gbinder_ipc_parent_class)->finalize(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -1610,7 +1718,9 @@ gbinder_ipc_finalize(
 | 
			
		||||
    g_mutex_clear(&priv->looper_mutex);
 | 
			
		||||
    g_mutex_clear(&priv->local_objects_mutex);
 | 
			
		||||
    g_mutex_clear(&priv->remote_objects_mutex);
 | 
			
		||||
    g_thread_pool_free(priv->tx_pool, FALSE, TRUE);
 | 
			
		||||
    if (priv->tx_pool) {
 | 
			
		||||
        g_thread_pool_free(priv->tx_pool, FALSE, TRUE);
 | 
			
		||||
    }
 | 
			
		||||
    GASSERT(!g_hash_table_size(priv->tx_table));
 | 
			
		||||
    g_hash_table_unref(priv->tx_table);
 | 
			
		||||
    gutil_idle_pool_unref(self->pool);
 | 
			
		||||
@@ -1631,6 +1741,91 @@ gbinder_ipc_class_init(
 | 
			
		||||
    object_class->finalize = gbinder_ipc_finalize;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Runs at exit */
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_exit()
 | 
			
		||||
{
 | 
			
		||||
    GHashTableIter it;
 | 
			
		||||
    gpointer key, value;
 | 
			
		||||
    GSList* ipcs = NULL;
 | 
			
		||||
    GSList* i;
 | 
			
		||||
 | 
			
		||||
    /* Lock */
 | 
			
		||||
    pthread_mutex_lock(&gbinder_ipc_mutex);
 | 
			
		||||
    if (gbinder_ipc_table) {
 | 
			
		||||
        g_hash_table_iter_init(&it, gbinder_ipc_table);
 | 
			
		||||
        while (g_hash_table_iter_next(&it, NULL, &value)) {
 | 
			
		||||
            ipcs = g_slist_append(ipcs, gbinder_ipc_ref(value));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    pthread_mutex_unlock(&gbinder_ipc_mutex);
 | 
			
		||||
    /* Unlock */
 | 
			
		||||
 | 
			
		||||
    for (i = ipcs; i; i = i->next) {
 | 
			
		||||
        GBinderIpc* ipc = GBINDER_IPC(i->data);
 | 
			
		||||
        GBinderIpcPriv* priv = ipc->priv;
 | 
			
		||||
        GThreadPool* pool = priv->tx_pool;
 | 
			
		||||
        GSList* local_objs = NULL;
 | 
			
		||||
        GSList* tx_keys = NULL;
 | 
			
		||||
        GSList* k;
 | 
			
		||||
        GSList* l;
 | 
			
		||||
 | 
			
		||||
        /* Terminate looper threads */
 | 
			
		||||
        GVERBOSE_("%s", ipc->dev);
 | 
			
		||||
        gbinder_ipc_stop_loopers(ipc);
 | 
			
		||||
 | 
			
		||||
        /* Make sure pooled transaction complete too */
 | 
			
		||||
        priv->tx_pool = NULL;
 | 
			
		||||
        g_thread_pool_free(pool, FALSE, TRUE);
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * Since this function is supposed to be invoked on the main thread,
 | 
			
		||||
         * there's no need to synchronize access to priv->tx_table. In any
 | 
			
		||||
         * case, this must be the last thread associated with this object.
 | 
			
		||||
         */
 | 
			
		||||
        g_hash_table_iter_init(&it, priv->tx_table);
 | 
			
		||||
        while (g_hash_table_iter_next(&it, &key, NULL)) {
 | 
			
		||||
            tx_keys = g_slist_append(tx_keys, key);
 | 
			
		||||
        }
 | 
			
		||||
        for (k = tx_keys; k; k = k->next) {
 | 
			
		||||
            GBinderIpcTxPriv* tx = g_hash_table_lookup(priv->tx_table, k->data);
 | 
			
		||||
            GSource* source = g_source_ref(tx->completion);
 | 
			
		||||
 | 
			
		||||
            GVERBOSE_("tx %lu", tx->pub.id);
 | 
			
		||||
            g_source_destroy(source);
 | 
			
		||||
            g_source_unref(source);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* The above loop must destroy all uncompleted transactions */
 | 
			
		||||
        GASSERT(!g_hash_table_size(priv->tx_table));
 | 
			
		||||
        g_slist_free(tx_keys);
 | 
			
		||||
 | 
			
		||||
        /* Lock */
 | 
			
		||||
        g_mutex_lock(&priv->local_objects_mutex);
 | 
			
		||||
        if (priv->local_objects) {
 | 
			
		||||
            g_hash_table_iter_init(&it, priv->local_objects);
 | 
			
		||||
            while (g_hash_table_iter_next(&it, NULL, &value)) {
 | 
			
		||||
                local_objs = g_slist_append(local_objs,
 | 
			
		||||
                    gbinder_local_object_ref(value));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        g_mutex_unlock(&priv->local_objects_mutex);
 | 
			
		||||
        /* Unlock */
 | 
			
		||||
 | 
			
		||||
        /* Drop remote references */
 | 
			
		||||
        for (l = local_objs; l; l = l->next) {
 | 
			
		||||
            GBinderLocalObject* obj = GBINDER_LOCAL_OBJECT(l->data);
 | 
			
		||||
 | 
			
		||||
            while (obj->strong_refs > 0) {
 | 
			
		||||
                obj->strong_refs--;
 | 
			
		||||
                gbinder_local_object_unref(obj);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        g_slist_free_full(local_objs, g_object_unref);
 | 
			
		||||
    }
 | 
			
		||||
    g_slist_free_full(ipcs, g_object_unref);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -68,39 +68,52 @@ void
 | 
			
		||||
    int status,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
GBinderIpc*
 | 
			
		||||
gbinder_ipc_new(
 | 
			
		||||
   const char* dev,
 | 
			
		||||
   const GBinderRpcProtocol* protocol);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
GBinderIpc*
 | 
			
		||||
gbinder_ipc_ref(
 | 
			
		||||
    GBinderIpc* ipc);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_unref(
 | 
			
		||||
    GBinderIpc* ipc);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_looper_check(
 | 
			
		||||
   GBinderIpc* ipc);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
GBinderObjectRegistry*
 | 
			
		||||
gbinder_ipc_object_registry(
 | 
			
		||||
    GBinderIpc* ipc);
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_ipc_new_local_object(
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_register_local_object(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    const char* iface,
 | 
			
		||||
    GBinderLocalTransactFunc txproc,
 | 
			
		||||
    void* data);
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_ipc_get_remote_object(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    gboolean maybe_dead);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_invalidate_remote_handle(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
GBinderRemoteReply*
 | 
			
		||||
gbinder_ipc_transact_sync_reply(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
@@ -109,6 +122,7 @@ gbinder_ipc_transact_sync_reply(
 | 
			
		||||
    GBinderLocalRequest* req,
 | 
			
		||||
    int* status);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
int
 | 
			
		||||
gbinder_ipc_transact_sync_oneway(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
@@ -116,6 +130,7 @@ gbinder_ipc_transact_sync_oneway(
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    GBinderLocalRequest* req);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_ipc_transact(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
@@ -127,6 +142,7 @@ gbinder_ipc_transact(
 | 
			
		||||
    GDestroyNotify destroy,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_ipc_transact_custom(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
@@ -135,23 +151,33 @@ gbinder_ipc_transact_custom(
 | 
			
		||||
    GDestroyNotify destroy,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_cancel(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    gulong id);
 | 
			
		||||
 | 
			
		||||
/* Internal for GBinderLocalObject */
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_local_object_disposed(
 | 
			
		||||
    GBinderIpc* self,
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
 | 
			
		||||
/* Internal for GBinderRemoteObject */
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_remote_object_disposed(
 | 
			
		||||
    GBinderIpc* self,
 | 
			
		||||
    GBinderRemoteObject* obj);
 | 
			
		||||
 | 
			
		||||
/* Declared for unit tests */
 | 
			
		||||
G_GNUC_INTERNAL
 | 
			
		||||
__attribute__((destructor))
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_exit(
 | 
			
		||||
    void);
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_IPC_H */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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
 | 
			
		||||
@@ -38,11 +38,13 @@
 | 
			
		||||
#include "gbinder_writer.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_strv.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
struct gbinder_local_object_priv {
 | 
			
		||||
    GMainContext* context;
 | 
			
		||||
    char* iface;
 | 
			
		||||
    char** ifaces;
 | 
			
		||||
    GBinderLocalTransactFunc txproc;
 | 
			
		||||
    void* user_data;
 | 
			
		||||
};
 | 
			
		||||
@@ -53,6 +55,13 @@ G_DEFINE_TYPE(GBinderLocalObject, gbinder_local_object, G_TYPE_OBJECT)
 | 
			
		||||
    G_TYPE_INSTANCE_GET_CLASS((obj), GBINDER_TYPE_LOCAL_OBJECT, \
 | 
			
		||||
    GBinderLocalObjectClass)
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
(*GBinderLocalObjectTxHandler)(
 | 
			
		||||
    GBinderLocalObject* self,
 | 
			
		||||
    GBinderRemoteRequest* req,
 | 
			
		||||
    int* status);
 | 
			
		||||
 | 
			
		||||
enum gbinder_local_object_signal {
 | 
			
		||||
    SIGNAL_WEAK_REFS_CHANGED,
 | 
			
		||||
    SIGNAL_STRONG_REFS_CHANGED,
 | 
			
		||||
@@ -78,6 +87,9 @@ gbinder_local_object_default_can_handle_transaction(
 | 
			
		||||
    guint code)
 | 
			
		||||
{
 | 
			
		||||
    switch (code) {
 | 
			
		||||
    case GBINDER_PING_TRANSACTION:
 | 
			
		||||
    case GBINDER_INTERFACE_TRANSACTION:
 | 
			
		||||
        return GBINDER_LOCAL_TRANSACTION_LOOPER;
 | 
			
		||||
    case HIDL_PING_TRANSACTION:
 | 
			
		||||
    case HIDL_GET_DESCRIPTOR_TRANSACTION:
 | 
			
		||||
    case HIDL_DESCRIPTOR_CHAIN_TRANSACTION:
 | 
			
		||||
@@ -110,6 +122,39 @@ gbinder_local_object_default_handle_transaction(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_local_object_ping_transaction(
 | 
			
		||||
    GBinderLocalObject* self,
 | 
			
		||||
    GBinderRemoteRequest* req,
 | 
			
		||||
    int* status)
 | 
			
		||||
{
 | 
			
		||||
    const GBinderIo* io = gbinder_local_object_io(self);
 | 
			
		||||
    GBinderLocalReply* reply = gbinder_local_reply_new(io);
 | 
			
		||||
 | 
			
		||||
    GVERBOSE("  PING_TRANSACTION");
 | 
			
		||||
    gbinder_local_reply_append_int32(reply, GBINDER_STATUS_OK);
 | 
			
		||||
    *status = GBINDER_STATUS_OK;
 | 
			
		||||
    return reply;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_local_object_interface_transaction(
 | 
			
		||||
    GBinderLocalObject* self,
 | 
			
		||||
    GBinderRemoteRequest* req,
 | 
			
		||||
    int* status)
 | 
			
		||||
{
 | 
			
		||||
    const GBinderIo* io = gbinder_local_object_io(self);
 | 
			
		||||
    GBinderLocalObjectPriv* priv = self->priv;
 | 
			
		||||
    GBinderLocalReply* reply = gbinder_local_reply_new(io);
 | 
			
		||||
 | 
			
		||||
    GVERBOSE("  INTERFACE_TRANSACTION");
 | 
			
		||||
    gbinder_local_reply_append_string16(reply, priv->ifaces[0]);
 | 
			
		||||
    *status = GBINDER_STATUS_OK;
 | 
			
		||||
    return reply;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_local_object_hidl_ping_transaction(
 | 
			
		||||
@@ -120,12 +165,10 @@ gbinder_local_object_hidl_ping_transaction(
 | 
			
		||||
    /*android.hidl.base@1.0::IBase interfaceDescriptor() */
 | 
			
		||||
    const GBinderIo* io = gbinder_local_object_io(self);
 | 
			
		||||
    GBinderLocalReply* reply = gbinder_local_reply_new(io);
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
 | 
			
		||||
    GVERBOSE("  HIDL_PING_TRANSACTION \"%s\"",
 | 
			
		||||
        gbinder_remote_request_interface(req));
 | 
			
		||||
    gbinder_local_reply_init_writer(reply, &writer);
 | 
			
		||||
    gbinder_writer_append_int32(&writer, GBINDER_STATUS_OK);
 | 
			
		||||
    gbinder_local_reply_append_int32(reply, GBINDER_STATUS_OK);
 | 
			
		||||
    *status = GBINDER_STATUS_OK;
 | 
			
		||||
    return reply;
 | 
			
		||||
}
 | 
			
		||||
@@ -139,6 +182,7 @@ gbinder_local_object_hidl_get_descriptor_transaction(
 | 
			
		||||
{
 | 
			
		||||
    /*android.hidl.base@1.0::IBase interfaceDescriptor() */
 | 
			
		||||
    const GBinderIo* io = gbinder_local_object_io(self);
 | 
			
		||||
    GBinderLocalObjectPriv* priv = self->priv;
 | 
			
		||||
    GBinderLocalReply* reply = gbinder_local_reply_new(io);
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
 | 
			
		||||
@@ -146,8 +190,7 @@ gbinder_local_object_hidl_get_descriptor_transaction(
 | 
			
		||||
        gbinder_remote_request_interface(req));
 | 
			
		||||
    gbinder_local_reply_init_writer(reply, &writer);
 | 
			
		||||
    gbinder_writer_append_int32(&writer, GBINDER_STATUS_OK);
 | 
			
		||||
    gbinder_writer_append_hidl_string(&writer, self->iface ? self->iface :
 | 
			
		||||
        hidl_base_interface);
 | 
			
		||||
    gbinder_writer_append_hidl_string(&writer, priv->ifaces[0]);
 | 
			
		||||
    *status = GBINDER_STATUS_OK;
 | 
			
		||||
    return reply;
 | 
			
		||||
}
 | 
			
		||||
@@ -163,17 +206,14 @@ gbinder_local_object_hidl_descriptor_chain_transaction(
 | 
			
		||||
    const GBinderIo* io = gbinder_local_object_io(self);
 | 
			
		||||
    GBinderLocalReply* reply = gbinder_local_reply_new(io);
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
    const char* chain[2];
 | 
			
		||||
    int n = 0;
 | 
			
		||||
 | 
			
		||||
    GVERBOSE("  HIDL_DESCRIPTOR_CHAIN_TRANSACTION \"%s\"",
 | 
			
		||||
        gbinder_remote_request_interface(req));
 | 
			
		||||
    if (self->iface) chain[n++] = self->iface;
 | 
			
		||||
    chain[n++] = hidl_base_interface;
 | 
			
		||||
 | 
			
		||||
    gbinder_local_reply_init_writer(reply, &writer);
 | 
			
		||||
    gbinder_writer_append_int32(&writer, GBINDER_STATUS_OK);
 | 
			
		||||
    gbinder_writer_append_hidl_string_vec(&writer, chain, n);
 | 
			
		||||
    gbinder_writer_append_hidl_string_vec(&writer, (const char**)
 | 
			
		||||
        self->ifaces, -1);
 | 
			
		||||
    *status = GBINDER_STATUS_OK;
 | 
			
		||||
    return reply;
 | 
			
		||||
}
 | 
			
		||||
@@ -187,23 +227,31 @@ gbinder_local_object_default_handle_looper_transaction(
 | 
			
		||||
    guint flags,
 | 
			
		||||
    int* status)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObjectTxHandler handler = NULL;
 | 
			
		||||
 | 
			
		||||
    switch (code) {
 | 
			
		||||
    case GBINDER_PING_TRANSACTION:
 | 
			
		||||
        handler = gbinder_local_object_ping_transaction;
 | 
			
		||||
        break;
 | 
			
		||||
    case GBINDER_INTERFACE_TRANSACTION:
 | 
			
		||||
        handler = gbinder_local_object_interface_transaction;
 | 
			
		||||
        break;
 | 
			
		||||
    case HIDL_PING_TRANSACTION:
 | 
			
		||||
        GASSERT(!(flags & GBINDER_TX_FLAG_ONEWAY));
 | 
			
		||||
        return gbinder_local_object_hidl_ping_transaction
 | 
			
		||||
            (self, req, status);
 | 
			
		||||
        handler = gbinder_local_object_hidl_ping_transaction;
 | 
			
		||||
        break;
 | 
			
		||||
    case HIDL_GET_DESCRIPTOR_TRANSACTION:
 | 
			
		||||
        GASSERT(!(flags & GBINDER_TX_FLAG_ONEWAY));
 | 
			
		||||
        return gbinder_local_object_hidl_get_descriptor_transaction
 | 
			
		||||
            (self, req, status);
 | 
			
		||||
        handler = gbinder_local_object_hidl_get_descriptor_transaction;
 | 
			
		||||
        break;
 | 
			
		||||
    case HIDL_DESCRIPTOR_CHAIN_TRANSACTION:
 | 
			
		||||
        GASSERT(!(flags & GBINDER_TX_FLAG_ONEWAY));
 | 
			
		||||
        return gbinder_local_object_hidl_descriptor_chain_transaction
 | 
			
		||||
            (self, req, status);
 | 
			
		||||
        handler = gbinder_local_object_hidl_descriptor_chain_transaction;
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        if (status) *status = (-EBADMSG);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    GASSERT(!(flags & GBINDER_TX_FLAG_ONEWAY));
 | 
			
		||||
    return handler(self, req, status);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -282,20 +330,40 @@ gbinder_local_object_handle_release_proc(
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_local_object_new(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    const char* iface,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderLocalTransactFunc txproc,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
    void* user_data) /* Since 1.0.30 */
 | 
			
		||||
{
 | 
			
		||||
    /* Should only be called from gbinder_ipc_new_local_local_object() */
 | 
			
		||||
    if (G_LIKELY(ipc)) {
 | 
			
		||||
        GBinderLocalObject* self = g_object_new
 | 
			
		||||
            (GBINDER_TYPE_LOCAL_OBJECT, NULL);
 | 
			
		||||
        GBinderLocalObjectPriv* priv = self->priv;
 | 
			
		||||
        guint i = 0, n = gutil_strv_length((char**)ifaces);
 | 
			
		||||
        gboolean append_base_interface;
 | 
			
		||||
 | 
			
		||||
        if (g_strcmp0(gutil_strv_last((char**)ifaces), hidl_base_interface)) {
 | 
			
		||||
            append_base_interface = TRUE;
 | 
			
		||||
            n++;
 | 
			
		||||
        } else {
 | 
			
		||||
            append_base_interface = FALSE;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        priv->ifaces = g_new(char*, n + 1);
 | 
			
		||||
        if (ifaces) {
 | 
			
		||||
            while (*ifaces) {
 | 
			
		||||
                priv->ifaces[i++] = g_strdup(*ifaces++);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (append_base_interface) {
 | 
			
		||||
            priv->ifaces[i++] = g_strdup(hidl_base_interface);
 | 
			
		||||
        }
 | 
			
		||||
        priv->ifaces[i] = NULL;
 | 
			
		||||
 | 
			
		||||
        self->ipc = gbinder_ipc_ref(ipc);
 | 
			
		||||
        self->iface = priv->iface = g_strdup(iface);
 | 
			
		||||
        self->ifaces = (const char**)priv->ifaces;
 | 
			
		||||
        priv->txproc = txproc;
 | 
			
		||||
        priv->user_data = user_data;
 | 
			
		||||
        gbinder_ipc_register_local_object(ipc, self);
 | 
			
		||||
        return self;
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
@@ -491,7 +559,7 @@ gbinder_local_object_finalize(
 | 
			
		||||
 | 
			
		||||
    GASSERT(!self->strong_refs);
 | 
			
		||||
    gbinder_ipc_unref(self->ipc);
 | 
			
		||||
    g_free(priv->iface);
 | 
			
		||||
    g_strfreev(priv->ifaces);
 | 
			
		||||
    G_OBJECT_CLASS(gbinder_local_object_parent_class)->finalize(local);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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
 | 
			
		||||
@@ -55,7 +55,7 @@ struct gbinder_local_object {
 | 
			
		||||
    GObject object;
 | 
			
		||||
    GBinderLocalObjectPriv* priv;
 | 
			
		||||
    GBinderIpc* ipc;
 | 
			
		||||
    const char* iface;
 | 
			
		||||
    const char* const* ifaces;
 | 
			
		||||
    gint weak_refs;
 | 
			
		||||
    gint strong_refs;
 | 
			
		||||
};
 | 
			
		||||
@@ -87,14 +87,6 @@ GType gbinder_local_object_get_type(void);
 | 
			
		||||
#define gbinder_local_object_dev(obj) (gbinder_driver_dev((obj)->ipc->driver))
 | 
			
		||||
#define gbinder_local_object_io(obj) (gbinder_driver_io((obj)->ipc->driver))
 | 
			
		||||
 | 
			
		||||
/* Should only be called from gbinder_ipc_new_local_object() */
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_local_object_new(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    const char* iface,
 | 
			
		||||
    GBinderLocalTransactFunc handler,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_local_object_add_weak_refs_changed_handler(
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -320,9 +320,9 @@ gbinder_reader_read_object(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_reader_read_buffer_impl(
 | 
			
		||||
gbinder_reader_read_buffer_object(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    GBinderBuffer** out)
 | 
			
		||||
    GBinderIoBufferObject* out)
 | 
			
		||||
{
 | 
			
		||||
    GBinderReaderPriv* p = gbinder_reader_cast(reader);
 | 
			
		||||
 | 
			
		||||
@@ -339,7 +339,6 @@ gbinder_reader_read_buffer_impl(
 | 
			
		||||
            return TRUE;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (out) *out = NULL;
 | 
			
		||||
    return FALSE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -347,34 +346,36 @@ GBinderBuffer*
 | 
			
		||||
gbinder_reader_read_buffer(
 | 
			
		||||
    GBinderReader* reader)
 | 
			
		||||
{
 | 
			
		||||
    GBinderBuffer* buf = NULL;
 | 
			
		||||
    GBinderIoBufferObject obj;
 | 
			
		||||
 | 
			
		||||
    gbinder_reader_read_buffer_impl(reader, &buf);
 | 
			
		||||
    return buf;
 | 
			
		||||
    if (gbinder_reader_read_buffer_object(reader, &obj)) {
 | 
			
		||||
        const GBinderReaderData* data = gbinder_reader_cast(reader)->data;
 | 
			
		||||
        GBinderBuffer* buf = data->buffer;
 | 
			
		||||
 | 
			
		||||
        return gbinder_buffer_new_with_parent(buf, obj.data, obj.size);
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_reader_skip_buffer(
 | 
			
		||||
    GBinderReader* reader)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_reader_read_buffer_impl(reader, NULL);
 | 
			
		||||
    return gbinder_reader_read_buffer_object(reader, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Helper for gbinder_reader_read_hidl_struct() macro */
 | 
			
		||||
const void*
 | 
			
		||||
gbinder_reader_read_hidl_struct1(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    gsize size) /* since 1.0.9 */
 | 
			
		||||
    gsize size) /* Since 1.0.9 */
 | 
			
		||||
{
 | 
			
		||||
    const void* result = NULL;
 | 
			
		||||
    GBinderBuffer* buf = gbinder_reader_read_buffer(reader);
 | 
			
		||||
    GBinderIoBufferObject obj;
 | 
			
		||||
 | 
			
		||||
    /* Check the size */
 | 
			
		||||
    if (buf && buf->size == size) {
 | 
			
		||||
        result = buf->data;
 | 
			
		||||
    if (gbinder_reader_read_buffer_object(reader, &obj) && obj.size == size) {
 | 
			
		||||
        return obj.data;
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_buffer_free(buf);
 | 
			
		||||
    return result;
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Doesn't copy the data */
 | 
			
		||||
@@ -384,30 +385,28 @@ gbinder_reader_read_hidl_vec(
 | 
			
		||||
    gsize* count,
 | 
			
		||||
    gsize* elemsize)
 | 
			
		||||
{
 | 
			
		||||
    GBinderBuffer* buf = gbinder_reader_read_buffer(reader);
 | 
			
		||||
    gsize out_count = 0, out_elemsize = 0;
 | 
			
		||||
    GBinderIoBufferObject obj;
 | 
			
		||||
    const void* out = NULL;
 | 
			
		||||
    gsize out_count = 0, out_elemsize = 0;
 | 
			
		||||
 | 
			
		||||
    if (buf && buf->size == sizeof(GBinderHidlVec)) {
 | 
			
		||||
        const GBinderHidlVec* vec = buf->data;
 | 
			
		||||
    if (gbinder_reader_read_buffer_object(reader, &obj) &&
 | 
			
		||||
        obj.data && obj.size == sizeof(GBinderHidlVec)) {
 | 
			
		||||
        const GBinderHidlVec* vec = obj.data;
 | 
			
		||||
        const void* next = vec->data.ptr;
 | 
			
		||||
 | 
			
		||||
        if (next) {
 | 
			
		||||
            GBinderBuffer* vbuf = gbinder_reader_read_buffer(reader);
 | 
			
		||||
 | 
			
		||||
            if (vbuf && vbuf->data == next && ((!vec->count && !vbuf->size) ||
 | 
			
		||||
                (vec->count && vbuf->size && !(vbuf->size % vec->count)))) {
 | 
			
		||||
                out_elemsize = vec->count ? (vbuf->size / vec->count) : 0;
 | 
			
		||||
            if (gbinder_reader_read_buffer_object(reader, &obj) &&
 | 
			
		||||
                obj.data == next && ((!vec->count && !obj.size) ||
 | 
			
		||||
                (vec->count && obj.size && !(obj.size % vec->count)))) {
 | 
			
		||||
                out_elemsize = vec->count ? (obj.size / vec->count) : 0;
 | 
			
		||||
                out_count = vec->count;
 | 
			
		||||
                out = vbuf->data;
 | 
			
		||||
                out = obj.data;
 | 
			
		||||
            }
 | 
			
		||||
            gbinder_buffer_free(vbuf);
 | 
			
		||||
        } else if (!vec->count) {
 | 
			
		||||
            /* Any non-NULL pointer just to indicate success */
 | 
			
		||||
            /* Any non-NULL pointer just to indicate success? */
 | 
			
		||||
            out = vec;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_buffer_free(buf);
 | 
			
		||||
    if (elemsize) {
 | 
			
		||||
        *elemsize = out_elemsize;
 | 
			
		||||
    }
 | 
			
		||||
@@ -422,7 +421,7 @@ const void*
 | 
			
		||||
gbinder_reader_read_hidl_vec1(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    gsize* count,
 | 
			
		||||
    guint expected_elem_size) /* since 1.0.9 */
 | 
			
		||||
    guint expected_elem_size) /* Since 1.0.9 */
 | 
			
		||||
{
 | 
			
		||||
    gsize actual;
 | 
			
		||||
    const void* data = gbinder_reader_read_hidl_vec(reader, count, &actual);
 | 
			
		||||
@@ -431,89 +430,94 @@ gbinder_reader_read_hidl_vec1(
 | 
			
		||||
    return (data && (actual == expected_elem_size || !actual)) ? data : NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_reader_read_hidl_string_c(
 | 
			
		||||
    GBinderReader* reader) /* Since 1.0.23 */
 | 
			
		||||
{
 | 
			
		||||
    GBinderIoBufferObject obj;
 | 
			
		||||
 | 
			
		||||
    if (gbinder_reader_read_buffer_object(reader, &obj) &&
 | 
			
		||||
        obj.data && obj.size == sizeof(GBinderHidlString)) {
 | 
			
		||||
        const GBinderHidlString* str = obj.data;
 | 
			
		||||
 | 
			
		||||
        if (gbinder_reader_read_buffer_object(reader, &obj) &&
 | 
			
		||||
            obj.has_parent &&
 | 
			
		||||
            obj.parent_offset == GBINDER_HIDL_STRING_BUFFER_OFFSET &&
 | 
			
		||||
            obj.data == str->data.str &&
 | 
			
		||||
            obj.size == str->len + 1 &&
 | 
			
		||||
            str->data.str[str->len] == 0) {
 | 
			
		||||
            return str->data.str;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char*
 | 
			
		||||
gbinder_reader_read_hidl_string(
 | 
			
		||||
    GBinderReader* reader)
 | 
			
		||||
{
 | 
			
		||||
    GBinderBuffer* buf = gbinder_reader_read_buffer(reader);
 | 
			
		||||
    char* str = NULL;
 | 
			
		||||
 | 
			
		||||
    if (buf && buf->size == sizeof(GBinderHidlString)) {
 | 
			
		||||
        const GBinderHidlString* s = buf->data;
 | 
			
		||||
        GBinderBuffer* sbuf = gbinder_reader_read_buffer(reader);
 | 
			
		||||
 | 
			
		||||
        if (sbuf && sbuf->size == s->len + 1 &&
 | 
			
		||||
            sbuf->data == s->data.str &&
 | 
			
		||||
            s->data.str[s->len] == 0) {
 | 
			
		||||
            str = g_strdup(s->data.str);
 | 
			
		||||
        }
 | 
			
		||||
        gbinder_buffer_free(sbuf);
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_buffer_free(buf);
 | 
			
		||||
    return str;
 | 
			
		||||
    /* This function should've been called gbinder_reader_dup_hidl_string */
 | 
			
		||||
    return g_strdup(gbinder_reader_read_hidl_string_c(reader));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char**
 | 
			
		||||
gbinder_reader_read_hidl_string_vec(
 | 
			
		||||
    GBinderReader* reader)
 | 
			
		||||
{
 | 
			
		||||
    GBinderBuffer* buf = gbinder_reader_read_buffer(reader);
 | 
			
		||||
    GBinderIoBufferObject obj;
 | 
			
		||||
 | 
			
		||||
    /* First buffer contains hidl_vector */
 | 
			
		||||
    if (buf && buf->size == sizeof(GBinderHidlVec)) {
 | 
			
		||||
        GBinderHidlVec* vec = buf->data;
 | 
			
		||||
    if (gbinder_reader_read_buffer_object(reader, &obj) &&
 | 
			
		||||
        obj.data && obj.size == sizeof(GBinderHidlVec)) {
 | 
			
		||||
        GBinderHidlVec* vec = obj.data;
 | 
			
		||||
        const guint n = vec->count;
 | 
			
		||||
        const void* next = vec->data.ptr;
 | 
			
		||||
 | 
			
		||||
        gbinder_buffer_free(buf);
 | 
			
		||||
        if (!next && !n) {
 | 
			
		||||
            char** out = g_new(char*, 1);
 | 
			
		||||
            /* Should this be considered an error? */
 | 
			
		||||
            return g_new0(char*, 1);
 | 
			
		||||
        } else if (gbinder_reader_read_buffer_object(reader, &obj) &&
 | 
			
		||||
                   /* The second buffer (if any) contains n hidl_string's */
 | 
			
		||||
                   obj.parent_offset == GBINDER_HIDL_VEC_BUFFER_OFFSET &&
 | 
			
		||||
                   obj.has_parent &&
 | 
			
		||||
                   obj.data == next &&
 | 
			
		||||
                   obj.size == (sizeof(GBinderHidlString) * n)) {
 | 
			
		||||
            const GBinderHidlString* strings = obj.data;
 | 
			
		||||
            GPtrArray* list = g_ptr_array_sized_new(n + 1);
 | 
			
		||||
            guint i;
 | 
			
		||||
 | 
			
		||||
            out[0] = NULL;
 | 
			
		||||
            return out;
 | 
			
		||||
        } else {
 | 
			
		||||
            /* The second buffer (if any) contains n hidl_string's */
 | 
			
		||||
            buf = gbinder_reader_read_buffer(reader);
 | 
			
		||||
            if (buf && buf->data == next &&
 | 
			
		||||
                buf->size == (sizeof(GBinderHidlString) * n)) {
 | 
			
		||||
                const GBinderHidlString* strings = buf->data;
 | 
			
		||||
                GBinderBuffer* sbuf;
 | 
			
		||||
                GPtrArray* list = g_ptr_array_new();
 | 
			
		||||
                guint i;
 | 
			
		||||
            /* Now we expect n buffers containing the actual data */
 | 
			
		||||
            for (i = 0; i < n &&
 | 
			
		||||
                gbinder_reader_read_buffer_object(reader, &obj); i++) {
 | 
			
		||||
                const GBinderHidlString* s = strings + i;
 | 
			
		||||
                const gsize expected_offset = (i * sizeof(*s)) +
 | 
			
		||||
                    GBINDER_HIDL_STRING_BUFFER_OFFSET;
 | 
			
		||||
                if (obj.has_parent &&
 | 
			
		||||
                    obj.parent_offset == expected_offset &&
 | 
			
		||||
                    obj.data == s->data.str &&
 | 
			
		||||
                    obj.size == s->len + 1 &&
 | 
			
		||||
                    s->data.str[s->len] == 0) {
 | 
			
		||||
                    char* name = g_strdup(s->data.str);
 | 
			
		||||
 | 
			
		||||
                /* Now we expect n buffers containing the actual data */
 | 
			
		||||
                for (i=0; i<n &&
 | 
			
		||||
                    (sbuf = gbinder_reader_read_buffer(reader)); i++) {
 | 
			
		||||
                    const GBinderHidlString* s = strings + i;
 | 
			
		||||
                    if (sbuf->size == s->len + 1 &&
 | 
			
		||||
                        sbuf->data == s->data.str &&
 | 
			
		||||
                        s->data.str[s->len] == 0) {
 | 
			
		||||
                        char* name = g_strdup(s->data.str);
 | 
			
		||||
 | 
			
		||||
                        g_ptr_array_add(list, name);
 | 
			
		||||
                        GVERBOSE_("%u. %s", i + 1, name);
 | 
			
		||||
                        gbinder_buffer_free(sbuf);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        GWARN("Unexpected hidl_string buffer %p/%u vs %p/%u",
 | 
			
		||||
                            sbuf->data, (guint)sbuf->size, s->data.str, s->len);
 | 
			
		||||
                        gbinder_buffer_free(sbuf);
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                    g_ptr_array_add(list, name);
 | 
			
		||||
                    GVERBOSE_("%u. %s", i + 1, name);
 | 
			
		||||
                } else {
 | 
			
		||||
                    GWARN("Unexpected hidl_string buffer %p/%u vs %p/%u",
 | 
			
		||||
                        obj.data, (guint)obj.size, s->data.str, s->len);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (i == n) {
 | 
			
		||||
                    gbinder_buffer_free(buf);
 | 
			
		||||
                    g_ptr_array_add(list, NULL);
 | 
			
		||||
                    return (char**)g_ptr_array_free(list, FALSE);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                g_ptr_array_set_free_func(list, g_free);
 | 
			
		||||
                g_ptr_array_free(list, TRUE);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (i == n) {
 | 
			
		||||
                g_ptr_array_add(list, NULL);
 | 
			
		||||
                return (char**)g_ptr_array_free(list, FALSE);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            g_ptr_array_set_free_func(list, g_free);
 | 
			
		||||
            g_ptr_array_free(list, TRUE);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    GWARN("Invalid hidl_vec<string>");
 | 
			
		||||
    gbinder_buffer_free(buf);
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -546,7 +550,7 @@ gbinder_reader_read_nullable_string16(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    char** out)
 | 
			
		||||
{
 | 
			
		||||
    gunichar2* str;
 | 
			
		||||
    const gunichar2* str;
 | 
			
		||||
    gsize len;
 | 
			
		||||
 | 
			
		||||
    if (gbinder_reader_read_nullable_string16_utf16(reader, &str, &len)) {
 | 
			
		||||
@@ -561,8 +565,8 @@ gbinder_reader_read_nullable_string16(
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_reader_read_nullable_string16_utf16(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    gunichar2** out,
 | 
			
		||||
    gsize* out_len) /* since 1.0.17 */
 | 
			
		||||
    const gunichar2** out,
 | 
			
		||||
    gsize* out_len) /* Since 1.0.17 */
 | 
			
		||||
{
 | 
			
		||||
    GBinderReaderPriv* p = gbinder_reader_cast(reader);
 | 
			
		||||
 | 
			
		||||
@@ -582,7 +586,7 @@ gbinder_reader_read_nullable_string16_utf16(
 | 
			
		||||
            return TRUE;
 | 
			
		||||
        } else if (len >= 0) {
 | 
			
		||||
            const guint32 padded_len = G_ALIGN4((len + 1)*2);
 | 
			
		||||
            gunichar2* utf16 = (gunichar2*)(p->ptr + 4);
 | 
			
		||||
            const gunichar2* utf16 = (gunichar2*)(p->ptr + 4);
 | 
			
		||||
 | 
			
		||||
            if ((p->ptr + padded_len + 4) <= p->end) {
 | 
			
		||||
                p->ptr += padded_len + 4;
 | 
			
		||||
@@ -599,6 +603,21 @@ gbinder_reader_read_nullable_string16_utf16(
 | 
			
		||||
    return FALSE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const gunichar2*
 | 
			
		||||
gbinder_reader_read_string16_utf16(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    gsize* len) /* Since 1.0.26 */
 | 
			
		||||
{
 | 
			
		||||
    const gunichar2* str;
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * Use gbinder_reader_read_nullable_string16_utf16 to distinguish
 | 
			
		||||
     * NULL string from a parsing failure.
 | 
			
		||||
     */
 | 
			
		||||
    return gbinder_reader_read_nullable_string16_utf16(reader, &str, len) ?
 | 
			
		||||
        str : NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char*
 | 
			
		||||
gbinder_reader_read_string16(
 | 
			
		||||
    GBinderReader* reader)
 | 
			
		||||
@@ -638,7 +657,7 @@ gbinder_reader_skip_string16(
 | 
			
		||||
const void*
 | 
			
		||||
gbinder_reader_read_byte_array(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    gsize* len) /* since 1.0.12 */
 | 
			
		||||
    gsize* len) /* Since 1.0.12 */
 | 
			
		||||
{
 | 
			
		||||
    GBinderReaderPriv* p = gbinder_reader_cast(reader);
 | 
			
		||||
    const void* data = NULL;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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_driver.h"
 | 
			
		||||
#include "gbinder_ipc.h"
 | 
			
		||||
#include "gbinder_remote_object_p.h"
 | 
			
		||||
#include "gbinder_servicemanager_p.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
struct gbinder_remote_object_priv {
 | 
			
		||||
@@ -65,9 +66,20 @@ void
 | 
			
		||||
gbinder_remote_object_died_on_main_thread(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* ipc = self->ipc;
 | 
			
		||||
    GBinderDriver* driver = ipc->driver;
 | 
			
		||||
 | 
			
		||||
    GASSERT(!self->dead);
 | 
			
		||||
    self->dead = TRUE;
 | 
			
		||||
    g_signal_emit(self, gbinder_remote_object_signals[SIGNAL_DEATH], 0);
 | 
			
		||||
    if (!self->dead) {
 | 
			
		||||
        self->dead = TRUE;
 | 
			
		||||
        /* ServiceManager always has the same handle, and can be reanimated. */
 | 
			
		||||
        if (self->handle != GBINDER_SERVICEMANAGER_HANDLE) {
 | 
			
		||||
            gbinder_ipc_invalidate_remote_handle(self->ipc, self->handle);
 | 
			
		||||
        }
 | 
			
		||||
        gbinder_driver_clear_death_notification(driver, self);
 | 
			
		||||
        gbinder_driver_release(driver, self->handle);
 | 
			
		||||
        g_signal_emit(self, gbinder_remote_object_signals[SIGNAL_DEATH], 0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -79,6 +91,47 @@ gbinder_remote_object_died_handle(
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Internal interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_remote_object_reanimate(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
{
 | 
			
		||||
    /*
 | 
			
		||||
     * Don't try to reanimate those who hasn't died yet. Reanimation is
 | 
			
		||||
     * kind of a special case and should only be used for servicemanager
 | 
			
		||||
     * objects.
 | 
			
		||||
     */
 | 
			
		||||
    if (self->dead) {
 | 
			
		||||
        GBinderIpc* ipc = self->ipc;
 | 
			
		||||
        GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
 | 
			
		||||
 | 
			
		||||
        /* Kick the horse */
 | 
			
		||||
        GASSERT(self->handle == GBINDER_SERVICEMANAGER_HANDLE);
 | 
			
		||||
        if (gbinder_driver_ping(ipc->driver, reg, self->handle) == 0) {
 | 
			
		||||
            /* Wow, it's alive! */
 | 
			
		||||
            self->dead = FALSE;
 | 
			
		||||
            gbinder_driver_acquire(ipc->driver, self->handle);
 | 
			
		||||
            gbinder_driver_request_death_notification(ipc->driver, self);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return !self->dead;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_object_handle_death_notification(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
{
 | 
			
		||||
    /* This function is invoked from the looper thread, the caller has
 | 
			
		||||
     * checked the object pointer */
 | 
			
		||||
    GVERBOSE_("%p %u", self, self->handle);
 | 
			
		||||
    g_main_context_invoke_full(self->priv->context, G_PRIORITY_DEFAULT,
 | 
			
		||||
        gbinder_remote_object_died_handle, gbinder_remote_object_ref(self),
 | 
			
		||||
        g_object_unref);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -86,15 +139,19 @@ gbinder_remote_object_died_handle(
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_remote_object_new(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    gboolean dead)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(ipc) && gbinder_driver_acquire(ipc->driver, handle)) {
 | 
			
		||||
    if (G_LIKELY(ipc)) {
 | 
			
		||||
        GBinderRemoteObject* self = g_object_new
 | 
			
		||||
            (GBINDER_TYPE_REMOTE_OBJECT, NULL);
 | 
			
		||||
 | 
			
		||||
        self->ipc = gbinder_ipc_ref(ipc);
 | 
			
		||||
        self->handle = handle;
 | 
			
		||||
        gbinder_driver_request_death_notification(ipc->driver, self);
 | 
			
		||||
        if (!(self->dead = dead)) {
 | 
			
		||||
            gbinder_driver_acquire(ipc->driver, handle);
 | 
			
		||||
            gbinder_driver_request_death_notification(ipc->driver, self);
 | 
			
		||||
        }
 | 
			
		||||
        return self;
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
@@ -121,6 +178,13 @@ gbinder_remote_object_unref(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderIpc*
 | 
			
		||||
gbinder_remote_object_ipc(
 | 
			
		||||
    GBinderRemoteObject* self) /* Since 1.0.30 */
 | 
			
		||||
{
 | 
			
		||||
    return G_LIKELY(self) ? self->ipc : NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_remote_object_is_dead(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
@@ -152,18 +216,6 @@ gbinder_remote_object_remove_handler(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_object_handle_death_notification(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
{
 | 
			
		||||
    /* This function is invoked from the looper thread, the caller has
 | 
			
		||||
     * checked the object pointer */
 | 
			
		||||
    GVERBOSE_("%p %u", self, self->handle);
 | 
			
		||||
    g_main_context_invoke_full(self->priv->context, G_PRIORITY_DEFAULT,
 | 
			
		||||
        gbinder_remote_object_died_handle, gbinder_remote_object_ref(self),
 | 
			
		||||
        g_object_unref);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Internals
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -200,8 +252,10 @@ gbinder_remote_object_finalize(
 | 
			
		||||
    GBinderIpc* ipc = self->ipc;
 | 
			
		||||
    GBinderDriver* driver = ipc->driver;
 | 
			
		||||
 | 
			
		||||
    gbinder_driver_clear_death_notification(driver, self);
 | 
			
		||||
    gbinder_driver_release(driver, self->handle);
 | 
			
		||||
    if (!self->dead) {
 | 
			
		||||
        gbinder_driver_clear_death_notification(driver, self);
 | 
			
		||||
        gbinder_driver_release(driver, self->handle);
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    G_OBJECT_CLASS(gbinder_remote_object_parent_class)->finalize(remote);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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,12 @@ struct gbinder_remote_object {
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_remote_object_new(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle);
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    gboolean maybe_dead);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_remote_object_reanimate(
 | 
			
		||||
    GBinderRemoteObject* obj);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_object_handle_death_notification(
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -50,6 +50,14 @@
 | 
			
		||||
#define STRICT_MODE_PENALTY_GATHER (0x40 << 16)
 | 
			
		||||
#define BINDER_RPC_FLAGS (STRICT_MODE_PENALTY_GATHER)
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_binder_write_ping(
 | 
			
		||||
    GBinderWriter* writer)
 | 
			
		||||
{
 | 
			
		||||
    /* No payload */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_binder_write_rpc_header(
 | 
			
		||||
@@ -99,6 +107,15 @@ gbinder_rpc_protocol_hwbinder_write_rpc_header(
 | 
			
		||||
    gbinder_writer_append_string8(writer, iface);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_hwbinder_write_ping(
 | 
			
		||||
    GBinderWriter* writer)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_rpc_protocol_hwbinder_write_rpc_header(writer,
 | 
			
		||||
        "android.hidl.base@1.0::IBase");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_rpc_protocol_hwbinder_read_rpc_header(
 | 
			
		||||
@@ -115,13 +132,17 @@ gbinder_rpc_protocol_hwbinder_read_rpc_header(
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
    .ping_tx = GBINDER_PING_TRANSACTION,
 | 
			
		||||
    .write_ping = gbinder_rpc_protocol_binder_write_ping,
 | 
			
		||||
    .write_rpc_header = gbinder_rpc_protocol_binder_write_rpc_header,
 | 
			
		||||
    .read_rpc_header = gbinder_rpc_protocol_binder_read_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
 | 
			
		||||
    .ping_tx = HIDL_PING_TRANSACTION,
 | 
			
		||||
    .write_ping = gbinder_rpc_protocol_hwbinder_write_ping,
 | 
			
		||||
    .write_rpc_header = gbinder_rpc_protocol_hwbinder_write_rpc_header,
 | 
			
		||||
    .read_rpc_header = gbinder_rpc_protocol_hwbinder_read_rpc_header
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const GBinderRpcProtocol*
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -42,9 +42,11 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
struct gbinder_rpc_protocol {
 | 
			
		||||
    guint32 ping_tx;
 | 
			
		||||
    void (*write_ping)(GBinderWriter* writer);
 | 
			
		||||
    void (*write_rpc_header)(GBinderWriter* writer, const char* iface);
 | 
			
		||||
    const char* (*read_rpc_header)(GBinderReader* reader, guint32 txcode,
 | 
			
		||||
        char** iface);
 | 
			
		||||
    void (*write_rpc_header)(GBinderWriter* writer, const char* iface);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern const GBinderRpcProtocol gbinder_rpc_protocol_binder;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -41,9 +41,14 @@
 | 
			
		||||
#include <gbinder_client.h>
 | 
			
		||||
 | 
			
		||||
#include <gutil_idlepool.h>
 | 
			
		||||
#include <gutil_misc.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
#define PRESENSE_WAIT_MS_MIN  (100)
 | 
			
		||||
#define PRESENSE_WAIT_MS_MAX  (1000)
 | 
			
		||||
#define PRESENSE_WAIT_MS_STEP (100)
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_servicemanager_watch {
 | 
			
		||||
    char* name;
 | 
			
		||||
    char* detail;
 | 
			
		||||
@@ -53,6 +58,10 @@ typedef struct gbinder_servicemanager_watch {
 | 
			
		||||
 | 
			
		||||
struct gbinder_servicemanager_priv {
 | 
			
		||||
    GHashTable* watch_table;
 | 
			
		||||
    gulong death_id;
 | 
			
		||||
    gboolean present;
 | 
			
		||||
    guint presence_check_id;
 | 
			
		||||
    guint presence_check_delay_ms;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_ABSTRACT_TYPE(GBinderServiceManager, gbinder_servicemanager,
 | 
			
		||||
@@ -72,10 +81,12 @@ G_DEFINE_ABSTRACT_TYPE(GBinderServiceManager, gbinder_servicemanager,
 | 
			
		||||
    G_TYPE_CHECK_CLASS_TYPE(klass, GBINDER_TYPE_SERVICEMANAGER)
 | 
			
		||||
 | 
			
		||||
enum gbinder_servicemanager_signal {
 | 
			
		||||
    SIGNAL_PRESENCE,
 | 
			
		||||
    SIGNAL_REGISTRATION,
 | 
			
		||||
    SIGNAL_COUNT
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static const char SIGNAL_PRESENCE_NAME[] = "servicemanager-presence";
 | 
			
		||||
static const char SIGNAL_REGISTRATION_NAME[] = "servicemanager-registration";
 | 
			
		||||
#define DETAIL_LEN 32
 | 
			
		||||
 | 
			
		||||
@@ -154,6 +165,7 @@ gbinder_servicemanager_list_tx_done(
 | 
			
		||||
    if (!data->func(data->sm, data->result, data->user_data)) {
 | 
			
		||||
        g_strfreev(data->result);
 | 
			
		||||
    }
 | 
			
		||||
    data->result = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -163,6 +175,7 @@ gbinder_servicemanager_list_tx_free(
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerListTxData* data = user_data;
 | 
			
		||||
 | 
			
		||||
    g_strfreev(data->result);
 | 
			
		||||
    gbinder_servicemanager_unref(data->sm);
 | 
			
		||||
    g_slice_free(GBinderServiceManagerListTxData, data);
 | 
			
		||||
}
 | 
			
		||||
@@ -253,6 +266,129 @@ gbinder_servicemanager_add_service_tx_free(
 | 
			
		||||
    g_slice_free(GBinderServiceManagerAddServiceTxData, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_reanimated(
 | 
			
		||||
    GBinderServiceManager* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    if (priv->presence_check_id) {
 | 
			
		||||
        g_source_remove(priv->presence_check_id);
 | 
			
		||||
        priv->presence_check_id = 0;
 | 
			
		||||
    }
 | 
			
		||||
    GINFO("Service manager %s has appeared", self->dev);
 | 
			
		||||
    /* Re-arm the watches */
 | 
			
		||||
    if (g_hash_table_size(priv->watch_table) > 0) {
 | 
			
		||||
        gpointer value;
 | 
			
		||||
        GHashTableIter it;
 | 
			
		||||
        GBinderServiceManagerClass* klass =
 | 
			
		||||
            GBINDER_SERVICEMANAGER_GET_CLASS(self);
 | 
			
		||||
 | 
			
		||||
        g_hash_table_iter_init(&it, priv->watch_table);
 | 
			
		||||
        while (g_hash_table_iter_next(&it, NULL, &value)) {
 | 
			
		||||
            GBinderServiceManagerWatch* watch = value;
 | 
			
		||||
 | 
			
		||||
            GASSERT(!watch->watched);
 | 
			
		||||
            watch->watched = klass->watch(self, watch->name);
 | 
			
		||||
            if (watch->watched) {
 | 
			
		||||
                GDEBUG("Watching %s", watch->name);
 | 
			
		||||
            } else {
 | 
			
		||||
                GWARN("Failed to watch %s", watch->name);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    g_signal_emit(self, gbinder_servicemanager_signals[SIGNAL_PRESENCE], 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_servicemanager_presense_check_timer(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManager* self = GBINDER_SERVICEMANAGER(user_data);
 | 
			
		||||
    GBinderRemoteObject* remote = self->client->remote;
 | 
			
		||||
    GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
    gboolean result;
 | 
			
		||||
 | 
			
		||||
    GASSERT(remote->dead);
 | 
			
		||||
    gbinder_servicemanager_ref(self);
 | 
			
		||||
    if (gbinder_remote_object_reanimate(remote)) {
 | 
			
		||||
        /* Done */
 | 
			
		||||
        priv->presence_check_id = 0;
 | 
			
		||||
        gbinder_servicemanager_reanimated(self);
 | 
			
		||||
        result = G_SOURCE_REMOVE;
 | 
			
		||||
    } else if (priv->presence_check_delay_ms < PRESENSE_WAIT_MS_MAX) {
 | 
			
		||||
        priv->presence_check_delay_ms += PRESENSE_WAIT_MS_STEP;
 | 
			
		||||
        priv->presence_check_id = g_timeout_add(priv->presence_check_delay_ms,
 | 
			
		||||
            gbinder_servicemanager_presense_check_timer, self);
 | 
			
		||||
        result = G_SOURCE_REMOVE;
 | 
			
		||||
    } else {
 | 
			
		||||
        result = G_SOURCE_CONTINUE;
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_servicemanager_unref(self);
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_presence_check_start(
 | 
			
		||||
    GBinderServiceManager* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    GASSERT(!priv->presence_check_id);
 | 
			
		||||
    priv->presence_check_delay_ms = PRESENSE_WAIT_MS_MIN;
 | 
			
		||||
    priv->presence_check_id = g_timeout_add(PRESENSE_WAIT_MS_MIN,
 | 
			
		||||
        gbinder_servicemanager_presense_check_timer, self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_died(
 | 
			
		||||
    GBinderRemoteObject* remote,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManager* self = GBINDER_SERVICEMANAGER(user_data);
 | 
			
		||||
    GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    GWARN("Service manager %s has died", self->dev);
 | 
			
		||||
    gbinder_servicemanager_presence_check_start(self);
 | 
			
		||||
 | 
			
		||||
    /* Will re-arm watches after servicemanager gets restarted */
 | 
			
		||||
    if (g_hash_table_size(priv->watch_table) > 0) {
 | 
			
		||||
        gpointer value;
 | 
			
		||||
        GHashTableIter it;
 | 
			
		||||
        GBinderServiceManagerClass* klass =
 | 
			
		||||
            GBINDER_SERVICEMANAGER_GET_CLASS(self);
 | 
			
		||||
 | 
			
		||||
        g_hash_table_iter_init(&it, priv->watch_table);
 | 
			
		||||
        while (g_hash_table_iter_next(&it, NULL, &value)) {
 | 
			
		||||
            GBinderServiceManagerWatch* watch = value;
 | 
			
		||||
 | 
			
		||||
            if (watch->watched) {
 | 
			
		||||
                GDEBUG("Unwatching %s", watch->name);
 | 
			
		||||
                watch->watched = FALSE;
 | 
			
		||||
                klass->unwatch(self, watch->name);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    g_signal_emit(self, gbinder_servicemanager_signals[SIGNAL_PRESENCE], 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_sleep_ms(
 | 
			
		||||
    gulong ms)
 | 
			
		||||
{
 | 
			
		||||
    struct timespec wait;
 | 
			
		||||
 | 
			
		||||
    wait.tv_sec = ms/1000;                /* seconds */
 | 
			
		||||
    wait.tv_nsec = (ms % 1000) * 1000000; /* nanoseconds */
 | 
			
		||||
    while (nanosleep(&wait, &wait) == -1 && errno == EINTR &&
 | 
			
		||||
        (wait.tv_sec > 0 || wait.tv_nsec > 0));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Internal interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -271,21 +407,25 @@ gbinder_servicemanager_new_with_type(
 | 
			
		||||
        if (!dev) dev = klass->default_device;
 | 
			
		||||
        ipc = gbinder_ipc_new(dev, klass->rpc_protocol);
 | 
			
		||||
        if (ipc) {
 | 
			
		||||
            /* Create a possible dead remote object */
 | 
			
		||||
            GBinderRemoteObject* object = gbinder_ipc_get_remote_object
 | 
			
		||||
                (ipc, klass->handle);
 | 
			
		||||
                (ipc, GBINDER_SERVICEMANAGER_HANDLE, TRUE);
 | 
			
		||||
 | 
			
		||||
            if (object) {
 | 
			
		||||
                gboolean first_ref;
 | 
			
		||||
 | 
			
		||||
                /* Lock */
 | 
			
		||||
                g_mutex_lock(&klass->mutex);
 | 
			
		||||
                if (klass->table) {
 | 
			
		||||
                    self = g_hash_table_lookup(klass->table, dev);
 | 
			
		||||
                }
 | 
			
		||||
                if (self) {
 | 
			
		||||
                    first_ref = FALSE;
 | 
			
		||||
                    gbinder_servicemanager_ref(self);
 | 
			
		||||
                } else {
 | 
			
		||||
                    char* key = g_strdup(dev); /* Owned by the hashtable */
 | 
			
		||||
 | 
			
		||||
                    GVERBOSE_("%s", dev);
 | 
			
		||||
                    first_ref = TRUE;
 | 
			
		||||
                    self = g_object_new(type, NULL);
 | 
			
		||||
                    self->client = gbinder_client_new(object, klass->iface);
 | 
			
		||||
                    self->dev = gbinder_remote_object_dev(object);
 | 
			
		||||
@@ -297,6 +437,20 @@ gbinder_servicemanager_new_with_type(
 | 
			
		||||
                }
 | 
			
		||||
                g_mutex_unlock(&klass->mutex);
 | 
			
		||||
                /* Unlock */
 | 
			
		||||
                if (first_ref) {
 | 
			
		||||
                    GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
                    priv->death_id =
 | 
			
		||||
                        gbinder_remote_object_add_death_handler(object,
 | 
			
		||||
                            gbinder_servicemanager_died, self);
 | 
			
		||||
                    /* Query the actual state if necessary */
 | 
			
		||||
                    gbinder_remote_object_reanimate(object);
 | 
			
		||||
                    if (object->dead) {
 | 
			
		||||
                        gbinder_servicemanager_presence_check_start(self);
 | 
			
		||||
                    }
 | 
			
		||||
                    GDEBUG("%s has %sservice manager", dev,
 | 
			
		||||
                        object->dead ? "no " : "");
 | 
			
		||||
                }
 | 
			
		||||
                gbinder_remote_object_unref(object);
 | 
			
		||||
            }
 | 
			
		||||
            gbinder_ipc_unref(ipc);
 | 
			
		||||
@@ -357,10 +511,25 @@ gbinder_servicemanager_new_local_object(
 | 
			
		||||
    const char* iface,
 | 
			
		||||
    GBinderLocalTransactFunc txproc,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    const char* ifaces[2];
 | 
			
		||||
 | 
			
		||||
    ifaces[0] = iface;
 | 
			
		||||
    ifaces[1] = NULL;
 | 
			
		||||
    return gbinder_servicemanager_new_local_object2
 | 
			
		||||
        (self, ifaces, txproc, user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_servicemanager_new_local_object2(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderLocalTransactFunc txproc,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        return gbinder_ipc_new_local_object(gbinder_client_ipc(self->client),
 | 
			
		||||
            iface, txproc, user_data);
 | 
			
		||||
        return gbinder_local_object_new(gbinder_client_ipc(self->client),
 | 
			
		||||
            ifaces, txproc, user_data);
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
@@ -384,6 +553,58 @@ gbinder_servicemanager_unref(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_servicemanager_is_present(
 | 
			
		||||
    GBinderServiceManager* self) /* Since 1.0.25 */
 | 
			
		||||
{
 | 
			
		||||
    return G_LIKELY(self) && !self->client->remote->dead;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_servicemanager_wait(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    long max_wait_ms) /* Since 1.0.25 */
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderRemoteObject* remote = self->client->remote;
 | 
			
		||||
 | 
			
		||||
        if (!remote->dead) {
 | 
			
		||||
            return TRUE;
 | 
			
		||||
        } else if (gbinder_remote_object_reanimate(remote)) {
 | 
			
		||||
            gbinder_servicemanager_reanimated(self);
 | 
			
		||||
            return TRUE;
 | 
			
		||||
        } else if (max_wait_ms != 0) {
 | 
			
		||||
            /* Zero timeout means a singe check and it's already done */
 | 
			
		||||
            long delay_ms = PRESENSE_WAIT_MS_MIN;
 | 
			
		||||
 | 
			
		||||
            while (max_wait_ms != 0) {
 | 
			
		||||
                if (max_wait_ms > 0) {
 | 
			
		||||
                    if (max_wait_ms < delay_ms) {
 | 
			
		||||
                        delay_ms = max_wait_ms;
 | 
			
		||||
                        max_wait_ms = 0;
 | 
			
		||||
                    } else {
 | 
			
		||||
                        max_wait_ms -= delay_ms;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                gbinder_servicemanager_sleep_ms(delay_ms);
 | 
			
		||||
                if (gbinder_remote_object_reanimate(remote)) {
 | 
			
		||||
                    gbinder_servicemanager_reanimated(self);
 | 
			
		||||
                    return TRUE;
 | 
			
		||||
                }
 | 
			
		||||
                if (delay_ms < PRESENSE_WAIT_MS_MAX) {
 | 
			
		||||
                    delay_ms += PRESENSE_WAIT_MS_STEP;
 | 
			
		||||
                    if (delay_ms > PRESENSE_WAIT_MS_MAX) {
 | 
			
		||||
                        delay_ms = PRESENSE_WAIT_MS_MAX;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            /* Timeout */
 | 
			
		||||
            GWARN("Timeout waiting for service manager %s", self->dev);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return FALSE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_servicemanager_list(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
@@ -513,6 +734,16 @@ gbinder_servicemanager_cancel(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_servicemanager_add_presence_handler(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    GBinderServiceManagerFunc func,
 | 
			
		||||
    void* user_data) /* Since 1.0.25 */
 | 
			
		||||
{
 | 
			
		||||
    return (G_LIKELY(self) && G_LIKELY(func)) ? g_signal_connect(self,
 | 
			
		||||
        SIGNAL_PRESENCE_NAME, G_CALLBACK(func), user_data) : 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_servicemanager_add_registration_handler(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
@@ -546,8 +777,8 @@ gbinder_servicemanager_add_registration_handler(
 | 
			
		||||
                watch = gbinder_servicemanager_watch_new(name);
 | 
			
		||||
                g_hash_table_insert(priv->watch_table, watch->name, watch);
 | 
			
		||||
            }
 | 
			
		||||
            if (!watch->watched) {
 | 
			
		||||
                watch->watched = klass->watch(self, name);
 | 
			
		||||
            if (!watch->watched && !self->client->remote->dead) {
 | 
			
		||||
                watch->watched = klass->watch(self, watch->name);
 | 
			
		||||
                if (watch->watched) {
 | 
			
		||||
                    GDEBUG("Watching %s", watch->name);
 | 
			
		||||
                } else {
 | 
			
		||||
@@ -570,26 +801,46 @@ gbinder_servicemanager_remove_handler(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    gulong id) /* Since 1.0.13 */
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self) && G_LIKELY(id)) {
 | 
			
		||||
        GBinderServiceManagerClass* klass =
 | 
			
		||||
            GBINDER_SERVICEMANAGER_GET_CLASS(self);
 | 
			
		||||
        GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
        GHashTableIter it;
 | 
			
		||||
        gpointer value;
 | 
			
		||||
    gbinder_servicemanager_remove_handlers(self, &id, 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
        g_signal_handler_disconnect(self, id);
 | 
			
		||||
        g_hash_table_iter_init(&it, priv->watch_table);
 | 
			
		||||
        while (g_hash_table_iter_next(&it, NULL, &value)) {
 | 
			
		||||
            GBinderServiceManagerWatch* watch = value;
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_remove_handlers(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    gulong* ids,
 | 
			
		||||
    guint count) /* Since 1.0.25 */
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self) && G_LIKELY(ids) && G_LIKELY(count)) {
 | 
			
		||||
        guint i, disconnected = 0;
 | 
			
		||||
 | 
			
		||||
            if (watch->watched && !g_signal_has_handler_pending(self,
 | 
			
		||||
                gbinder_servicemanager_signals[SIGNAL_REGISTRATION],
 | 
			
		||||
                watch->quark, TRUE)) {
 | 
			
		||||
                /* This must be the one we have just removed */
 | 
			
		||||
                GDEBUG("Unwatching %s", watch->name);
 | 
			
		||||
                watch->watched = FALSE;
 | 
			
		||||
                klass->unwatch(self, watch->name);
 | 
			
		||||
                break;
 | 
			
		||||
        for (i = 0; i < count; i++) {
 | 
			
		||||
            if (ids[i]) {
 | 
			
		||||
                g_signal_handler_disconnect(self, ids[i]);
 | 
			
		||||
                disconnected++;
 | 
			
		||||
                ids[i] = 0;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (disconnected) {
 | 
			
		||||
            GBinderServiceManagerClass* klass =
 | 
			
		||||
                GBINDER_SERVICEMANAGER_GET_CLASS(self);
 | 
			
		||||
            GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
            GHashTableIter it;
 | 
			
		||||
            gpointer value;
 | 
			
		||||
 | 
			
		||||
            g_hash_table_iter_init(&it, priv->watch_table);
 | 
			
		||||
            while (disconnected && g_hash_table_iter_next(&it, NULL, &value)) {
 | 
			
		||||
                GBinderServiceManagerWatch* watch = value;
 | 
			
		||||
 | 
			
		||||
                if (watch->watched && !g_signal_has_handler_pending(self,
 | 
			
		||||
                    gbinder_servicemanager_signals[SIGNAL_REGISTRATION],
 | 
			
		||||
                    watch->quark, TRUE)) {
 | 
			
		||||
                    /* This must be one of those we have just removed */
 | 
			
		||||
                    GDEBUG("Unwatching %s", watch->name);
 | 
			
		||||
                    watch->watched = FALSE;
 | 
			
		||||
                    klass->unwatch(self, watch->name);
 | 
			
		||||
                    disconnected--;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -662,6 +913,10 @@ gbinder_servicemanager_finalize(
 | 
			
		||||
    GBinderServiceManager* self = GBINDER_SERVICEMANAGER(object);
 | 
			
		||||
    GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    if (priv->presence_check_id) {
 | 
			
		||||
        g_source_remove(priv->presence_check_id);
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_remote_object_remove_handler(self->client->remote, priv->death_id);
 | 
			
		||||
    g_hash_table_destroy(priv->watch_table);
 | 
			
		||||
    gutil_idle_pool_destroy(self->pool);
 | 
			
		||||
    gbinder_client_unref(self->client);
 | 
			
		||||
@@ -674,13 +929,18 @@ gbinder_servicemanager_class_init(
 | 
			
		||||
    GBinderServiceManagerClass* klass)
 | 
			
		||||
{
 | 
			
		||||
    GObjectClass* object_class = G_OBJECT_CLASS(klass);
 | 
			
		||||
    GType type = G_OBJECT_CLASS_TYPE(klass);
 | 
			
		||||
 | 
			
		||||
    g_mutex_init(&klass->mutex);
 | 
			
		||||
    g_type_class_add_private(klass, sizeof(GBinderServiceManagerPriv));
 | 
			
		||||
    object_class->dispose = gbinder_servicemanager_dispose;
 | 
			
		||||
    object_class->finalize = gbinder_servicemanager_finalize;
 | 
			
		||||
    gbinder_servicemanager_signals[SIGNAL_PRESENCE] =
 | 
			
		||||
        g_signal_new(SIGNAL_PRESENCE_NAME, type,
 | 
			
		||||
            G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL,
 | 
			
		||||
            G_TYPE_NONE, 0);
 | 
			
		||||
    gbinder_servicemanager_signals[SIGNAL_REGISTRATION] =
 | 
			
		||||
        g_signal_new(SIGNAL_REGISTRATION_NAME, G_OBJECT_CLASS_TYPE(klass),
 | 
			
		||||
        g_signal_new(SIGNAL_REGISTRATION_NAME, type,
 | 
			
		||||
            G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED, 0, NULL, NULL, NULL,
 | 
			
		||||
            G_TYPE_NONE, 1, G_TYPE_STRING);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -39,6 +39,9 @@
 | 
			
		||||
 | 
			
		||||
#include <glib-object.h>
 | 
			
		||||
 | 
			
		||||
/* As a special case, ServiceManager's handle is zero */
 | 
			
		||||
#define GBINDER_SERVICEMANAGER_HANDLE (0)
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_servicemanager_priv GBinderServiceManagerPriv;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_servicemanager {
 | 
			
		||||
@@ -60,7 +63,6 @@ typedef struct gbinder_servicemanager_class {
 | 
			
		||||
    GMutex mutex;
 | 
			
		||||
    GHashTable* table;
 | 
			
		||||
 | 
			
		||||
    guint32 handle;
 | 
			
		||||
    const char* iface;
 | 
			
		||||
    const char* default_device;
 | 
			
		||||
    const GBinderRpcProtocol* rpc_protocol;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										173
									
								
								src/gbinder_servicename.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								src/gbinder_servicename.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,173 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
 * are met:
 | 
			
		||||
 *
 | 
			
		||||
 *   1. Redistributions of source code must retain the above copyright
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer.
 | 
			
		||||
 *   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 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
 | 
			
		||||
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | 
			
		||||
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
 | 
			
		||||
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 | 
			
		||||
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 | 
			
		||||
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
			
		||||
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
			
		||||
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 | 
			
		||||
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 | 
			
		||||
 * THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
#include "gbinder_servicename.h"
 | 
			
		||||
#include "gbinder_servicemanager.h"
 | 
			
		||||
#include "gbinder_local_object.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_macros.h>
 | 
			
		||||
 | 
			
		||||
/* Since 1.0.26 */
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_servicename_priv {
 | 
			
		||||
    GBinderServiceName pub;
 | 
			
		||||
    gint refcount;
 | 
			
		||||
    char* name;
 | 
			
		||||
    GBinderLocalObject* object;
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    gulong presence_id;
 | 
			
		||||
    gulong add_call_id;
 | 
			
		||||
} GBinderServiceNamePriv;
 | 
			
		||||
 | 
			
		||||
GBINDER_INLINE_FUNC GBinderServiceNamePriv*
 | 
			
		||||
gbinder_servicename_cast(GBinderServiceName* pub)
 | 
			
		||||
    { return G_CAST(pub, GBinderServiceNamePriv, pub); }
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Implementation
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicename_add_service_done(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    int status,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceNamePriv* priv = user_data;
 | 
			
		||||
 | 
			
		||||
    GASSERT(priv->add_call_id);
 | 
			
		||||
    priv->add_call_id = 0;
 | 
			
		||||
    if (status) {
 | 
			
		||||
        GWARN("Error %d adding name \"%s\"", status, priv->name);
 | 
			
		||||
    } else {
 | 
			
		||||
        GDEBUG("Service \"%s\" has been registered", priv->name);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicename_add_service(
 | 
			
		||||
    GBinderServiceNamePriv* priv)
 | 
			
		||||
{
 | 
			
		||||
    GDEBUG("Adding service \"%s\"", priv->name);
 | 
			
		||||
    gbinder_servicemanager_cancel(priv->sm, priv->add_call_id);
 | 
			
		||||
    priv->add_call_id = gbinder_servicemanager_add_service(priv->sm,
 | 
			
		||||
        priv->name, priv->object, gbinder_servicename_add_service_done, priv);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicename_presence_handler(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceNamePriv* priv = user_data;
 | 
			
		||||
 | 
			
		||||
    if (gbinder_servicemanager_is_present(sm)) {
 | 
			
		||||
        gbinder_servicename_add_service(priv);
 | 
			
		||||
    } else if (priv->add_call_id) {
 | 
			
		||||
        gbinder_servicemanager_cancel(priv->sm, priv->add_call_id);
 | 
			
		||||
        priv->add_call_id = 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
GBinderServiceName*
 | 
			
		||||
gbinder_servicename_new(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    GBinderLocalObject* object,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(sm) && G_LIKELY(object) && G_LIKELY(name)) {
 | 
			
		||||
        GBinderServiceNamePriv* priv = g_slice_new0(GBinderServiceNamePriv);
 | 
			
		||||
        GBinderServiceName* self = &priv->pub;
 | 
			
		||||
 | 
			
		||||
        g_atomic_int_set(&priv->refcount, 1);
 | 
			
		||||
        priv->object = gbinder_local_object_ref(object);
 | 
			
		||||
        priv->sm = gbinder_servicemanager_ref(sm);
 | 
			
		||||
        self->name = priv->name = g_strdup(name);
 | 
			
		||||
        priv->presence_id = gbinder_servicemanager_add_presence_handler(sm,
 | 
			
		||||
            gbinder_servicename_presence_handler, priv);
 | 
			
		||||
        if (gbinder_servicemanager_is_present(sm)) {
 | 
			
		||||
            gbinder_servicename_add_service(priv);
 | 
			
		||||
        }
 | 
			
		||||
        return self;
 | 
			
		||||
    } else {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderServiceName*
 | 
			
		||||
gbinder_servicename_ref(
 | 
			
		||||
    GBinderServiceName* self)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderServiceNamePriv* priv = gbinder_servicename_cast(self);
 | 
			
		||||
 | 
			
		||||
        GASSERT(priv->refcount > 0);
 | 
			
		||||
        g_atomic_int_inc(&priv->refcount);
 | 
			
		||||
    }
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicename_unref(
 | 
			
		||||
    GBinderServiceName* self)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderServiceNamePriv* priv = gbinder_servicename_cast(self);
 | 
			
		||||
 | 
			
		||||
        GASSERT(priv->refcount > 0);
 | 
			
		||||
        if (g_atomic_int_dec_and_test(&priv->refcount)) {
 | 
			
		||||
            gbinder_servicemanager_cancel(priv->sm, priv->add_call_id);
 | 
			
		||||
            gbinder_servicemanager_remove_handler(priv->sm, priv->presence_id);
 | 
			
		||||
            gbinder_servicemanager_unref(priv->sm);
 | 
			
		||||
            gbinder_local_object_unref(priv->object);
 | 
			
		||||
            g_free(priv->name);
 | 
			
		||||
            g_slice_free(GBinderServiceName, self);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -40,7 +40,6 @@ typedef struct gbinder_cleanup GBinderCleanup;
 | 
			
		||||
typedef struct gbinder_driver GBinderDriver;
 | 
			
		||||
typedef struct gbinder_handler GBinderHandler;
 | 
			
		||||
typedef struct gbinder_io GBinderIo;
 | 
			
		||||
typedef struct gbinder_ipc GBinderIpc;
 | 
			
		||||
typedef struct gbinder_object_registry GBinderObjectRegistry;
 | 
			
		||||
typedef struct gbinder_output_data GBinderOutputData;
 | 
			
		||||
typedef struct gbinder_rpc_protocol GBinderRpcProtocol;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -149,6 +149,14 @@ gbinder_writer_init(
 | 
			
		||||
    gbinder_writer_cast(self)->data = data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gsize
 | 
			
		||||
gbinder_writer_bytes_written(
 | 
			
		||||
    GBinderWriter* self) /* since 1.0.21 */
 | 
			
		||||
{
 | 
			
		||||
    GBinderWriterData* data = gbinder_writer_data(self);
 | 
			
		||||
    return data->bytes->len;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_append_bool(
 | 
			
		||||
    GBinderWriter* self,
 | 
			
		||||
@@ -199,6 +207,26 @@ gbinder_writer_data_append_int32(
 | 
			
		||||
    *ptr = value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_overwrite_int32(
 | 
			
		||||
    GBinderWriter* self,
 | 
			
		||||
    gsize offset,
 | 
			
		||||
    gint32 value) /* since 1.0.21 */
 | 
			
		||||
{
 | 
			
		||||
    GBinderWriterData* data = gbinder_writer_data(self);
 | 
			
		||||
 | 
			
		||||
    if (G_LIKELY(data)) {
 | 
			
		||||
        GByteArray* buf = data->bytes;
 | 
			
		||||
 | 
			
		||||
        if (buf->len >= offset + sizeof(gint32)) {
 | 
			
		||||
            *((gint32*)(buf->data + offset)) = value;
 | 
			
		||||
        } else {
 | 
			
		||||
            GWARN("Can't overwrite at %lu as buffer is only %u bytes long",
 | 
			
		||||
                (gulong)offset, buf->len);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_append_int64(
 | 
			
		||||
    GBinderWriter* self,
 | 
			
		||||
 
 | 
			
		||||
@@ -5,5 +5,6 @@ all:
 | 
			
		||||
	@$(MAKE) -C binder-client $*
 | 
			
		||||
	@$(MAKE) -C binder-dump $*
 | 
			
		||||
	@$(MAKE) -C binder-list $*
 | 
			
		||||
	@$(MAKE) -C binder-ping $*
 | 
			
		||||
	@$(MAKE) -C binder-service $*
 | 
			
		||||
	@$(MAKE) -C rild-card-status $*
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Contact: Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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
 | 
			
		||||
@@ -245,7 +245,7 @@ int main(int argc, char* argv[])
 | 
			
		||||
    app.opt = &opt;
 | 
			
		||||
    if (app_init(&opt, argc, argv)) {
 | 
			
		||||
        app.sm = gbinder_servicemanager_new(opt.dev);
 | 
			
		||||
        if (app.sm) {
 | 
			
		||||
        if (gbinder_servicemanager_wait(app.sm, -1)) {
 | 
			
		||||
            if (opt.async) {
 | 
			
		||||
                app_async(&app);
 | 
			
		||||
            } else {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										140
									
								
								test/binder-ping/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								test/binder-ping/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,140 @@
 | 
			
		||||
# -*- Mode: makefile-gmake -*-
 | 
			
		||||
 | 
			
		||||
.PHONY: all debug release clean cleaner
 | 
			
		||||
.PHONY: libgbinder-release libgbinder-debug
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Required packages
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
PKGS = glib-2.0 gio-2.0 gio-unix-2.0 libglibutil
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Default target
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
all: debug release
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Executable
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
EXE = binder-ping
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Sources
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
SRC = $(EXE).c
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Directories
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
SRC_DIR = .
 | 
			
		||||
BUILD_DIR = build
 | 
			
		||||
LIB_DIR = ../..
 | 
			
		||||
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
 | 
			
		||||
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Tools and flags
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
CC = $(CROSS_COMPILE)gcc
 | 
			
		||||
LD = $(CC)
 | 
			
		||||
WARNINGS = -Wall
 | 
			
		||||
INCLUDES = -I$(LIB_DIR)/include
 | 
			
		||||
BASE_FLAGS = -fPIC
 | 
			
		||||
CFLAGS = $(BASE_FLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \
 | 
			
		||||
  $(shell pkg-config --cflags $(PKGS))
 | 
			
		||||
LDFLAGS = $(BASE_FLAGS) $(shell pkg-config --libs $(PKGS))
 | 
			
		||||
QUIET_MAKE = make --no-print-directory
 | 
			
		||||
DEBUG_FLAGS = -g
 | 
			
		||||
RELEASE_FLAGS =
 | 
			
		||||
 | 
			
		||||
ifndef KEEP_SYMBOLS
 | 
			
		||||
KEEP_SYMBOLS = 0
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
ifneq ($(KEEP_SYMBOLS),0)
 | 
			
		||||
RELEASE_FLAGS += -g
 | 
			
		||||
SUBMAKE_OPTS += KEEP_SYMBOLS=1
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
DEBUG_LDFLAGS = $(LDFLAGS) $(DEBUG_FLAGS)
 | 
			
		||||
RELEASE_LDFLAGS = $(LDFLAGS) $(RELEASE_FLAGS)
 | 
			
		||||
DEBUG_CFLAGS = $(CFLAGS) $(DEBUG_FLAGS) -DDEBUG
 | 
			
		||||
RELEASE_CFLAGS = $(CFLAGS) $(RELEASE_FLAGS) -O2
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Files
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
DEBUG_OBJS = $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
 | 
			
		||||
RELEASE_OBJS = $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
 | 
			
		||||
DEBUG_SO_FILE := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_debug_so)
 | 
			
		||||
RELEASE_SO_FILE := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_release_so)
 | 
			
		||||
DEBUG_LINK_FILE := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_debug_link)
 | 
			
		||||
RELEASE_LINK_FILE := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_release_link)
 | 
			
		||||
DEBUG_SO = $(LIB_DIR)/$(DEBUG_SO_FILE)
 | 
			
		||||
RELEASE_SO = $(LIB_DIR)/$(RELEASE_SO_FILE)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Dependencies
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d)
 | 
			
		||||
ifneq ($(MAKECMDGOALS),clean)
 | 
			
		||||
ifneq ($(strip $(DEPS)),)
 | 
			
		||||
-include $(DEPS)
 | 
			
		||||
endif
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
 | 
			
		||||
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Rules
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
DEBUG_EXE = $(DEBUG_BUILD_DIR)/$(EXE)
 | 
			
		||||
RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
 | 
			
		||||
 | 
			
		||||
debug: libgbinder-debug $(DEBUG_EXE)
 | 
			
		||||
 | 
			
		||||
release: libgbinder-release $(RELEASE_EXE)
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm -f *~
 | 
			
		||||
	rm -fr $(BUILD_DIR)
 | 
			
		||||
 | 
			
		||||
cleaner: clean
 | 
			
		||||
	@make -C $(LIB_DIR) clean
 | 
			
		||||
 | 
			
		||||
$(DEBUG_BUILD_DIR):
 | 
			
		||||
	mkdir -p $@
 | 
			
		||||
 | 
			
		||||
$(RELEASE_BUILD_DIR):
 | 
			
		||||
	mkdir -p $@
 | 
			
		||||
 | 
			
		||||
$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
 | 
			
		||||
	$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
 | 
			
		||||
 | 
			
		||||
$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
 | 
			
		||||
	$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
 | 
			
		||||
 | 
			
		||||
$(DEBUG_EXE): $(DEBUG_SO) $(DEBUG_BUILD_DIR) $(DEBUG_OBJS)
 | 
			
		||||
	$(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) $< -o $@
 | 
			
		||||
 | 
			
		||||
$(RELEASE_EXE): $(RELEASE_SO) $(RELEASE_BUILD_DIR) $(RELEASE_OBJS)
 | 
			
		||||
	$(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) $< -o $@
 | 
			
		||||
ifeq ($(KEEP_SYMBOLS),0)
 | 
			
		||||
	strip $@
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
libgbinder-debug:
 | 
			
		||||
	@make $(SUBMAKE_OPTS) -C $(LIB_DIR) $(DEBUG_SO_FILE) $(DEBUG_LINK_FILE)
 | 
			
		||||
 | 
			
		||||
libgbinder-release:
 | 
			
		||||
	@make $(SUBMAKE_OPTS) -C $(LIB_DIR) $(RELEASE_SO_FILE) $(RELEASE_LINK_FILE)
 | 
			
		||||
							
								
								
									
										187
									
								
								test/binder-ping/binder-ping.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								test/binder-ping/binder-ping.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,187 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2020 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
 * are met:
 | 
			
		||||
 *
 | 
			
		||||
 *   1. Redistributions of source code must retain the above copyright
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer.
 | 
			
		||||
 *   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 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
 | 
			
		||||
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | 
			
		||||
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
 | 
			
		||||
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 | 
			
		||||
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 | 
			
		||||
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
			
		||||
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
			
		||||
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 | 
			
		||||
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 | 
			
		||||
 * THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <gbinder.h>
 | 
			
		||||
 | 
			
		||||
#include <gutil_log.h>
 | 
			
		||||
 | 
			
		||||
#define RET_OK          (0)
 | 
			
		||||
#define RET_NOTFOUND    (1)
 | 
			
		||||
#define RET_INVARG      (2)
 | 
			
		||||
#define RET_ERR         (3)
 | 
			
		||||
 | 
			
		||||
#define DEFAULT_BINDER          GBINDER_DEFAULT_HWBINDER
 | 
			
		||||
#define AIDL_PING_TRANSACTION   GBINDER_FOURCC('_','P','N','G')
 | 
			
		||||
#define HIDL_PING_TRANSACTION   GBINDER_FOURCC(0x0f,'P','N','G')
 | 
			
		||||
 | 
			
		||||
typedef struct app_options {
 | 
			
		||||
    const char* fqname;
 | 
			
		||||
    char* dev;
 | 
			
		||||
    guint32 ping_code;
 | 
			
		||||
    const char* iface;
 | 
			
		||||
} AppOptions;
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
app_run(
 | 
			
		||||
    const AppOptions* opt)
 | 
			
		||||
{
 | 
			
		||||
    int ret = RET_NOTFOUND;
 | 
			
		||||
    GBinderServiceManager* sm = gbinder_servicemanager_new(opt->dev);
 | 
			
		||||
 | 
			
		||||
    if (sm) {
 | 
			
		||||
        int status = 0;
 | 
			
		||||
        GBinderRemoteObject* remote = gbinder_servicemanager_get_service_sync
 | 
			
		||||
            (sm, opt->fqname, &status);
 | 
			
		||||
 | 
			
		||||
        if (remote) {
 | 
			
		||||
            int status;
 | 
			
		||||
            GBinderClient* client = gbinder_client_new(remote, opt->iface);
 | 
			
		||||
            GBinderRemoteReply* reply = gbinder_client_transact_sync_reply
 | 
			
		||||
                (client, opt->ping_code, NULL, &status);
 | 
			
		||||
                             
 | 
			
		||||
            if (reply) {
 | 
			
		||||
                GINFO("OK");
 | 
			
		||||
                ret = RET_OK;
 | 
			
		||||
            } else {
 | 
			
		||||
                GERR("Ping failed (%d)", status);
 | 
			
		||||
                ret = RET_ERR;
 | 
			
		||||
            }
 | 
			
		||||
            gbinder_remote_reply_unref(reply);
 | 
			
		||||
            gbinder_client_unref(client);
 | 
			
		||||
        } else {
 | 
			
		||||
            GERR("%s not found", opt->fqname);
 | 
			
		||||
        }
 | 
			
		||||
        gbinder_servicemanager_unref(sm);
 | 
			
		||||
    } else {
 | 
			
		||||
        GERR("No servicemanager at %s", opt->dev);
 | 
			
		||||
    }
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
app_log_verbose(
 | 
			
		||||
    const gchar* name,
 | 
			
		||||
    const gchar* value,
 | 
			
		||||
    gpointer data,
 | 
			
		||||
    GError** error)
 | 
			
		||||
{
 | 
			
		||||
    gutil_log_default.level = GLOG_LEVEL_VERBOSE;
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
app_log_quiet(
 | 
			
		||||
    const gchar* name,
 | 
			
		||||
    const gchar* value,
 | 
			
		||||
    gpointer data,
 | 
			
		||||
    GError** error)
 | 
			
		||||
{
 | 
			
		||||
    gutil_log_default.level = GLOG_LEVEL_NONE;
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
app_init(
 | 
			
		||||
    AppOptions* opt,
 | 
			
		||||
    int argc,
 | 
			
		||||
    char* argv[])
 | 
			
		||||
{
 | 
			
		||||
    gboolean ok = FALSE;
 | 
			
		||||
    GOptionEntry entries[] = {
 | 
			
		||||
        { "verbose", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
 | 
			
		||||
          app_log_verbose, "Enable verbose output", NULL },
 | 
			
		||||
        { "quiet", 'q', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
 | 
			
		||||
          app_log_quiet, "Be quiet", NULL },
 | 
			
		||||
        { "device", 'd', 0, G_OPTION_ARG_STRING, &opt->dev,
 | 
			
		||||
          "Binder device [" DEFAULT_BINDER "]", "DEVICE" },
 | 
			
		||||
        { NULL }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    GError* error = NULL;
 | 
			
		||||
    GOptionContext* options = g_option_context_new("[FQNAME]");
 | 
			
		||||
 | 
			
		||||
    gutil_log_timestamp = FALSE;
 | 
			
		||||
    gutil_log_default.level = GLOG_LEVEL_DEFAULT;
 | 
			
		||||
 | 
			
		||||
    g_option_context_add_main_entries(options, entries, NULL);
 | 
			
		||||
    if (g_option_context_parse(options, &argc, &argv, &error)) {
 | 
			
		||||
        if (!opt->dev || !opt->dev[0]) {
 | 
			
		||||
            opt->dev = g_strdup(DEFAULT_BINDER);
 | 
			
		||||
        }
 | 
			
		||||
        if (argc == 2) {
 | 
			
		||||
            opt->fqname = argv[1];
 | 
			
		||||
            if (g_strcmp0(opt->dev, GBINDER_DEFAULT_BINDER)) {
 | 
			
		||||
                opt->ping_code = HIDL_PING_TRANSACTION;
 | 
			
		||||
                opt->iface = "android.hidl.base@1.0::IBase";
 | 
			
		||||
            } else {
 | 
			
		||||
                opt->ping_code = AIDL_PING_TRANSACTION;
 | 
			
		||||
                opt->iface = "android.os.IBinder";
 | 
			
		||||
            }
 | 
			
		||||
            ok = TRUE;
 | 
			
		||||
        } else {
 | 
			
		||||
            char* help = g_option_context_get_help(options, TRUE, NULL);
 | 
			
		||||
 | 
			
		||||
            fprintf(stderr, "%s", help);
 | 
			
		||||
            g_free(help);
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        GERR("%s", error->message);
 | 
			
		||||
        g_error_free(error);
 | 
			
		||||
    }
 | 
			
		||||
    g_option_context_free(options);
 | 
			
		||||
    return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(int argc, char* argv[])
 | 
			
		||||
{
 | 
			
		||||
    AppOptions opt;
 | 
			
		||||
    int ret = RET_INVARG;
 | 
			
		||||
 | 
			
		||||
    memset(&opt, 0, sizeof(opt));
 | 
			
		||||
    if (app_init(&opt, argc, argv)) {
 | 
			
		||||
        ret = app_run(&opt);
 | 
			
		||||
    }
 | 
			
		||||
    g_free(opt.dev);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -181,6 +181,23 @@ app_add_service_done(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
app_sm_presence_handler(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    App* app = user_data;
 | 
			
		||||
 | 
			
		||||
    if (gbinder_servicemanager_is_present(app->sm)) {
 | 
			
		||||
        GINFO("Service manager has reappeared");
 | 
			
		||||
        gbinder_servicemanager_add_service(app->sm, app->opt->name, app->obj,
 | 
			
		||||
            app_add_service_done, app);
 | 
			
		||||
    } else {
 | 
			
		||||
        GINFO("Service manager has died");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
app_run(
 | 
			
		||||
@@ -189,6 +206,8 @@ app_run(
 | 
			
		||||
    const char* name = app->opt->name;
 | 
			
		||||
    guint sigtrm = g_unix_signal_add(SIGTERM, app_signal, app);
 | 
			
		||||
    guint sigint = g_unix_signal_add(SIGINT, app_signal, app);
 | 
			
		||||
    gulong presence_id = gbinder_servicemanager_add_presence_handler
 | 
			
		||||
        (app->sm, app_sm_presence_handler, app);
 | 
			
		||||
 | 
			
		||||
    app->loop = g_main_loop_new(NULL, TRUE);
 | 
			
		||||
 | 
			
		||||
@@ -199,6 +218,7 @@ app_run(
 | 
			
		||||
 | 
			
		||||
    if (sigtrm) g_source_remove(sigtrm);
 | 
			
		||||
    if (sigint) g_source_remove(sigint);
 | 
			
		||||
    gbinder_servicemanager_remove_handler(app->sm, presence_id);
 | 
			
		||||
    g_main_loop_unref(app->loop);
 | 
			
		||||
    app->loop = NULL;
 | 
			
		||||
}
 | 
			
		||||
@@ -297,7 +317,7 @@ int main(int argc, char* argv[])
 | 
			
		||||
    app.opt = &opt;
 | 
			
		||||
    if (app_init(&opt, argc, argv)) {
 | 
			
		||||
        app.sm = gbinder_servicemanager_new(opt.dev);
 | 
			
		||||
        if (app.sm) {
 | 
			
		||||
        if (gbinder_servicemanager_wait(app.sm, -1)) {
 | 
			
		||||
            app.obj = gbinder_servicemanager_new_local_object
 | 
			
		||||
                (app.sm, opt.iface, app_reply, &app);
 | 
			
		||||
            app_run(&app);
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@ all:
 | 
			
		||||
	@$(MAKE) -C unit_remote_reply $*
 | 
			
		||||
	@$(MAKE) -C unit_remote_request $*
 | 
			
		||||
	@$(MAKE) -C unit_servicemanager $*
 | 
			
		||||
	@$(MAKE) -C unit_servicename $*
 | 
			
		||||
	@$(MAKE) -C unit_servicepoll $*
 | 
			
		||||
	@$(MAKE) -C unit_writer $*
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -138,10 +138,10 @@ test_banner:
 | 
			
		||||
	@echo "===========" $(EXE) "=========== "
 | 
			
		||||
 | 
			
		||||
test: test_banner debug 
 | 
			
		||||
	@LD_LIBRARY_PATH="$(LIB_DIR)/$(DEBUG_LIB_PATH)" $(DEBUG_EXE)
 | 
			
		||||
	@$(DEBUG_EXE)
 | 
			
		||||
 | 
			
		||||
valgrind: test_banner debug
 | 
			
		||||
	@LD_LIBRARY_PATH="$(LIB_DIR)/$(DEBUG_LIB_PATH)" G_DEBUG=gc-friendly G_SLICE=always-malloc valgrind --tool=memcheck --leak-check=full --show-possibly-lost=no $(DEBUG_EXE)
 | 
			
		||||
	@G_DEBUG=gc-friendly G_SLICE=always-malloc valgrind --tool=memcheck --leak-check=full --show-possibly-lost=no $(DEBUG_EXE)
 | 
			
		||||
 | 
			
		||||
$(DEBUG_BUILD_DIR):
 | 
			
		||||
	mkdir -p $@
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -45,6 +45,7 @@ GLOG_MODULE_DEFINE2("test_binder", gutil_log_default);
 | 
			
		||||
 | 
			
		||||
static GHashTable* test_fd_map = NULL;
 | 
			
		||||
static GHashTable* test_node_map = NULL;
 | 
			
		||||
static GPrivate test_looper;
 | 
			
		||||
 | 
			
		||||
#define public_fd  fd[0]
 | 
			
		||||
#define private_fd fd[1]
 | 
			
		||||
@@ -58,6 +59,22 @@ static GHashTable* test_node_map = NULL;
 | 
			
		||||
#define TF_ACCEPT_FDS  0x10
 | 
			
		||||
 | 
			
		||||
typedef struct test_binder_io TestBinderIo;
 | 
			
		||||
typedef struct test_binder TestBinder;
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
void
 | 
			
		||||
(*TestBinderPushDataFunc)(
 | 
			
		||||
    int fd,
 | 
			
		||||
    const void* data);
 | 
			
		||||
 | 
			
		||||
typedef struct test_binder_submit_thread {
 | 
			
		||||
    GThread* thread;
 | 
			
		||||
    GCond cond;
 | 
			
		||||
    GMutex mutex;
 | 
			
		||||
    gboolean run;
 | 
			
		||||
    GSList* queue;
 | 
			
		||||
    TestBinder* binder;
 | 
			
		||||
} TestBinderSubmitThread;
 | 
			
		||||
 | 
			
		||||
typedef struct test_binder_node {
 | 
			
		||||
    char* path;
 | 
			
		||||
@@ -68,6 +85,8 @@ typedef struct test_binder_node {
 | 
			
		||||
 | 
			
		||||
typedef struct test_binder {
 | 
			
		||||
    TestBinderNode* node;
 | 
			
		||||
    TestBinderSubmitThread* submit_thread;
 | 
			
		||||
    gboolean looper_enabled;
 | 
			
		||||
    int fd[2];
 | 
			
		||||
} TestBinder;
 | 
			
		||||
 | 
			
		||||
@@ -104,6 +123,11 @@ typedef struct binder_pre_cookie_64 {
 | 
			
		||||
    guint64 cookie;
 | 
			
		||||
} BinderPtrCookie64;
 | 
			
		||||
 | 
			
		||||
typedef struct binder_handle_cookie_64 {
 | 
			
		||||
  guint32 handle;
 | 
			
		||||
  guint64 cookie;
 | 
			
		||||
} __attribute__((packed)) BinderHandleCookie64;
 | 
			
		||||
 | 
			
		||||
#define BC_TRANSACTION_64       _IOW('c', 0, BinderTransactionData64)
 | 
			
		||||
#define BC_REPLY_64             _IOW('c', 1, BinderTransactionData64)
 | 
			
		||||
#define BC_FREE_BUFFER_64       _IOW('c', 3, guint64)
 | 
			
		||||
@@ -113,6 +137,8 @@ typedef struct binder_pre_cookie_64 {
 | 
			
		||||
#define BC_DECREFS              _IOW('c', 7, guint32)
 | 
			
		||||
#define BC_ENTER_LOOPER          _IO('c', 12)
 | 
			
		||||
#define BC_EXIT_LOOPER           _IO('c', 13)
 | 
			
		||||
#define BC_REQUEST_DEATH_NOTIFICATION_64 _IOW('c', 14, BinderHandleCookie64)
 | 
			
		||||
#define BC_CLEAR_DEATH_NOTIFICATION_64   _IOW('c', 15, BinderHandleCookie64)
 | 
			
		||||
 | 
			
		||||
#define BR_TRANSACTION_64       _IOR('r', 2, BinderTransactionData64)
 | 
			
		||||
#define BR_REPLY_64             _IOR('r', 3, BinderTransactionData64)
 | 
			
		||||
@@ -126,6 +152,110 @@ typedef struct binder_pre_cookie_64 {
 | 
			
		||||
#define BR_DEAD_BINDER_64       _IOR('r', 15, guint64)
 | 
			
		||||
#define BR_FAILED_REPLY          _IO('r', 17)
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gpointer
 | 
			
		||||
test_binder_submit_thread_proc(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    TestBinderSubmitThread* submit = data;
 | 
			
		||||
    TestBinder* binder = submit->binder;
 | 
			
		||||
    GMutex* mutex = &submit->mutex;
 | 
			
		||||
    GCond* cond = &submit->cond;
 | 
			
		||||
 | 
			
		||||
    GDEBUG("Submit thread started");
 | 
			
		||||
    g_mutex_lock(mutex);
 | 
			
		||||
    while (submit->run) {
 | 
			
		||||
        GBytes* next = NULL;
 | 
			
		||||
 | 
			
		||||
        while (submit->run && !next) {
 | 
			
		||||
            if (submit->queue) {
 | 
			
		||||
                next = submit->queue->data;
 | 
			
		||||
                submit->queue = g_slist_remove(submit->queue, next);
 | 
			
		||||
                break;
 | 
			
		||||
            } else {
 | 
			
		||||
                g_cond_wait(cond, mutex);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (next) {
 | 
			
		||||
            int bytes_available = 0;
 | 
			
		||||
            int err = ioctl(binder->public_fd, FIONREAD, &bytes_available);
 | 
			
		||||
 | 
			
		||||
            /* Wait until the queue is empty */
 | 
			
		||||
            g_assert(err >= 0);
 | 
			
		||||
            while (bytes_available > 0 && submit->run) {
 | 
			
		||||
                /* Wait a bit between polls */
 | 
			
		||||
                g_cond_wait_until(cond, mutex, g_get_monotonic_time () +
 | 
			
		||||
                    100 * G_TIME_SPAN_MILLISECOND);
 | 
			
		||||
                err = ioctl(binder->public_fd, FIONREAD, &bytes_available);
 | 
			
		||||
                g_assert(err >= 0);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (submit->run) {
 | 
			
		||||
                gsize len;
 | 
			
		||||
                gconstpointer data = g_bytes_get_data(next, &len);
 | 
			
		||||
 | 
			
		||||
                GDEBUG("Submitting command 0x%08x", *(guint32*)data);
 | 
			
		||||
                g_assert(write(binder->private_fd, data, len) == len);
 | 
			
		||||
            }
 | 
			
		||||
            g_bytes_unref(next);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    g_mutex_unlock(mutex);
 | 
			
		||||
    GDEBUG("Submit thread exiting");
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
TestBinderSubmitThread*
 | 
			
		||||
test_binder_submit_thread_new(
 | 
			
		||||
    TestBinder* binder)
 | 
			
		||||
{
 | 
			
		||||
    TestBinderSubmitThread* submit = g_new0(TestBinderSubmitThread, 1);
 | 
			
		||||
 | 
			
		||||
    submit->run = TRUE;
 | 
			
		||||
    submit->binder = binder;
 | 
			
		||||
    g_cond_init(&submit->cond);
 | 
			
		||||
    g_mutex_init(&submit->mutex);
 | 
			
		||||
    submit->thread = g_thread_new(binder->node->path,
 | 
			
		||||
        test_binder_submit_thread_proc, submit);
 | 
			
		||||
    return submit;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_binder_submit_thread_free(
 | 
			
		||||
    TestBinderSubmitThread* submit)
 | 
			
		||||
{
 | 
			
		||||
    if (submit) {
 | 
			
		||||
        g_mutex_lock(&submit->mutex);
 | 
			
		||||
        submit->run = FALSE;
 | 
			
		||||
        g_cond_signal(&submit->cond);
 | 
			
		||||
        g_mutex_unlock(&submit->mutex);
 | 
			
		||||
        g_thread_join(submit->thread);
 | 
			
		||||
 | 
			
		||||
        g_slist_free_full(submit->queue, (GDestroyNotify) g_bytes_unref);
 | 
			
		||||
        g_cond_clear(&submit->cond);
 | 
			
		||||
        g_mutex_clear(&submit->mutex);
 | 
			
		||||
        g_free(submit);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_binder_submit_later(
 | 
			
		||||
    TestBinderSubmitThread* submit,
 | 
			
		||||
    const void* data)
 | 
			
		||||
{
 | 
			
		||||
    const guint32* cmd = data;
 | 
			
		||||
 | 
			
		||||
    g_mutex_lock(&submit->mutex);
 | 
			
		||||
    submit->queue = g_slist_append(submit->queue,
 | 
			
		||||
        g_bytes_new(cmd, sizeof(*cmd) + _IOC_SIZE(*cmd)));
 | 
			
		||||
    g_cond_signal(&submit->cond);
 | 
			
		||||
    g_mutex_unlock(&submit->mutex);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_io_free_buffer(
 | 
			
		||||
@@ -151,11 +281,11 @@ test_io_handle_write_read_64(
 | 
			
		||||
    TestBinder* binder,
 | 
			
		||||
    void* data)
 | 
			
		||||
{
 | 
			
		||||
    int err, bytes_available = 0;
 | 
			
		||||
    BinderWriteRead64* wr = data;
 | 
			
		||||
    gssize bytes_left = wr->write_size - wr->write_consumed;
 | 
			
		||||
    const guint8* write_ptr = (void*)(gsize)
 | 
			
		||||
        (wr->write_buffer + wr->write_consumed);
 | 
			
		||||
    gboolean is_looper;
 | 
			
		||||
 | 
			
		||||
    while (bytes_left >= sizeof(guint32)) {
 | 
			
		||||
        const guint cmd = *(guint32*)write_ptr;
 | 
			
		||||
@@ -176,12 +306,18 @@ test_io_handle_write_read_64(
 | 
			
		||||
                test_io_free_buffer(binder,
 | 
			
		||||
                    GSIZE_TO_POINTER(*(guint64*)write_ptr));
 | 
			
		||||
                break;
 | 
			
		||||
            case BC_ENTER_LOOPER:
 | 
			
		||||
                 g_private_set(&test_looper, GINT_TO_POINTER(TRUE));
 | 
			
		||||
                 break;
 | 
			
		||||
            case BC_EXIT_LOOPER:
 | 
			
		||||
                 g_private_set(&test_looper, NULL);
 | 
			
		||||
                 break;
 | 
			
		||||
            case BC_REQUEST_DEATH_NOTIFICATION_64:
 | 
			
		||||
            case BC_CLEAR_DEATH_NOTIFICATION_64:
 | 
			
		||||
            case BC_INCREFS:
 | 
			
		||||
            case BC_ACQUIRE:
 | 
			
		||||
            case BC_RELEASE:
 | 
			
		||||
            case BC_DECREFS:
 | 
			
		||||
            case BC_ENTER_LOOPER:
 | 
			
		||||
            case BC_EXIT_LOOPER:
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
#pragma message("TODO: implement more BINDER_WRITE_READ commands")
 | 
			
		||||
@@ -198,24 +334,45 @@ test_io_handle_write_read_64(
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Now read the data from the socket */
 | 
			
		||||
    err = ioctl(binder->public_fd, FIONREAD, &bytes_available);
 | 
			
		||||
    if (err >= 0) {
 | 
			
		||||
        int bytes_read = 0;
 | 
			
		||||
        if (bytes_available > 0) {
 | 
			
		||||
            bytes_read = read(binder->public_fd,
 | 
			
		||||
                (void*)(gsize)(wr->read_buffer + wr->read_consumed),
 | 
			
		||||
                wr->read_size - wr->read_consumed);
 | 
			
		||||
        }
 | 
			
		||||
    is_looper = g_private_get(&test_looper) ? TRUE : FALSE;
 | 
			
		||||
    if (binder->looper_enabled || !is_looper) {
 | 
			
		||||
        /* Now read the data from the socket */
 | 
			
		||||
        int bytes_available = 0;
 | 
			
		||||
        int err = ioctl(binder->public_fd, FIONREAD, &bytes_available);
 | 
			
		||||
 | 
			
		||||
        if (bytes_read >= 0) {
 | 
			
		||||
            wr->read_consumed += bytes_read;
 | 
			
		||||
            return 0;
 | 
			
		||||
        } else {
 | 
			
		||||
            err = bytes_read;
 | 
			
		||||
        if (err >= 0) {
 | 
			
		||||
            int bytes_read = 0;
 | 
			
		||||
 | 
			
		||||
            if (bytes_available >= 4) {
 | 
			
		||||
                bytes_read = read(binder->public_fd,
 | 
			
		||||
                    (void*)(gsize)(wr->read_buffer + wr->read_consumed),
 | 
			
		||||
                    wr->read_size - wr->read_consumed);
 | 
			
		||||
            } else {
 | 
			
		||||
                struct timespec wait;
 | 
			
		||||
 | 
			
		||||
                wait.tv_sec = 0;
 | 
			
		||||
                wait.tv_nsec = 10 * 1000000; /* 10 ms */
 | 
			
		||||
                nanosleep(&wait, &wait);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (bytes_read >= 0) {
 | 
			
		||||
                wr->read_consumed += bytes_read;
 | 
			
		||||
                return 0;
 | 
			
		||||
            } else {
 | 
			
		||||
                err = bytes_read;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return err;
 | 
			
		||||
    } else {
 | 
			
		||||
        if (wr->read_size > 0) {
 | 
			
		||||
            struct timespec wait;
 | 
			
		||||
 | 
			
		||||
            wait.tv_sec = 0;
 | 
			
		||||
            wait.tv_nsec = 100 * 1000000; /* 100 ms */
 | 
			
		||||
            nanosleep(&wait, &wait);
 | 
			
		||||
        }
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    return err;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const TestBinderIo test_io_64 = {
 | 
			
		||||
@@ -274,6 +431,17 @@ test_io_destroy_none(
 | 
			
		||||
    GDEBUG("Not freeing %p", data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_set_looper_enabled(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gboolean enabled)
 | 
			
		||||
{
 | 
			
		||||
    TestBinder* binder = test_binder_from_fd(fd);
 | 
			
		||||
 | 
			
		||||
    g_assert(binder);
 | 
			
		||||
    binder->looper_enabled = enabled;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_set_destroy(
 | 
			
		||||
    int fd,
 | 
			
		||||
@@ -291,43 +459,35 @@ test_binder_set_destroy(
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_push_data(
 | 
			
		||||
    int fd,
 | 
			
		||||
    const void* data)
 | 
			
		||||
{
 | 
			
		||||
    const guint32* cmd = data;
 | 
			
		||||
    const int len = sizeof(*cmd) + _IOC_SIZE(*cmd);
 | 
			
		||||
    TestBinder* binder = test_binder_from_fd(fd);
 | 
			
		||||
 | 
			
		||||
    g_assert(binder);
 | 
			
		||||
    g_assert(write(binder->private_fd, data, len) == len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_binder_push_data_later(
 | 
			
		||||
    int fd,
 | 
			
		||||
    const void* data)
 | 
			
		||||
{
 | 
			
		||||
    TestBinder* binder = test_binder_from_fd(fd);
 | 
			
		||||
 | 
			
		||||
    if (binder) {
 | 
			
		||||
        const guint32* cmd = data;
 | 
			
		||||
        const int len = sizeof(*cmd) + _IOC_SIZE(*cmd);
 | 
			
		||||
 | 
			
		||||
        return write(binder->private_fd, data, len) == len;
 | 
			
		||||
    g_assert(binder);
 | 
			
		||||
    if (!binder->submit_thread) {
 | 
			
		||||
        binder->submit_thread = test_binder_submit_thread_new(binder);
 | 
			
		||||
    }
 | 
			
		||||
    return FALSE;
 | 
			
		||||
    test_binder_submit_later(binder->submit_thread, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_binder_fill_transaction_data(
 | 
			
		||||
    BinderTransactionData64* tr,
 | 
			
		||||
    guint64 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* bytes)
 | 
			
		||||
{
 | 
			
		||||
    g_assert(bytes);
 | 
			
		||||
 | 
			
		||||
    memset(tr, 0, sizeof(*tr));
 | 
			
		||||
    tr->handle = handle;
 | 
			
		||||
    tr->code = code;
 | 
			
		||||
    tr->data_size = bytes->len;
 | 
			
		||||
    tr->sender_pid = getpid();
 | 
			
		||||
    tr->sender_euid = geteuid();
 | 
			
		||||
    /* This memory should eventually get deallocated with BC_FREE_BUFFER_64 */
 | 
			
		||||
    tr->data_buffer = (gsize)g_memdup(bytes->data, bytes->len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
test_binder_push_ptr_cookie(
 | 
			
		||||
    int fd,
 | 
			
		||||
    guint32 cmd,
 | 
			
		||||
@@ -339,60 +499,69 @@ test_binder_push_ptr_cookie(
 | 
			
		||||
    memcpy(buf, &cmd, sizeof(cmd));
 | 
			
		||||
    memset(data, 0, sizeof(*data));
 | 
			
		||||
    data->ptr = (gsize)ptr;
 | 
			
		||||
    return test_binder_push_data(fd, buf);
 | 
			
		||||
    test_binder_push_data(fd, buf);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_noop(
 | 
			
		||||
    int fd)
 | 
			
		||||
{
 | 
			
		||||
    guint32 cmd = BR_NOOP;
 | 
			
		||||
 | 
			
		||||
    return test_binder_push_data(fd, &cmd);
 | 
			
		||||
    test_binder_push_data(fd, &cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_increfs(
 | 
			
		||||
    int fd,
 | 
			
		||||
    void* ptr)
 | 
			
		||||
{
 | 
			
		||||
    return test_binder_push_ptr_cookie(fd, BR_INCREFS_64, ptr);
 | 
			
		||||
    test_binder_push_ptr_cookie(fd, BR_INCREFS_64, ptr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_acquire(
 | 
			
		||||
    int fd,
 | 
			
		||||
    void* ptr)
 | 
			
		||||
{
 | 
			
		||||
    return test_binder_push_ptr_cookie(fd, BR_ACQUIRE_64, ptr);
 | 
			
		||||
    test_binder_push_ptr_cookie(fd, BR_ACQUIRE_64, ptr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_release(
 | 
			
		||||
    int fd,
 | 
			
		||||
    void* ptr)
 | 
			
		||||
{
 | 
			
		||||
    return test_binder_push_ptr_cookie(fd, BR_RELEASE_64, ptr);
 | 
			
		||||
    test_binder_push_ptr_cookie(fd, BR_RELEASE_64, ptr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_decrefs(
 | 
			
		||||
    int fd,
 | 
			
		||||
    void* ptr)
 | 
			
		||||
{
 | 
			
		||||
    return test_binder_push_ptr_cookie(fd, BR_DECREFS_64, ptr);
 | 
			
		||||
    test_binder_push_ptr_cookie(fd, BR_DECREFS_64, ptr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_transaction_complete(
 | 
			
		||||
    int fd)
 | 
			
		||||
{
 | 
			
		||||
    guint32 cmd = BR_TRANSACTION_COMPLETE;
 | 
			
		||||
 | 
			
		||||
    return test_binder_push_data(fd, &cmd);
 | 
			
		||||
    test_binder_push_data(fd, &cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_transaction_complete_later(
 | 
			
		||||
    int fd)
 | 
			
		||||
{
 | 
			
		||||
    guint32 cmd = BR_TRANSACTION_COMPLETE;
 | 
			
		||||
 | 
			
		||||
    test_binder_push_data_later(fd, &cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_dead_binder(
 | 
			
		||||
    int fd,
 | 
			
		||||
    guint handle)
 | 
			
		||||
@@ -403,28 +572,47 @@ test_binder_br_dead_binder(
 | 
			
		||||
    buf[0] = BR_DEAD_BINDER_64;
 | 
			
		||||
    memcpy(buf + 1, &handle64, sizeof(handle64));
 | 
			
		||||
 | 
			
		||||
    return test_binder_push_data(fd, buf);
 | 
			
		||||
    test_binder_push_data(fd, buf);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_dead_reply(
 | 
			
		||||
    int fd)
 | 
			
		||||
{
 | 
			
		||||
    guint32 cmd = BR_DEAD_REPLY;
 | 
			
		||||
 | 
			
		||||
    return test_binder_push_data(fd, &cmd);
 | 
			
		||||
    test_binder_push_data(fd, &cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_failed_reply(
 | 
			
		||||
    int fd)
 | 
			
		||||
{
 | 
			
		||||
    guint32 cmd = BR_FAILED_REPLY;
 | 
			
		||||
 | 
			
		||||
    return test_binder_push_data(fd, &cmd);
 | 
			
		||||
    test_binder_push_data(fd, &cmd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_binder_fill_transaction_data(
 | 
			
		||||
    BinderTransactionData64* tr,
 | 
			
		||||
    guint64 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* bytes)
 | 
			
		||||
{
 | 
			
		||||
    memset(tr, 0, sizeof(*tr));
 | 
			
		||||
    tr->handle = handle;
 | 
			
		||||
    tr->code = code;
 | 
			
		||||
    tr->data_size = bytes ? bytes->len : 0;
 | 
			
		||||
    tr->sender_pid = getpid();
 | 
			
		||||
    tr->sender_euid = geteuid();
 | 
			
		||||
    /* This memory should eventually get deallocated with BC_FREE_BUFFER_64 */
 | 
			
		||||
    tr->data_buffer = (gsize)g_memdup(bytes ? (void*)bytes->data : (void*)"",
 | 
			
		||||
        tr->data_size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_transaction(
 | 
			
		||||
    int fd,
 | 
			
		||||
    void* target,
 | 
			
		||||
@@ -438,15 +626,17 @@ test_binder_br_transaction(
 | 
			
		||||
    test_binder_fill_transaction_data((void*)(buf + sizeof(cmd)),
 | 
			
		||||
        (gsize)target, code, bytes);
 | 
			
		||||
 | 
			
		||||
    return test_binder_push_data(fd, buf);
 | 
			
		||||
    test_binder_push_data(fd, buf);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
test_binder_br_reply(
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_reply1(
 | 
			
		||||
    int fd,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* bytes)
 | 
			
		||||
    const GByteArray* bytes,
 | 
			
		||||
    TestBinderPushDataFunc push)
 | 
			
		||||
{
 | 
			
		||||
    guint32 cmd = BR_REPLY_64;
 | 
			
		||||
    guint8 buf[sizeof(guint32) + sizeof(BinderTransactionData64)];
 | 
			
		||||
@@ -455,13 +645,34 @@ test_binder_br_reply(
 | 
			
		||||
    test_binder_fill_transaction_data((void*)(buf + sizeof(cmd)),
 | 
			
		||||
        handle, code, bytes);
 | 
			
		||||
 | 
			
		||||
    return test_binder_push_data(fd, buf);
 | 
			
		||||
    push(fd, buf);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
test_binder_br_reply_status(
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_reply(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gint32 status)
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* bytes)
 | 
			
		||||
{
 | 
			
		||||
    test_binder_br_reply1(fd, handle, code, bytes, test_binder_push_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_reply_later(
 | 
			
		||||
    int fd,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* bytes)
 | 
			
		||||
{
 | 
			
		||||
    test_binder_br_reply1(fd, handle, code, bytes, test_binder_push_data_later);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_reply_status1(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gint32 status,
 | 
			
		||||
    TestBinderPushDataFunc push)
 | 
			
		||||
{
 | 
			
		||||
    guint8 buf[sizeof(guint32) + sizeof(BinderTransactionData64)];
 | 
			
		||||
    guint32* cmd = (void*)buf;
 | 
			
		||||
@@ -473,7 +684,24 @@ test_binder_br_reply_status(
 | 
			
		||||
    tr->data_size = sizeof(status);
 | 
			
		||||
    /* This memory should eventually get deallocated with BC_FREE_BUFFER_64 */
 | 
			
		||||
    tr->data_buffer = (gsize)g_memdup(&status, sizeof(status));
 | 
			
		||||
    return test_binder_push_data(fd, buf);
 | 
			
		||||
 | 
			
		||||
    push(fd, buf);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_reply_status(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gint32 status)
 | 
			
		||||
{
 | 
			
		||||
    test_binder_br_reply_status1(fd, status, test_binder_push_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_reply_status_later(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gint32 status)
 | 
			
		||||
{
 | 
			
		||||
    test_binder_br_reply_status1(fd, status, test_binder_push_data_later);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
@@ -532,6 +760,7 @@ gbinder_system_close(
 | 
			
		||||
            g_hash_table_unref(test_fd_map);
 | 
			
		||||
            test_fd_map = NULL;
 | 
			
		||||
        }
 | 
			
		||||
        test_binder_submit_thread_free(binder->submit_thread);
 | 
			
		||||
        test_binder_node_unref(binder->node);
 | 
			
		||||
        close(binder->public_fd);
 | 
			
		||||
        close(binder->private_fd);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -35,66 +35,87 @@
 | 
			
		||||
 | 
			
		||||
#include "test_common.h"
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_noop(
 | 
			
		||||
    int fd);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_increfs(
 | 
			
		||||
    int fd,
 | 
			
		||||
    void* ptr);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_acquire(
 | 
			
		||||
    int fd,
 | 
			
		||||
    void* ptr);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_release(
 | 
			
		||||
    int fd,
 | 
			
		||||
    void* ptr);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_decrefs(
 | 
			
		||||
    int fd,
 | 
			
		||||
    void* ptr);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_transaction_complete(
 | 
			
		||||
    int fd);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_transaction_complete_later(
 | 
			
		||||
    int fd);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_dead_binder(
 | 
			
		||||
    int fd,
 | 
			
		||||
    guint handle);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_dead_reply(
 | 
			
		||||
    int fd);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_failed_reply(
 | 
			
		||||
    int fd);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_transaction(
 | 
			
		||||
    int fd,
 | 
			
		||||
    void* target,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* bytes);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_reply(
 | 
			
		||||
    int fd,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* bytes);
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_reply_status(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gint32 status);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_reply_later(
 | 
			
		||||
    int fd,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* bytes);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_reply_status_later(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gint32 status);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_set_looper_enabled(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gboolean enabled);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_set_destroy(
 | 
			
		||||
    int fd,
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ unit_remote_object \
 | 
			
		||||
unit_remote_reply \
 | 
			
		||||
unit_remote_request \
 | 
			
		||||
unit_servicemanager \
 | 
			
		||||
unit_servicename \
 | 
			
		||||
unit_servicepoll \
 | 
			
		||||
unit_writer"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -14,8 +14,8 @@
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer in the
 | 
			
		||||
 *      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.
 | 
			
		||||
 *      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,16 +74,15 @@ void
 | 
			
		||||
test_null(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderClient* null = NULL;
 | 
			
		||||
 | 
			
		||||
    g_assert(!gbinder_client_new(NULL, NULL));
 | 
			
		||||
    g_assert(!gbinder_client_ref(null));
 | 
			
		||||
    gbinder_client_unref(null);
 | 
			
		||||
    g_assert(!gbinder_client_ref(NULL));
 | 
			
		||||
    g_assert(!gbinder_client_interface(NULL));
 | 
			
		||||
    gbinder_client_unref(NULL);
 | 
			
		||||
    g_assert(!gbinder_client_new_request(NULL));
 | 
			
		||||
    g_assert(!gbinder_client_transact_sync_reply(null, 0, NULL, NULL));
 | 
			
		||||
    g_assert(gbinder_client_transact_sync_oneway(null, 0, NULL) == (-EINVAL));
 | 
			
		||||
    g_assert(!gbinder_client_transact(null, 0, 0, NULL, NULL, NULL, NULL));
 | 
			
		||||
    gbinder_client_cancel(null, 0);
 | 
			
		||||
    g_assert(!gbinder_client_transact_sync_reply(NULL, 0, NULL, NULL));
 | 
			
		||||
    g_assert(gbinder_client_transact_sync_oneway(NULL, 0, NULL) == (-EINVAL));
 | 
			
		||||
    g_assert(!gbinder_client_transact(NULL, 0, 0, NULL, NULL, NULL, NULL));
 | 
			
		||||
    gbinder_client_cancel(NULL, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -98,10 +97,12 @@ test_basic(
 | 
			
		||||
    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");
 | 
			
		||||
    const char* iface = "foo";
 | 
			
		||||
    GBinderClient* client = gbinder_client_new(obj, iface);
 | 
			
		||||
 | 
			
		||||
    g_assert(client);
 | 
			
		||||
    g_assert(gbinder_client_ref(client) == client);
 | 
			
		||||
    g_assert(!g_strcmp0(gbinder_client_interface(client), iface));
 | 
			
		||||
    gbinder_client_unref(client);
 | 
			
		||||
    gbinder_client_cancel(client, 0); /* does nothing */
 | 
			
		||||
 | 
			
		||||
@@ -129,6 +130,45 @@ test_no_header(
 | 
			
		||||
    gbinder_client_unref(client);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * dead
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_dead_done(
 | 
			
		||||
    GBinderRemoteObject* obj,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GVERBOSE_("");
 | 
			
		||||
    test_quit_later((GMainLoop*)user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_dead(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const guint handle = 1;
 | 
			
		||||
    GBinderClient* client = test_client_new(handle, "foo");
 | 
			
		||||
    GBinderRemoteObject* obj = client->remote;
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    const int fd = gbinder_driver_fd(gbinder_client_ipc(client)->driver);
 | 
			
		||||
    gbinder_remote_object_add_death_handler(obj, test_dead_done, loop);
 | 
			
		||||
 | 
			
		||||
    test_binder_br_dead_binder(fd, handle);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
    g_assert(gbinder_remote_object_is_dead(obj));
 | 
			
		||||
 | 
			
		||||
    g_assert(!gbinder_client_transact_sync_reply(client, 0, NULL, NULL));
 | 
			
		||||
    g_assert(gbinder_client_transact_sync_oneway(client, 0, NULL) == -ESTALE);
 | 
			
		||||
    g_assert(!gbinder_client_transact(client, 0, 0, NULL, NULL, NULL, NULL));
 | 
			
		||||
 | 
			
		||||
    gbinder_client_unref(client);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * sync_oneway
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -182,10 +222,10 @@ test_sync_reply_tx(
 | 
			
		||||
    data = gbinder_local_reply_data(reply);
 | 
			
		||||
    g_assert(data);
 | 
			
		||||
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_transaction_complete(fd));
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_reply(fd, handle, code, data->bytes));
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_reply(fd, handle, code, data->bytes);
 | 
			
		||||
 | 
			
		||||
    tx_reply = gbinder_client_transact_sync_reply(client, 0, req, &status);
 | 
			
		||||
    g_assert(tx_reply);
 | 
			
		||||
@@ -283,10 +323,10 @@ test_reply_tx(
 | 
			
		||||
    data = gbinder_local_reply_data(reply);
 | 
			
		||||
    g_assert(data);
 | 
			
		||||
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_transaction_complete(fd));
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_reply(fd, handle, code, data->bytes));
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_reply(fd, handle, code, data->bytes);
 | 
			
		||||
 | 
			
		||||
    id = gbinder_client_transact(client, 0, 0, req, done, destroy, loop);
 | 
			
		||||
    g_assert(id);
 | 
			
		||||
@@ -351,6 +391,7 @@ int main(int argc, char* argv[])
 | 
			
		||||
    g_test_init(&argc, &argv, NULL);
 | 
			
		||||
    g_test_add_func(TEST_("null"), test_null);
 | 
			
		||||
    g_test_add_func(TEST_("basic"), test_basic);
 | 
			
		||||
    g_test_add_func(TEST_("dead"), test_dead);
 | 
			
		||||
    g_test_add_func(TEST_("no_header"), test_no_header);
 | 
			
		||||
    g_test_add_func(TEST_("sync_oneway"), test_sync_oneway);
 | 
			
		||||
    g_test_add_func(TEST_("sync_reply"), test_sync_reply);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -91,7 +91,7 @@ test_noop(
 | 
			
		||||
 | 
			
		||||
    g_assert(driver);
 | 
			
		||||
    g_assert(fd >= 0);
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    g_assert(gbinder_driver_poll(driver, NULL) == POLLIN);
 | 
			
		||||
    g_assert(gbinder_driver_read(driver, NULL, NULL) == 0);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -14,8 +14,8 @@
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer in the
 | 
			
		||||
 *      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.
 | 
			
		||||
 *      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
 | 
			
		||||
@@ -34,7 +34,7 @@
 | 
			
		||||
 | 
			
		||||
#include "gbinder_ipc.h"
 | 
			
		||||
#include "gbinder_driver.h"
 | 
			
		||||
#include "gbinder_local_object.h"
 | 
			
		||||
#include "gbinder_local_object_p.h"
 | 
			
		||||
#include "gbinder_local_reply_p.h"
 | 
			
		||||
#include "gbinder_local_request_p.h"
 | 
			
		||||
#include "gbinder_object_registry.h"
 | 
			
		||||
@@ -127,6 +127,48 @@ test_basic(
 | 
			
		||||
 | 
			
		||||
    /* Invalid path */
 | 
			
		||||
    g_assert(!gbinder_ipc_new("invalid path", NULL));
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * async_oneway
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_async_oneway_done(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    GBinderRemoteReply* reply,
 | 
			
		||||
    int status,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    g_assert(!status);
 | 
			
		||||
    g_assert(!reply);
 | 
			
		||||
    test_quit_later((GMainLoop*)user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_async_oneway(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    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);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    id = gbinder_ipc_transact(ipc, 0, 1, GBINDER_TX_FLAG_ONEWAY,
 | 
			
		||||
        req, test_async_oneway_done, NULL, loop);
 | 
			
		||||
    g_assert(id);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -143,11 +185,12 @@ test_sync_oneway(
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
 | 
			
		||||
 | 
			
		||||
    g_assert(test_binder_br_transaction_complete(fd));
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    g_assert(gbinder_ipc_transact_sync_oneway(ipc, 0, 1, req) ==
 | 
			
		||||
        GBINDER_STATUS_OK);
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -175,10 +218,10 @@ test_sync_reply_ok_status(
 | 
			
		||||
    data = gbinder_local_reply_data(reply);
 | 
			
		||||
    g_assert(data);
 | 
			
		||||
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_transaction_complete(fd));
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_reply(fd, handle, code, data->bytes));
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_reply(fd, handle, code, data->bytes);
 | 
			
		||||
 | 
			
		||||
    tx_reply = gbinder_ipc_transact_sync_reply(ipc, handle, code, req, status);
 | 
			
		||||
    g_assert(tx_reply);
 | 
			
		||||
@@ -191,6 +234,7 @@ test_sync_reply_ok_status(
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    gbinder_local_reply_unref(reply);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -223,16 +267,17 @@ test_sync_reply_error(
 | 
			
		||||
    const gint expected_status = GBINDER_STATUS_FAILED;
 | 
			
		||||
    int status = INT_MAX;
 | 
			
		||||
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_transaction_complete(fd));
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_reply_status(fd, expected_status));
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_reply_status(fd, expected_status);
 | 
			
		||||
 | 
			
		||||
    g_assert(!gbinder_ipc_transact_sync_reply(ipc, handle, code, req, &status));
 | 
			
		||||
    g_assert(status == expected_status);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -286,10 +331,10 @@ test_transact_ok(
 | 
			
		||||
    data = gbinder_local_reply_data(reply);
 | 
			
		||||
    g_assert(data);
 | 
			
		||||
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_transaction_complete(fd));
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_reply(fd, handle, code, data->bytes));
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_reply(fd, handle, code, data->bytes);
 | 
			
		||||
 | 
			
		||||
    id = gbinder_ipc_transact(ipc, handle, code, 0, req,
 | 
			
		||||
        test_transact_ok_done, test_transact_ok_destroy, loop);
 | 
			
		||||
@@ -302,6 +347,7 @@ test_transact_ok(
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    gbinder_local_reply_unref(reply);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -335,8 +381,8 @@ test_transact_dead(
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_dead_reply(fd));
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_dead_reply(fd);
 | 
			
		||||
 | 
			
		||||
    id = gbinder_ipc_transact(ipc, 1, 2, 0, req, test_transact_dead_done,
 | 
			
		||||
        NULL, loop);
 | 
			
		||||
@@ -348,6 +394,7 @@ test_transact_dead(
 | 
			
		||||
    gbinder_ipc_cancel(ipc, id);
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -381,8 +428,8 @@ test_transact_failed(
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_failed_reply(fd));
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_failed_reply(fd);
 | 
			
		||||
 | 
			
		||||
    id = gbinder_ipc_transact(ipc, 1, 2, 0, req, test_transact_failed_done,
 | 
			
		||||
        NULL, loop);
 | 
			
		||||
@@ -394,6 +441,7 @@ test_transact_failed(
 | 
			
		||||
    gbinder_ipc_cancel(ipc, id);
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -429,8 +477,8 @@ test_transact_status(
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    g_assert(test_binder_br_noop(fd));
 | 
			
		||||
    g_assert(test_binder_br_reply_status(fd, EXPECTED_STATUS));
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_reply_status(fd, EXPECTED_STATUS);
 | 
			
		||||
 | 
			
		||||
    id = gbinder_ipc_transact(ipc, 1, 2, 0, req, test_transact_status_done,
 | 
			
		||||
        NULL, loop);
 | 
			
		||||
@@ -442,6 +490,7 @@ test_transact_status(
 | 
			
		||||
    gbinder_ipc_cancel(ipc, id);
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -471,6 +520,7 @@ test_transact_custom(
 | 
			
		||||
    g_assert(id);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
@@ -501,10 +551,44 @@ test_transact_custom2(
 | 
			
		||||
    g_assert(id);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * transact_custom3
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_transact_custom3_exec(
 | 
			
		||||
    const GBinderIpcTx* tx)
 | 
			
		||||
{
 | 
			
		||||
    GVERBOSE_("");
 | 
			
		||||
    gbinder_ipc_unref(tx->ipc);
 | 
			
		||||
    test_quit_later((GMainLoop*)tx->user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_transact_custom3(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    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_custom3_exec,
 | 
			
		||||
        NULL, NULL, loop);
 | 
			
		||||
 | 
			
		||||
    g_assert(id);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    /* Reference to GBinderIpc is released by test_transact_custom3_exec */
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * transact_cancel
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -550,6 +634,7 @@ test_transact_cancel(
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -594,6 +679,7 @@ test_transact_cancel2(
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -634,9 +720,10 @@ test_transact_incoming(
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    const char* dev = gbinder_driver_dev(ipc->driver);
 | 
			
		||||
    const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
 | 
			
		||||
    const char* const ifaces[] = { "test", NULL };
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_ipc_new_local_object
 | 
			
		||||
        (ipc, "test", test_transact_incoming_proc, loop);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new
 | 
			
		||||
        (ipc, ifaces, test_transact_incoming_proc, loop);
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
 | 
			
		||||
    GBinderOutputData* data;
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
@@ -647,6 +734,7 @@ test_transact_incoming(
 | 
			
		||||
    data = gbinder_local_request_data(req);
 | 
			
		||||
 | 
			
		||||
    test_binder_br_transaction(fd, obj, 1, data->bytes);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    /* Now we need to wait until GBinderIpc is destroyed */
 | 
			
		||||
@@ -657,6 +745,7 @@ test_transact_incoming(
 | 
			
		||||
    g_idle_add(test_unref_ipc, ipc);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -695,9 +784,10 @@ test_transact_status_reply(
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    const char* dev = gbinder_driver_dev(ipc->driver);
 | 
			
		||||
    const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
 | 
			
		||||
    const char* const ifaces[] = { "test", NULL };
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_ipc_new_local_object
 | 
			
		||||
        (ipc, "test", test_transact_status_reply_proc, loop);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new
 | 
			
		||||
        (ipc, ifaces, test_transact_status_reply_proc, loop);
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
 | 
			
		||||
    GBinderOutputData* data;
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
@@ -708,6 +798,7 @@ test_transact_status_reply(
 | 
			
		||||
    data = gbinder_local_request_data(req);
 | 
			
		||||
 | 
			
		||||
    test_binder_br_transaction(fd, obj, 1, data->bytes);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    /* Now we need to wait until GBinderIpc is destroyed */
 | 
			
		||||
@@ -718,6 +809,7 @@ test_transact_status_reply(
 | 
			
		||||
    g_idle_add(test_unref_ipc, ipc);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -799,9 +891,10 @@ test_transact_async(
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    const char* dev = gbinder_driver_dev(ipc->driver);
 | 
			
		||||
    const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
 | 
			
		||||
    const char* const ifaces[] = { "test", NULL };
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_ipc_new_local_object
 | 
			
		||||
        (ipc, "test", test_transact_async_proc, loop);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new
 | 
			
		||||
        (ipc, ifaces, test_transact_async_proc, loop);
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
 | 
			
		||||
    GBinderOutputData* data;
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
@@ -812,6 +905,7 @@ test_transact_async(
 | 
			
		||||
    data = gbinder_local_request_data(req);
 | 
			
		||||
 | 
			
		||||
    test_binder_br_transaction(fd, obj, 1, data->bytes);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    /* Now we need to wait until GBinderIpc is destroyed */
 | 
			
		||||
@@ -822,6 +916,7 @@ test_transact_async(
 | 
			
		||||
    g_idle_add(test_unref_ipc, ipc);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -869,9 +964,10 @@ test_transact_async_sync(
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    const char* dev = gbinder_driver_dev(ipc->driver);
 | 
			
		||||
    const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
 | 
			
		||||
    const char* const ifaces[] = { "test", NULL };
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_ipc_new_local_object
 | 
			
		||||
        (ipc, "test", test_transact_async_sync_proc, loop);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new
 | 
			
		||||
        (ipc, ifaces, test_transact_async_sync_proc, loop);
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
 | 
			
		||||
    GBinderOutputData* data;
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
@@ -882,6 +978,7 @@ test_transact_async_sync(
 | 
			
		||||
    data = gbinder_local_request_data(req);
 | 
			
		||||
 | 
			
		||||
    test_binder_br_transaction(fd, obj, 1, data->bytes);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    /* Now we need to wait until GBinderIpc is destroyed */
 | 
			
		||||
@@ -892,6 +989,86 @@ test_transact_async_sync(
 | 
			
		||||
    g_idle_add(test_unref_ipc, ipc);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * drop_remote_refs
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_drop_remote_refs_cb(
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GVERBOSE_("%d", obj->strong_refs);
 | 
			
		||||
    g_assert(obj->strong_refs == 1);
 | 
			
		||||
    test_quit_later((GMainLoop*)user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_drop_remote_refs(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new
 | 
			
		||||
        (ipc, NULL, NULL, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    gulong id = gbinder_local_object_add_strong_refs_changed_handler(obj,
 | 
			
		||||
        test_drop_remote_refs_cb, loop);
 | 
			
		||||
 | 
			
		||||
    test_binder_br_acquire(fd, obj);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    g_assert(obj->strong_refs == 1);
 | 
			
		||||
    gbinder_local_object_remove_handler(obj, id);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
 | 
			
		||||
    /* gbinder_ipc_exit will drop the remote reference */
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * cancel_on_exit
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_cancel_on_exit_not_reached(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    GBinderRemoteReply* reply,
 | 
			
		||||
    int status,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    g_assert_not_reached();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_cancel_on_exit(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
 | 
			
		||||
    const GBinderIo* io = gbinder_driver_io(ipc->driver);
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
 | 
			
		||||
    /* This transaction will be cancelled by gbinder_ipc_exit */
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    gbinder_ipc_transact(ipc, 0, 1, GBINDER_TX_FLAG_ONEWAY,
 | 
			
		||||
        req, test_cancel_on_exit_not_reached, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_ipc_exit();
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -907,6 +1084,7 @@ int main(int argc, char* argv[])
 | 
			
		||||
    g_test_init(&argc, &argv, NULL);
 | 
			
		||||
    g_test_add_func(TEST_("null"), test_null);
 | 
			
		||||
    g_test_add_func(TEST_("basic"), test_basic);
 | 
			
		||||
    g_test_add_func(TEST_("async_oneway"), test_async_oneway);
 | 
			
		||||
    g_test_add_func(TEST_("sync_oneway"), test_sync_oneway);
 | 
			
		||||
    g_test_add_func(TEST_("sync_reply_ok"), test_sync_reply_ok);
 | 
			
		||||
    g_test_add_func(TEST_("sync_reply_error"), test_sync_reply_error);
 | 
			
		||||
@@ -916,12 +1094,15 @@ int main(int argc, char* argv[])
 | 
			
		||||
    g_test_add_func(TEST_("transact_status"), test_transact_status);
 | 
			
		||||
    g_test_add_func(TEST_("transact_custom"), test_transact_custom);
 | 
			
		||||
    g_test_add_func(TEST_("transact_custom2"), test_transact_custom2);
 | 
			
		||||
    g_test_add_func(TEST_("transact_custom3"), test_transact_custom3);
 | 
			
		||||
    g_test_add_func(TEST_("transact_cancel"), test_transact_cancel);
 | 
			
		||||
    g_test_add_func(TEST_("transact_cancel2"), test_transact_cancel2);
 | 
			
		||||
    g_test_add_func(TEST_("transact_incoming"), test_transact_incoming);
 | 
			
		||||
    g_test_add_func(TEST_("transact_status_reply"), test_transact_status_reply);
 | 
			
		||||
    g_test_add_func(TEST_("transact_async"), test_transact_async);
 | 
			
		||||
    g_test_add_func(TEST_("transact_async_sync"), test_transact_async_sync);
 | 
			
		||||
    g_test_add_func(TEST_("drop_remote_refs"), test_drop_remote_refs);
 | 
			
		||||
    g_test_add_func(TEST_("cancel_on_exit"), test_cancel_on_exit);
 | 
			
		||||
    test_init(&test_opt, argc, argv);
 | 
			
		||||
    return g_test_run();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -150,6 +150,8 @@ void
 | 
			
		||||
test_basic(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char* const ifaces_foo[] = { "foo", NULL };
 | 
			
		||||
    const char* const ifaces_bar[] = { "bar", NULL };
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
 | 
			
		||||
    GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
 | 
			
		||||
    GBinderLocalObject* foo;
 | 
			
		||||
@@ -159,8 +161,8 @@ test_basic(
 | 
			
		||||
    g_assert(!gbinder_object_registry_get_local(reg, ipc));
 | 
			
		||||
 | 
			
		||||
    /* Create a new local objects */
 | 
			
		||||
    foo = gbinder_ipc_new_local_object(ipc, "foo", NULL, NULL);
 | 
			
		||||
    bar = gbinder_ipc_new_local_object(ipc, "bar", NULL, NULL);
 | 
			
		||||
    foo = gbinder_local_object_new(ipc, ifaces_foo, NULL, NULL);
 | 
			
		||||
    bar = gbinder_local_object_new(ipc, ifaces_bar, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
    /* But ipc is still not a local object! */
 | 
			
		||||
    g_assert(!gbinder_object_registry_get_local(reg, ipc));
 | 
			
		||||
@@ -195,6 +197,100 @@ static
 | 
			
		||||
void
 | 
			
		||||
test_ping(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    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, NULL);
 | 
			
		||||
    GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
 | 
			
		||||
    GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new(ipc, NULL, NULL, NULL);
 | 
			
		||||
    GBinderLocalReply* reply;
 | 
			
		||||
    GBinderOutputData* out_data;
 | 
			
		||||
    static const guint8 result[] = { 0x00, 0x00, 0x00, 0x00 };
 | 
			
		||||
 | 
			
		||||
    g_assert(gbinder_local_object_can_handle_transaction(obj, NULL,
 | 
			
		||||
        GBINDER_PING_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
 | 
			
		||||
 | 
			
		||||
    /* If can_handle_transaction() returns TRANSACTION_LOOPER then it must be
 | 
			
		||||
     * handled by handle_looper_transaction() */
 | 
			
		||||
    g_assert(!gbinder_local_object_handle_transaction(obj, req,
 | 
			
		||||
        GBINDER_PING_TRANSACTION, 0, &status));
 | 
			
		||||
    g_assert(status == (-EBADMSG));
 | 
			
		||||
    reply = gbinder_local_object_handle_looper_transaction(obj, req,
 | 
			
		||||
        GBINDER_PING_TRANSACTION, 0, &status);
 | 
			
		||||
    g_assert(reply);
 | 
			
		||||
    g_assert(status == GBINDER_STATUS_OK);
 | 
			
		||||
 | 
			
		||||
    out_data = gbinder_local_reply_data(reply);
 | 
			
		||||
    g_assert(out_data);
 | 
			
		||||
    g_assert(out_data->bytes);
 | 
			
		||||
    g_assert(out_data->bytes->len == sizeof(result));
 | 
			
		||||
    g_assert(!memcmp(out_data->bytes->data, result, sizeof(result)));
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
    gbinder_local_reply_unref(reply);
 | 
			
		||||
    gbinder_remote_request_unref(req);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_interface(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    int status = INT_MAX;
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
 | 
			
		||||
    const char* const ifaces[] = { "x", NULL };
 | 
			
		||||
    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_local_object_new(ipc, ifaces, NULL, NULL);
 | 
			
		||||
    GBinderLocalReply* reply;
 | 
			
		||||
    GBinderOutputData* out_data;
 | 
			
		||||
    static const guint8 result[] = {
 | 
			
		||||
        TEST_INT32_BYTES(1),
 | 
			
		||||
        TEST_INT16_BYTES('x'), 0x00, 0x00
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    g_assert(gbinder_local_object_can_handle_transaction(obj, NULL,
 | 
			
		||||
        GBINDER_INTERFACE_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
 | 
			
		||||
 | 
			
		||||
    /* If can_handle_transaction() returns TRANSACTION_LOOPER then it must be
 | 
			
		||||
     * handled by handle_looper_transaction() */
 | 
			
		||||
    g_assert(!gbinder_local_object_handle_transaction(obj, req,
 | 
			
		||||
        GBINDER_INTERFACE_TRANSACTION, 0, &status));
 | 
			
		||||
    g_assert(status == (-EBADMSG));
 | 
			
		||||
    reply = gbinder_local_object_handle_looper_transaction(obj, req,
 | 
			
		||||
        GBINDER_INTERFACE_TRANSACTION, 0, &status);
 | 
			
		||||
    g_assert(reply);
 | 
			
		||||
    g_assert(status == GBINDER_STATUS_OK);
 | 
			
		||||
 | 
			
		||||
    out_data = gbinder_local_reply_data(reply);
 | 
			
		||||
    g_assert(out_data);
 | 
			
		||||
    g_assert(out_data->bytes);
 | 
			
		||||
    g_assert(out_data->bytes->len == sizeof(result));
 | 
			
		||||
    g_assert(!memcmp(out_data->bytes->data, result, sizeof(result)));
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
    gbinder_local_reply_unref(reply);
 | 
			
		||||
    gbinder_remote_request_unref(req);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * hidl_ping
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_ping(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    static const guint8 req_data [] = { TEST_BASE_INTERFACE_HEADER_BYTES };
 | 
			
		||||
    int status = INT_MAX;
 | 
			
		||||
@@ -203,9 +299,10 @@ test_ping(
 | 
			
		||||
    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, NULL, NULL, NULL);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new(ipc, NULL, NULL, NULL);
 | 
			
		||||
    GBinderLocalReply* reply;
 | 
			
		||||
    GBinderOutputData* out_data;
 | 
			
		||||
    static const guint8 result[] = { 0x00, 0x00, 0x00, 0x00 };
 | 
			
		||||
 | 
			
		||||
    gbinder_remote_request_set_data(req, HIDL_PING_TRANSACTION,
 | 
			
		||||
        gbinder_buffer_new(ipc->driver, g_memdup(req_data, sizeof(req_data)),
 | 
			
		||||
@@ -224,6 +321,12 @@ test_ping(
 | 
			
		||||
    g_assert(reply);
 | 
			
		||||
    g_assert(status == GBINDER_STATUS_OK);
 | 
			
		||||
 | 
			
		||||
    out_data = gbinder_local_reply_data(reply);
 | 
			
		||||
    g_assert(out_data);
 | 
			
		||||
    g_assert(out_data->bytes);
 | 
			
		||||
    g_assert(out_data->bytes->len == sizeof(result));
 | 
			
		||||
    g_assert(!memcmp(out_data->bytes->data, result, sizeof(result)));
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
    gbinder_local_reply_unref(reply);
 | 
			
		||||
@@ -246,8 +349,7 @@ test_get_descriptor(
 | 
			
		||||
    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, NULL, NULL, NULL);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new(ipc, NULL, NULL, NULL);
 | 
			
		||||
    GBinderLocalReply* reply;
 | 
			
		||||
 | 
			
		||||
    gbinder_remote_request_set_data(req, HIDL_PING_TRANSACTION,
 | 
			
		||||
@@ -298,15 +400,16 @@ test_descriptor_chain(
 | 
			
		||||
    };
 | 
			
		||||
    int status = INT_MAX;
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    const char* const ifaces[] = { "android.hidl.base@1.0::IBase", NULL };
 | 
			
		||||
    const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(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, NULL, NULL, NULL);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new(ipc, ifaces, NULL, NULL);
 | 
			
		||||
    GBinderLocalReply* reply;
 | 
			
		||||
    GBinderOutputData* reply_data;
 | 
			
		||||
 | 
			
		||||
    gbinder_remote_request_set_data(req, HIDL_PING_TRANSACTION,
 | 
			
		||||
    gbinder_remote_request_set_data(req, HIDL_DESCRIPTOR_CHAIN_TRANSACTION,
 | 
			
		||||
        gbinder_buffer_new(ipc->driver, g_memdup(req_data, sizeof(req_data)),
 | 
			
		||||
        sizeof(req_data), NULL));
 | 
			
		||||
    g_assert(!g_strcmp0(gbinder_remote_request_interface(req), base_interface));
 | 
			
		||||
@@ -323,6 +426,11 @@ test_descriptor_chain(
 | 
			
		||||
    g_assert(reply);
 | 
			
		||||
    g_assert(status == GBINDER_STATUS_OK);
 | 
			
		||||
 | 
			
		||||
    /* Should get 3 buffers - vector, string and its contents */
 | 
			
		||||
    reply_data = gbinder_local_reply_data(reply);
 | 
			
		||||
    g_assert(gbinder_output_data_offsets(reply_data)->count == 3);
 | 
			
		||||
    g_assert(gbinder_output_data_buffers_size(reply_data) == 64);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
    gbinder_local_reply_unref(reply);
 | 
			
		||||
@@ -364,13 +472,14 @@ test_custom_iface(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    static const guint8 req_data [] = { CUSTOM_INTERFACE_HEADER_BYTES };
 | 
			
		||||
    const char* const ifaces[] = { custom_iface, NULL };
 | 
			
		||||
    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, 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,
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new(ipc, ifaces,
 | 
			
		||||
        test_custom_iface_handler, &count);
 | 
			
		||||
    GBinderLocalReply* reply;
 | 
			
		||||
    GBinderReaderData reader_data;
 | 
			
		||||
@@ -470,13 +579,14 @@ test_reply_status(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    static const guint8 req_data [] = { CUSTOM_INTERFACE_HEADER_BYTES };
 | 
			
		||||
    const char* const ifaces[] = { custom_iface, NULL };
 | 
			
		||||
    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, 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,
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new(ipc, ifaces,
 | 
			
		||||
        test_reply_status_handler, &count);
 | 
			
		||||
 | 
			
		||||
    gbinder_remote_request_set_data(req, HIDL_PING_TRANSACTION,
 | 
			
		||||
@@ -515,7 +625,7 @@ test_increfs(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_ipc_new_local_object
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new
 | 
			
		||||
        (ipc, NULL, NULL, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
@@ -525,7 +635,7 @@ test_increfs(
 | 
			
		||||
    /* ipc is not an object, will be ignored */
 | 
			
		||||
    test_binder_br_increfs(fd, ipc);
 | 
			
		||||
    test_binder_br_increfs(fd, obj);
 | 
			
		||||
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    g_assert(obj->weak_refs == 1);
 | 
			
		||||
@@ -557,7 +667,7 @@ test_decrefs(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_ipc_new_local_object
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new
 | 
			
		||||
        (ipc, NULL, NULL, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
@@ -568,7 +678,7 @@ test_decrefs(
 | 
			
		||||
    test_binder_br_decrefs(fd, ipc);
 | 
			
		||||
    test_binder_br_increfs(fd, obj);
 | 
			
		||||
    test_binder_br_decrefs(fd, obj);
 | 
			
		||||
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    g_assert(obj->weak_refs == 0);
 | 
			
		||||
@@ -599,7 +709,7 @@ test_acquire(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_ipc_new_local_object
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new
 | 
			
		||||
        (ipc, NULL, NULL, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
@@ -609,7 +719,7 @@ test_acquire(
 | 
			
		||||
    /* ipc is not an object, will be ignored */
 | 
			
		||||
    test_binder_br_acquire(fd, ipc);
 | 
			
		||||
    test_binder_br_acquire(fd, obj);
 | 
			
		||||
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    g_assert(obj->strong_refs == 1);
 | 
			
		||||
@@ -641,8 +751,7 @@ test_release(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_ipc_new_local_object
 | 
			
		||||
        (ipc, NULL, NULL, NULL);
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new(ipc, NULL, NULL, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    gulong id = gbinder_local_object_add_strong_refs_changed_handler(obj,
 | 
			
		||||
@@ -652,7 +761,7 @@ test_release(
 | 
			
		||||
    test_binder_br_release(fd, ipc);
 | 
			
		||||
    test_binder_br_acquire(fd, obj);
 | 
			
		||||
    test_binder_br_release(fd, obj);
 | 
			
		||||
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    g_assert(obj->strong_refs == 0);
 | 
			
		||||
@@ -674,6 +783,8 @@ int main(int argc, char* argv[])
 | 
			
		||||
    g_test_add_func(TEST_PREFIX "null", test_null);
 | 
			
		||||
    g_test_add_func(TEST_PREFIX "basic", test_basic);
 | 
			
		||||
    g_test_add_func(TEST_PREFIX "ping", test_ping);
 | 
			
		||||
    g_test_add_func(TEST_PREFIX "interface", test_interface);
 | 
			
		||||
    g_test_add_func(TEST_PREFIX "hidl_ping", test_hidl_ping);
 | 
			
		||||
    g_test_add_func(TEST_PREFIX "get_descriptor", test_get_descriptor);
 | 
			
		||||
    g_test_add_func(TEST_PREFIX "descriptor_chain", test_descriptor_chain);
 | 
			
		||||
    g_test_add_func(TEST_PREFIX "custom_iface", test_custom_iface);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -313,7 +313,7 @@ void
 | 
			
		||||
test_string16(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    static const const char input[] = "x";
 | 
			
		||||
    static const char input[] = "x";
 | 
			
		||||
    static const guint8 output[] = {
 | 
			
		||||
        TEST_INT32_BYTES(1),
 | 
			
		||||
        TEST_INT16_BYTES('x'), 0x00, 0x00
 | 
			
		||||
@@ -400,8 +400,8 @@ test_local_object(
 | 
			
		||||
    GBinderOutputData* data;
 | 
			
		||||
    GUtilIntArray* offsets;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(NULL, NULL);
 | 
			
		||||
    GBinderLocalObject* obj =
 | 
			
		||||
        gbinder_ipc_new_local_object(ipc, "foo", NULL, NULL);
 | 
			
		||||
    const char* const ifaces[] = { "android.hidl.base@1.0::IBase", NULL };
 | 
			
		||||
    GBinderLocalObject* obj = gbinder_local_object_new(ipc, ifaces, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
    /* Append a real object (64-bit I/O is used by test_binder.c) */
 | 
			
		||||
    reply = gbinder_local_object_new_reply(obj);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -341,7 +341,7 @@ void
 | 
			
		||||
test_string16(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    static const const char input[] = "x";
 | 
			
		||||
    static const char input[] = "x";
 | 
			
		||||
    static const guint8 output[] = {
 | 
			
		||||
        TEST_INT32_BYTES(1),
 | 
			
		||||
        TEST_INT16_BYTES('x'), 0x00, 0x00
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -100,6 +100,7 @@ test_empty(
 | 
			
		||||
    g_assert(!gbinder_reader_read_hidl_vec1(&reader, &count, 1));
 | 
			
		||||
    g_assert(!count);
 | 
			
		||||
    g_assert(!elemsize);
 | 
			
		||||
    g_assert(!gbinder_reader_skip_hidl_string(&reader));
 | 
			
		||||
    g_assert(!gbinder_reader_read_hidl_string(&reader));
 | 
			
		||||
    g_assert(!gbinder_reader_read_hidl_string_vec(&reader));
 | 
			
		||||
    g_assert(!gbinder_reader_skip_buffer(&reader));
 | 
			
		||||
@@ -451,8 +452,8 @@ test_string16_null(
 | 
			
		||||
    GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
 | 
			
		||||
    GBinderReader reader;
 | 
			
		||||
    GBinderReaderData data;
 | 
			
		||||
    gunichar2* out2 = NULL;
 | 
			
		||||
    gsize len = 0;
 | 
			
		||||
    const gunichar2* out2 = NULL;
 | 
			
		||||
    gsize len = 1;
 | 
			
		||||
    char dummy;
 | 
			
		||||
    char* out = &dummy;
 | 
			
		||||
 | 
			
		||||
@@ -466,12 +467,23 @@ test_string16_null(
 | 
			
		||||
    g_assert(gbinder_reader_read_nullable_string16_utf16(&reader, NULL, NULL));
 | 
			
		||||
    g_assert(gbinder_reader_at_end(&reader));
 | 
			
		||||
 | 
			
		||||
    len = 1;
 | 
			
		||||
    gbinder_reader_init(&reader, &data, 0, sizeof(test_string16_in_null));
 | 
			
		||||
    g_assert(gbinder_reader_read_nullable_string16_utf16(&reader, &out2, &len));
 | 
			
		||||
    g_assert(gbinder_reader_at_end(&reader));
 | 
			
		||||
    g_assert(!out2);
 | 
			
		||||
    g_assert(!len);
 | 
			
		||||
 | 
			
		||||
    gbinder_reader_init(&reader, &data, 0, sizeof(test_string16_in_null));
 | 
			
		||||
    g_assert(!gbinder_reader_read_string16_utf16(&reader, NULL));
 | 
			
		||||
    g_assert(gbinder_reader_at_end(&reader));
 | 
			
		||||
 | 
			
		||||
    len = 1;
 | 
			
		||||
    gbinder_reader_init(&reader, &data, 0, sizeof(test_string16_in_null));
 | 
			
		||||
    g_assert(!gbinder_reader_read_string16_utf16(&reader, &len));
 | 
			
		||||
    g_assert(gbinder_reader_at_end(&reader));
 | 
			
		||||
    g_assert(!len);
 | 
			
		||||
 | 
			
		||||
    gbinder_reader_init(&reader, &data, 0, sizeof(test_string16_in_null));
 | 
			
		||||
    g_assert(gbinder_reader_read_nullable_string16(&reader, NULL));
 | 
			
		||||
    g_assert(gbinder_reader_at_end(&reader));
 | 
			
		||||
@@ -503,7 +515,7 @@ test_string16(
 | 
			
		||||
    GBinderReader reader;
 | 
			
		||||
    GBinderReaderData data;
 | 
			
		||||
    const gboolean valid = (test->out != NULL);
 | 
			
		||||
    gunichar2* out2 = NULL;
 | 
			
		||||
    const gunichar2* out2 = NULL;
 | 
			
		||||
    gsize len = 0;
 | 
			
		||||
    char* str = NULL;
 | 
			
		||||
 | 
			
		||||
@@ -512,6 +524,18 @@ test_string16(
 | 
			
		||||
    data.buffer = gbinder_buffer_new(driver, g_memdup(test->in, test->in_size),
 | 
			
		||||
        test->in_size, NULL);
 | 
			
		||||
 | 
			
		||||
    gbinder_reader_init(&reader, &data, 0, test->in_size);
 | 
			
		||||
    if (valid) {
 | 
			
		||||
        out2 = gbinder_reader_read_string16_utf16(&reader, &len);
 | 
			
		||||
        g_assert(out2);
 | 
			
		||||
        g_assert((gsize)len == strlen(test->out));
 | 
			
		||||
        g_assert(gbinder_reader_at_end(&reader) == (!test->remaining));
 | 
			
		||||
    } else {
 | 
			
		||||
        g_assert(!gbinder_reader_read_string16_utf16(&reader, NULL));
 | 
			
		||||
    }
 | 
			
		||||
    g_assert(gbinder_reader_at_end(&reader) == (!test->remaining));
 | 
			
		||||
    g_assert(gbinder_reader_bytes_remaining(&reader) == test->remaining);
 | 
			
		||||
 | 
			
		||||
    gbinder_reader_init(&reader, &data, 0, test->in_size);
 | 
			
		||||
    g_assert(gbinder_reader_read_nullable_string16_utf16(&reader, NULL,
 | 
			
		||||
        NULL) == valid);
 | 
			
		||||
@@ -692,7 +716,6 @@ static const BinderObject64 test_hidl_vec_short_buf [] = {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* NULL buffer with size 1 */
 | 
			
		||||
static const guint test_hidl_vec_badnull_offsets [] = {0};
 | 
			
		||||
static const GBinderHidlVec test_hidl_vec_badnull = {{0}, 1, TRUE};
 | 
			
		||||
static const BinderObject64 test_hidl_vec_badnull_buf [] = {
 | 
			
		||||
    {
 | 
			
		||||
@@ -939,6 +962,40 @@ test_hidl_string_err(
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string_err_skip(
 | 
			
		||||
    gconstpointer test_data)
 | 
			
		||||
{
 | 
			
		||||
    const TestHidlStringErr* test = test_data;
 | 
			
		||||
    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, NULL);
 | 
			
		||||
    GBinderReaderData data;
 | 
			
		||||
    GBinderReader reader;
 | 
			
		||||
 | 
			
		||||
    g_assert(ipc);
 | 
			
		||||
    memset(&data, 0, sizeof(data));
 | 
			
		||||
    data.buffer = buf;
 | 
			
		||||
    data.reg = gbinder_ipc_object_registry(ipc);
 | 
			
		||||
    if (test->offset) {
 | 
			
		||||
        guint i;
 | 
			
		||||
 | 
			
		||||
        data.objects = g_new(void*, test->offset_count + 1);
 | 
			
		||||
        for (i = 0; i < test->offset_count; i++) {
 | 
			
		||||
            data.objects[i] = (guint8*)buf->data + test->offset[i];
 | 
			
		||||
        }
 | 
			
		||||
        data.objects[i] = NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    gbinder_reader_init(&reader, &data, 0, test->in_size);
 | 
			
		||||
    g_assert(!gbinder_reader_skip_hidl_string(&reader));
 | 
			
		||||
 | 
			
		||||
    g_free(data.objects);
 | 
			
		||||
    gbinder_buffer_free(buf);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * fd_ok
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -1189,6 +1246,324 @@ test_dupfd_badfd(
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * hidl_string
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string(
 | 
			
		||||
    const guint8* input,
 | 
			
		||||
    gsize size,
 | 
			
		||||
    const guint* offsets,
 | 
			
		||||
    guint bufcount,
 | 
			
		||||
    const char* result)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER, NULL);
 | 
			
		||||
    GBinderBuffer* buf = gbinder_buffer_new(ipc->driver, g_memdup(input, size),
 | 
			
		||||
        size, NULL);
 | 
			
		||||
    GBinderRemoteObject* obj = NULL;
 | 
			
		||||
    GBinderReaderData data;
 | 
			
		||||
    GBinderReader reader;
 | 
			
		||||
    guint i;
 | 
			
		||||
 | 
			
		||||
    g_assert(ipc);
 | 
			
		||||
    memset(&data, 0, sizeof(data));
 | 
			
		||||
    data.buffer = buf;
 | 
			
		||||
    data.reg = gbinder_ipc_object_registry(ipc);
 | 
			
		||||
    data.objects = g_new(void*, bufcount + 1);
 | 
			
		||||
    for (i = 0; i < bufcount; i++) {
 | 
			
		||||
        data.objects[i] = buf->data + offsets[i];
 | 
			
		||||
    }
 | 
			
		||||
    data.objects[i] = NULL;
 | 
			
		||||
    gbinder_reader_init(&reader, &data, 0, buf->size);
 | 
			
		||||
 | 
			
		||||
    g_assert(gbinder_reader_read_hidl_string_c(&reader) == result);
 | 
			
		||||
 | 
			
		||||
    g_free(data.objects);
 | 
			
		||||
    gbinder_remote_object_unref(obj);
 | 
			
		||||
    gbinder_buffer_free(buf);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string1(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char contents[] = "test";
 | 
			
		||||
    const GBinderHidlString str = {
 | 
			
		||||
        .data = { (uintptr_t)contents },
 | 
			
		||||
        .len = sizeof(contents) - 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR), TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&str), TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Buffer object #2 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)contents),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(contents)),
 | 
			
		||||
        TEST_INT64_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET)
 | 
			
		||||
    };
 | 
			
		||||
    static const guint offsets[] = { 0, BUFFER_OBJECT_SIZE_64 };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string(TEST_ARRAY_AND_SIZE(input),
 | 
			
		||||
        TEST_ARRAY_AND_COUNT(offsets), contents);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string2(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char contents[] = "test";
 | 
			
		||||
    const GBinderHidlString str = {
 | 
			
		||||
        .data = { (uintptr_t)contents },
 | 
			
		||||
        .len = sizeof(contents) - 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR), TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&str), TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Invalid object type */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_HANDLE),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)contents),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(contents)),
 | 
			
		||||
        TEST_INT64_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET)
 | 
			
		||||
    };
 | 
			
		||||
    static const guint offsets[] = { 0, BUFFER_OBJECT_SIZE_64 };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string(TEST_ARRAY_AND_SIZE(input),
 | 
			
		||||
        TEST_ARRAY_AND_COUNT(offsets), NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string3(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char contents[] = "test";
 | 
			
		||||
    const GBinderHidlString str = {
 | 
			
		||||
        .data = { (uintptr_t)contents },
 | 
			
		||||
        .len = sizeof(contents) - 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR), TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&str), TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* No parent */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR), TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)contents),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(contents)),
 | 
			
		||||
        TEST_INT64_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET)
 | 
			
		||||
    };
 | 
			
		||||
    static const guint offsets[] = { 0, BUFFER_OBJECT_SIZE_64 };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string(TEST_ARRAY_AND_SIZE(input),
 | 
			
		||||
        TEST_ARRAY_AND_COUNT(offsets), NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string4(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char contents[] = "test";
 | 
			
		||||
    const GBinderHidlString str = {
 | 
			
		||||
        .data = { (uintptr_t)contents },
 | 
			
		||||
        .len = sizeof(contents) - 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR), TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&str), TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Invalid length */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)contents),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(contents) - 1),
 | 
			
		||||
        TEST_INT64_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET)
 | 
			
		||||
    };
 | 
			
		||||
    static const guint offsets[] = { 0, BUFFER_OBJECT_SIZE_64 };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string(TEST_ARRAY_AND_SIZE(input),
 | 
			
		||||
        TEST_ARRAY_AND_COUNT(offsets), NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string5(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char contents[] = "test";
 | 
			
		||||
    const GBinderHidlString str = {
 | 
			
		||||
        .data = { (uintptr_t)contents },
 | 
			
		||||
        .len = sizeof(contents) - 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR), TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&str), TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Invalid pointer */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)contents + 1),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(contents)),
 | 
			
		||||
        TEST_INT64_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET)
 | 
			
		||||
    };
 | 
			
		||||
    static const guint offsets[] = { 0, BUFFER_OBJECT_SIZE_64 };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string(TEST_ARRAY_AND_SIZE(input),
 | 
			
		||||
        TEST_ARRAY_AND_COUNT(offsets), NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string6(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    /* No NULL-terminated */
 | 
			
		||||
    const char contents[] = "testx";
 | 
			
		||||
    const GBinderHidlString str = {
 | 
			
		||||
        .data = { (uintptr_t)contents },
 | 
			
		||||
        .len = 4,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR), TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&str), TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Buffer object #2 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)contents),
 | 
			
		||||
        TEST_INT64_BYTES(5),
 | 
			
		||||
        TEST_INT64_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET)
 | 
			
		||||
    };
 | 
			
		||||
    static const guint offsets[] = { 0, BUFFER_OBJECT_SIZE_64 };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string(TEST_ARRAY_AND_SIZE(input),
 | 
			
		||||
        TEST_ARRAY_AND_COUNT(offsets), NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string7(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char contents[] = "test";
 | 
			
		||||
    const GBinderHidlString str = {
 | 
			
		||||
        .data = { (uintptr_t)contents },
 | 
			
		||||
        .len = sizeof(contents) - 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR), TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&str), TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Invalid parent offset */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)contents),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(contents)),
 | 
			
		||||
        TEST_INT64_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET + 1)
 | 
			
		||||
    };
 | 
			
		||||
    static const guint offsets[] = { 0, BUFFER_OBJECT_SIZE_64 };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string(TEST_ARRAY_AND_SIZE(input),
 | 
			
		||||
        TEST_ARRAY_AND_COUNT(offsets), NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * buffer
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_buffer(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const int data1 = 0x1234;
 | 
			
		||||
    const int data2 = 0x5678;
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR), TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&data1), TEST_INT64_BYTES(sizeof(data1)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Buffer object #2 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&data2), TEST_INT64_BYTES(sizeof(data2)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Not a buffer object */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_HANDLE), TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0)
 | 
			
		||||
    };
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER, NULL);
 | 
			
		||||
    GBinderBuffer* buf = gbinder_buffer_new(ipc->driver,
 | 
			
		||||
        g_memdup(input, sizeof(input)), sizeof(input), NULL);
 | 
			
		||||
    GBinderRemoteObject* obj = NULL;
 | 
			
		||||
    GBinderReaderData data;
 | 
			
		||||
    GBinderReader reader;
 | 
			
		||||
    GBinderBuffer* res;
 | 
			
		||||
 | 
			
		||||
    g_assert(ipc);
 | 
			
		||||
    memset(&data, 0, sizeof(data));
 | 
			
		||||
    data.buffer = buf;
 | 
			
		||||
    data.reg = gbinder_ipc_object_registry(ipc);
 | 
			
		||||
    data.objects = g_new(void*, 4);
 | 
			
		||||
    data.objects[0] = buf->data;
 | 
			
		||||
    data.objects[1] = buf->data + BUFFER_OBJECT_SIZE_64;
 | 
			
		||||
    data.objects[2] = buf->data + 2 * BUFFER_OBJECT_SIZE_64;
 | 
			
		||||
    data.objects[3] = NULL;
 | 
			
		||||
    gbinder_reader_init(&reader, &data, 0, buf->size);
 | 
			
		||||
 | 
			
		||||
    g_assert(gbinder_reader_skip_buffer(&reader));
 | 
			
		||||
    res = gbinder_reader_read_buffer(&reader);
 | 
			
		||||
    g_assert(res);
 | 
			
		||||
    g_assert(res->data == &data2);
 | 
			
		||||
 | 
			
		||||
    /* The next one is not a buffer object */
 | 
			
		||||
    g_assert(!gbinder_reader_skip_buffer(&reader));
 | 
			
		||||
 | 
			
		||||
    gbinder_buffer_free(res);
 | 
			
		||||
    g_free(data.objects);
 | 
			
		||||
    gbinder_remote_object_unref(obj);
 | 
			
		||||
    gbinder_buffer_free(buf);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * object
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -1337,6 +1712,290 @@ test_vec(
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * hidl_string_vec
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string_vec(
 | 
			
		||||
    const guint8* input,
 | 
			
		||||
    gsize size,
 | 
			
		||||
    const char* const* result)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_HWBINDER, NULL);
 | 
			
		||||
    GBinderBuffer* buf = gbinder_buffer_new(ipc->driver, g_memdup(input, size),
 | 
			
		||||
        size, NULL);
 | 
			
		||||
    GBinderRemoteObject* obj = NULL;
 | 
			
		||||
    GBinderReaderData data;
 | 
			
		||||
    GBinderReader reader;
 | 
			
		||||
    char** out;
 | 
			
		||||
    guint i;
 | 
			
		||||
 | 
			
		||||
    g_assert(ipc);
 | 
			
		||||
    memset(&data, 0, sizeof(data));
 | 
			
		||||
    data.buffer = buf;
 | 
			
		||||
    data.reg = gbinder_ipc_object_registry(ipc);
 | 
			
		||||
 | 
			
		||||
    /* We assume that input consists only from buffer objects */
 | 
			
		||||
    g_assert(!(size % BUFFER_OBJECT_SIZE_64));
 | 
			
		||||
    data.objects = g_new(void*, size/BUFFER_OBJECT_SIZE_64 + 1);
 | 
			
		||||
    for (i = 0; i < size/BUFFER_OBJECT_SIZE_64; i++) {
 | 
			
		||||
        data.objects[i] = buf->data + i * BUFFER_OBJECT_SIZE_64;
 | 
			
		||||
    }
 | 
			
		||||
    data.objects[i] = NULL;
 | 
			
		||||
 | 
			
		||||
    gbinder_reader_init(&reader, &data, 0, buf->size);
 | 
			
		||||
    out = gbinder_reader_read_hidl_string_vec(&reader)
 | 
			
		||||
;
 | 
			
		||||
    if (out) {
 | 
			
		||||
        const guint n = g_strv_length(out);
 | 
			
		||||
 | 
			
		||||
        g_assert(result);
 | 
			
		||||
        g_assert(n == g_strv_length((char**)result));
 | 
			
		||||
        for (i = 0; i < n; i++) {
 | 
			
		||||
            g_assert(!g_strcmp0(out[i], result[i]));
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        g_assert(!result);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    g_strfreev(out);
 | 
			
		||||
    g_free(data.objects);
 | 
			
		||||
    gbinder_remote_object_unref(obj);
 | 
			
		||||
    gbinder_buffer_free(buf);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string_vec1(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    static const char contents[] = "test";
 | 
			
		||||
    const GBinderHidlString str = {
 | 
			
		||||
        .data = { (uintptr_t)contents },
 | 
			
		||||
        .len = sizeof(contents) - 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    const GBinderHidlVec vec = {
 | 
			
		||||
        .data = { .ptr = &str },
 | 
			
		||||
        .count = 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&vec),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(vec)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Buffer object #2 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&str),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(1),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_VEC_BUFFER_OFFSET),
 | 
			
		||||
        /* Buffer object #3 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&contents),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(contents)),
 | 
			
		||||
        TEST_INT64_BYTES(2),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET)
 | 
			
		||||
    };
 | 
			
		||||
    static const char* const result[] = { contents, NULL };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string_vec(TEST_ARRAY_AND_SIZE(input), result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string_vec2(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    static const char str1[] = "meh";
 | 
			
		||||
    static const char str2[] = "foobar";
 | 
			
		||||
    const GBinderHidlString str[] = {
 | 
			
		||||
        {
 | 
			
		||||
            .data = { (uintptr_t)str1 },
 | 
			
		||||
            .len = sizeof(str1) - 1,
 | 
			
		||||
            .owns_buffer = TRUE
 | 
			
		||||
        },{
 | 
			
		||||
            .data = { (uintptr_t)str2 },
 | 
			
		||||
            .len = sizeof(str2) - 1,
 | 
			
		||||
            .owns_buffer = TRUE
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    const GBinderHidlVec vec = {
 | 
			
		||||
        .data = { .ptr = &str },
 | 
			
		||||
        .count = 2,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&vec),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(vec)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Buffer object #2 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)str),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(1),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_VEC_BUFFER_OFFSET),
 | 
			
		||||
        /* Buffer object #3 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)str1),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(str1)),
 | 
			
		||||
        TEST_INT64_BYTES(2),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET),
 | 
			
		||||
        /* Buffer object #4 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)str2),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(str2)),
 | 
			
		||||
        TEST_INT64_BYTES(2),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(GBinderHidlString) +
 | 
			
		||||
            GBINDER_HIDL_STRING_BUFFER_OFFSET)
 | 
			
		||||
                        
 | 
			
		||||
    };
 | 
			
		||||
    static const char* const result[] = { str1, str2, NULL };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string_vec(TEST_ARRAY_AND_SIZE(input), result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string_vec3(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    static const char contents[] = "test";
 | 
			
		||||
    const GBinderHidlString str = {
 | 
			
		||||
        .data = { (uintptr_t)contents },
 | 
			
		||||
        .len = sizeof(contents) - 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    const GBinderHidlVec vec = {
 | 
			
		||||
        .data = { .ptr = &str },
 | 
			
		||||
        .count = 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&vec),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(vec)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Buffer object #2 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&str),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(1),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_VEC_BUFFER_OFFSET)
 | 
			
		||||
        /* The next buffer is missing */
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string_vec(TEST_ARRAY_AND_SIZE(input), NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string_vec4(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    static const char contents[] = "test";
 | 
			
		||||
    const GBinderHidlString str = {
 | 
			
		||||
        .data = { (uintptr_t)contents },
 | 
			
		||||
        .len = sizeof(contents) - 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    const GBinderHidlVec vec = {
 | 
			
		||||
        .data = { .ptr = &str },
 | 
			
		||||
        .count = 1,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&vec),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(vec)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* The next buffer is missing */
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string_vec(TEST_ARRAY_AND_SIZE(input), NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_hidl_string_vec5(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    static const char str1[] = "meh";
 | 
			
		||||
    static const char str2[] = "foobar";
 | 
			
		||||
    const GBinderHidlString str[] = {
 | 
			
		||||
        {
 | 
			
		||||
            .data = { (uintptr_t)str1 },
 | 
			
		||||
            .len = sizeof(str1) - 1,
 | 
			
		||||
            .owns_buffer = TRUE
 | 
			
		||||
        },{
 | 
			
		||||
            .data = { (uintptr_t)str2 },
 | 
			
		||||
            .len = sizeof(str2) - 1,
 | 
			
		||||
            .owns_buffer = TRUE
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    const GBinderHidlVec vec = {
 | 
			
		||||
        .data = { .ptr = &str },
 | 
			
		||||
        .count = 2,
 | 
			
		||||
        .owns_buffer = TRUE
 | 
			
		||||
    };
 | 
			
		||||
    /* Using 64-bit I/O */
 | 
			
		||||
    const guint8 input[] = {
 | 
			
		||||
        /* Buffer object #1 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(0),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)&vec),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(vec)),
 | 
			
		||||
        TEST_INT64_BYTES(0), TEST_INT64_BYTES(0),
 | 
			
		||||
        /* Buffer object #2 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)str),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(str)),
 | 
			
		||||
        TEST_INT64_BYTES(1),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_VEC_BUFFER_OFFSET),
 | 
			
		||||
        /* Buffer object #3 */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)str1),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(str1)),
 | 
			
		||||
        TEST_INT64_BYTES(2),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET),
 | 
			
		||||
        /* Buffer object #4 (with invalid offset) */
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_TYPE_PTR),
 | 
			
		||||
        TEST_INT32_BYTES(BINDER_BUFFER_FLAG_HAS_PARENT),
 | 
			
		||||
        TEST_INT64_BYTES((uintptr_t)str2),
 | 
			
		||||
        TEST_INT64_BYTES(sizeof(str2)),
 | 
			
		||||
        TEST_INT64_BYTES(2),
 | 
			
		||||
        TEST_INT64_BYTES(GBINDER_HIDL_STRING_BUFFER_OFFSET)
 | 
			
		||||
                        
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    test_hidl_string_vec(TEST_ARRAY_AND_SIZE(input), NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * byte_array
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -1548,6 +2207,11 @@ int main(int argc, char* argv[])
 | 
			
		||||
 | 
			
		||||
        g_test_add_data_func(path, test, test_hidl_string_err);
 | 
			
		||||
        g_free(path);
 | 
			
		||||
 | 
			
		||||
        path = g_strconcat(TEST_("hidl_string/err-skip-"), test->name,
 | 
			
		||||
            NULL);
 | 
			
		||||
        g_test_add_data_func(path, test, test_hidl_string_err_skip);
 | 
			
		||||
        g_free(path);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    g_test_add_func(TEST_("fd/ok"), test_fd_ok);
 | 
			
		||||
@@ -1556,10 +2220,23 @@ int main(int argc, char* argv[])
 | 
			
		||||
    g_test_add_func(TEST_("dupfd/ok"), test_dupfd_ok);
 | 
			
		||||
    g_test_add_func(TEST_("dupfd/badtype"), test_dupfd_badtype);
 | 
			
		||||
    g_test_add_func(TEST_("dupfd/badfd"), test_dupfd_badfd);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string/1"), test_hidl_string1);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string/2"), test_hidl_string2);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string/3"), test_hidl_string3);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string/4"), test_hidl_string4);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string/5"), test_hidl_string5);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string/6"), test_hidl_string6);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string/7"), test_hidl_string7);
 | 
			
		||||
    g_test_add_func(TEST_("buffer"), test_buffer);
 | 
			
		||||
    g_test_add_func(TEST_("object/valid"), test_object);
 | 
			
		||||
    g_test_add_func(TEST_("object/invalid"), test_object_invalid);
 | 
			
		||||
    g_test_add_func(TEST_("object/no_reg"), test_object_no_reg);
 | 
			
		||||
    g_test_add_func(TEST_("vec"), test_vec);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string_vec/1"), test_hidl_string_vec1);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string_vec/2"), test_hidl_string_vec2);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string_vec/3"), test_hidl_string_vec3);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string_vec/4"), test_hidl_string_vec4);
 | 
			
		||||
    g_test_add_func(TEST_("hidl_string_vec/5"), test_hidl_string_vec5);
 | 
			
		||||
    g_test_add_func(TEST_("byte_array"), test_byte_array);
 | 
			
		||||
    g_test_add_func(TEST_("copy"), test_copy);
 | 
			
		||||
    test_init(&test_opt, argc, argv);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -50,8 +50,9 @@ void
 | 
			
		||||
test_null(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    g_assert(!gbinder_remote_object_new(NULL, 0));
 | 
			
		||||
    g_assert(!gbinder_remote_object_new(NULL, 0, FALSE));
 | 
			
		||||
    g_assert(!gbinder_remote_object_ref(NULL));
 | 
			
		||||
    g_assert(!gbinder_remote_object_ipc(NULL));
 | 
			
		||||
    gbinder_remote_object_unref(NULL);
 | 
			
		||||
    g_assert(gbinder_remote_object_is_dead(NULL));
 | 
			
		||||
    g_assert(!gbinder_remote_object_add_death_handler(NULL, NULL, NULL));
 | 
			
		||||
@@ -76,11 +77,14 @@ test_basic(
 | 
			
		||||
    g_assert(obj2);
 | 
			
		||||
    g_assert(obj1->handle == 1u);
 | 
			
		||||
    g_assert(obj2->handle == 2u);
 | 
			
		||||
    g_assert(gbinder_remote_object_ipc(obj1) == ipc);
 | 
			
		||||
    g_assert(gbinder_remote_object_ipc(obj2) == ipc);
 | 
			
		||||
    g_assert(!gbinder_remote_object_is_dead(obj1));
 | 
			
		||||
    g_assert(gbinder_remote_object_reanimate(obj1));
 | 
			
		||||
    g_assert(gbinder_remote_object_ref(obj1) == obj1);
 | 
			
		||||
    gbinder_remote_object_unref(obj1); /* Compensate the above reference */
 | 
			
		||||
    g_assert(!gbinder_remote_object_add_death_handler(obj1, NULL, NULL));
 | 
			
		||||
    g_assert(gbinder_ipc_get_remote_object(ipc, 1) == obj1);
 | 
			
		||||
    g_assert(gbinder_ipc_get_remote_object(ipc, 1, TRUE) == obj1);
 | 
			
		||||
    gbinder_remote_object_unref(obj1); /* Compensate the above reference */
 | 
			
		||||
    gbinder_remote_object_unref(obj1);
 | 
			
		||||
    gbinder_remote_object_unref(obj2);
 | 
			
		||||
@@ -109,11 +113,14 @@ test_dead(
 | 
			
		||||
    const guint handle = 1;
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
 | 
			
		||||
    GBinderRemoteObject* obj = gbinder_ipc_get_remote_object(ipc, handle);
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    GBinderRemoteObject* obj = gbinder_ipc_get_remote_object
 | 
			
		||||
        (ipc, handle, FALSE);
 | 
			
		||||
    gulong id = gbinder_remote_object_add_death_handler
 | 
			
		||||
        (obj, test_dead_done, loop);
 | 
			
		||||
 | 
			
		||||
    test_binder_br_dead_binder(gbinder_driver_fd(ipc->driver), handle);
 | 
			
		||||
    test_binder_br_dead_binder(fd, handle);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
    g_assert(gbinder_remote_object_is_dead(obj));
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -30,8 +30,9 @@
 | 
			
		||||
 * THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "test_common.h"
 | 
			
		||||
#include "test_binder.h"
 | 
			
		||||
 | 
			
		||||
#include "gbinder_driver.h"
 | 
			
		||||
#include "gbinder_client_p.h"
 | 
			
		||||
#include "gbinder_remote_object_p.h"
 | 
			
		||||
#include "gbinder_ipc.h"
 | 
			
		||||
@@ -41,6 +42,7 @@
 | 
			
		||||
 | 
			
		||||
#include <gutil_strv.h>
 | 
			
		||||
#include <gutil_macros.h>
 | 
			
		||||
#include <gutil_log.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
@@ -92,6 +94,47 @@ test_transact_func(
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_inc(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    (*((int*)user_data))++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_reg_inc(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GVERBOSE_("\"%s\"", name);
 | 
			
		||||
    (*((int*)user_data))++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_quit(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    test_quit_later((GMainLoop*)user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_setup_ping(
 | 
			
		||||
    GBinderIpc* ipc)
 | 
			
		||||
{
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    test_binder_br_reply(fd, 0, 0, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * TestServiceManager
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -131,7 +174,7 @@ test_servicemanager_get_service(
 | 
			
		||||
    if (gutil_strv_contains(self->services, name)) {
 | 
			
		||||
        if (!self->remote) {
 | 
			
		||||
            self->remote = gbinder_ipc_get_remote_object
 | 
			
		||||
                (gbinder_client_ipc(sm->client), 1);
 | 
			
		||||
                (gbinder_client_ipc(sm->client), 1, TRUE);
 | 
			
		||||
        }
 | 
			
		||||
        *status = GBINDER_STATUS_OK;
 | 
			
		||||
        return gbinder_remote_object_ref(self->remote);
 | 
			
		||||
@@ -166,7 +209,6 @@ typedef TestServiceManager TestHwServiceManager;
 | 
			
		||||
G_DEFINE_TYPE(TestHwServiceManager, test_hwservicemanager,
 | 
			
		||||
    GBINDER_TYPE_SERVICEMANAGER)
 | 
			
		||||
 | 
			
		||||
#define TEST_HWSERVICEMANAGER_HANDLE (0)
 | 
			
		||||
#define TEST_HWSERVICEMANAGER_IFACE "android.hidl.manager@1.0::IServiceManager"
 | 
			
		||||
#define TEST_TYPE_HWSERVICEMANAGER (test_hwservicemanager_get_type())
 | 
			
		||||
#define TEST_IS_HWSERVICEMANAGER(obj) \
 | 
			
		||||
@@ -237,7 +279,6 @@ void
 | 
			
		||||
test_hwservicemanager_class_init(
 | 
			
		||||
    TestHwServiceManagerClass* klass)
 | 
			
		||||
{
 | 
			
		||||
    klass->handle = TEST_HWSERVICEMANAGER_HANDLE;
 | 
			
		||||
    klass->iface = TEST_HWSERVICEMANAGER_IFACE;
 | 
			
		||||
    klass->default_device = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    klass->rpc_protocol = &gbinder_rpc_protocol_hwbinder;
 | 
			
		||||
@@ -269,7 +310,6 @@ typedef TestServiceManager TestDefServiceManager;
 | 
			
		||||
G_DEFINE_TYPE(TestDefServiceManager, test_defservicemanager,
 | 
			
		||||
    GBINDER_TYPE_SERVICEMANAGER)
 | 
			
		||||
 | 
			
		||||
#define TEST_DEFSERVICEMANAGER_HANDLE (0)
 | 
			
		||||
#define TEST_DEFSERVICEMANAGER_IFACE "android.os.IServiceManager"
 | 
			
		||||
#define TEST_TYPE_DEFSERVICEMANAGER (test_defservicemanager_get_type())
 | 
			
		||||
#define TEST_IS_DEFSERVICEMANAGER(obj) \
 | 
			
		||||
@@ -323,7 +363,6 @@ void
 | 
			
		||||
test_defservicemanager_class_init(
 | 
			
		||||
    TestDefServiceManagerClass* klass)
 | 
			
		||||
{
 | 
			
		||||
    klass->handle = TEST_DEFSERVICEMANAGER_HANDLE;
 | 
			
		||||
    klass->iface = TEST_DEFSERVICEMANAGER_IFACE;
 | 
			
		||||
    klass->default_device = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    klass->rpc_protocol = &gbinder_rpc_protocol_binder;
 | 
			
		||||
@@ -355,6 +394,8 @@ test_null(
 | 
			
		||||
    g_assert(!gbinder_servicemanager_new_with_type(0, NULL));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_new_local_object(NULL, NULL, NULL, NULL));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_ref(NULL));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_is_present(NULL));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_wait(NULL, 0));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_list(NULL, NULL, NULL));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_list_sync(NULL));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_get_service(NULL, NULL, NULL, NULL));
 | 
			
		||||
@@ -362,9 +403,11 @@ test_null(
 | 
			
		||||
    g_assert(!gbinder_servicemanager_add_service(NULL, NULL, NULL, NULL, NULL));
 | 
			
		||||
    g_assert(gbinder_servicemanager_add_service_sync(NULL, NULL, NULL) ==
 | 
			
		||||
        (-EINVAL));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_add_presence_handler(NULL, NULL, NULL));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_add_registration_handler(NULL, NULL,
 | 
			
		||||
        NULL, NULL));
 | 
			
		||||
    gbinder_servicemanager_remove_handler(NULL, 0);
 | 
			
		||||
    gbinder_servicemanager_remove_handlers(NULL, NULL, 0);
 | 
			
		||||
    gbinder_servicemanager_cancel(NULL, 0);
 | 
			
		||||
    gbinder_servicemanager_unref(NULL);
 | 
			
		||||
}
 | 
			
		||||
@@ -379,9 +422,13 @@ test_invalid(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    int status = 0;
 | 
			
		||||
    GBinderServiceManager* sm =
 | 
			
		||||
        gbinder_servicemanager_new(GBINDER_DEFAULT_HWBINDER);
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    gulong id = 0;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    g_assert(!gbinder_servicemanager_new_with_type(GBINDER_TYPE_LOCAL_OBJECT,
 | 
			
		||||
        NULL));
 | 
			
		||||
    g_assert(TEST_IS_HWSERVICEMANAGER(sm));
 | 
			
		||||
@@ -399,12 +446,16 @@ test_invalid(
 | 
			
		||||
        (-EINVAL));
 | 
			
		||||
    g_assert(gbinder_servicemanager_add_service_sync(sm, "foo", NULL) ==
 | 
			
		||||
        (-EINVAL));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_add_presence_handler(sm, NULL, NULL));
 | 
			
		||||
    g_assert(!gbinder_servicemanager_add_registration_handler(sm, NULL, NULL,
 | 
			
		||||
        NULL));
 | 
			
		||||
 | 
			
		||||
    gbinder_servicemanager_cancel(sm, 0);
 | 
			
		||||
    gbinder_servicemanager_remove_handler(sm, 0);
 | 
			
		||||
    gbinder_servicemanager_remove_handlers(sm, NULL, 0);
 | 
			
		||||
    gbinder_servicemanager_remove_handlers(sm, &id, 0);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -416,10 +467,13 @@ void
 | 
			
		||||
test_basic(
 | 
			
		||||
    void)
 | 
			
		||||
{ 
 | 
			
		||||
    GBinderServiceManager* sm =
 | 
			
		||||
        gbinder_servicemanager_new(GBINDER_DEFAULT_HWBINDER);
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    GBinderLocalObject* obj;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    g_assert(sm);
 | 
			
		||||
    obj = gbinder_servicemanager_new_local_object(sm, "foo.bar",
 | 
			
		||||
        test_transact_func, NULL);
 | 
			
		||||
@@ -429,6 +483,290 @@ test_basic(
 | 
			
		||||
    g_assert(gbinder_servicemanager_ref(sm) == sm);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * not_present
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_not_present(
 | 
			
		||||
    void)
 | 
			
		||||
{ 
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
 | 
			
		||||
    /* This makes presence detection PING fail */
 | 
			
		||||
    test_binder_br_reply_status(fd, -1);
 | 
			
		||||
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    g_assert(sm);
 | 
			
		||||
    g_assert(!gbinder_servicemanager_is_present(sm));
 | 
			
		||||
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * wait
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_wait(
 | 
			
		||||
    void)
 | 
			
		||||
{ 
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    const glong forever = (test_opt.flags & TEST_FLAG_DEBUG) ?
 | 
			
		||||
        (TEST_TIMEOUT_SEC * 1000) : -1;
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    gulong id;
 | 
			
		||||
    int count = 0;
 | 
			
		||||
 | 
			
		||||
    /* This makes presence detection PING fail */
 | 
			
		||||
    test_binder_br_reply_status(fd, -1);
 | 
			
		||||
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    g_assert(sm);
 | 
			
		||||
    g_assert(!gbinder_servicemanager_is_present(sm));
 | 
			
		||||
 | 
			
		||||
    /* Register the listener */
 | 
			
		||||
    id = gbinder_servicemanager_add_presence_handler(sm, test_inc, &count);
 | 
			
		||||
    g_assert(id);
 | 
			
		||||
 | 
			
		||||
    /* Make this wait fail */
 | 
			
		||||
    test_binder_br_reply_status(fd, -1);
 | 
			
		||||
    g_assert(!gbinder_servicemanager_wait(sm, 0));
 | 
			
		||||
 | 
			
		||||
    /* This makes presence detection PING succeed */
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    test_binder_br_reply(fd, 0, 0, NULL);
 | 
			
		||||
    g_assert(gbinder_servicemanager_wait(sm, forever));
 | 
			
		||||
 | 
			
		||||
    /* The next check succeeds too (without any I/O ) */
 | 
			
		||||
    g_assert(gbinder_servicemanager_is_present(sm));
 | 
			
		||||
    g_assert(gbinder_servicemanager_wait(sm, 0));
 | 
			
		||||
 | 
			
		||||
    /* The listener must have been invoked exactly once */
 | 
			
		||||
    g_assert(count == 1);
 | 
			
		||||
    gbinder_servicemanager_remove_handler(sm, id);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * wait_long
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_wait_long(
 | 
			
		||||
    void)
 | 
			
		||||
{ 
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    gulong id;
 | 
			
		||||
    int count = 0;
 | 
			
		||||
 | 
			
		||||
    /* This makes presence detection PING fail */
 | 
			
		||||
    test_binder_br_reply_status(fd, -1);
 | 
			
		||||
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    g_assert(sm);
 | 
			
		||||
    g_assert(!gbinder_servicemanager_is_present(sm));
 | 
			
		||||
 | 
			
		||||
    /* Register the listener */
 | 
			
		||||
    id = gbinder_servicemanager_add_presence_handler(sm, test_inc, &count);
 | 
			
		||||
    g_assert(id);
 | 
			
		||||
 | 
			
		||||
    /* Make the first presence detection PING fail and second succeed */
 | 
			
		||||
    test_binder_br_reply_status(fd, -1);
 | 
			
		||||
    test_binder_br_reply_status_later(fd, -1);
 | 
			
		||||
    test_binder_br_transaction_complete_later(fd);
 | 
			
		||||
    test_binder_br_reply_later(fd, 0, 0, NULL);
 | 
			
		||||
    g_assert(gbinder_servicemanager_wait(sm, TEST_TIMEOUT_SEC * 1000));
 | 
			
		||||
 | 
			
		||||
    /* The next check succeeds too (without any I/O ) */
 | 
			
		||||
    g_assert(gbinder_servicemanager_is_present(sm));
 | 
			
		||||
    g_assert(gbinder_servicemanager_wait(sm, 0));
 | 
			
		||||
 | 
			
		||||
    /* The listener must have been invoked exactly once */
 | 
			
		||||
    g_assert(count == 1);
 | 
			
		||||
    gbinder_servicemanager_remove_handler(sm, id);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * wait_async
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_wait_async(
 | 
			
		||||
    void)
 | 
			
		||||
{ 
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    gulong id[2];
 | 
			
		||||
    int count = 0;
 | 
			
		||||
 | 
			
		||||
    /* This makes presence detection PING fail */
 | 
			
		||||
    test_binder_br_reply_status(fd, -1);
 | 
			
		||||
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    g_assert(sm);
 | 
			
		||||
    g_assert(!gbinder_servicemanager_is_present(sm));
 | 
			
		||||
 | 
			
		||||
    /* Register the listeners */
 | 
			
		||||
    id[0] = gbinder_servicemanager_add_presence_handler(sm, test_inc, &count);
 | 
			
		||||
    id[1] = gbinder_servicemanager_add_presence_handler(sm, test_quit, loop);
 | 
			
		||||
    g_assert(id[0]);
 | 
			
		||||
    g_assert(id[1]);
 | 
			
		||||
 | 
			
		||||
    /* Make the first presence detection PING fail and second succeed */
 | 
			
		||||
    test_binder_br_reply_status(fd, -1);
 | 
			
		||||
    test_binder_br_transaction_complete_later(fd);
 | 
			
		||||
    test_binder_br_reply_later(fd, 0, 0, NULL);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    /* The listener must have been invoked exactly once */
 | 
			
		||||
    g_assert(count == 1);
 | 
			
		||||
    gbinder_servicemanager_remove_all_handlers(sm, id);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * death
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_death(
 | 
			
		||||
    void)
 | 
			
		||||
{ 
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    gulong id[3];
 | 
			
		||||
    int count = 0, reg_count = 0;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    g_assert(sm);
 | 
			
		||||
    g_assert(gbinder_servicemanager_is_present(sm));
 | 
			
		||||
 | 
			
		||||
    /* Register the listeners */
 | 
			
		||||
    id[0] = gbinder_servicemanager_add_presence_handler(sm, test_inc, &count);
 | 
			
		||||
    id[1] = gbinder_servicemanager_add_presence_handler(sm, test_quit, loop);
 | 
			
		||||
    id[2] = gbinder_servicemanager_add_registration_handler(sm, "foo",
 | 
			
		||||
        test_reg_inc, ®_count);
 | 
			
		||||
    g_assert(id[0]);
 | 
			
		||||
    g_assert(id[1]);
 | 
			
		||||
    g_assert(id[2]);
 | 
			
		||||
 | 
			
		||||
    /* Generate death notification (need looper for that) */
 | 
			
		||||
    test_binder_br_dead_binder(fd, 0);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    /* No registrations must have occured */
 | 
			
		||||
    g_assert(!reg_count);
 | 
			
		||||
 | 
			
		||||
    /* The listener must have been invoked exactly once */
 | 
			
		||||
    g_assert(count == 1);
 | 
			
		||||
    g_assert(!gbinder_servicemanager_is_present(sm));
 | 
			
		||||
    gbinder_servicemanager_remove_all_handlers(sm, id);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * reanimate
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_reanimate_quit(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    if (gbinder_servicemanager_is_present(sm)) {
 | 
			
		||||
        GDEBUG("Service manager is back");
 | 
			
		||||
        test_quit_later((GMainLoop*)user_data);
 | 
			
		||||
    } else {
 | 
			
		||||
        const int fd = gbinder_driver_fd(sm->client->remote->ipc->driver);
 | 
			
		||||
 | 
			
		||||
        /* Disable looper and reanimate the object */
 | 
			
		||||
        GDEBUG("Reanimating...");
 | 
			
		||||
        test_binder_set_looper_enabled(fd, FALSE);
 | 
			
		||||
        test_binder_br_transaction_complete(fd);
 | 
			
		||||
        test_binder_br_reply(fd, 0, 0, NULL);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_reanimate(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    gulong id[3];
 | 
			
		||||
    int count = 0, reg_count = 0;
 | 
			
		||||
 | 
			
		||||
    /* Create live service manager */
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    g_assert(sm);
 | 
			
		||||
    g_assert(gbinder_servicemanager_is_present(sm));
 | 
			
		||||
 | 
			
		||||
    /* Register the listeners */
 | 
			
		||||
    id[0] = gbinder_servicemanager_add_presence_handler(sm, test_inc, &count);
 | 
			
		||||
    id[1] = gbinder_servicemanager_add_presence_handler(sm,
 | 
			
		||||
        test_reanimate_quit, loop);
 | 
			
		||||
    id[2] = gbinder_servicemanager_add_registration_handler(sm, "foo",
 | 
			
		||||
        test_reg_inc, ®_count);
 | 
			
		||||
    g_assert(id[0]);
 | 
			
		||||
    g_assert(id[1]);
 | 
			
		||||
    g_assert(id[2]);
 | 
			
		||||
 | 
			
		||||
    /* Generate death notification (need looper for that) */
 | 
			
		||||
    test_binder_br_dead_binder(fd, 0);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    /* No registrations must have occured */
 | 
			
		||||
    g_assert(!reg_count);
 | 
			
		||||
 | 
			
		||||
    /* Presence must have changed twice */
 | 
			
		||||
    g_assert(count == 2);
 | 
			
		||||
    g_assert(gbinder_servicemanager_is_present(sm));
 | 
			
		||||
 | 
			
		||||
    gbinder_servicemanager_remove_all_handlers(sm, id);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -440,18 +778,29 @@ void
 | 
			
		||||
test_reuse(
 | 
			
		||||
    void)
 | 
			
		||||
{ 
 | 
			
		||||
    GBinderServiceManager* m1 =
 | 
			
		||||
        gbinder_servicemanager_new(GBINDER_DEFAULT_BINDER);
 | 
			
		||||
    GBinderServiceManager* m2 =
 | 
			
		||||
        gbinder_servicemanager_new(GBINDER_DEFAULT_BINDER);
 | 
			
		||||
    GBinderServiceManager* vnd1 =
 | 
			
		||||
        gbinder_servicemanager_new("/dev/vpnbinder");
 | 
			
		||||
    GBinderServiceManager* vnd2 =
 | 
			
		||||
        gbinder_servicemanager_new("/dev/vpnbinder");
 | 
			
		||||
    GBinderServiceManager* hw1 =
 | 
			
		||||
        gbinder_servicemanager_new(GBINDER_DEFAULT_HWBINDER);
 | 
			
		||||
    GBinderServiceManager* hw2 =
 | 
			
		||||
        gbinder_servicemanager_new(GBINDER_DEFAULT_HWBINDER);
 | 
			
		||||
    const char* binder_dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    const char* vndbinder_dev = "/dev/vpnbinder";
 | 
			
		||||
    const char* hwbinder_dev = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    GBinderIpc* binder_ipc = gbinder_ipc_new(binder_dev, NULL);
 | 
			
		||||
    GBinderIpc* vndbinder_ipc = gbinder_ipc_new(vndbinder_dev, NULL);
 | 
			
		||||
    GBinderIpc* hwbinder_ipc = gbinder_ipc_new(hwbinder_dev, NULL);
 | 
			
		||||
    GBinderServiceManager* m1;
 | 
			
		||||
    GBinderServiceManager* m2;
 | 
			
		||||
    GBinderServiceManager* vnd1;
 | 
			
		||||
    GBinderServiceManager* vnd2;
 | 
			
		||||
    GBinderServiceManager* hw1;
 | 
			
		||||
    GBinderServiceManager* hw2;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(binder_ipc);
 | 
			
		||||
    test_setup_ping(vndbinder_ipc);
 | 
			
		||||
    test_setup_ping(hwbinder_ipc);
 | 
			
		||||
 | 
			
		||||
    m1 = gbinder_servicemanager_new(binder_dev);
 | 
			
		||||
    m2 = gbinder_servicemanager_new(binder_dev);
 | 
			
		||||
    vnd1 = gbinder_servicemanager_new(vndbinder_dev);
 | 
			
		||||
    vnd2 = gbinder_servicemanager_new(vndbinder_dev);
 | 
			
		||||
    hw1 = gbinder_servicemanager_new(hwbinder_dev);
 | 
			
		||||
    hw2 = gbinder_servicemanager_new(hwbinder_dev);
 | 
			
		||||
 | 
			
		||||
    g_assert(m1);
 | 
			
		||||
    g_assert(m1 == m2);
 | 
			
		||||
@@ -471,6 +820,9 @@ test_reuse(
 | 
			
		||||
    gbinder_servicemanager_unref(vnd2);
 | 
			
		||||
    gbinder_servicemanager_unref(hw1);
 | 
			
		||||
    gbinder_servicemanager_unref(hw2);
 | 
			
		||||
    gbinder_ipc_unref(binder_ipc);
 | 
			
		||||
    gbinder_ipc_unref(vndbinder_ipc);
 | 
			
		||||
    gbinder_ipc_unref(hwbinder_ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -480,15 +832,22 @@ test_reuse(
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_notify_type(
 | 
			
		||||
    GType t)
 | 
			
		||||
    GType t,
 | 
			
		||||
    const char* dev)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManager* sm = gbinder_servicemanager_new_with_type(t, NULL);
 | 
			
		||||
    TestHwServiceManager* test = TEST_SERVICEMANAGER2(sm, t);
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    TestHwServiceManager* test;
 | 
			
		||||
    const char* name = "foo";
 | 
			
		||||
    int count = 0;
 | 
			
		||||
    gulong id1 = gbinder_servicemanager_add_registration_handler(sm, name,
 | 
			
		||||
    gulong id1, id2;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new_with_type(t, NULL);
 | 
			
		||||
    test = TEST_SERVICEMANAGER2(sm, t);
 | 
			
		||||
    id1 = gbinder_servicemanager_add_registration_handler(sm, name,
 | 
			
		||||
        test_registration_func_inc, &count);
 | 
			
		||||
    gulong id2 = gbinder_servicemanager_add_registration_handler(sm, name,
 | 
			
		||||
    id2 = gbinder_servicemanager_add_registration_handler(sm, name,
 | 
			
		||||
        test_registration_func_inc, &count);
 | 
			
		||||
 | 
			
		||||
    g_assert(id1 && id2);
 | 
			
		||||
@@ -507,6 +866,7 @@ test_notify_type(
 | 
			
		||||
    gbinder_servicemanager_remove_handler(sm, id1);
 | 
			
		||||
    gbinder_servicemanager_remove_handler(sm, id2);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -514,8 +874,8 @@ void
 | 
			
		||||
test_notify(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    test_notify_type(TEST_TYPE_HWSERVICEMANAGER);
 | 
			
		||||
    test_notify_type(TEST_TYPE_DEFSERVICEMANAGER);
 | 
			
		||||
    test_notify_type(TEST_TYPE_HWSERVICEMANAGER, GBINDER_DEFAULT_HWBINDER);
 | 
			
		||||
    test_notify_type(TEST_TYPE_DEFSERVICEMANAGER, GBINDER_DEFAULT_BINDER);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -541,12 +901,17 @@ void
 | 
			
		||||
test_list(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManager* sm = gbinder_servicemanager_new(NULL);
 | 
			
		||||
    TestHwServiceManager* test = TEST_SERVICEMANAGER(sm);
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    TestHwServiceManager* test;
 | 
			
		||||
    char** list;
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    test = TEST_SERVICEMANAGER(sm);
 | 
			
		||||
    test->services = gutil_strv_add(test->services, "foo");
 | 
			
		||||
    list = gbinder_servicemanager_list_sync(sm);
 | 
			
		||||
    g_assert(gutil_strv_equal(test->services, list));
 | 
			
		||||
@@ -558,6 +923,7 @@ test_list(
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -583,15 +949,21 @@ void
 | 
			
		||||
test_get(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManager* sm = gbinder_servicemanager_new(NULL);
 | 
			
		||||
    TestHwServiceManager* test = TEST_SERVICEMANAGER(sm);
 | 
			
		||||
    int status = -1;
 | 
			
		||||
    GBinderLocalObject* obj =
 | 
			
		||||
        gbinder_servicemanager_new_local_object(sm, "foo.bar",
 | 
			
		||||
            test_transact_func, NULL);
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    TestHwServiceManager* test;
 | 
			
		||||
    int status = -1;
 | 
			
		||||
    GBinderLocalObject* obj;
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    test = TEST_SERVICEMANAGER(sm);
 | 
			
		||||
    obj = gbinder_servicemanager_new_local_object(sm, "foo.bar",
 | 
			
		||||
       test_transact_func, NULL);
 | 
			
		||||
 | 
			
		||||
    /* Add a service */
 | 
			
		||||
    g_assert(obj);
 | 
			
		||||
    g_assert(gbinder_servicemanager_add_service_sync(sm, "foo", obj) ==
 | 
			
		||||
@@ -614,6 +986,7 @@ test_get(
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -637,13 +1010,21 @@ void
 | 
			
		||||
test_add(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManager* sm = gbinder_servicemanager_new(NULL);
 | 
			
		||||
    TestHwServiceManager* test = TEST_SERVICEMANAGER(sm);
 | 
			
		||||
    GBinderLocalObject* obj =
 | 
			
		||||
        gbinder_servicemanager_new_local_object(sm, "foo.bar",
 | 
			
		||||
            test_transact_func, NULL);
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    gulong id = gbinder_servicemanager_add_service(sm, "foo", obj,
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    TestHwServiceManager* test;
 | 
			
		||||
    GBinderLocalObject* obj;
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    test = TEST_SERVICEMANAGER(sm);
 | 
			
		||||
 | 
			
		||||
    obj = gbinder_servicemanager_new_local_object(sm, "foo.bar",
 | 
			
		||||
        test_transact_func, NULL);
 | 
			
		||||
    id = gbinder_servicemanager_add_service(sm, "foo", obj,
 | 
			
		||||
        test_add_func, loop);
 | 
			
		||||
 | 
			
		||||
    g_assert(id);
 | 
			
		||||
@@ -651,6 +1032,7 @@ test_add(
 | 
			
		||||
    g_assert(gutil_strv_contains(test->services, "foo"));
 | 
			
		||||
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -666,6 +1048,12 @@ int main(int argc, char* argv[])
 | 
			
		||||
    g_test_add_func(TEST_("null"), test_null);
 | 
			
		||||
    g_test_add_func(TEST_("invalid"), test_invalid);
 | 
			
		||||
    g_test_add_func(TEST_("basic"), test_basic);
 | 
			
		||||
    g_test_add_func(TEST_("not_present"), test_not_present);
 | 
			
		||||
    g_test_add_func(TEST_("wait"), test_wait);
 | 
			
		||||
    g_test_add_func(TEST_("wait_long"), test_wait_long);
 | 
			
		||||
    g_test_add_func(TEST_("wait_async"), test_wait_async);
 | 
			
		||||
    g_test_add_func(TEST_("death"), test_death);
 | 
			
		||||
    g_test_add_func(TEST_("reanimate"), test_reanimate);
 | 
			
		||||
    g_test_add_func(TEST_("reuse"), test_reuse);
 | 
			
		||||
    g_test_add_func(TEST_("notify"), test_notify);
 | 
			
		||||
    g_test_add_func(TEST_("list"), test_list);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								unit/unit_servicename/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								unit/unit_servicename/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
# -*- Mode: makefile-gmake -*-
 | 
			
		||||
 | 
			
		||||
EXE = unit_servicename
 | 
			
		||||
 | 
			
		||||
include ../common/Makefile
 | 
			
		||||
							
								
								
									
										500
									
								
								unit/unit_servicename/unit_servicename.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										500
									
								
								unit/unit_servicename/unit_servicename.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,500 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without
 | 
			
		||||
 * modification, are permitted provided that the following conditions
 | 
			
		||||
 * are met:
 | 
			
		||||
 *
 | 
			
		||||
 *   1. Redistributions of source code must retain the above copyright
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer.
 | 
			
		||||
 *   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 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
 | 
			
		||||
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 | 
			
		||||
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
 | 
			
		||||
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 | 
			
		||||
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 | 
			
		||||
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
			
		||||
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
			
		||||
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 | 
			
		||||
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 | 
			
		||||
 * THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "test_binder.h"
 | 
			
		||||
 | 
			
		||||
#include "gbinder_servicename.h"
 | 
			
		||||
#include "gbinder_servicemanager_p.h"
 | 
			
		||||
#include "gbinder_local_object.h"
 | 
			
		||||
#include "gbinder_rpc_protocol.h"
 | 
			
		||||
#include "gbinder_driver.h"
 | 
			
		||||
#include "gbinder_ipc.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_strv.h>
 | 
			
		||||
#include <gutil_log.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
static TestOpt test_opt;
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_quit(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    test_quit_later((GMainLoop*)user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_quit_when_destroyed(
 | 
			
		||||
    gpointer loop,
 | 
			
		||||
    GObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    test_quit_later((GMainLoop*)loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_setup_ping(
 | 
			
		||||
    GBinderIpc* ipc)
 | 
			
		||||
{
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    test_binder_br_reply(fd, 0, 0, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * TestServiceManager
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
typedef GBinderServiceManagerClass TestServiceManagerClass;
 | 
			
		||||
typedef struct test_servicemanager {
 | 
			
		||||
    GBinderServiceManager manager;
 | 
			
		||||
    GCond cond;
 | 
			
		||||
    GMutex mutex;
 | 
			
		||||
    char** services;
 | 
			
		||||
    gboolean block_add;
 | 
			
		||||
    int add_result;
 | 
			
		||||
} TestServiceManager;
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE(TestServiceManager, test_servicemanager,
 | 
			
		||||
    GBINDER_TYPE_SERVICEMANAGER)
 | 
			
		||||
 | 
			
		||||
#define TEST_SERVICEMANAGER_IFACE "android.os.IServiceManager"
 | 
			
		||||
#define TEST_TYPE_SERVICEMANAGER (test_servicemanager_get_type())
 | 
			
		||||
#define TEST_SERVICEMANAGER(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), \
 | 
			
		||||
    TEST_TYPE_SERVICEMANAGER, TestServiceManager)
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
char**
 | 
			
		||||
test_servicemanager_list(
 | 
			
		||||
    GBinderServiceManager* manager)
 | 
			
		||||
{
 | 
			
		||||
    char** ret;
 | 
			
		||||
    TestServiceManager* self = TEST_SERVICEMANAGER(manager);
 | 
			
		||||
 | 
			
		||||
    g_mutex_lock(&self->mutex);
 | 
			
		||||
    ret = g_strdupv(self->services);
 | 
			
		||||
    GDEBUG("%u", gutil_strv_length(ret));
 | 
			
		||||
    g_mutex_unlock(&self->mutex);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
test_servicemanager_get_service(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    int* status)
 | 
			
		||||
{
 | 
			
		||||
    *status = (-ENOENT);
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
test_servicemanager_add_service(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    TestServiceManager* self = TEST_SERVICEMANAGER(manager);
 | 
			
		||||
 | 
			
		||||
    g_mutex_lock(&self->mutex);
 | 
			
		||||
    if (!gutil_strv_contains(self->services, name)) {
 | 
			
		||||
        self->services = gutil_strv_add(self->services, name);
 | 
			
		||||
    }
 | 
			
		||||
    while (self->block_add) {
 | 
			
		||||
        g_cond_wait(&self->cond, &self->mutex);
 | 
			
		||||
    }
 | 
			
		||||
    g_mutex_unlock(&self->mutex);
 | 
			
		||||
    return self->add_result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBINDER_SERVICEMANAGER_NAME_CHECK
 | 
			
		||||
test_servicemanager_check_name(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    return name ?
 | 
			
		||||
        GBINDER_SERVICEMANAGER_NAME_INVALID :
 | 
			
		||||
        GBINDER_SERVICEMANAGER_NAME_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
test_servicemanager_watch(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_servicemanager_unwatch(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_servicemanager_init(
 | 
			
		||||
    TestServiceManager* self)
 | 
			
		||||
{
 | 
			
		||||
    g_cond_init(&self->cond);
 | 
			
		||||
    g_mutex_init(&self->mutex);
 | 
			
		||||
    self->add_result = GBINDER_STATUS_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_servicemanager_finalize(
 | 
			
		||||
    GObject* object)
 | 
			
		||||
{
 | 
			
		||||
    TestServiceManager* self = TEST_SERVICEMANAGER(object);
 | 
			
		||||
 | 
			
		||||
    g_cond_clear(&self->cond);
 | 
			
		||||
    g_mutex_clear(&self->mutex);
 | 
			
		||||
    g_strfreev(self->services);
 | 
			
		||||
    G_OBJECT_CLASS(test_servicemanager_parent_class)->finalize(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_servicemanager_class_init(
 | 
			
		||||
    TestServiceManagerClass* klass)
 | 
			
		||||
{
 | 
			
		||||
    klass->iface = TEST_SERVICEMANAGER_IFACE;
 | 
			
		||||
    klass->default_device = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    klass->rpc_protocol = &gbinder_rpc_protocol_binder;
 | 
			
		||||
    klass->list = test_servicemanager_list;
 | 
			
		||||
    klass->get_service = test_servicemanager_get_service;
 | 
			
		||||
    klass->add_service = test_servicemanager_add_service;
 | 
			
		||||
    klass->check_name = test_servicemanager_check_name;
 | 
			
		||||
    klass->watch = test_servicemanager_watch;
 | 
			
		||||
    klass->unwatch = test_servicemanager_unwatch;
 | 
			
		||||
    G_OBJECT_CLASS(klass)->finalize = test_servicemanager_finalize;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_defaultservicemanager_new(
 | 
			
		||||
    const char* dev)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_servicemanager_new_with_type(TEST_TYPE_SERVICEMANAGER, dev);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_hwservicemanager_new(
 | 
			
		||||
    const char* dev)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_servicemanager_new(dev);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * null
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_null(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
 | 
			
		||||
    g_assert(!gbinder_servicename_new(NULL, NULL, NULL));
 | 
			
		||||
    g_assert(!gbinder_servicename_new(sm, NULL, NULL));
 | 
			
		||||
    g_assert(!gbinder_servicename_ref(NULL));
 | 
			
		||||
    gbinder_servicename_unref(NULL);
 | 
			
		||||
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * basic
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_basic(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char* obj_name = "test";
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    const char* const ifaces[] = { "interface", NULL };
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderLocalObject* obj;
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    GBinderServiceName* sn;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    obj = gbinder_local_object_new(ipc, ifaces, NULL, NULL);
 | 
			
		||||
    g_assert(!gbinder_servicename_new(sm, obj, NULL));
 | 
			
		||||
 | 
			
		||||
    sn = gbinder_servicename_new(sm, obj, obj_name);
 | 
			
		||||
    g_assert(sn);
 | 
			
		||||
    g_assert(!g_strcmp0(sn->name, obj_name));
 | 
			
		||||
 | 
			
		||||
    g_assert(gbinder_servicename_ref(sn) == sn);
 | 
			
		||||
    gbinder_servicename_unref(sn);
 | 
			
		||||
 | 
			
		||||
    gbinder_servicename_unref(sn);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
 | 
			
		||||
    /* We need to wait until GBinderIpc is destroyed */
 | 
			
		||||
    GDEBUG("waiting for GBinderIpc to get destroyed");
 | 
			
		||||
    g_object_weak_ref(G_OBJECT(ipc), test_quit_when_destroyed, loop);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * present
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_present(
 | 
			
		||||
    int add_result)
 | 
			
		||||
{
 | 
			
		||||
    const char* obj_name = "test";
 | 
			
		||||
    const char* const ifaces[] = { "interface", NULL };
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderLocalObject* obj;
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    GBinderServiceName* sn;
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    TEST_SERVICEMANAGER(sm)->add_result = add_result;
 | 
			
		||||
    obj = gbinder_local_object_new(ipc, ifaces, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
    sn = gbinder_servicename_new(sm, obj, obj_name);
 | 
			
		||||
    g_assert(sn);
 | 
			
		||||
    g_assert(!g_strcmp0(sn->name, obj_name));
 | 
			
		||||
 | 
			
		||||
    /* Immediately generate death notification (need looper for that) */
 | 
			
		||||
    test_binder_br_dead_binder(fd, 0);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    id = gbinder_servicemanager_add_presence_handler(sm, test_quit, loop);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_servicename_unref(sn);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
    gbinder_servicemanager_remove_handler(sm, id);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
 | 
			
		||||
    /* We need to wait until GBinderIpc is destroyed */
 | 
			
		||||
    GDEBUG("waiting for GBinderIpc to get destroyed");
 | 
			
		||||
    g_object_weak_ref(G_OBJECT(ipc), test_quit_when_destroyed, loop);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_present_ok(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    test_present(GBINDER_STATUS_OK);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_present_err(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    test_present(-1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * not_present
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_not_present(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char* obj_name = "test";
 | 
			
		||||
    const char* const ifaces[] = { "interface", NULL };
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderLocalObject* obj;
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    GBinderServiceName* sn;
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    /* This makes presence detection PING fail */
 | 
			
		||||
    test_binder_br_reply_status(fd, -1);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    g_assert(!gbinder_servicemanager_is_present(sm));
 | 
			
		||||
    id = gbinder_servicemanager_add_presence_handler(sm, test_quit, loop);
 | 
			
		||||
    obj = gbinder_local_object_new(ipc, ifaces, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
    sn = gbinder_servicename_new(sm, obj, obj_name);
 | 
			
		||||
    g_assert(sn);
 | 
			
		||||
    g_assert(!g_strcmp0(sn->name, obj_name));
 | 
			
		||||
 | 
			
		||||
    /* Make the next presence detection PING succeed */
 | 
			
		||||
    test_binder_br_transaction_complete_later(fd);
 | 
			
		||||
    test_binder_br_reply_later(fd, 0, 0, NULL);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    gbinder_servicename_unref(sn);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
    gbinder_servicemanager_remove_handler(sm, id);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
 | 
			
		||||
    /* We need to wait until GBinderIpc is destroyed */
 | 
			
		||||
    GDEBUG("waiting for GBinderIpc to get destroyed");
 | 
			
		||||
    g_object_weak_ref(G_OBJECT(ipc), test_quit_when_destroyed, loop);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * cancel
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_cancel(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char* obj_name = "test";
 | 
			
		||||
    const char* const ifaces[] = { "interface", NULL };
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderLocalObject* obj;
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    TestServiceManager* test;
 | 
			
		||||
    GBinderServiceName* sn;
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    sm = gbinder_servicemanager_new(dev);
 | 
			
		||||
    obj = gbinder_local_object_new(ipc, ifaces, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
    /* Block name add calls */
 | 
			
		||||
    test = TEST_SERVICEMANAGER(sm);
 | 
			
		||||
    g_mutex_lock(&test->mutex);
 | 
			
		||||
    test->block_add = TRUE;
 | 
			
		||||
    g_mutex_unlock(&test->mutex);
 | 
			
		||||
 | 
			
		||||
    /* This adds the name but the call blocks */
 | 
			
		||||
    sn = gbinder_servicename_new(sm, obj, obj_name);
 | 
			
		||||
    g_assert(sn);
 | 
			
		||||
    g_assert(!g_strcmp0(sn->name, obj_name));
 | 
			
		||||
 | 
			
		||||
    /* Immediately generate death notification (need looper for that) */
 | 
			
		||||
    test_binder_br_dead_binder(fd, 0);
 | 
			
		||||
    test_binder_set_looper_enabled(fd, TRUE);
 | 
			
		||||
    id = gbinder_servicemanager_add_presence_handler(sm, test_quit, loop);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    /* Add call is supposed to be cancelled */
 | 
			
		||||
    gbinder_servicename_unref(sn);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
    gbinder_servicemanager_remove_handler(sm, id);
 | 
			
		||||
    gbinder_servicemanager_unref(sm);
 | 
			
		||||
 | 
			
		||||
    /* Unblock pending add */
 | 
			
		||||
    g_mutex_lock(&test->mutex);
 | 
			
		||||
    test->block_add = FALSE;
 | 
			
		||||
    g_cond_signal(&test->cond);
 | 
			
		||||
    g_mutex_unlock(&test->mutex);
 | 
			
		||||
 | 
			
		||||
    /* We need to wait until GBinderIpc is destroyed */
 | 
			
		||||
    GDEBUG("waiting for GBinderIpc to get destroyed");
 | 
			
		||||
    g_object_weak_ref(G_OBJECT(ipc), test_quit_when_destroyed, loop);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    test_run(&test_opt, loop);
 | 
			
		||||
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Common
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
#define TEST_(test) "/servicename/" test
 | 
			
		||||
 | 
			
		||||
int main(int argc, char* argv[])
 | 
			
		||||
{
 | 
			
		||||
    g_test_init(&argc, &argv, NULL);
 | 
			
		||||
    g_test_add_func(TEST_("null"), test_null);
 | 
			
		||||
    g_test_add_func(TEST_("basic"), test_basic);
 | 
			
		||||
    g_test_add_func(TEST_("present_ok"), test_present_ok);
 | 
			
		||||
    g_test_add_func(TEST_("present_err"), test_present_err);
 | 
			
		||||
    g_test_add_func(TEST_("not_present"), test_not_present);
 | 
			
		||||
    g_test_add_func(TEST_("cancel"), test_cancel);
 | 
			
		||||
    test_init(&test_opt, argc, argv);
 | 
			
		||||
    return g_test_run();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -30,8 +30,10 @@
 | 
			
		||||
 * THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "test_common.h"
 | 
			
		||||
#include "test_binder.h"
 | 
			
		||||
 | 
			
		||||
#include "gbinder_driver.h"
 | 
			
		||||
#include "gbinder_ipc.h"
 | 
			
		||||
#include "gbinder_servicemanager_p.h"
 | 
			
		||||
#include "gbinder_servicepoll.h"
 | 
			
		||||
#include "gbinder_rpc_protocol.h"
 | 
			
		||||
@@ -43,6 +45,18 @@
 | 
			
		||||
 | 
			
		||||
static TestOpt test_opt;
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_setup_ping(
 | 
			
		||||
    GBinderIpc* ipc)
 | 
			
		||||
{
 | 
			
		||||
    const int fd = gbinder_driver_fd(ipc->driver);
 | 
			
		||||
 | 
			
		||||
    test_binder_br_noop(fd);
 | 
			
		||||
    test_binder_br_transaction_complete(fd);
 | 
			
		||||
    test_binder_br_reply(fd, 0, 0, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * TestServiceManager
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -57,7 +71,6 @@ typedef struct test_servicemanager {
 | 
			
		||||
G_DEFINE_TYPE(TestServiceManager, test_servicemanager,
 | 
			
		||||
    GBINDER_TYPE_SERVICEMANAGER)
 | 
			
		||||
 | 
			
		||||
#define TEST_SERVICEMANAGER_HANDLE (0)
 | 
			
		||||
#define TEST_SERVICEMANAGER_IFACE "android.os.IServiceManager"
 | 
			
		||||
#define TEST_TYPE_SERVICEMANAGER (test_servicemanager_get_type())
 | 
			
		||||
#define TEST_SERVICEMANAGER(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), \
 | 
			
		||||
@@ -159,7 +172,6 @@ void
 | 
			
		||||
test_servicemanager_class_init(
 | 
			
		||||
    TestServiceManagerClass* klass)
 | 
			
		||||
{
 | 
			
		||||
    klass->handle = TEST_SERVICEMANAGER_HANDLE;
 | 
			
		||||
    klass->iface = TEST_SERVICEMANAGER_IFACE;
 | 
			
		||||
    klass->default_device = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    klass->rpc_protocol = &gbinder_rpc_protocol_binder;
 | 
			
		||||
@@ -212,10 +224,15 @@ void
 | 
			
		||||
test_basic(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GBinderServicePoll* weakptr = NULL;
 | 
			
		||||
    GBinderServiceManager* manager = gbinder_servicemanager_new(NULL);
 | 
			
		||||
    GBinderServicePoll* poll = gbinder_servicepoll_new(manager, NULL);
 | 
			
		||||
    GBinderServiceManager* manager;
 | 
			
		||||
    GBinderServicePoll* poll;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    manager = gbinder_servicemanager_new(dev);
 | 
			
		||||
    poll = gbinder_servicepoll_new(manager, NULL);
 | 
			
		||||
    g_assert(poll);
 | 
			
		||||
    g_assert(gbinder_servicepoll_manager(poll) == manager);
 | 
			
		||||
    g_assert(!gbinder_servicepoll_is_known_name(poll, "foo"));
 | 
			
		||||
@@ -230,6 +247,7 @@ test_basic(
 | 
			
		||||
    gbinder_servicepoll_unref(poll);
 | 
			
		||||
 | 
			
		||||
    gbinder_servicemanager_unref(manager);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -282,13 +300,19 @@ void
 | 
			
		||||
test_notify1(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServicePoll* weakptr = NULL;
 | 
			
		||||
    GBinderServiceManager* manager = gbinder_servicemanager_new(NULL);
 | 
			
		||||
    TestServiceManager* test = TEST_SERVICEMANAGER(manager);
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderServicePoll* weakptr = NULL;
 | 
			
		||||
    GBinderServiceManager* manager;
 | 
			
		||||
    TestServiceManager* test;
 | 
			
		||||
    GBinderServicePoll* poll;
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    manager = gbinder_servicemanager_new(dev);
 | 
			
		||||
    test = TEST_SERVICEMANAGER(manager);
 | 
			
		||||
 | 
			
		||||
    gbinder_servicepoll_interval_ms = 100;
 | 
			
		||||
    poll = gbinder_servicepoll_new(manager, &weakptr);
 | 
			
		||||
    g_timeout_add(2 * gbinder_servicepoll_interval_ms,
 | 
			
		||||
@@ -307,6 +331,7 @@ test_notify1(
 | 
			
		||||
    gbinder_servicepoll_unref(poll);
 | 
			
		||||
    g_assert(!weakptr);
 | 
			
		||||
    gbinder_servicemanager_unref(manager);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -349,13 +374,19 @@ void
 | 
			
		||||
test_notify2(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServicePoll* weakptr = NULL;
 | 
			
		||||
    GBinderServiceManager* manager = gbinder_servicemanager_new(NULL);
 | 
			
		||||
    TestServiceManager* test = TEST_SERVICEMANAGER(manager);
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderServicePoll* weakptr = NULL;
 | 
			
		||||
    GBinderServiceManager* manager;
 | 
			
		||||
    TestServiceManager* test;
 | 
			
		||||
    GBinderServicePoll* poll;
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    manager = gbinder_servicemanager_new(dev);
 | 
			
		||||
    test = TEST_SERVICEMANAGER(manager);
 | 
			
		||||
 | 
			
		||||
    gbinder_servicepoll_interval_ms = 100;
 | 
			
		||||
    poll = gbinder_servicepoll_new(manager, &weakptr);
 | 
			
		||||
    g_timeout_add(2 * gbinder_servicepoll_interval_ms,
 | 
			
		||||
@@ -378,6 +409,7 @@ test_notify2(
 | 
			
		||||
    gbinder_servicepoll_unref(poll);
 | 
			
		||||
    g_assert(!weakptr);
 | 
			
		||||
    gbinder_servicemanager_unref(manager);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -401,13 +433,20 @@ void
 | 
			
		||||
test_already_there(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServicePoll* weakptr = NULL;
 | 
			
		||||
    GBinderServiceManager* manager = gbinder_servicemanager_new(NULL);
 | 
			
		||||
    GBinderServicePoll* poll = gbinder_servicepoll_new(manager, &weakptr);
 | 
			
		||||
    TestServiceManager* test = TEST_SERVICEMANAGER(manager);
 | 
			
		||||
    const char* dev = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
    GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
 | 
			
		||||
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
 | 
			
		||||
    GBinderServicePoll* weakptr = NULL;
 | 
			
		||||
    GBinderServiceManager* manager;
 | 
			
		||||
    TestServiceManager* test;
 | 
			
		||||
    GBinderServicePoll* poll;
 | 
			
		||||
    gulong id;
 | 
			
		||||
 | 
			
		||||
    test_setup_ping(ipc);
 | 
			
		||||
    manager = gbinder_servicemanager_new(dev);
 | 
			
		||||
    poll = gbinder_servicepoll_new(manager, &weakptr);
 | 
			
		||||
    test = TEST_SERVICEMANAGER(manager);
 | 
			
		||||
 | 
			
		||||
    test->services = gutil_strv_add(test->services, "foo");
 | 
			
		||||
    id = gbinder_servicepoll_add_handler(poll, test_already_there_proc, loop);
 | 
			
		||||
 | 
			
		||||
@@ -418,6 +457,7 @@ test_already_there(
 | 
			
		||||
    gbinder_servicepoll_unref(poll);
 | 
			
		||||
    g_assert(!weakptr);
 | 
			
		||||
    gbinder_servicemanager_unref(manager);
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    g_main_loop_unref(loop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -99,6 +99,7 @@ test_null(
 | 
			
		||||
    gbinder_writer_append_byte_array(&writer, NULL, 0);
 | 
			
		||||
    gbinder_writer_add_cleanup(NULL, NULL, 0);
 | 
			
		||||
    gbinder_writer_add_cleanup(NULL, g_free, 0);
 | 
			
		||||
    gbinder_writer_overwrite_int32(NULL, 0, 0);
 | 
			
		||||
 | 
			
		||||
    g_assert(!gbinder_output_data_offsets(NULL));
 | 
			
		||||
    g_assert(!gbinder_output_data_buffers_size(NULL));
 | 
			
		||||
@@ -164,6 +165,19 @@ test_int32(
 | 
			
		||||
    g_assert(!gbinder_output_data_buffers_size(data));
 | 
			
		||||
    g_assert(data->bytes->len == sizeof(value));
 | 
			
		||||
    g_assert(!memcmp(data->bytes->data, &value, data->bytes->len));
 | 
			
		||||
 | 
			
		||||
    const guint32 value2 = 2345678;
 | 
			
		||||
    gbinder_writer_overwrite_int32(&writer, 0, value2);
 | 
			
		||||
    data = gbinder_local_request_data(req);
 | 
			
		||||
    g_assert(!gbinder_output_data_offsets(data));
 | 
			
		||||
    g_assert(!gbinder_output_data_buffers_size(data));
 | 
			
		||||
    g_assert(data->bytes->len == sizeof(value2));
 | 
			
		||||
    g_assert(!memcmp(data->bytes->data, &value2, data->bytes->len));
 | 
			
		||||
    
 | 
			
		||||
    // test overlap over the end of the buffer
 | 
			
		||||
    gbinder_writer_overwrite_int32(&writer, 2, value2);
 | 
			
		||||
    g_assert(data->bytes->len == sizeof(value2));
 | 
			
		||||
    
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -924,6 +938,26 @@ test_byte_array(
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * bytes_written
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
test_bytes_written(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    const guint32 value = 1234567;
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_local_request_new(&gbinder_io_32, NULL);
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_init_writer(req, &writer);
 | 
			
		||||
    g_assert(gbinder_writer_bytes_written(&writer) == 0);
 | 
			
		||||
    gbinder_writer_append_int32(&writer, value);
 | 
			
		||||
    g_assert(gbinder_writer_bytes_written(&writer) == sizeof(value));
 | 
			
		||||
    
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
}
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Common
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -995,6 +1029,7 @@ int main(int argc, char* argv[])
 | 
			
		||||
    g_test_add_func(TEST_("local_object"), test_local_object);
 | 
			
		||||
    g_test_add_func(TEST_("remote_object"), test_remote_object);
 | 
			
		||||
    g_test_add_func(TEST_("byte_array"), test_byte_array);
 | 
			
		||||
    g_test_add_func(TEST_("bytes_written"), test_bytes_written);
 | 
			
		||||
    test_init(&test_opt, argc, argv);
 | 
			
		||||
    return g_test_run();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user