Compare commits
	
		
			175 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					7f72021075 | ||
| 
						 | 
					846037073b | ||
| 
						 | 
					f0b55886b2 | ||
| 
						 | 
					165d386436 | ||
| 
						 | 
					a07e0f2a99 | ||
| 
						 | 
					bc172346e0 | ||
| 
						 | 
					5801ed4f15 | ||
| 
						 | 
					e8c5a0c0bb | ||
| 
						 | 
					94b74ee948 | ||
| 
						 | 
					1bfacab88d | ||
| 
						 | 
					704e7d011c | ||
| 
						 | 
					3a4ae9a716 | ||
| 
						 | 
					5ddc9d94d6 | ||
| 
						 | 
					159708d829 | ||
| 
						 | 
					5753cdab1a | ||
| 
						 | 
					d4ea1261eb | ||
| 
						 | 
					7e3ac0a761 | ||
| 
						 | 
					76494c3e3d | ||
| 
						 | 
					dfbc8acd9e | ||
| 
						 | 
					158d33db5a | ||
| 
						 | 
					4b11769895 | ||
| 
						 | 
					4da96dd0b5 | ||
| 
						 | 
					d9bfb9e200 | ||
| 
						 | 
					f088e6d1bb | ||
| 
						 | 
					ca665ad3d1 | ||
| 
						 | 
					6ed9082e69 | ||
| 
						 | 
					5332dd3482 | ||
| 
						 | 
					a15f63621e | ||
| 
						 | 
					e4b5f081bd | ||
| 
						 | 
					5fab0bcdaa | ||
| 
						 | 
					5c1b23f30e | ||
| 
						 | 
					8f720e11de | ||
| 
						 | 
					3c2cd5d599 | ||
| 
						 | 
					8df1e70c0b | ||
| 
						 | 
					3833a36693 | ||
| 
						 | 
					38fd1e6dcb | ||
| 
						 | 
					5fa4cd03de | ||
| 
						 | 
					d6c0cdd231 | ||
| 
						 | 
					c38843d9c9 | ||
| 
						 | 
					a6a5df963f | ||
| 
						 | 
					b60960d955 | ||
| 
						 | 
					0adb80a9ed | ||
| 
						 | 
					f591433118 | ||
| 
						 | 
					5a897a34c2 | ||
| 
						 | 
					138423de4a | ||
| 
						 | 
					1d9f9c4487 | ||
| 
						 | 
					82f71a6c91 | ||
| 
						 | 
					0c85299efc | ||
| 
						 | 
					50195aae1d | ||
| 
						 | 
					586425bc2d | ||
| 
						 | 
					b0bde6b652 | ||
| 
						 | 
					be2369c64c | ||
| 
						 | 
					c2cf68cab6 | ||
| 
						 | 
					f7d1863615 | ||
| 
						 | 
					0bb0aee6cb | ||
| 
						 | 
					b392e019f3 | ||
| 
						 | 
					8eb5fa7394 | ||
| 
						 | 
					c5c04db81a | ||
| 
						 | 
					4056cfaa15 | ||
| 
						 | 
					ba8b226d89 | ||
| 
						 | 
					88df2edb95 | ||
| 
						 | 
					b856cf2141 | ||
| 
						 | 
					f4a2429a13 | ||
| 
						 | 
					7d1f8ad4e7 | ||
| 
						 | 
					82656db49d | ||
| 
						 | 
					d6dac912dd | ||
| 
						 | 
					207f9398b4 | ||
| 
						 | 
					7b51a82de8 | ||
| 
						 | 
					66f08bf0db | ||
| 
						 | 
					90384e921f | ||
| 
						 | 
					1ae7c2697c | ||
| 
						 | 
					536143c1d7 | ||
| 
						 | 
					6025950aab | ||
| 
						 | 
					4d69940b96 | ||
| 
						 | 
					b1f49cae13 | ||
| 
						 | 
					80e9be5343 | ||
| 
						 | 
					d6d6b76fa5 | ||
| 
						 | 
					d18a352a82 | ||
| 
						 | 
					5fbaabb47e | ||
| 
						 | 
					83cc13b817 | ||
| 
						 | 
					1679cda4c5 | ||
| 
						 | 
					e5f11aafc1 | ||
| 
						 | 
					f262c77b17 | ||
| 
						 | 
					3ef00effc5 | ||
| 
						 | 
					1ce13bea91 | ||
| 
						 | 
					eaab366dcb | ||
| 
						 | 
					784f06c415 | ||
| 
						 | 
					4b07e80a8f | ||
| 
						 | 
					9f7fac407d | ||
| 
						 | 
					47b6668876 | ||
| 
						 | 
					951977961b | ||
| 
						 | 
					f069c3a595 | ||
| 
						 | 
					b84194e8c7 | ||
| 
						 | 
					e06e989aa5 | ||
| 
						 | 
					ab75505437 | ||
| 
						 | 
					e97663b58e | ||
| 
						 | 
					a92f57a30c | ||
| 
						 | 
					ebb9381e46 | ||
| 
						 | 
					5fb441fb81 | ||
| 
						 | 
					f3a00fe8a2 | ||
| 
						 | 
					573494570c | ||
| 
						 | 
					92392f5c9a | ||
| 
						 | 
					8a634a0d95 | ||
| 
						 | 
					23c5d48b5d | ||
| 
						 | 
					f000b344dd | ||
| 
						 | 
					42177e1ff2 | ||
| 
						 | 
					091ca483e7 | ||
| 
						 | 
					42ce4f8821 | ||
| 
						 | 
					9a1781765b | ||
| 
						 | 
					544b8181e5 | ||
| 
						 | 
					82ea37ead9 | ||
| 
						 | 
					882ef93084 | ||
| 
						 | 
					881469ab7f | ||
| 
						 | 
					d7834650ae | ||
| 
						 | 
					20bf183a10 | ||
| 
						 | 
					c990ac66da | ||
| 
						 | 
					0964163a35 | ||
| 
						 | 
					fc980b1bc9 | ||
| 
						 | 
					e76c8a3ba7 | ||
| 
						 | 
					5805290369 | ||
| 
						 | 
					7dd9623929 | ||
| 
						 | 
					95ac07e4de | ||
| 
						 | 
					92cd463b34 | ||
| 
						 | 
					6832546dca | ||
| 
						 | 
					049042b134 | ||
| 
						 | 
					6d2f2efe31 | ||
| 
						 | 
					bcce4831e3 | ||
| 
						 | 
					7fb3053135 | ||
| 
						 | 
					00359a0fc8 | ||
| 
						 | 
					ccf3e1237c | ||
| 
						 | 
					e02f00fd41 | ||
| 
						 | 
					e45e640f3c | ||
| 
						 | 
					75e8015c43 | ||
| 
						 | 
					2c52fcc156 | ||
| 
						 | 
					dc5b51a41f | ||
| 
						 | 
					d12cee4690 | ||
| 
						 | 
					a74c4ac148 | ||
| 
						 | 
					53e50a8107 | ||
| 
						 | 
					e896ba94cc | ||
| 
						 | 
					87ff990c73 | ||
| 
						 | 
					e406162be2 | ||
| 
						 | 
					2de4120f25 | ||
| 
						 | 
					d8dc58a133 | ||
| 
						 | 
					8684bffe97 | ||
| 
						 | 
					a08513ade0 | ||
| 
						 | 
					1a57e01e07 | ||
| 
						 | 
					6d4faf19b8 | ||
| 
						 | 
					96e6845e16 | ||
| 
						 | 
					b33adeb708 | ||
| 
						 | 
					ea0e294a74 | ||
| 
						 | 
					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 | 
							
								
								
									
										14
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,13 +1,13 @@
 | 
			
		||||
*~
 | 
			
		||||
debian/files
 | 
			
		||||
debian/libgbinder-dev.debhelper.log
 | 
			
		||||
debian/libgbinder-dev.substvars
 | 
			
		||||
debian/libgbinder-dev
 | 
			
		||||
debian/libgbinder.debhelper.log
 | 
			
		||||
debian/libgbinder.postinst.debhelper
 | 
			
		||||
debian/libgbinder.postrm.debhelper
 | 
			
		||||
debian/libgbinder.substvars
 | 
			
		||||
debian/libgbinder
 | 
			
		||||
debian/libgbinder-dev
 | 
			
		||||
debian/libgbinder-tools
 | 
			
		||||
debian/*.debhelper.log
 | 
			
		||||
debian/*.debhelper
 | 
			
		||||
debian/*.substvars
 | 
			
		||||
debian/libgbinder.install
 | 
			
		||||
debian/libgbinder-dev.install
 | 
			
		||||
debian/tmp
 | 
			
		||||
documentation.list
 | 
			
		||||
installroot
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								AUTHORS
									
									
									
									
									
								
							@@ -3,3 +3,6 @@ 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>
 | 
			
		||||
Rinigus <rinigus.git@gmail.com>
 | 
			
		||||
George Hopkins <george-hopkins@null.net>
 | 
			
		||||
Bart Ribbers <bribbers@disroot.org>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								LICENSE
									
									
									
									
									
								
							@@ -1,5 +1,5 @@
 | 
			
		||||
Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 | 
			
		||||
You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										139
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										139
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,16 +1,25 @@
 | 
			
		||||
# -*- Mode: makefile-gmake -*-
 | 
			
		||||
#
 | 
			
		||||
# LIBGLIBUTIL_PATH can be defined to point to libglibutil root directory
 | 
			
		||||
# for side-by-side build.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
.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
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Required packages
 | 
			
		||||
# Library version
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
PKGS = libglibutil glib-2.0 gobject-2.0
 | 
			
		||||
VERSION_MAJOR = 1
 | 
			
		||||
VERSION_MINOR = 1
 | 
			
		||||
VERSION_RELEASE = 13
 | 
			
		||||
 | 
			
		||||
# Version for pkg-config
 | 
			
		||||
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Default target
 | 
			
		||||
@@ -19,15 +28,34 @@ PKGS = libglibutil glib-2.0 gobject-2.0
 | 
			
		||||
all: debug release pkgconfig
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Library version
 | 
			
		||||
# Required packages
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
VERSION_MAJOR = 1
 | 
			
		||||
VERSION_MINOR = 0
 | 
			
		||||
VERSION_RELEASE = 30
 | 
			
		||||
PKGS = glib-2.0 gobject-2.0
 | 
			
		||||
 | 
			
		||||
# Version for pkg-config
 | 
			
		||||
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
 | 
			
		||||
ifeq ($(LIBGLIBUTIL_PATH),)
 | 
			
		||||
 | 
			
		||||
# Assume that libglibutil devel package is installed
 | 
			
		||||
PKGS += libglibutil
 | 
			
		||||
 | 
			
		||||
else
 | 
			
		||||
 | 
			
		||||
# Side-by-side build
 | 
			
		||||
INCLUDES += -I$(LIBGLIBUTIL_PATH)/include
 | 
			
		||||
DEBUG_LIBS = -L$(LIBGLIBUTIL_PATH)/build/debug -lglibutil
 | 
			
		||||
RELEASE_LIBS = -L$(LIBGLIBUTIL_PATH)/build/release -lglibutil
 | 
			
		||||
DEBUG_DEPS = libglibutil_debug
 | 
			
		||||
RELEASE_DEPS = libglibutil_release
 | 
			
		||||
 | 
			
		||||
.PHONY: libglibutil_debug libglibutil_release
 | 
			
		||||
 | 
			
		||||
libglibutil_debug:
 | 
			
		||||
	make -C $(LIBGLIBUTIL_PATH) debug
 | 
			
		||||
 | 
			
		||||
libglibutil_release:
 | 
			
		||||
	make -C $(LIBGLIBUTIL_PATH) release
 | 
			
		||||
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Library name
 | 
			
		||||
@@ -47,16 +75,21 @@ LIB = $(LIB_NAME).a
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
SRC = \
 | 
			
		||||
  gbinder_bridge.c \
 | 
			
		||||
  gbinder_buffer.c \
 | 
			
		||||
  gbinder_cleanup.c \
 | 
			
		||||
  gbinder_client.c \
 | 
			
		||||
  gbinder_config.c \
 | 
			
		||||
  gbinder_driver.c \
 | 
			
		||||
  gbinder_eventloop.c \
 | 
			
		||||
  gbinder_io_32.c \
 | 
			
		||||
  gbinder_io_64.c \
 | 
			
		||||
  gbinder_ipc.c \
 | 
			
		||||
  gbinder_local_object.c \
 | 
			
		||||
  gbinder_local_reply.c \
 | 
			
		||||
  gbinder_local_request.c \
 | 
			
		||||
  gbinder_log.c \
 | 
			
		||||
  gbinder_proxy_object.c \
 | 
			
		||||
  gbinder_reader.c \
 | 
			
		||||
  gbinder_remote_object.c \
 | 
			
		||||
  gbinder_remote_reply.c \
 | 
			
		||||
@@ -67,9 +100,10 @@ SRC = \
 | 
			
		||||
  gbinder_writer.c
 | 
			
		||||
 | 
			
		||||
SRC += \
 | 
			
		||||
  gbinder_defaultservicemanager.c \
 | 
			
		||||
  gbinder_hwservicemanager.c \
 | 
			
		||||
  gbinder_servicemanager.c
 | 
			
		||||
  gbinder_servicemanager.c \
 | 
			
		||||
  gbinder_servicemanager_aidl.c \
 | 
			
		||||
  gbinder_servicemanager_aidl2.c \
 | 
			
		||||
  gbinder_servicemanager_hidl.c
 | 
			
		||||
 | 
			
		||||
SRC += \
 | 
			
		||||
  gbinder_system.c
 | 
			
		||||
@@ -89,10 +123,11 @@ COVERAGE_BUILD_DIR = $(BUILD_DIR)/coverage
 | 
			
		||||
# Tools and flags
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
CC = $(CROSS_COMPILE)gcc
 | 
			
		||||
CC ?= $(CROSS_COMPILE)gcc
 | 
			
		||||
STRIP ?= strip
 | 
			
		||||
LD = $(CC)
 | 
			
		||||
WARNINGS = -Wall -Wstrict-aliasing -Wunused-result
 | 
			
		||||
INCLUDES = -I$(INCLUDE_DIR)
 | 
			
		||||
INCLUDES += -I$(INCLUDE_DIR)
 | 
			
		||||
BASE_FLAGS = -fPIC
 | 
			
		||||
FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
 | 
			
		||||
  -MMD -MP $(shell pkg-config --cflags $(PKGS))
 | 
			
		||||
@@ -102,16 +137,13 @@ DEBUG_FLAGS = -g
 | 
			
		||||
RELEASE_FLAGS =
 | 
			
		||||
COVERAGE_FLAGS = -g
 | 
			
		||||
 | 
			
		||||
ifndef KEEP_SYMBOLS
 | 
			
		||||
KEEP_SYMBOLS = 0
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
KEEP_SYMBOLS ?= 0
 | 
			
		||||
ifneq ($(KEEP_SYMBOLS),0)
 | 
			
		||||
RELEASE_FLAGS += -g
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_FLAGS)
 | 
			
		||||
RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS)
 | 
			
		||||
DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_LIBS) $(DEBUG_FLAGS)
 | 
			
		||||
RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_LIBS) $(RELEASE_FLAGS)
 | 
			
		||||
DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG
 | 
			
		||||
RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2
 | 
			
		||||
COVERAGE_CFLAGS = $(FULL_CFLAGS) $(COVERAGE_FLAGS) --coverage
 | 
			
		||||
@@ -125,6 +157,16 @@ DEBUG_OBJS = $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
 | 
			
		||||
RELEASE_OBJS = $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
 | 
			
		||||
COVERAGE_OBJS = $(SRC:%.c=$(COVERAGE_BUILD_DIR)/%.o)
 | 
			
		||||
 | 
			
		||||
DEBUG_SO = $(DEBUG_BUILD_DIR)/$(LIB_SO)
 | 
			
		||||
RELEASE_SO = $(RELEASE_BUILD_DIR)/$(LIB_SO)
 | 
			
		||||
DEBUG_LINK = $(DEBUG_BUILD_DIR)/$(LIB_SYMLINK1)
 | 
			
		||||
RELEASE_LINK = $(RELEASE_BUILD_DIR)/$(LIB_SYMLINK1)
 | 
			
		||||
DEBUG_DEV_LINK = $(DEBUG_BUILD_DIR)/$(LIB_DEV_SYMLINK)
 | 
			
		||||
RELEASE_DEV_LINK = $(RELEASE_BUILD_DIR)/$(LIB_DEV_SYMLINK)
 | 
			
		||||
DEBUG_LIB = $(DEBUG_BUILD_DIR)/$(LIB)
 | 
			
		||||
RELEASE_LIB = $(RELEASE_BUILD_DIR)/$(LIB)
 | 
			
		||||
COVERAGE_LIB = $(COVERAGE_BUILD_DIR)/$(LIB)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Dependencies
 | 
			
		||||
#
 | 
			
		||||
@@ -137,25 +179,22 @@ endif
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
$(PKGCONFIG): | $(BUILD_DIR)
 | 
			
		||||
$(DEBUG_OBJS) $(DEBUG_SO): | $(DEBUG_BUILD_DIR)
 | 
			
		||||
$(RELEASE_OBJS) $(RELEASE_SO): | $(RELEASE_BUILD_DIR)
 | 
			
		||||
$(DEBUG_OBJS) $(DEBUG_SO): | $(DEBUG_BUILD_DIR) $(DEBUG_DEPS)
 | 
			
		||||
$(RELEASE_OBJS) $(RELEASE_SO): | $(RELEASE_BUILD_DIR) $(RELEASE_DEPS)
 | 
			
		||||
$(COVERAGE_OBJS) $(COVERAGE_LIB): | $(COVERAGE_BUILD_DIR)
 | 
			
		||||
 | 
			
		||||
$(DEBUG_LINK): | $(DEBUG_LIB)
 | 
			
		||||
$(RELEASE_LINK): | $(RELEASE_LIB)
 | 
			
		||||
$(DEBUG_DEV_LINK): | $(DEBUG_LINK)
 | 
			
		||||
$(RELEASE_DEV_LINK): | $(RELEASE_LINK)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Rules
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
DEBUG_SO = $(DEBUG_BUILD_DIR)/$(LIB_SO)
 | 
			
		||||
RELEASE_SO = $(RELEASE_BUILD_DIR)/$(LIB_SO)
 | 
			
		||||
DEBUG_LINK = $(DEBUG_BUILD_DIR)/$(LIB_SYMLINK1)
 | 
			
		||||
RELEASE_LINK = $(RELEASE_BUILD_DIR)/$(LIB_SYMLINK1)
 | 
			
		||||
DEBUG_LIB = $(DEBUG_BUILD_DIR)/$(LIB)
 | 
			
		||||
RELEASE_LIB = $(RELEASE_BUILD_DIR)/$(LIB)
 | 
			
		||||
COVERAGE_LIB = $(COVERAGE_BUILD_DIR)/$(LIB)
 | 
			
		||||
debug: $(DEBUG_SO) $(DEBUG_LINK) $(DEBUG_DEV_LINK)
 | 
			
		||||
 | 
			
		||||
debug: $(DEBUG_SO)
 | 
			
		||||
 | 
			
		||||
release: $(RELEASE_SO)
 | 
			
		||||
release: $(RELEASE_SO) $(RELEASE_LINK) $(RELEASE_DEV_LINK)
 | 
			
		||||
 | 
			
		||||
debug_lib: $(DEBUG_LIB)
 | 
			
		||||
 | 
			
		||||
@@ -201,6 +240,7 @@ clean:
 | 
			
		||||
	rm -fr debian/tmp debian/libgbinder debian/libgbinder-dev
 | 
			
		||||
	rm -f documentation.list debian/files debian/*.substvars
 | 
			
		||||
	rm -f debian/*.debhelper.log debian/*.debhelper debian/*~
 | 
			
		||||
	rm -f debian/libgbinder.install debian/libgbinder-dev.install
 | 
			
		||||
 | 
			
		||||
test:
 | 
			
		||||
	make -C unit test
 | 
			
		||||
@@ -228,13 +268,11 @@ $(COVERAGE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
 | 
			
		||||
 | 
			
		||||
$(DEBUG_SO): $(DEBUG_OBJS)
 | 
			
		||||
	$(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) -o $@
 | 
			
		||||
	ln -sf $(LIB_SO) $(DEBUG_LINK)
 | 
			
		||||
 | 
			
		||||
$(RELEASE_SO): $(RELEASE_OBJS)
 | 
			
		||||
	$(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) -o $@
 | 
			
		||||
	ln -sf $(LIB_SO) $(RELEASE_LINK)
 | 
			
		||||
ifeq ($(KEEP_SYMBOLS),0)
 | 
			
		||||
	strip $@
 | 
			
		||||
	$(STRIP) $@
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
$(DEBUG_LIB): $(DEBUG_OBJS)
 | 
			
		||||
@@ -245,12 +283,35 @@ $(RELEASE_LIB): $(RELEASE_OBJS)
 | 
			
		||||
	$(AR) rc $@ $?
 | 
			
		||||
	ranlib $@
 | 
			
		||||
 | 
			
		||||
$(DEBUG_LINK):
 | 
			
		||||
	ln -sf $(LIB_SO) $@
 | 
			
		||||
 | 
			
		||||
$(RELEASE_LINK):
 | 
			
		||||
	ln -sf $(LIB_SO) $@
 | 
			
		||||
 | 
			
		||||
$(DEBUG_DEV_LINK):
 | 
			
		||||
	ln -sf $(LIB_SYMLINK1) $@
 | 
			
		||||
 | 
			
		||||
$(RELEASE_DEV_LINK):
 | 
			
		||||
	ln -sf $(LIB_SYMLINK1) $@
 | 
			
		||||
 | 
			
		||||
$(COVERAGE_LIB): $(COVERAGE_OBJS)
 | 
			
		||||
	$(AR) rc $@ $?
 | 
			
		||||
	ranlib $@
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# LIBDIR usually gets substituted with arch specific dir.
 | 
			
		||||
# It's relative in deb build and can be whatever in rpm build.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
LIBDIR ?= usr/lib
 | 
			
		||||
ABS_LIBDIR := $(shell echo /$(LIBDIR) | sed -r 's|/+|/|g')
 | 
			
		||||
 | 
			
		||||
$(PKGCONFIG): $(LIB_NAME).pc.in Makefile
 | 
			
		||||
	sed -e 's/\[version\]/'$(PCVERSION)/g $< > $@
 | 
			
		||||
	sed -e 's|@version@|$(PCVERSION)|g' -e 's|@libdir@|$(ABS_LIBDIR)|g' $< > $@
 | 
			
		||||
 | 
			
		||||
debian/%.install: debian/%.install.in
 | 
			
		||||
	sed 's|@LIBDIR@|$(LIBDIR)|g' $< > $@
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Install
 | 
			
		||||
@@ -262,12 +323,12 @@ INSTALL = install
 | 
			
		||||
INSTALL_DIRS = $(INSTALL) -d
 | 
			
		||||
INSTALL_FILES = $(INSTALL) -m $(INSTALL_PERM)
 | 
			
		||||
 | 
			
		||||
INSTALL_LIB_DIR = $(DESTDIR)/usr/lib
 | 
			
		||||
INSTALL_LIB_DIR = $(DESTDIR)$(ABS_LIBDIR)
 | 
			
		||||
INSTALL_INCLUDE_DIR = $(DESTDIR)/usr/include/$(NAME)
 | 
			
		||||
INSTALL_PKGCONFIG_DIR = $(DESTDIR)/usr/lib/pkgconfig
 | 
			
		||||
INSTALL_PKGCONFIG_DIR = $(DESTDIR)$(ABS_LIBDIR)/pkgconfig
 | 
			
		||||
 | 
			
		||||
install: $(INSTALL_LIB_DIR)
 | 
			
		||||
	$(INSTALL_FILES) $(RELEASE_SO) $(INSTALL_LIB_DIR)
 | 
			
		||||
	$(INSTALL) -m 755 $(RELEASE_SO) $(INSTALL_LIB_DIR)
 | 
			
		||||
	ln -sf $(LIB_SO) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK2)
 | 
			
		||||
	ln -sf $(LIB_SYMLINK2) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK1)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										39
									
								
								README
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								README
									
									
									
									
									
								
							@@ -1,7 +1,44 @@
 | 
			
		||||
GLib-style interface to binder (Android IPC mechanism)
 | 
			
		||||
 | 
			
		||||
Provides:
 | 
			
		||||
Key features:
 | 
			
		||||
 | 
			
		||||
1. Integration with GLib event loop
 | 
			
		||||
2. Detection of 32 vs 64 bit kernel at runtime
 | 
			
		||||
3. Asynchronous transactions that don't block the event thread
 | 
			
		||||
4. Stable service manager and low-level transation APIs
 | 
			
		||||
 | 
			
		||||
Android keeps changing both low-level RPC and service manager
 | 
			
		||||
protocols from version to version. To counter that, libgbinder
 | 
			
		||||
implements configirable backends for different variants of those,
 | 
			
		||||
and yet keeping its own API unchanged.
 | 
			
		||||
 | 
			
		||||
Configuration is loaded from [Protocol] and [ServiceManager] sections
 | 
			
		||||
of /etc/gbinder.conf file. The keys are binder device names or the
 | 
			
		||||
special Default value, the value is the identifier of the protocol
 | 
			
		||||
or service manager variant, respectively.
 | 
			
		||||
 | 
			
		||||
In addition to reading /etc/gbinder.conf if it exists, /etc/gbinder.d
 | 
			
		||||
directory is scanned for .conf files, the file list is sorted, files are
 | 
			
		||||
loaded one by one, overwriting the entries loaded from /etc/gbinder.conf
 | 
			
		||||
or from the previously processed file.
 | 
			
		||||
 | 
			
		||||
Known protocol and service manager variants are aidl, aidl2 and hidl.
 | 
			
		||||
This list is expected to expand further in the future. The default
 | 
			
		||||
configuration is as follows:
 | 
			
		||||
 | 
			
		||||
  [Protocol]
 | 
			
		||||
  Default = aidl
 | 
			
		||||
  /dev/binder = aidl
 | 
			
		||||
  /dev/hwbinder = hidl
 | 
			
		||||
 | 
			
		||||
  [ServiceManager]
 | 
			
		||||
  Default = aidl
 | 
			
		||||
  /dev/binder = aidl
 | 
			
		||||
  /dev/hwbinder = hidl
 | 
			
		||||
 | 
			
		||||
Alternatively, one can specify the desired Android API level:
 | 
			
		||||
 | 
			
		||||
  [General]
 | 
			
		||||
  ApiLevel = 29
 | 
			
		||||
 | 
			
		||||
and let libgbinder pick the appropriate preset.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										223
									
								
								debian/changelog
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										223
									
								
								debian/changelog
									
									
									
									
										vendored
									
									
								
							@@ -1,3 +1,226 @@
 | 
			
		||||
libgbinder (1.1.13) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Added gbinder_writer_strdup()
 | 
			
		||||
  * Added gbinder_writer_append_hidl_string_copy()
 | 
			
		||||
  * Dropped pkgconfig requirement for devel package
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Thu, 28 Oct 2021 14:31:01 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.12) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Added binder-call test tool
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Fri, 24 Sep 2021 16:46:05 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.11) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Fix potential deadlock in gbinder_ipc_looper_free()
 | 
			
		||||
  * Fix occasional crashes in pthread_setname_np()
 | 
			
		||||
  * Fix unit tests on some musl-based systems
 | 
			
		||||
  * Make unit tests comptible with glib < 2.36
 | 
			
		||||
  * Bump libglibutil requirement for debian build
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Thu, 02 Sep 2021 12:32:39 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.10) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Release dead binder nodes
 | 
			
		||||
  * Use gutil_memdup() instead of g_memdup()
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Mon, 10 May 2021 02:36:43 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.9) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Include definition of _IOC_SIZE
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 20 Apr 2021 12:52:41 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.8) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Handle out-of-range transaction codes
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Fri, 16 Apr 2021 19:11:14 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.7) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Dropped use of g_main_context_invoke_full()
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Wed, 31 Mar 2021 23:10:37 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.6) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Implemented support for passing object over the bridge
 | 
			
		||||
  * Retry service name registration
 | 
			
		||||
  * Wait for completion of the reply
 | 
			
		||||
  * Fixed death handling by GBinderBridge
 | 
			
		||||
  * Added gbinder_bridge_new2()
 | 
			
		||||
  * Added -s option to binder-bridge
 | 
			
		||||
  * Fixed invalid slice deallocation
 | 
			
		||||
  * Made unit tests more reliable
 | 
			
		||||
  * Make sure that libgbinder doesn't block on exit
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 02 Mar 2021 18:18:03 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.5) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Fixed gbinder_remote_reply_copy_to_local() for empty replies
 | 
			
		||||
  * Improved binder simulation
 | 
			
		||||
  * Added GBinderBridge object
 | 
			
		||||
  * Added proxy_object and bridge unit tests
 | 
			
		||||
  * Added binder-bridge to libgbinder-tools package
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Fri, 29 Jan 2021 04:00:09 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.4) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Fixed a threading issue
 | 
			
		||||
  * Decode NULL object reference
 | 
			
		||||
  * Added new basic HIDL types
 | 
			
		||||
  * Set TF_ACCEPT_FDS transaction flag
 | 
			
		||||
  * Added servicemanager_hidl unit test
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Thu, 21 Jan 2021 03:34:45 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.3) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Improved unit test coverage
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Wed, 23 Dec 2020 21:48:27 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.2) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Fixed random unit text failures
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Wed, 23 Dec 2020 12:39:22 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.1) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Handle corner cases for abandoned loopers
 | 
			
		||||
  * Pass 0x0f priority to aidl2 service list request.
 | 
			
		||||
  * Improved binder simulation for unit tests
 | 
			
		||||
  * Added servicemanager_aidl unit test
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 22 Dec 2020 15:15:10 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.1.0) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Made RPC protocol configurable per binder device
 | 
			
		||||
  * Made service managers configurable per binder device
 | 
			
		||||
  * Added support for multiple config files
 | 
			
		||||
  * Added "aidl2" variant of service manager
 | 
			
		||||
  * Added "aidl2" variant of RPC protocol
 | 
			
		||||
  * Added support for API level presets
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Fri, 04 Dec 2020 13:47:26 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.47) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Make library executable on RPM based systems
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Sat, 19 Sep 2020 20:14:20 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.46) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Make sure we drop fds that are going to be closed
 | 
			
		||||
  * Better diagnostics for polling failures
 | 
			
		||||
  * Package binder-list and binder-ping utilities
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Fri, 31 Jul 2020 02:04:38 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.45) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Always provide data buffer for hidl vector
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Mon, 27 Jul 2020 23:19:25 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.44) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Never drop valid incoming transactions
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Mon, 29 Jun 2020 17:05:22 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.43) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Hide internal symbols
 | 
			
		||||
  * Respect arch specific lib dir
 | 
			
		||||
  * Allow strip command to be replaced via environment variable
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Wed, 03 Jun 2020 15:15:40 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.42) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Allow GBinderClient to use multiple interfaces
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 05 May 2020 19:56:39 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.41) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Stop using GUtilIdlePool
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 14 Apr 2020 12:36:54 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.40) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Support integration with non-glib event loops
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Thu, 09 Apr 2020 17:22:12 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.39) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Adapted to side-by-side linking
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Thu, 02 Apr 2020 18:07:16 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.38) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Allow to configure log level via environment
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Thu, 02 Apr 2020 00:12:01 +0300
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.37) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Allow side-by-side linking with libglibutil
 | 
			
		||||
  * Fixed compilation warnings
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Tue, 17 Mar 2020 20:15:11 +0200
 | 
			
		||||
 | 
			
		||||
libgbinder (1.0.36) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  * Allow overwriting CC
 | 
			
		||||
 | 
			
		||||
 -- Slava Monich <slava.monich@jolla.com>  Mon, 16 Mar 2020 16:15:24 +0200
 | 
			
		||||
 | 
			
		||||
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()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								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.35)
 | 
			
		||||
Build-Depends: debhelper (>= 8.1.3), libglib2.0-dev (>= 2.0), libglibutil (>= 1.0.52), flex, bison
 | 
			
		||||
Standards-Version: 3.8.4
 | 
			
		||||
 | 
			
		||||
Package: libgbinder
 | 
			
		||||
Section: libs
 | 
			
		||||
Architecture: any
 | 
			
		||||
Depends: libglibutil (>= 1.0.35), ${shlibs:Depends}, ${misc:Depends}
 | 
			
		||||
Depends: libglibutil (>= 1.0.52), ${shlibs:Depends}, ${misc:Depends}
 | 
			
		||||
Description: Binder client library
 | 
			
		||||
 | 
			
		||||
Package: libgbinder-dev
 | 
			
		||||
@@ -16,3 +16,9 @@ Section: libdevel
 | 
			
		||||
Architecture: any
 | 
			
		||||
Depends: libgbinder (= ${binary:Version}), ${misc:Depends}
 | 
			
		||||
Description: Development files for libgbinder
 | 
			
		||||
 | 
			
		||||
Package: libgbinder-tools
 | 
			
		||||
Section: utils
 | 
			
		||||
Architecture: any
 | 
			
		||||
Depends: libgbinder, ${misc:Depends}
 | 
			
		||||
Description: Binder command line utilities
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										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-2021 Jolla Ltd.
 | 
			
		||||
Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 | 
			
		||||
You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								debian/libgbinder-dev.install
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								debian/libgbinder-dev.install
									
									
									
									
										vendored
									
									
								
							@@ -1,3 +0,0 @@
 | 
			
		||||
debian/tmp/usr/lib/libgbinder.so usr/lib
 | 
			
		||||
include/*.h usr/include/gbinder
 | 
			
		||||
build/libgbinder.pc usr/lib/pkgconfig
 | 
			
		||||
							
								
								
									
										3
									
								
								debian/libgbinder-dev.install.in
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								debian/libgbinder-dev.install.in
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
debian/tmp/@LIBDIR@/libgbinder.so @LIBDIR@
 | 
			
		||||
debian/tmp/@LIBDIR@/pkgconfig/libgbinder.pc @LIBDIR@/pkgconfig
 | 
			
		||||
debian/tmp/usr/include/* usr/include
 | 
			
		||||
							
								
								
									
										1
									
								
								debian/libgbinder-tools.install
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								debian/libgbinder-tools.install
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
debian/tmp/usr/bin/* usr/bin
 | 
			
		||||
							
								
								
									
										1
									
								
								debian/libgbinder.install
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								debian/libgbinder.install
									
									
									
									
										vendored
									
									
								
							@@ -1 +0,0 @@
 | 
			
		||||
debian/tmp/usr/lib/libgbinder.so.* usr/lib
 | 
			
		||||
							
								
								
									
										1
									
								
								debian/libgbinder.install.in
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								debian/libgbinder.install.in
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
debian/tmp/@LIBDIR@/libgbinder.so.* @LIBDIR@
 | 
			
		||||
							
								
								
									
										15
									
								
								debian/rules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								debian/rules
									
									
									
									
										vendored
									
									
								
							@@ -4,8 +4,21 @@
 | 
			
		||||
# Uncomment this to turn on verbose mode.
 | 
			
		||||
#export DH_VERBOSE=1
 | 
			
		||||
 | 
			
		||||
LIBDIR=usr/lib/$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
 | 
			
		||||
 | 
			
		||||
override_dh_auto_build:
 | 
			
		||||
	dh_auto_build -- LIBDIR=$(LIBDIR) release pkgconfig debian/libgbinder.install debian/libgbinder-dev.install
 | 
			
		||||
	dh_auto_build -- -C test/binder-bridge release
 | 
			
		||||
	dh_auto_build -- -C test/binder-call release
 | 
			
		||||
	dh_auto_build -- -C test/binder-list release
 | 
			
		||||
	dh_auto_build -- -C test/binder-ping release
 | 
			
		||||
 | 
			
		||||
override_dh_auto_install:
 | 
			
		||||
	dh_auto_install -- install-dev
 | 
			
		||||
	dh_auto_install -- LIBDIR=$(LIBDIR) install-dev
 | 
			
		||||
	dh_auto_install -- -C test/binder-bridge
 | 
			
		||||
	dh_auto_install -- -C test/binder-call
 | 
			
		||||
	dh_auto_install -- -C test/binder-list
 | 
			
		||||
	dh_auto_install -- -C test/binder-ping
 | 
			
		||||
 | 
			
		||||
%:
 | 
			
		||||
	dh $@
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -35,6 +35,7 @@
 | 
			
		||||
 | 
			
		||||
/* Convenience header to pull in everything at once */
 | 
			
		||||
 | 
			
		||||
#include "gbinder_bridge.h"
 | 
			
		||||
#include "gbinder_buffer.h"
 | 
			
		||||
#include "gbinder_client.h"
 | 
			
		||||
#include "gbinder_local_object.h"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										89
									
								
								include/gbinder_bridge.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								include/gbinder_bridge.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,89 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2021 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_BRIDGE_H
 | 
			
		||||
#define GBINDER_BRIDGE_H
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types.h"
 | 
			
		||||
 | 
			
		||||
/* Since 1.1.5 */
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * A binder bridge object.
 | 
			
		||||
 *
 | 
			
		||||
 * For example, bridging "foobar" with interfaces ["example@1.0::IFoo",
 | 
			
		||||
 * "example@1.0::IBar"] would:
 | 
			
		||||
 *
 | 
			
		||||
 * 1. Watch "example@1.0::IFoo/foobar" and "example@1.0::IBar/foobar" on dest
 | 
			
		||||
 * 2. When those names appears, register objects with the same name on src
 | 
			
		||||
 * 3. Pass calls coming from src to the dest objects and replies in the
 | 
			
		||||
 *    opposite direction
 | 
			
		||||
 * 4. When dest objects disappear, remove the corresponding bridging objects
 | 
			
		||||
 *    from src
 | 
			
		||||
 *
 | 
			
		||||
 * and so on.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
GBinderBridge*
 | 
			
		||||
gbinder_bridge_new(
 | 
			
		||||
    const char* name,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderServiceManager* src,
 | 
			
		||||
    GBinderServiceManager* dest) /* Since 1.1.5 */
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT;
 | 
			
		||||
 | 
			
		||||
GBinderBridge*
 | 
			
		||||
gbinder_bridge_new2(
 | 
			
		||||
    const char* src_name,
 | 
			
		||||
    const char* dest_name,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderServiceManager* src,
 | 
			
		||||
    GBinderServiceManager* dest) /* Since 1.1.6 */
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_bridge_free(
 | 
			
		||||
    GBinderBridge* bridge); /* Since 1.1.5 */
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_BRIDGE_H */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -37,6 +37,11 @@
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_client_iface_info {
 | 
			
		||||
    const char* iface;
 | 
			
		||||
    guint32 last_code;
 | 
			
		||||
} GBinderClientIfaceInfo;
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
void
 | 
			
		||||
(*GBinderClientReplyFunc)(
 | 
			
		||||
@@ -50,6 +55,12 @@ gbinder_client_new(
 | 
			
		||||
    GBinderRemoteObject* object,
 | 
			
		||||
    const char* iface);
 | 
			
		||||
 | 
			
		||||
GBinderClient*
 | 
			
		||||
gbinder_client_new2(
 | 
			
		||||
    GBinderRemoteObject* object,
 | 
			
		||||
    const GBinderClientIfaceInfo* ifaces,
 | 
			
		||||
    gsize count); /* since 1.0.42 */
 | 
			
		||||
 | 
			
		||||
GBinderClient*
 | 
			
		||||
gbinder_client_ref(
 | 
			
		||||
    GBinderClient* client);
 | 
			
		||||
@@ -62,10 +73,20 @@ const char*
 | 
			
		||||
gbinder_client_interface(
 | 
			
		||||
    GBinderClient* client); /* since 1.0.22 */
 | 
			
		||||
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_client_interface2(
 | 
			
		||||
    GBinderClient* client,
 | 
			
		||||
    guint32 code); /* since 1.0.42 */
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_client_new_request(
 | 
			
		||||
    GBinderClient* client);
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_client_new_request2(
 | 
			
		||||
    GBinderClient* client,
 | 
			
		||||
    guint32 code); /* since 1.0.42 */
 | 
			
		||||
 | 
			
		||||
GBinderRemoteReply*
 | 
			
		||||
gbinder_client_transact_sync_reply(
 | 
			
		||||
    GBinderClient* client,
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										194
									
								
								include/gbinder_eventloop.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										194
									
								
								include/gbinder_eventloop.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,194 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef GBINDER_EVENTLOOP_H
 | 
			
		||||
#define GBINDER_EVENTLOOP_H
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types.h"
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
/* Since 1.0.40 */
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_eventloop_integration GBinderEventLoopIntegration;
 | 
			
		||||
typedef void (*GBinderEventLoopCallbackFunc)(gpointer data);
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_eventloop_timeout {
 | 
			
		||||
    const GBinderEventLoopIntegration* eventloop;
 | 
			
		||||
} GBinderEventLoopTimeout;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_eventloop_callback {
 | 
			
		||||
    const GBinderEventLoopIntegration* eventloop;
 | 
			
		||||
} GBinderEventLoopCallback;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Main event loop integration. There is only one main event loop in the
 | 
			
		||||
 * process (by definition).
 | 
			
		||||
 *
 | 
			
		||||
 * By default, GLib event loop is being used for callbacks and timeouts.
 | 
			
		||||
 *
 | 
			
		||||
 * It may be necessary to replace it with e.g. Qt event loop. Quite often
 | 
			
		||||
 * Qt event loop is implemented by QEventDispatcherGlib which is sitting
 | 
			
		||||
 * on top of GLib event and therefore works with the default implementation.
 | 
			
		||||
 * But it won't work with e.g. QEventDispatcherUNIX.
 | 
			
		||||
 *
 | 
			
		||||
 * For Qt programs that use QEventDispatcherUNIX, it needs to be replaced
 | 
			
		||||
 * with the one provided by libqbinder.
 | 
			
		||||
 */
 | 
			
		||||
typedef struct gbinder_eventloop_integration {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * timeout_add
 | 
			
		||||
     *
 | 
			
		||||
     * Sets a function to be called at regular intervals (in milliseconds).
 | 
			
		||||
     * If the function returns G_SOURCE_REMOVE, timeout is automatically
 | 
			
		||||
     * destroyed (you must not call timeout_remove in this case). If the
 | 
			
		||||
     * function returns G_SOURCE_CONTINUE, it will be called again after
 | 
			
		||||
     * the same interval.
 | 
			
		||||
     */
 | 
			
		||||
    GBinderEventLoopTimeout* (*timeout_add)(guint millis, GSourceFunc func,
 | 
			
		||||
        gpointer data);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * timeout_remove
 | 
			
		||||
     *
 | 
			
		||||
     * Removes a pending timeout and destroys it. The caller makes sure that
 | 
			
		||||
     * argument is not NULL. Note that timeout is automatically destroyed if
 | 
			
		||||
     * the callback function returns G_SOURCE_REMOVE.
 | 
			
		||||
     */
 | 
			
		||||
    void (*timeout_remove)(GBinderEventLoopTimeout* timeout);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * callback_new
 | 
			
		||||
     *
 | 
			
		||||
     * Creates a callback object. It returns you a reference, you must
 | 
			
		||||
     * eventually pass the returned object to callback_unref to drop
 | 
			
		||||
     * this reference.
 | 
			
		||||
     *
 | 
			
		||||
     * Note that it doesn't automatically schedule the callback. You
 | 
			
		||||
     * must explicitly call callback_schedule to actually schedule it.
 | 
			
		||||
     * The finalize function is invoked regardless of whether callback
 | 
			
		||||
     * was cancelled or not.
 | 
			
		||||
     */
 | 
			
		||||
    GBinderEventLoopCallback* (*callback_new)(GBinderEventLoopCallbackFunc fun,
 | 
			
		||||
        gpointer data, GDestroyNotify finalize);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * callback_ref
 | 
			
		||||
     *
 | 
			
		||||
     * Increments the reference count. That prevents the object from being
 | 
			
		||||
     * deleted before you drop this reference. The caller makes sure that
 | 
			
		||||
     * argument is not NULL.
 | 
			
		||||
     */
 | 
			
		||||
    void (*callback_ref)(GBinderEventLoopCallback* cb);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * callback_unref
 | 
			
		||||
     *
 | 
			
		||||
     * Decrements the reference count (drops the reference). When reference
 | 
			
		||||
     * count reaches zero, the object gets deleted. The caller makes sure
 | 
			
		||||
     * that argument is not NULL.
 | 
			
		||||
     *
 | 
			
		||||
     * Note that calling callback_schedule temporarily adds an internal
 | 
			
		||||
     * reference until the callback is invoked or callback_cancel is called,
 | 
			
		||||
     * whichever happens first.
 | 
			
		||||
     */
 | 
			
		||||
    void (*callback_unref)(GBinderEventLoopCallback* cb);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * callback_schedule
 | 
			
		||||
     *
 | 
			
		||||
     * Schedules the callback to be invoked in the main loop at some point
 | 
			
		||||
     * in the future (but as soon as possible). The caller makes sure that
 | 
			
		||||
     * argument is not NULL.
 | 
			
		||||
     *
 | 
			
		||||
     * This adds an internal reference to the GBinderEventLoopCallback object
 | 
			
		||||
     * until the callback is invoked or callback_cancel is called, whichever
 | 
			
		||||
     * happens first.
 | 
			
		||||
     */
 | 
			
		||||
    void (*callback_schedule)(GBinderEventLoopCallback* cb);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * callback_cancel
 | 
			
		||||
     *
 | 
			
		||||
     * Makes sure that callback won't be invoked (if it hasn't been
 | 
			
		||||
     * invoked yet) and drops the internal reference. Does nothing
 | 
			
		||||
     * if the callback has already been invoked. The caller makes sure that
 | 
			
		||||
     * argument is not NULL.
 | 
			
		||||
     */
 | 
			
		||||
    void (*callback_cancel)(GBinderEventLoopCallback* cb);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * cleanup
 | 
			
		||||
     *
 | 
			
		||||
     * This function is called when event loop integration is being replaced
 | 
			
		||||
     * with a different one, or libgbinder is being unloaded.
 | 
			
		||||
     */
 | 
			
		||||
    void (*cleanup)(void);
 | 
			
		||||
 | 
			
		||||
    /* Padding for future expansion */
 | 
			
		||||
    void (*_reserved1)(void);
 | 
			
		||||
    void (*_reserved2)(void);
 | 
			
		||||
    void (*_reserved3)(void);
 | 
			
		||||
    void (*_reserved4)(void);
 | 
			
		||||
    void (*_reserved5)(void);
 | 
			
		||||
    void (*_reserved6)(void);
 | 
			
		||||
    void (*_reserved7)(void);
 | 
			
		||||
    void (*_reserved8)(void);
 | 
			
		||||
    void (*_reserved9)(void);
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * api_level will remain zero (and ignored) until we run out of
 | 
			
		||||
     * the above placeholders. Hopefully, forever.
 | 
			
		||||
     */
 | 
			
		||||
    int api_level;
 | 
			
		||||
} GBinderEventLoopIntegration;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * gbinder_eventloop_set should be called before libgbinder creates any of
 | 
			
		||||
 * its internal threads. And it must be done from the main thread.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
gbinder_eventloop_set(
 | 
			
		||||
    const GBinderEventLoopIntegration* loop);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_EVENTLOOP_H */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -80,25 +80,29 @@ gbinder_servicemanager_new(
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_defaultservicemanager_new(
 | 
			
		||||
    const char* dev);
 | 
			
		||||
    const char* dev)
 | 
			
		||||
    G_DEPRECATED_FOR(gbinder_servicemanager_new);
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_hwservicemanager_new(
 | 
			
		||||
    const char* dev);
 | 
			
		||||
    const char* dev)
 | 
			
		||||
    G_DEPRECATED_FOR(gbinder_servicemanager_new);
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_servicemanager_new_local_object(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    const char* iface,
 | 
			
		||||
    GBinderLocalTransactFunc handler,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
    void* user_data)
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT;
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_servicemanager_new_local_object2(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderLocalTransactFunc handler,
 | 
			
		||||
    void* user_data); /* Since 1.0.29 */
 | 
			
		||||
    void* user_data) /* Since 1.0.29 */
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT;
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_servicemanager_ref(
 | 
			
		||||
@@ -125,7 +129,9 @@ gbinder_servicemanager_list(
 | 
			
		||||
 | 
			
		||||
char**
 | 
			
		||||
gbinder_servicemanager_list_sync(
 | 
			
		||||
    GBinderServiceManager* sm);
 | 
			
		||||
    GBinderServiceManager* sm)
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT
 | 
			
		||||
    G_GNUC_MALLOC;
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_servicemanager_get_service(
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -59,6 +59,7 @@ G_BEGIN_DECLS
 | 
			
		||||
 * 6. Reader parses the data coming with RemoteRequest and RemoteReply
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_bridge GBinderBridge; /* Since 1.1.5 */
 | 
			
		||||
typedef struct gbinder_buffer GBinderBuffer;
 | 
			
		||||
typedef struct gbinder_client GBinderClient;
 | 
			
		||||
typedef struct gbinder_ipc GBinderIpc;
 | 
			
		||||
@@ -76,16 +77,20 @@ typedef struct gbinder_parent GBinderParent;
 | 
			
		||||
 | 
			
		||||
/* Basic HIDL types */
 | 
			
		||||
 | 
			
		||||
#define GBINDER_ALIGNED(x) __attribute__ ((aligned(x)))
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_hidl_vec {
 | 
			
		||||
    union {
 | 
			
		||||
        guint64 value;
 | 
			
		||||
        const void* ptr;
 | 
			
		||||
    } data;
 | 
			
		||||
    guint32 count;
 | 
			
		||||
    guint32 owns_buffer;
 | 
			
		||||
    guint8 owns_buffer;
 | 
			
		||||
    guint8 pad[3];
 | 
			
		||||
} GBinderHidlVec;
 | 
			
		||||
 | 
			
		||||
#define GBINDER_HIDL_VEC_BUFFER_OFFSET (0)
 | 
			
		||||
G_STATIC_ASSERT(sizeof(GBinderHidlVec) == 16);
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_hidl_string {
 | 
			
		||||
    union {
 | 
			
		||||
@@ -93,10 +98,51 @@ typedef struct gbinder_hidl_string {
 | 
			
		||||
        const char* str;
 | 
			
		||||
    } data;
 | 
			
		||||
    guint32 len;
 | 
			
		||||
    guint32 owns_buffer;
 | 
			
		||||
    guint8 owns_buffer;
 | 
			
		||||
    guint8 pad[3];
 | 
			
		||||
} GBinderHidlString;
 | 
			
		||||
 | 
			
		||||
#define GBINDER_HIDL_STRING_BUFFER_OFFSET (0)
 | 
			
		||||
G_STATIC_ASSERT(sizeof(GBinderHidlString) == 16);
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_fds {
 | 
			
		||||
    guint32 version GBINDER_ALIGNED(4);
 | 
			
		||||
    guint32 num_fds GBINDER_ALIGNED(4);
 | 
			
		||||
    guint32 num_ints GBINDER_ALIGNED(4);
 | 
			
		||||
} GBINDER_ALIGNED(4) GBinderFds;  /* Since 1.1.4 */
 | 
			
		||||
 | 
			
		||||
/* Actual fds immediately follow GBinderFds: */
 | 
			
		||||
#define gbinder_fds_get_fd(fds,i) (((const int*)((fds) + 1))[i])
 | 
			
		||||
 | 
			
		||||
#define GBINDER_HIDL_FDS_VERSION (12)
 | 
			
		||||
G_STATIC_ASSERT(sizeof(GBinderFds) == GBINDER_HIDL_FDS_VERSION);
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_hidl_handle {
 | 
			
		||||
    union {
 | 
			
		||||
        guint64 value;
 | 
			
		||||
        const GBinderFds* fds;
 | 
			
		||||
    } data;
 | 
			
		||||
    guint8 owns_handle;
 | 
			
		||||
    guint8 pad[7];
 | 
			
		||||
} GBinderHidlHandle; /* Since 1.1.4 */
 | 
			
		||||
 | 
			
		||||
#define GBINDER_HIDL_HANDLE_VALUE_OFFSET (0)
 | 
			
		||||
G_STATIC_ASSERT(sizeof(GBinderHidlHandle) == 16);
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_hidl_memory {
 | 
			
		||||
    union {
 | 
			
		||||
        guint64 value;
 | 
			
		||||
        const GBinderFds* fds;
 | 
			
		||||
    } data;
 | 
			
		||||
    guint8 owns_buffer;
 | 
			
		||||
    guint8 pad[7];
 | 
			
		||||
    guint64 size;
 | 
			
		||||
    GBinderHidlString name;
 | 
			
		||||
} GBinderHidlMemory; /* Since 1.1.4 */
 | 
			
		||||
 | 
			
		||||
#define GBINDER_HIDL_MEMORY_PTR_OFFSET (0)
 | 
			
		||||
#define GBINDER_HIDL_MEMORY_NAME_OFFSET (24)
 | 
			
		||||
G_STATIC_ASSERT(sizeof(GBinderHidlMemory) == 40);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Each RPC call is identified by the interface name returned
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -121,13 +121,13 @@ gbinder_writer_append_fd(
 | 
			
		||||
 | 
			
		||||
gsize
 | 
			
		||||
gbinder_writer_bytes_written(
 | 
			
		||||
    GBinderWriter* writer); /* since 1.0.21 */
 | 
			
		||||
    GBinderWriter* writer); /* Since 1.0.21 */
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_overwrite_int32(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    gsize offset,
 | 
			
		||||
    gint32 value); /* since 1.0.21 */
 | 
			
		||||
    gint32 value); /* Since 1.0.21 */
 | 
			
		||||
 | 
			
		||||
guint
 | 
			
		||||
gbinder_writer_append_buffer_object_with_parent(
 | 
			
		||||
@@ -147,13 +147,18 @@ gbinder_writer_append_hidl_vec(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const void* base,
 | 
			
		||||
    guint count,
 | 
			
		||||
    guint elemsize); /* since 1.0.8 */
 | 
			
		||||
    guint elemsize); /* Since 1.0.8 */
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_append_hidl_string(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const char* str);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_append_hidl_string_copy(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const char* str); /* Since 1.1.13 */
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_append_hidl_string_vec(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
@@ -174,17 +179,19 @@ void
 | 
			
		||||
gbinder_writer_append_byte_array(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const void* byte_array,
 | 
			
		||||
    gint32 len); /* since 1.0.12 */
 | 
			
		||||
    gint32 len); /* Since 1.0.12 */
 | 
			
		||||
 | 
			
		||||
/* Note: memory allocated by GBinderWriter is owned by GBinderWriter */
 | 
			
		||||
 | 
			
		||||
void*
 | 
			
		||||
gbinder_writer_malloc(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    gsize size); /* since 1.0.19 */
 | 
			
		||||
    gsize size); /* Since 1.0.19 */
 | 
			
		||||
 | 
			
		||||
void*
 | 
			
		||||
gbinder_writer_malloc0(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    gsize size); /* since 1.0.19 */
 | 
			
		||||
    gsize size); /* Since 1.0.19 */
 | 
			
		||||
 | 
			
		||||
#define gbinder_writer_new(writer,type) \
 | 
			
		||||
    ((type*) gbinder_writer_malloc(writer, sizeof(type)))
 | 
			
		||||
@@ -192,17 +199,22 @@ gbinder_writer_malloc0(
 | 
			
		||||
#define gbinder_writer_new0(writer,type) \
 | 
			
		||||
    ((type*) gbinder_writer_malloc0(writer, sizeof(type)))
 | 
			
		||||
 | 
			
		||||
void*
 | 
			
		||||
gbinder_writer_memdup(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const void* buf,
 | 
			
		||||
    gsize size); /* since 1.0.19 */
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_add_cleanup(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    GDestroyNotify destroy,
 | 
			
		||||
    gpointer data); /* since 1.0.19 */
 | 
			
		||||
    gpointer data); /* Since 1.0.19 */
 | 
			
		||||
 | 
			
		||||
void*
 | 
			
		||||
gbinder_writer_memdup(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const void* buf,
 | 
			
		||||
    gsize size); /* Since 1.0.19 */
 | 
			
		||||
 | 
			
		||||
char*
 | 
			
		||||
gbinder_writer_strdup(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const char* str); /* Since 1.1.13 */
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
name=gbinder
 | 
			
		||||
libdir=/usr/lib
 | 
			
		||||
libdir=@libdir@
 | 
			
		||||
includedir=/usr/include
 | 
			
		||||
 | 
			
		||||
Name: libgbinder
 | 
			
		||||
Description: Binder client library
 | 
			
		||||
Version: [version]
 | 
			
		||||
Requires: glib-2.0 libglibutil
 | 
			
		||||
Version: @version@
 | 
			
		||||
Requires.private: glib-2.0 libglibutil
 | 
			
		||||
Libs: -L${libdir} -l${name}
 | 
			
		||||
Cflags: -I${includedir} -I${includedir}/${name}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,20 @@
 | 
			
		||||
Name: libgbinder
 | 
			
		||||
Version: 1.0.30
 | 
			
		||||
 | 
			
		||||
Version: 1.1.13
 | 
			
		||||
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.35
 | 
			
		||||
 | 
			
		||||
%define libglibutil_version 1.0.52
 | 
			
		||||
 | 
			
		||||
BuildRequires: pkgconfig(glib-2.0)
 | 
			
		||||
BuildRequires: pkgconfig(libglibutil) >= 1.0.35
 | 
			
		||||
BuildRequires: pkgconfig(libglibutil) >= %{libglibutil_version}
 | 
			
		||||
BuildRequires: pkgconfig
 | 
			
		||||
BuildRequires: bison
 | 
			
		||||
BuildRequires: flex
 | 
			
		||||
Requires: libglibutil >= %{libglibutil_version}
 | 
			
		||||
Requires(post): /sbin/ldconfig
 | 
			
		||||
Requires(postun): /sbin/ldconfig
 | 
			
		||||
 | 
			
		||||
@@ -18,7 +24,6 @@ C interfaces for Android binder
 | 
			
		||||
%package devel
 | 
			
		||||
Summary: Development library for %{name}
 | 
			
		||||
Requires: %{name} = %{version}
 | 
			
		||||
Requires: pkgconfig
 | 
			
		||||
 | 
			
		||||
%description devel
 | 
			
		||||
This package contains the development library for %{name}.
 | 
			
		||||
@@ -27,11 +32,19 @@ This package contains the development library for %{name}.
 | 
			
		||||
%setup -q
 | 
			
		||||
 | 
			
		||||
%build
 | 
			
		||||
make KEEP_SYMBOLS=1 release pkgconfig
 | 
			
		||||
make %{_smp_mflags} LIBDIR=%{_libdir} KEEP_SYMBOLS=1 release pkgconfig
 | 
			
		||||
make -C test/binder-bridge KEEP_SYMBOLS=1 release
 | 
			
		||||
make -C test/binder-list KEEP_SYMBOLS=1 release
 | 
			
		||||
make -C test/binder-ping KEEP_SYMBOLS=1 release
 | 
			
		||||
make -C test/binder-call KEEP_SYMBOLS=1 release
 | 
			
		||||
 | 
			
		||||
%install
 | 
			
		||||
rm -rf %{buildroot}
 | 
			
		||||
make install-dev DESTDIR=%{buildroot}
 | 
			
		||||
make LIBDIR=%{_libdir} DESTDIR=%{buildroot} install-dev
 | 
			
		||||
make -C test/binder-bridge DESTDIR=%{buildroot} install
 | 
			
		||||
make -C test/binder-list DESTDIR=%{buildroot} install
 | 
			
		||||
make -C test/binder-ping DESTDIR=%{buildroot} install
 | 
			
		||||
make -C test/binder-call DESTDIR=%{buildroot} install
 | 
			
		||||
 | 
			
		||||
%check
 | 
			
		||||
make -C unit test
 | 
			
		||||
@@ -49,3 +62,19 @@ make -C unit test
 | 
			
		||||
%{_libdir}/pkgconfig/*.pc
 | 
			
		||||
%{_libdir}/%{name}.so
 | 
			
		||||
%{_includedir}/gbinder/*.h
 | 
			
		||||
 | 
			
		||||
# Tools
 | 
			
		||||
 | 
			
		||||
%package tools
 | 
			
		||||
Summary: Binder tools
 | 
			
		||||
Requires: %{name} >= %{version}
 | 
			
		||||
 | 
			
		||||
%description tools
 | 
			
		||||
Binder command line utilities
 | 
			
		||||
 | 
			
		||||
%files tools
 | 
			
		||||
%defattr(-,root,root,-)
 | 
			
		||||
%{_bindir}/binder-bridge
 | 
			
		||||
%{_bindir}/binder-list
 | 
			
		||||
%{_bindir}/binder-ping
 | 
			
		||||
%{_bindir}/binder-call
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										272
									
								
								src/gbinder_bridge.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										272
									
								
								src/gbinder_bridge.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,272 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2021 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_local_request.h"
 | 
			
		||||
#include "gbinder_local_reply.h"
 | 
			
		||||
#include "gbinder_proxy_object.h"
 | 
			
		||||
#include "gbinder_remote_request_p.h"
 | 
			
		||||
#include "gbinder_remote_reply.h"
 | 
			
		||||
#include "gbinder_remote_object_p.h"
 | 
			
		||||
#include "gbinder_servicename.h"
 | 
			
		||||
#include "gbinder_servicemanager_p.h"
 | 
			
		||||
#include "gbinder_client_p.h"
 | 
			
		||||
#include "gbinder_bridge.h"
 | 
			
		||||
#include "gbinder_ipc.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_strv.h>
 | 
			
		||||
#include <gutil_macros.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_bridge_interface {
 | 
			
		||||
    GBinderBridge* bridge;
 | 
			
		||||
    char* iface;
 | 
			
		||||
    char* fqname;
 | 
			
		||||
    char* src_name;
 | 
			
		||||
    char* dest_name;
 | 
			
		||||
    gulong dest_watch_id;
 | 
			
		||||
    gulong dest_death_id;
 | 
			
		||||
    GBinderRemoteObject* dest_obj;
 | 
			
		||||
    GBinderServiceName* src_service;
 | 
			
		||||
    GBinderProxyObject* proxy;
 | 
			
		||||
} GBinderBridgeInterface;
 | 
			
		||||
 | 
			
		||||
struct gbinder_bridge {
 | 
			
		||||
    GBinderBridgeInterface** ifaces;
 | 
			
		||||
    GBinderServiceManager* src;
 | 
			
		||||
    GBinderServiceManager* dest;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Implementation
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_bridge_dest_drop_remote_object(
 | 
			
		||||
    GBinderBridgeInterface* bi)
 | 
			
		||||
{
 | 
			
		||||
    if (bi->dest_obj) {
 | 
			
		||||
        GDEBUG("Detached from %s", bi->fqname);
 | 
			
		||||
        gbinder_remote_object_remove_handler(bi->dest_obj, bi->dest_death_id);
 | 
			
		||||
        gbinder_remote_object_unref(bi->dest_obj);
 | 
			
		||||
        bi->dest_death_id = 0;
 | 
			
		||||
        bi->dest_obj = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_bridge_interface_deactivate(
 | 
			
		||||
    GBinderBridgeInterface* bi)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_bridge_dest_drop_remote_object(bi);
 | 
			
		||||
    if (bi->proxy) {
 | 
			
		||||
        gbinder_local_object_drop(GBINDER_LOCAL_OBJECT(bi->proxy));
 | 
			
		||||
        bi->proxy = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    if (bi->src_service) {
 | 
			
		||||
        gbinder_servicename_unref(bi->src_service);
 | 
			
		||||
        bi->src_service = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_bridge_interface_free(
 | 
			
		||||
    GBinderBridgeInterface* bi)
 | 
			
		||||
{
 | 
			
		||||
    GBinderBridge* bridge = bi->bridge;
 | 
			
		||||
 | 
			
		||||
    gbinder_bridge_interface_deactivate(bi);
 | 
			
		||||
    gbinder_servicemanager_remove_handler(bridge->dest, bi->dest_watch_id);
 | 
			
		||||
    g_free(bi->iface);
 | 
			
		||||
    g_free(bi->fqname);
 | 
			
		||||
    g_free(bi->src_name);
 | 
			
		||||
    g_free(bi->dest_name);
 | 
			
		||||
    gutil_slice_free(bi);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_bridge_dest_death_proc(
 | 
			
		||||
    GBinderRemoteObject* obj,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderBridgeInterface* bi = user_data;
 | 
			
		||||
 | 
			
		||||
    GDEBUG("%s has died", bi->fqname);
 | 
			
		||||
    gbinder_bridge_interface_deactivate(bi);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_bridge_interface_activate(
 | 
			
		||||
    GBinderBridgeInterface* bi)
 | 
			
		||||
{
 | 
			
		||||
    GBinderBridge* bridge = bi->bridge;
 | 
			
		||||
    GBinderServiceManager* src = bridge->src;
 | 
			
		||||
    GBinderServiceManager* dest = bridge->dest;
 | 
			
		||||
 | 
			
		||||
    if (bi->dest_obj && bi->dest_obj->dead) {
 | 
			
		||||
        gbinder_bridge_dest_drop_remote_object(bi);
 | 
			
		||||
    }
 | 
			
		||||
    if (!bi->dest_obj) {
 | 
			
		||||
        bi->dest_obj = gbinder_servicemanager_get_service_sync(dest,
 | 
			
		||||
            bi->fqname, NULL);
 | 
			
		||||
        if (bi->dest_obj) {
 | 
			
		||||
            GDEBUG("Attached to %s", bi->fqname);
 | 
			
		||||
            gbinder_remote_object_ref(bi->dest_obj);
 | 
			
		||||
            bi->dest_death_id = gbinder_remote_object_add_death_handler
 | 
			
		||||
                (bi->dest_obj, gbinder_bridge_dest_death_proc, bi);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (bi->dest_obj && !bi->proxy) {
 | 
			
		||||
        bi->proxy = gbinder_proxy_object_new(gbinder_servicemanager_ipc(src),
 | 
			
		||||
            bi->dest_obj);
 | 
			
		||||
    }
 | 
			
		||||
    if (bi->proxy && !bi->src_service) {
 | 
			
		||||
        bi->src_service = gbinder_servicename_new(src,
 | 
			
		||||
            GBINDER_LOCAL_OBJECT(bi->proxy), bi->src_name);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_bridge_dest_registration_proc(
 | 
			
		||||
    GBinderServiceManager* sm,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderBridgeInterface* bi = user_data;
 | 
			
		||||
 | 
			
		||||
    if (!g_strcmp0(name, bi->fqname)) {
 | 
			
		||||
        GDEBUG("%s has been registered", bi->fqname);
 | 
			
		||||
        gbinder_bridge_interface_activate(bi);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderBridgeInterface*
 | 
			
		||||
gbinder_bridge_interface_new(
 | 
			
		||||
    GBinderBridge* self,
 | 
			
		||||
    const char* src_name,
 | 
			
		||||
    const char* dest_name,
 | 
			
		||||
    const char* iface)
 | 
			
		||||
{
 | 
			
		||||
    GBinderBridgeInterface* bi = g_slice_new0(GBinderBridgeInterface);
 | 
			
		||||
 | 
			
		||||
    bi->bridge = self;
 | 
			
		||||
    bi->iface = g_strdup(iface);
 | 
			
		||||
    bi->fqname = g_strconcat(iface, "/", dest_name, NULL);
 | 
			
		||||
    bi->src_name = g_strdup(src_name);
 | 
			
		||||
    bi->dest_name = g_strdup(dest_name);
 | 
			
		||||
    bi->dest_watch_id = gbinder_servicemanager_add_registration_handler
 | 
			
		||||
        (self->dest, bi->fqname, gbinder_bridge_dest_registration_proc, bi);
 | 
			
		||||
 | 
			
		||||
    /* Try to activate at startup */
 | 
			
		||||
    gbinder_bridge_interface_activate(bi);
 | 
			
		||||
    return bi;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
GBinderBridge*
 | 
			
		||||
gbinder_bridge_new(
 | 
			
		||||
    const char* name,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderServiceManager* src,
 | 
			
		||||
    GBinderServiceManager* dest) /* Since 1.1.5 */
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_bridge_new2(name, NULL, ifaces, src, dest);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderBridge*
 | 
			
		||||
gbinder_bridge_new2(
 | 
			
		||||
    const char* src_name,
 | 
			
		||||
    const char* dest_name,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderServiceManager* src,
 | 
			
		||||
    GBinderServiceManager* dest) /* Since 1.1.6 */
 | 
			
		||||
{
 | 
			
		||||
    const guint n = gutil_strv_length((const GStrV*)ifaces);
 | 
			
		||||
 | 
			
		||||
    if (!src_name) {
 | 
			
		||||
        src_name = dest_name;
 | 
			
		||||
    } else if (!dest_name) {
 | 
			
		||||
        dest_name = src_name;
 | 
			
		||||
    }
 | 
			
		||||
    if (G_LIKELY(src_name) && G_LIKELY(n) && G_LIKELY(src) && G_LIKELY(dest)) {
 | 
			
		||||
        GBinderBridge* self = g_slice_new0(GBinderBridge);
 | 
			
		||||
        guint i;
 | 
			
		||||
 | 
			
		||||
        self->src = gbinder_servicemanager_ref(src);
 | 
			
		||||
        self->dest = gbinder_servicemanager_ref(dest);
 | 
			
		||||
        self->ifaces = g_new(GBinderBridgeInterface*, n + 1);
 | 
			
		||||
        for (i = 0; i < n; i++) {
 | 
			
		||||
            self->ifaces[i] = gbinder_bridge_interface_new(self,
 | 
			
		||||
                src_name, dest_name, ifaces[i]);
 | 
			
		||||
        }
 | 
			
		||||
        self->ifaces[i] = NULL;
 | 
			
		||||
        return self;
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_bridge_free(
 | 
			
		||||
    GBinderBridge* self)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderBridgeInterface** bi = self->ifaces;
 | 
			
		||||
 | 
			
		||||
        while (*bi) {
 | 
			
		||||
            gbinder_bridge_interface_free(*bi);
 | 
			
		||||
            bi++;
 | 
			
		||||
        }
 | 
			
		||||
        gbinder_servicemanager_unref(self->src);
 | 
			
		||||
        gbinder_servicemanager_unref(self->dest);
 | 
			
		||||
        g_free(self->ifaces);
 | 
			
		||||
        gutil_slice_free(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-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -112,6 +112,47 @@ gbinder_buffer_contents_unref(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * GBinderBufferContentsList
 | 
			
		||||
 * It's actually a GSList containing GBinderBufferContents refs.
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
GBinderBufferContentsList*
 | 
			
		||||
gbinder_buffer_contents_list_add(
 | 
			
		||||
    GBinderBufferContentsList* list,
 | 
			
		||||
    GBinderBufferContents* contents)
 | 
			
		||||
{
 | 
			
		||||
    /* Prepend rather than append for better efficiency */
 | 
			
		||||
    return contents ? (GBinderBufferContentsList*) g_slist_prepend((GSList*)
 | 
			
		||||
            list, gbinder_buffer_contents_ref(contents)) : list;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderBufferContentsList*
 | 
			
		||||
gbinder_buffer_contents_list_dup(
 | 
			
		||||
    GBinderBufferContentsList* list)
 | 
			
		||||
{
 | 
			
		||||
    GSList* out = NULL;
 | 
			
		||||
 | 
			
		||||
    if (list) {
 | 
			
		||||
        GSList* l = (GSList*) list;
 | 
			
		||||
 | 
			
		||||
        /* The order gets reversed but it doesn't matter */
 | 
			
		||||
        while (l) {
 | 
			
		||||
            out = g_slist_prepend(out, gbinder_buffer_contents_ref(l->data));
 | 
			
		||||
            l = l->next;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return (GBinderBufferContentsList*) out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_buffer_contents_list_free(
 | 
			
		||||
    GBinderBufferContentsList* list)
 | 
			
		||||
{
 | 
			
		||||
    g_slist_free_full((GSList*) list, (GDestroyNotify)
 | 
			
		||||
        gbinder_buffer_contents_unref);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * GBinderBuffer
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -42,42 +42,67 @@ gbinder_buffer_new(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    void* data,
 | 
			
		||||
    gsize size,
 | 
			
		||||
    void** objects);
 | 
			
		||||
    void** objects)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderBuffer*
 | 
			
		||||
gbinder_buffer_new_with_parent(
 | 
			
		||||
    GBinderBuffer* parent,
 | 
			
		||||
    void* data,
 | 
			
		||||
    gsize size);
 | 
			
		||||
    gsize size)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderDriver*
 | 
			
		||||
gbinder_buffer_driver(
 | 
			
		||||
    GBinderBuffer* buf);
 | 
			
		||||
    GBinderBuffer* buf)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderBufferContents*
 | 
			
		||||
gbinder_buffer_contents(
 | 
			
		||||
    GBinderBuffer* buf);
 | 
			
		||||
    GBinderBuffer* buf)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gconstpointer
 | 
			
		||||
gbinder_buffer_data(
 | 
			
		||||
    GBinderBuffer* buf,
 | 
			
		||||
    gsize* size);
 | 
			
		||||
    gsize* size)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
const GBinderIo*
 | 
			
		||||
gbinder_buffer_io(
 | 
			
		||||
    GBinderBuffer* buf);
 | 
			
		||||
    GBinderBuffer* buf)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void**
 | 
			
		||||
gbinder_buffer_objects(
 | 
			
		||||
    GBinderBuffer* buffer);
 | 
			
		||||
    GBinderBuffer* buffer)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderBufferContents*
 | 
			
		||||
gbinder_buffer_contents_ref(
 | 
			
		||||
    GBinderBufferContents* contents);
 | 
			
		||||
    GBinderBufferContents* contents)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_buffer_contents_unref(
 | 
			
		||||
    GBinderBufferContents* contents);
 | 
			
		||||
    GBinderBufferContents* contents)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderBufferContentsList*
 | 
			
		||||
gbinder_buffer_contents_list_add(
 | 
			
		||||
    GBinderBufferContentsList* list,
 | 
			
		||||
    GBinderBufferContents* contents)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderBufferContentsList*
 | 
			
		||||
gbinder_buffer_contents_list_dup(
 | 
			
		||||
    GBinderBufferContentsList* list)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_buffer_contents_list_free(
 | 
			
		||||
    GBinderBufferContentsList* list)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_BUFFER_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -37,17 +37,20 @@
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_cleanup_free(
 | 
			
		||||
    GBinderCleanup* cleanup);
 | 
			
		||||
    GBinderCleanup* cleanup)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_cleanup_reset(
 | 
			
		||||
    GBinderCleanup* cleanup);
 | 
			
		||||
    GBinderCleanup* cleanup)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderCleanup*
 | 
			
		||||
gbinder_cleanup_add(
 | 
			
		||||
    GBinderCleanup* cleanup,
 | 
			
		||||
    GDestroyNotify destroy,
 | 
			
		||||
    gpointer pointer);
 | 
			
		||||
    gpointer pointer)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_CLEANUP_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -41,14 +41,22 @@
 | 
			
		||||
 | 
			
		||||
#include <gutil_macros.h>
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <limits.h>
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_client_iface_range {
 | 
			
		||||
    char* iface;
 | 
			
		||||
    GBytes* rpc_header;
 | 
			
		||||
    GBinderLocalRequest* basic_req;
 | 
			
		||||
    guint32 last_code;
 | 
			
		||||
} GBinderClientIfaceRange;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_client_priv {
 | 
			
		||||
    GBinderClient pub;
 | 
			
		||||
    guint32 refcount;
 | 
			
		||||
    char* iface;
 | 
			
		||||
    GBytes* rpc_header;
 | 
			
		||||
    GBinderLocalRequest* basic_req;
 | 
			
		||||
    GBinderClientIfaceRange* ranges;
 | 
			
		||||
    guint nr;
 | 
			
		||||
} GBinderClientPriv;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_client_tx {
 | 
			
		||||
@@ -65,19 +73,79 @@ static inline GBinderClientPriv* gbinder_client_cast(GBinderClient* client)
 | 
			
		||||
 * Implementation
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
const GBinderClientIfaceRange*
 | 
			
		||||
gbinder_client_find_range(
 | 
			
		||||
    GBinderClientPriv* priv,
 | 
			
		||||
    guint32 code)
 | 
			
		||||
{
 | 
			
		||||
    guint i;
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < priv->nr; i++) {
 | 
			
		||||
        const GBinderClientIfaceRange* r = priv->ranges + i;
 | 
			
		||||
 | 
			
		||||
        if (r->last_code >= code) {
 | 
			
		||||
            return r;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Generates basic request (without additional parameters) for the
 | 
			
		||||
 * specified interface and pulls header data out of it. The basic
 | 
			
		||||
 * request can be reused for those transactions which have no
 | 
			
		||||
 * additional parameters. The header data are needed for building
 | 
			
		||||
 * non-trivial requests.
 | 
			
		||||
 */
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_client_init_range(
 | 
			
		||||
    GBinderClientIfaceRange* r,
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    const GBinderClientIfaceInfo* info)
 | 
			
		||||
{
 | 
			
		||||
    GBinderOutputData* hdr;
 | 
			
		||||
 | 
			
		||||
    r->basic_req = gbinder_driver_local_request_new(driver, info->iface);
 | 
			
		||||
    hdr = gbinder_local_request_data(r->basic_req);
 | 
			
		||||
    r->rpc_header = g_bytes_new(hdr->bytes->data, hdr->bytes->len);
 | 
			
		||||
    r->iface = g_strdup(info->iface);
 | 
			
		||||
    r->last_code = info->last_code;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
gbinder_client_sort_ranges(
 | 
			
		||||
    const void* p1,
 | 
			
		||||
    const void* p2)
 | 
			
		||||
{
 | 
			
		||||
    const GBinderClientIfaceRange* r1 = p1;
 | 
			
		||||
    const GBinderClientIfaceRange* r2 = p2;
 | 
			
		||||
 | 
			
		||||
    return (r1->last_code < r2->last_code) ? (-1) :
 | 
			
		||||
        (r1->last_code > r2->last_code) ? 1 : 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_client_free(
 | 
			
		||||
    GBinderClientPriv* priv)
 | 
			
		||||
{
 | 
			
		||||
    GBinderClient* self = &priv->pub;
 | 
			
		||||
    guint i;
 | 
			
		||||
 | 
			
		||||
    gbinder_remote_object_unref(self->remote);
 | 
			
		||||
    gbinder_local_request_unref(priv->basic_req);
 | 
			
		||||
    g_free(priv->iface);
 | 
			
		||||
    if (priv->rpc_header) {
 | 
			
		||||
        g_bytes_unref(priv->rpc_header);
 | 
			
		||||
    for (i = 0; i < priv->nr; i++) {
 | 
			
		||||
        GBinderClientIfaceRange* r = priv->ranges + i;
 | 
			
		||||
 | 
			
		||||
        gbinder_local_request_unref(r->basic_req);
 | 
			
		||||
        g_free(r->iface);
 | 
			
		||||
        if (r->rpc_header) {
 | 
			
		||||
            g_bytes_unref(r->rpc_header);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    g_free(priv->ranges);
 | 
			
		||||
    gbinder_remote_object_unref(self->remote);
 | 
			
		||||
    g_slice_free(GBinderClientPriv, priv);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -110,14 +178,86 @@ gbinder_client_transact_destroy(
 | 
			
		||||
    g_slice_free(GBinderClientTx, tx);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Internal interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
GBinderRemoteReply*
 | 
			
		||||
gbinder_client_transact_sync_reply2(
 | 
			
		||||
    GBinderClient* self,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    GBinderLocalRequest* req,
 | 
			
		||||
    int* status,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderRemoteObject* obj = self->remote;
 | 
			
		||||
 | 
			
		||||
        if (G_LIKELY(!obj->dead)) {
 | 
			
		||||
            if (!req) {
 | 
			
		||||
                const GBinderClientIfaceRange* r = gbinder_client_find_range
 | 
			
		||||
                    (gbinder_client_cast(self), code);
 | 
			
		||||
 | 
			
		||||
                /* Default empty request (just the header, no parameters) */
 | 
			
		||||
                if (r) {
 | 
			
		||||
                    req = r->basic_req;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (req) {
 | 
			
		||||
                return api->sync_reply(obj->ipc, obj->handle, code, req,
 | 
			
		||||
                    status);
 | 
			
		||||
            } else {
 | 
			
		||||
                GWARN("Unable to build empty request for tx code %u", code);
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            GDEBUG("Refusing to perform transaction with a dead object");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_client_transact_sync_oneway2(
 | 
			
		||||
    GBinderClient* self,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    GBinderLocalRequest* req,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderRemoteObject* obj = self->remote;
 | 
			
		||||
 | 
			
		||||
        if (G_LIKELY(!obj->dead)) {
 | 
			
		||||
            if (!req) {
 | 
			
		||||
                const GBinderClientIfaceRange* r = gbinder_client_find_range
 | 
			
		||||
                    (gbinder_client_cast(self), code);
 | 
			
		||||
 | 
			
		||||
                /* Default empty request (just the header, no parameters) */
 | 
			
		||||
                if (r) {
 | 
			
		||||
                    req = r->basic_req;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (req) {
 | 
			
		||||
                return api->sync_oneway(obj->ipc, obj->handle, code, req);
 | 
			
		||||
            } else {
 | 
			
		||||
                GWARN("Unable to build empty request for tx code %u", code);
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            GDEBUG("Refusing to perform transaction with a dead object");
 | 
			
		||||
            return (-ESTALE);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return (-EINVAL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
GBinderClient*
 | 
			
		||||
gbinder_client_new(
 | 
			
		||||
gbinder_client_new2(
 | 
			
		||||
    GBinderRemoteObject* remote,
 | 
			
		||||
    const char* iface)
 | 
			
		||||
    const GBinderClientIfaceInfo* ifaces,
 | 
			
		||||
    gsize count)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(remote)) {
 | 
			
		||||
        GBinderClientPriv* priv = g_slice_new0(GBinderClientPriv);
 | 
			
		||||
@@ -126,22 +266,22 @@ gbinder_client_new(
 | 
			
		||||
 | 
			
		||||
        g_atomic_int_set(&priv->refcount, 1);
 | 
			
		||||
        self->remote = gbinder_remote_object_ref(remote);
 | 
			
		||||
        if (count > 0) {
 | 
			
		||||
            gsize i;
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * Generate basic request (without additional parameters) and pull
 | 
			
		||||
         * header data out of it. The basic request can be reused for those
 | 
			
		||||
         * transactions which has no additional parameters. The header data
 | 
			
		||||
         * are needed for building non-trivial requests.
 | 
			
		||||
         */
 | 
			
		||||
        if (iface) {
 | 
			
		||||
            GBinderOutputData* hdr;
 | 
			
		||||
 | 
			
		||||
            priv->basic_req = gbinder_driver_local_request_new(driver, iface);
 | 
			
		||||
            hdr = gbinder_local_request_data(priv->basic_req);
 | 
			
		||||
            priv->rpc_header = g_bytes_new(hdr->bytes->data, hdr->bytes->len);
 | 
			
		||||
            self->iface = priv->iface = g_strdup(iface);
 | 
			
		||||
            priv->nr = count;
 | 
			
		||||
            priv->ranges = g_new(GBinderClientIfaceRange, priv->nr);
 | 
			
		||||
            for (i = 0; i < count; i++) {
 | 
			
		||||
                gbinder_client_init_range(priv->ranges + i, driver, ifaces + i);
 | 
			
		||||
            }
 | 
			
		||||
            qsort(priv->ranges, count, sizeof(GBinderClientIfaceRange),
 | 
			
		||||
                gbinder_client_sort_ranges);
 | 
			
		||||
        } else {
 | 
			
		||||
            priv->basic_req = gbinder_local_request_new
 | 
			
		||||
            /* No interface info */
 | 
			
		||||
            priv->nr = 1;
 | 
			
		||||
            priv->ranges = g_new0(GBinderClientIfaceRange, 1);
 | 
			
		||||
            priv->ranges[0].last_code = UINT_MAX;
 | 
			
		||||
            priv->ranges[0].basic_req = gbinder_local_request_new
 | 
			
		||||
                (gbinder_driver_io(driver), NULL);
 | 
			
		||||
        }
 | 
			
		||||
        return self;
 | 
			
		||||
@@ -149,6 +289,18 @@ gbinder_client_new(
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderClient*
 | 
			
		||||
gbinder_client_new(
 | 
			
		||||
    GBinderRemoteObject* remote,
 | 
			
		||||
    const char* iface)
 | 
			
		||||
{
 | 
			
		||||
    GBinderClientIfaceInfo info;
 | 
			
		||||
 | 
			
		||||
    info.iface = iface;
 | 
			
		||||
    info.last_code = UINT_MAX;
 | 
			
		||||
    return gbinder_client_new2(remote, &info, 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderClient*
 | 
			
		||||
gbinder_client_ref(
 | 
			
		||||
    GBinderClient* self)
 | 
			
		||||
@@ -180,7 +332,23 @@ const char*
 | 
			
		||||
gbinder_client_interface(
 | 
			
		||||
    GBinderClient* self) /* since 1.0.22 */
 | 
			
		||||
{
 | 
			
		||||
    return G_LIKELY(self) ? gbinder_client_cast(self)->iface : NULL;
 | 
			
		||||
    return G_LIKELY(self) ? gbinder_client_cast(self)->ranges->iface : NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_client_interface2(
 | 
			
		||||
    GBinderClient* self,
 | 
			
		||||
    guint32 code) /* since 1.0.42 */
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        const GBinderClientIfaceRange* r =
 | 
			
		||||
            gbinder_client_find_range(gbinder_client_cast(self), code);
 | 
			
		||||
 | 
			
		||||
        if (r) {
 | 
			
		||||
            return r->iface;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
@@ -190,7 +358,27 @@ gbinder_client_new_request(
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderClientPriv* priv = gbinder_client_cast(self);
 | 
			
		||||
        const GBinderIo* io = gbinder_driver_io(self->remote->ipc->driver);
 | 
			
		||||
        return gbinder_local_request_new(io, priv->rpc_header);
 | 
			
		||||
 | 
			
		||||
        return gbinder_local_request_new(io, priv->ranges->rpc_header);
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_client_new_request2(
 | 
			
		||||
    GBinderClient* self,
 | 
			
		||||
    guint32 code) /* since 1.0.42 */
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderClientPriv* priv = gbinder_client_cast(self);
 | 
			
		||||
        const GBinderClientIfaceRange* r = gbinder_client_find_range
 | 
			
		||||
            (priv, code);
 | 
			
		||||
 | 
			
		||||
        if (r) {
 | 
			
		||||
            const GBinderIo* io = gbinder_driver_io(self->remote->ipc->driver);
 | 
			
		||||
 | 
			
		||||
            return gbinder_local_request_new(io, r->rpc_header);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
@@ -202,17 +390,8 @@ gbinder_client_transact_sync_reply(
 | 
			
		||||
    GBinderLocalRequest* req,
 | 
			
		||||
    int* status)
 | 
			
		||||
{
 | 
			
		||||
    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;
 | 
			
		||||
        }
 | 
			
		||||
        return gbinder_ipc_transact_sync_reply(obj->ipc, obj->handle,
 | 
			
		||||
            code, req, status);
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
    return gbinder_client_transact_sync_reply2(self, code, req, status,
 | 
			
		||||
        &gbinder_ipc_sync_main);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
@@ -221,18 +400,8 @@ gbinder_client_transact_sync_oneway(
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    GBinderLocalRequest* req)
 | 
			
		||||
{
 | 
			
		||||
    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;
 | 
			
		||||
        }
 | 
			
		||||
        return gbinder_ipc_transact_sync_oneway(obj->ipc, obj->handle,
 | 
			
		||||
            code, req);
 | 
			
		||||
    } else {
 | 
			
		||||
        return (-EINVAL);
 | 
			
		||||
    }
 | 
			
		||||
    return gbinder_client_transact_sync_oneway2(self, code, req,
 | 
			
		||||
        &gbinder_ipc_sync_main);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
@@ -247,23 +416,35 @@ 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)) {
 | 
			
		||||
            if (!req) {
 | 
			
		||||
                const GBinderClientIfaceRange* r = gbinder_client_find_range
 | 
			
		||||
                    (gbinder_client_cast(self), code);
 | 
			
		||||
 | 
			
		||||
        if (!req) {
 | 
			
		||||
            /* Default empty request (just the header, no parameters) */
 | 
			
		||||
            req = gbinder_client_cast(self)->basic_req;
 | 
			
		||||
                /* Default empty request (just the header, no parameters) */
 | 
			
		||||
                if (r) {
 | 
			
		||||
                    req = r->basic_req;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (req) {
 | 
			
		||||
                GBinderClientTx* tx = g_slice_new0(GBinderClientTx);
 | 
			
		||||
 | 
			
		||||
                tx->client = gbinder_client_ref(self);
 | 
			
		||||
                tx->reply = reply;
 | 
			
		||||
                tx->destroy = destroy;
 | 
			
		||||
                tx->user_data = user_data;
 | 
			
		||||
                return gbinder_ipc_transact(obj->ipc, obj->handle, code,
 | 
			
		||||
                    flags, req, gbinder_client_transact_reply,
 | 
			
		||||
                    gbinder_client_transact_destroy, tx);
 | 
			
		||||
            } else {
 | 
			
		||||
                GWARN("Unable to build empty request for tx code %u", code);
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            GDEBUG("Refusing to perform transaction with a dead object");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return gbinder_ipc_transact(obj->ipc, obj->handle, code, flags, req,
 | 
			
		||||
            gbinder_client_transact_reply, gbinder_client_transact_destroy, tx);
 | 
			
		||||
    } else {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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,10 +38,27 @@
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
 | 
			
		||||
struct gbinder_client {
 | 
			
		||||
    const char* iface;
 | 
			
		||||
    GBinderRemoteObject* remote;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
GBinderRemoteReply*
 | 
			
		||||
gbinder_client_transact_sync_reply2(
 | 
			
		||||
    GBinderClient* self,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    GBinderLocalRequest* req,
 | 
			
		||||
    int* status,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_client_transact_sync_oneway2(
 | 
			
		||||
    GBinderClient* self,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    GBinderLocalRequest* req,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#define gbinder_client_ipc(client) ((client)->remote->ipc)
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_CLIENT_PRIVATE_H */
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										384
									
								
								src/gbinder_config.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										384
									
								
								src/gbinder_config.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,384 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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_config.h"
 | 
			
		||||
#include "gbinder_eventloop_p.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_strv.h>
 | 
			
		||||
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * The contents of the config file is queried from (at least) two places,
 | 
			
		||||
 * and pretty much always this happens the same stack. Which means that
 | 
			
		||||
 * we can avoid reading the same file twice if we delay dereferencing of
 | 
			
		||||
 * GKeyFile until the next idle loop.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
static GKeyFile* gbinder_config_keyfile = NULL;
 | 
			
		||||
static GBinderEventLoopCallback* gbinder_config_autorelease = NULL;
 | 
			
		||||
 | 
			
		||||
static const char gbinder_config_suffix[] = ".conf";
 | 
			
		||||
static const char gbinder_config_default_file[] = "/etc/gbinder.conf";
 | 
			
		||||
static const char gbinder_config_default_dir[] = "/etc/gbinder.d";
 | 
			
		||||
 | 
			
		||||
const char* gbinder_config_file = gbinder_config_default_file;
 | 
			
		||||
const char* gbinder_config_dir = gbinder_config_default_dir;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Presets for particular API level can be chosen with ApiLevel
 | 
			
		||||
 * setting, e.g.
 | 
			
		||||
 *
 | 
			
		||||
 * [General]
 | 
			
		||||
 * ApiLevel=29
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
static const char CONF_GENERAL[] = "General";
 | 
			
		||||
static const char CONG_API_LEVEL[] = "ApiLevel";
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_config_preset_entry {
 | 
			
		||||
    const char* key;
 | 
			
		||||
    const char* value;
 | 
			
		||||
} GBinderConfigPresetEntry;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_config_preset_group {
 | 
			
		||||
    const char* name;
 | 
			
		||||
    const GBinderConfigPresetEntry* entries;
 | 
			
		||||
} GBinderConfigPresetGroup;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_config_preset {
 | 
			
		||||
    guint api_level;
 | 
			
		||||
    const GBinderConfigPresetGroup* groups;
 | 
			
		||||
} GBinderConfigPreset;
 | 
			
		||||
 | 
			
		||||
/* API level 28 */
 | 
			
		||||
 | 
			
		||||
static const GBinderConfigPresetEntry gbinder_config_28_servicemanager[] = {
 | 
			
		||||
    { "/dev/binder", "aidl2" },
 | 
			
		||||
    { "/dev/vndbinder", "aidl2" },
 | 
			
		||||
    { NULL, NULL }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static const GBinderConfigPresetGroup gbinder_config_28[] = {
 | 
			
		||||
    { GBINDER_CONFIG_GROUP_SERVICEMANAGER, gbinder_config_28_servicemanager },
 | 
			
		||||
    { NULL, NULL }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* API level 29 */
 | 
			
		||||
 | 
			
		||||
static const GBinderConfigPresetEntry gbinder_config_29_protocol[] = {
 | 
			
		||||
    { "/dev/binder", "aidl2" },
 | 
			
		||||
    { "/dev/vndbinder", "aidl2" },
 | 
			
		||||
    { NULL, NULL }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define gbinder_config_29_servicemanager gbinder_config_28_servicemanager
 | 
			
		||||
 | 
			
		||||
static const GBinderConfigPresetGroup gbinder_config_29[] = {
 | 
			
		||||
    { GBINDER_CONFIG_GROUP_PROTOCOL, gbinder_config_29_protocol },
 | 
			
		||||
    { GBINDER_CONFIG_GROUP_SERVICEMANAGER, gbinder_config_29_servicemanager },
 | 
			
		||||
    { NULL, NULL }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Presets sorted by API level in descending order */
 | 
			
		||||
 | 
			
		||||
static const GBinderConfigPreset gbinder_config_presets[] = {
 | 
			
		||||
    { 29, gbinder_config_29 },
 | 
			
		||||
    { 28, gbinder_config_28 }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
char**
 | 
			
		||||
gbinder_config_collect_files(
 | 
			
		||||
    const char* path,
 | 
			
		||||
    const char* suffix)
 | 
			
		||||
{
 | 
			
		||||
    /*
 | 
			
		||||
     * Returns sorted list of regular files in the directory,
 | 
			
		||||
     * optionally having the specified suffix (e.g. ".conf").
 | 
			
		||||
     * Returns NULL if nothing appropriate has been found.
 | 
			
		||||
     */
 | 
			
		||||
    char** files = NULL;
 | 
			
		||||
 | 
			
		||||
    if (path) {
 | 
			
		||||
        GDir* dir = g_dir_open(path, 0, NULL);
 | 
			
		||||
 | 
			
		||||
        if (dir) {
 | 
			
		||||
            GPtrArray* list = g_ptr_array_new();
 | 
			
		||||
            const gchar* name;
 | 
			
		||||
 | 
			
		||||
            while ((name = g_dir_read_name(dir)) != NULL) {
 | 
			
		||||
                if (g_str_has_suffix(name, suffix)) {
 | 
			
		||||
                    char* fullname = g_build_filename(path, name, NULL);
 | 
			
		||||
                    struct stat st;
 | 
			
		||||
 | 
			
		||||
                    if (!stat(fullname, &st) && S_ISREG(st.st_mode)) {
 | 
			
		||||
                        g_ptr_array_add(list, fullname);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        g_free(fullname);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (list->len > 0) {
 | 
			
		||||
                g_ptr_array_add(list, NULL);
 | 
			
		||||
                files = (char**) g_ptr_array_free(list, FALSE);
 | 
			
		||||
                gutil_strv_sort(files, TRUE);
 | 
			
		||||
            } else {
 | 
			
		||||
                g_ptr_array_free(list, TRUE);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            g_dir_close(dir);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return files;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GKeyFile*
 | 
			
		||||
gbinder_config_merge_keyfiles(
 | 
			
		||||
    GKeyFile* dest,
 | 
			
		||||
    GKeyFile* src)
 | 
			
		||||
{
 | 
			
		||||
    gsize i, ngroups;
 | 
			
		||||
    gchar** groups = g_key_file_get_groups(src, &ngroups);
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < ngroups; i++) {
 | 
			
		||||
        gsize k, nkeys;
 | 
			
		||||
        const char* group = groups[i];
 | 
			
		||||
        char** keys = g_key_file_get_keys(src, group, &nkeys, NULL);
 | 
			
		||||
 | 
			
		||||
        for (k = 0; k < nkeys; k++) {
 | 
			
		||||
            const char* key = keys[k];
 | 
			
		||||
            char* value = g_key_file_get_value(src, group, key, NULL);
 | 
			
		||||
 | 
			
		||||
            g_key_file_set_value(dest, group, key, value);
 | 
			
		||||
            g_free(value);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        g_strfreev(keys);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    g_strfreev(groups);
 | 
			
		||||
    return dest;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_config_apply_presets(
 | 
			
		||||
    GKeyFile* config,
 | 
			
		||||
    const GBinderConfigPreset* preset)
 | 
			
		||||
{
 | 
			
		||||
    const GBinderConfigPresetGroup* g;
 | 
			
		||||
 | 
			
		||||
    GDEBUG("Applying presets for API level %d", preset->api_level);
 | 
			
		||||
    for (g = preset->groups; g->name; g++) {
 | 
			
		||||
        const GBinderConfigPresetEntry* e;
 | 
			
		||||
 | 
			
		||||
        for (e = g->entries; e->key; e++) {
 | 
			
		||||
            if (!g_key_file_has_key(config, g->name, e->key, NULL)) {
 | 
			
		||||
                g_key_file_set_value(config, g->name, e->key, e->value);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GKeyFile*
 | 
			
		||||
gbinder_config_load_files()
 | 
			
		||||
{
 | 
			
		||||
    GError* error = NULL;
 | 
			
		||||
    GKeyFile* out = NULL;
 | 
			
		||||
    char** files = gbinder_config_collect_files(gbinder_config_dir,
 | 
			
		||||
        gbinder_config_suffix);
 | 
			
		||||
 | 
			
		||||
    if (gbinder_config_file &&
 | 
			
		||||
        g_file_test(gbinder_config_file, G_FILE_TEST_EXISTS)) {
 | 
			
		||||
        out = g_key_file_new();
 | 
			
		||||
        if (g_key_file_load_from_file(out, gbinder_config_file,
 | 
			
		||||
            G_KEY_FILE_NONE, &error)) {
 | 
			
		||||
            GDEBUG("Loaded %s", gbinder_config_file);
 | 
			
		||||
        } else {
 | 
			
		||||
            GERR("Error loading %s: %s", gbinder_config_file, error->message);
 | 
			
		||||
            g_error_free(error);
 | 
			
		||||
            error = NULL;
 | 
			
		||||
            gbinder_config_file = NULL; /* Don't retry */
 | 
			
		||||
            g_key_file_unref(out);
 | 
			
		||||
            out = NULL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Files in the config directory overwrite /etc/gbinder.conf */
 | 
			
		||||
    if (files) {
 | 
			
		||||
        char** ptr;
 | 
			
		||||
        GKeyFile* override = NULL;
 | 
			
		||||
 | 
			
		||||
        for (ptr = files; *ptr; ptr++) {
 | 
			
		||||
            const char* file = *ptr;
 | 
			
		||||
 | 
			
		||||
            if (!override) {
 | 
			
		||||
                override = g_key_file_new();
 | 
			
		||||
            }
 | 
			
		||||
            if (g_key_file_load_from_file(override, file,
 | 
			
		||||
                G_KEY_FILE_NONE, &error)) {
 | 
			
		||||
                GDEBUG("Loaded %s", file);
 | 
			
		||||
                if (!out) {
 | 
			
		||||
                    out = override;
 | 
			
		||||
                    override = NULL;
 | 
			
		||||
                } else {
 | 
			
		||||
                    out = gbinder_config_merge_keyfiles(out, override);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                GERR("Error loading %s: %s", file, error->message);
 | 
			
		||||
                g_error_free(error);
 | 
			
		||||
                error = NULL;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        g_strfreev(files);
 | 
			
		||||
        if (override) {
 | 
			
		||||
            g_key_file_unref(override);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (out) {
 | 
			
		||||
        /* Apply presets */
 | 
			
		||||
        const int api_level = g_key_file_get_integer(out,
 | 
			
		||||
            CONF_GENERAL, CONG_API_LEVEL, NULL);
 | 
			
		||||
 | 
			
		||||
        if (api_level > 0) {
 | 
			
		||||
            int i;
 | 
			
		||||
 | 
			
		||||
            GDEBUG("API level %d", api_level);
 | 
			
		||||
            for (i = 0; i < G_N_ELEMENTS(gbinder_config_presets); i++) {
 | 
			
		||||
                const GBinderConfigPreset* preset = gbinder_config_presets + i;
 | 
			
		||||
 | 
			
		||||
                if (api_level >= preset->api_level) {
 | 
			
		||||
                    gbinder_config_apply_presets(out, preset);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_config_autorelease_cb(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    GASSERT(gbinder_config_keyfile == data);
 | 
			
		||||
    gbinder_config_keyfile = NULL;
 | 
			
		||||
    g_key_file_unref(data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GKeyFile* /* autoreleased */
 | 
			
		||||
gbinder_config_get()
 | 
			
		||||
{
 | 
			
		||||
    if (!gbinder_config_keyfile &&
 | 
			
		||||
        (gbinder_config_file || gbinder_config_dir)) {
 | 
			
		||||
        gbinder_config_keyfile = gbinder_config_load_files();
 | 
			
		||||
        if (gbinder_config_keyfile) {
 | 
			
		||||
            /* See the comment at the top of the file why this is needed */
 | 
			
		||||
            gbinder_config_autorelease = gbinder_idle_callback_schedule_new
 | 
			
		||||
               (gbinder_config_autorelease_cb, gbinder_config_keyfile, NULL);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return gbinder_config_keyfile;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Helper for loading config group in device = ident format */
 | 
			
		||||
GHashTable*
 | 
			
		||||
gbinder_config_load(
 | 
			
		||||
    const char* group,
 | 
			
		||||
    GBinderConfigValueMapFunc mapper)
 | 
			
		||||
{
 | 
			
		||||
    GKeyFile* k = gbinder_config_get();
 | 
			
		||||
    GHashTable* map = g_hash_table_new_full(g_str_hash, g_str_equal,
 | 
			
		||||
        g_free, NULL);
 | 
			
		||||
 | 
			
		||||
    if (k) {
 | 
			
		||||
        gsize n;
 | 
			
		||||
        char** devs = g_key_file_get_keys(k, group, &n, NULL);
 | 
			
		||||
 | 
			
		||||
        if (devs) {
 | 
			
		||||
            gsize i;
 | 
			
		||||
 | 
			
		||||
            for (i = 0; i < n; i++) {
 | 
			
		||||
                char* dev = devs[i];
 | 
			
		||||
                char* sval = g_key_file_get_value(k, group, dev, NULL);
 | 
			
		||||
                gconstpointer val = mapper(sval);
 | 
			
		||||
 | 
			
		||||
                if (val) {
 | 
			
		||||
                    g_hash_table_replace(map, dev, (gpointer) val);
 | 
			
		||||
                } else {
 | 
			
		||||
                    GWARN("Unknown gbinder config '%s' for %s in group [%s]",
 | 
			
		||||
                        sval, dev, group);
 | 
			
		||||
                    g_free(dev);
 | 
			
		||||
                }
 | 
			
		||||
                g_free(sval);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /* Shallow delete (contents got stolen or freed) */
 | 
			
		||||
            g_free(devs);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return map;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_config_exit()
 | 
			
		||||
{
 | 
			
		||||
    if (gbinder_config_autorelease) {
 | 
			
		||||
        gbinder_idle_callback_destroy(gbinder_config_autorelease);
 | 
			
		||||
        gbinder_config_autorelease = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    if (gbinder_config_keyfile) {
 | 
			
		||||
        g_key_file_unref(gbinder_config_keyfile);
 | 
			
		||||
        gbinder_config_keyfile = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										78
									
								
								src/gbinder_config.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								src/gbinder_config.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,78 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef GBINDER_CONFIG_H
 | 
			
		||||
#define GBINDER_CONFIG_H
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
gconstpointer
 | 
			
		||||
(*GBinderConfigValueMapFunc)(
 | 
			
		||||
    const char* value);
 | 
			
		||||
 | 
			
		||||
GHashTable*
 | 
			
		||||
gbinder_config_load(
 | 
			
		||||
    const char* group,
 | 
			
		||||
    GBinderConfigValueMapFunc map)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GKeyFile* /* autoreleased */
 | 
			
		||||
gbinder_config_get(
 | 
			
		||||
    void)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
/* This one declared strictly for unit tests */
 | 
			
		||||
void
 | 
			
		||||
gbinder_config_exit(
 | 
			
		||||
    void)
 | 
			
		||||
    GBINDER_INTERNAL
 | 
			
		||||
    GBINDER_DESTRUCTOR;
 | 
			
		||||
 | 
			
		||||
/* And these too */
 | 
			
		||||
extern const char* gbinder_config_file GBINDER_INTERNAL;
 | 
			
		||||
extern const char* gbinder_config_dir GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
/* Configuration groups and special value */
 | 
			
		||||
#define GBINDER_CONFIG_GROUP_PROTOCOL "Protocol"
 | 
			
		||||
#define GBINDER_CONFIG_GROUP_SERVICEMANAGER "ServiceManager"
 | 
			
		||||
#define GBINDER_CONFIG_VALUE_DEFAULT "Default"
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_CONFIG_H */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
@@ -1,325 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 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_servicemanager_p.h"
 | 
			
		||||
#include "gbinder_rpc_protocol.h"
 | 
			
		||||
#include "gbinder_servicepoll.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gbinder_client.h>
 | 
			
		||||
#include <gbinder_local_request.h>
 | 
			
		||||
#include <gbinder_remote_reply.h>
 | 
			
		||||
 | 
			
		||||
#include <gutil_macros.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_defaultservicemanager_watch {
 | 
			
		||||
    GBinderServicePoll* poll;
 | 
			
		||||
    char* name;
 | 
			
		||||
    gulong handler_id;
 | 
			
		||||
    guint notify_id;
 | 
			
		||||
} GBinderDefaultServiceManagerWatch;
 | 
			
		||||
 | 
			
		||||
typedef GBinderServiceManagerClass GBinderDefaultServiceManagerClass;
 | 
			
		||||
typedef struct gbinder_defaultservicemanager {
 | 
			
		||||
    GBinderServiceManager manager;
 | 
			
		||||
    GBinderServicePoll* poll;
 | 
			
		||||
    GHashTable* watch_table;
 | 
			
		||||
} GBinderDefaultServiceManager;
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE(GBinderDefaultServiceManager,
 | 
			
		||||
    gbinder_defaultservicemanager,
 | 
			
		||||
    GBINDER_TYPE_SERVICEMANAGER)
 | 
			
		||||
 | 
			
		||||
#define PARENT_CLASS gbinder_defaultservicemanager_parent_class
 | 
			
		||||
#define GBINDER_TYPE_DEFAULTSERVICEMANAGER \
 | 
			
		||||
    gbinder_defaultservicemanager_get_type()
 | 
			
		||||
#define GBINDER_DEFAULTSERVICEMANAGER(obj) \
 | 
			
		||||
    G_TYPE_CHECK_INSTANCE_CAST((obj), GBINDER_TYPE_DEFAULTSERVICEMANAGER, \
 | 
			
		||||
    GBinderDefaultServiceManager)
 | 
			
		||||
 | 
			
		||||
enum gbinder_defaultservicemanager_calls {
 | 
			
		||||
    GET_SERVICE_TRANSACTION = GBINDER_FIRST_CALL_TRANSACTION,
 | 
			
		||||
    CHECK_SERVICE_TRANSACTION,
 | 
			
		||||
    ADD_SERVICE_TRANSACTION,
 | 
			
		||||
    LIST_SERVICES_TRANSACTION
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* As a special case, ServiceManager's handle is zero */
 | 
			
		||||
#define DEFAULTSERVICEMANAGER_HANDLE (0)
 | 
			
		||||
#define DEFAULTSERVICEMANAGER_IFACE  "android.os.IServiceManager"
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_defaultservicemanager_new(
 | 
			
		||||
    const char* dev)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_servicemanager_new_with_type
 | 
			
		||||
        (GBINDER_TYPE_DEFAULTSERVICEMANAGER, dev);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_defaultservicemanager_watch_proc(
 | 
			
		||||
    GBinderServicePoll* poll,
 | 
			
		||||
    const char* name_added,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderDefaultServiceManagerWatch* watch = user_data;
 | 
			
		||||
 | 
			
		||||
    if (!g_strcmp0(name_added, watch->name)) {
 | 
			
		||||
        GBinderServiceManager* manager =
 | 
			
		||||
            gbinder_servicepoll_manager(watch->poll);
 | 
			
		||||
 | 
			
		||||
        if (watch->notify_id) {
 | 
			
		||||
            g_source_remove(watch->notify_id);
 | 
			
		||||
            watch->notify_id = 0;
 | 
			
		||||
        }
 | 
			
		||||
        gbinder_servicemanager_service_registered(manager, name_added);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_defaultservicemanager_watch_notify(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderDefaultServiceManagerWatch* watch = user_data;
 | 
			
		||||
    GBinderServiceManager* manager = gbinder_servicepoll_manager(watch->poll);
 | 
			
		||||
    char* name = g_strdup(watch->name);
 | 
			
		||||
 | 
			
		||||
    GASSERT(watch->notify_id);
 | 
			
		||||
    watch->notify_id = 0;
 | 
			
		||||
    gbinder_servicemanager_service_registered(manager, name);
 | 
			
		||||
    g_free(name);
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_defaultservicemanager_watch_free(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderDefaultServiceManagerWatch* watch = user_data;
 | 
			
		||||
 | 
			
		||||
    if (watch->notify_id) {
 | 
			
		||||
        g_source_remove(watch->notify_id);
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_servicepoll_remove_handler(watch->poll, watch->handler_id);
 | 
			
		||||
    gbinder_servicepoll_unref(watch->poll);
 | 
			
		||||
    g_free(watch->name);
 | 
			
		||||
    g_slice_free(GBinderDefaultServiceManagerWatch, watch);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderDefaultServiceManagerWatch*
 | 
			
		||||
gbinder_defaultservicemanager_watch_new(
 | 
			
		||||
    GBinderDefaultServiceManager* manager,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    GBinderDefaultServiceManagerWatch* watch =
 | 
			
		||||
        g_slice_new0(GBinderDefaultServiceManagerWatch);
 | 
			
		||||
 | 
			
		||||
    watch->name = g_strdup(name);
 | 
			
		||||
    watch->poll = gbinder_servicepoll_new(&manager->manager, &manager->poll);
 | 
			
		||||
    watch->handler_id = gbinder_servicepoll_add_handler(watch->poll,
 | 
			
		||||
        gbinder_defaultservicemanager_watch_proc, watch);
 | 
			
		||||
    return watch;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_servicemanager_list_services_req(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    gint32 index)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_local_request_append_int32
 | 
			
		||||
        (gbinder_client_new_request(self->client), index);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
char**
 | 
			
		||||
gbinder_defaultservicemanager_list(
 | 
			
		||||
    GBinderServiceManager* self)
 | 
			
		||||
{
 | 
			
		||||
    GPtrArray* list = g_ptr_array_new();
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_servicemanager_list_services_req(self,0);
 | 
			
		||||
    GBinderRemoteReply* reply;
 | 
			
		||||
 | 
			
		||||
    while ((reply = gbinder_client_transact_sync_reply(self->client,
 | 
			
		||||
        LIST_SERVICES_TRANSACTION, req, NULL)) != NULL) {
 | 
			
		||||
        char* service = gbinder_remote_reply_read_string16(reply);
 | 
			
		||||
 | 
			
		||||
        gbinder_remote_reply_unref(reply);
 | 
			
		||||
        if (service) {
 | 
			
		||||
            g_ptr_array_add(list, service);
 | 
			
		||||
            gbinder_local_request_unref(req);
 | 
			
		||||
            req = gbinder_servicemanager_list_services_req(self, list->len);
 | 
			
		||||
        } else {
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    g_ptr_array_add(list, NULL);
 | 
			
		||||
    return (char**)g_ptr_array_free(list, FALSE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_defaultservicemanager_get_service(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    int* status)
 | 
			
		||||
{
 | 
			
		||||
    GBinderRemoteObject* obj;
 | 
			
		||||
    GBinderRemoteReply* reply;
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_client_new_request(self->client);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_append_string16(req, name);
 | 
			
		||||
    reply = gbinder_client_transact_sync_reply(self->client,
 | 
			
		||||
        CHECK_SERVICE_TRANSACTION, req, status);
 | 
			
		||||
 | 
			
		||||
    obj = gbinder_remote_reply_read_object(reply);
 | 
			
		||||
    gbinder_remote_reply_unref(reply);
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    return obj;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
gbinder_defaultservicemanager_add_service(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    int status;
 | 
			
		||||
    GBinderRemoteReply* reply;
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_client_new_request(self->client);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_append_string16(req, name);
 | 
			
		||||
    gbinder_local_request_append_local_object(req, obj);
 | 
			
		||||
    gbinder_local_request_append_int32(req, 0);
 | 
			
		||||
 | 
			
		||||
    reply = gbinder_client_transact_sync_reply(self->client,
 | 
			
		||||
        ADD_SERVICE_TRANSACTION, req, &status);
 | 
			
		||||
 | 
			
		||||
    gbinder_remote_reply_unref(reply);
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBINDER_SERVICEMANAGER_NAME_CHECK
 | 
			
		||||
gbinder_defaultservicemanager_check_name(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    return GBINDER_SERVICEMANAGER_NAME_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_defaultservicemanager_watch(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    GBinderDefaultServiceManager* self = GBINDER_DEFAULTSERVICEMANAGER(manager);
 | 
			
		||||
    GBinderDefaultServiceManagerWatch* watch =
 | 
			
		||||
        gbinder_defaultservicemanager_watch_new(self, name);
 | 
			
		||||
 | 
			
		||||
    g_hash_table_replace(self->watch_table, watch->name, watch);
 | 
			
		||||
    if (gbinder_servicepoll_is_known_name(watch->poll, name)) {
 | 
			
		||||
        watch->notify_id =
 | 
			
		||||
            g_idle_add(gbinder_defaultservicemanager_watch_notify, watch);
 | 
			
		||||
    }
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_defaultservicemanager_unwatch(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    g_hash_table_remove(GBINDER_DEFAULTSERVICEMANAGER(manager)->watch_table,
 | 
			
		||||
        name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_defaultservicemanager_init(
 | 
			
		||||
    GBinderDefaultServiceManager* self)
 | 
			
		||||
{
 | 
			
		||||
    self->watch_table = g_hash_table_new_full(g_str_hash, g_str_equal,
 | 
			
		||||
        NULL, gbinder_defaultservicemanager_watch_free);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_defaultservicemanager_finalize(
 | 
			
		||||
    GObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderDefaultServiceManager* self = GBINDER_DEFAULTSERVICEMANAGER(object);
 | 
			
		||||
 | 
			
		||||
    g_hash_table_destroy(self->watch_table);
 | 
			
		||||
    G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
    klass->list = gbinder_defaultservicemanager_list;
 | 
			
		||||
    klass->get_service = gbinder_defaultservicemanager_get_service;
 | 
			
		||||
    klass->add_service = gbinder_defaultservicemanager_add_service;
 | 
			
		||||
    klass->check_name = gbinder_defaultservicemanager_check_name;
 | 
			
		||||
    /* normalize_name is not needed */
 | 
			
		||||
    klass->watch = gbinder_defaultservicemanager_watch;
 | 
			
		||||
    klass->unwatch = gbinder_defaultservicemanager_unwatch;
 | 
			
		||||
    G_OBJECT_CLASS(klass)->finalize = gbinder_defaultservicemanager_finalize;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -32,6 +32,7 @@
 | 
			
		||||
 | 
			
		||||
#include "gbinder_driver.h"
 | 
			
		||||
#include "gbinder_buffer_p.h"
 | 
			
		||||
#include "gbinder_cleanup.h"
 | 
			
		||||
#include "gbinder_handler.h"
 | 
			
		||||
#include "gbinder_io.h"
 | 
			
		||||
#include "gbinder_local_object_p.h"
 | 
			
		||||
@@ -60,9 +61,7 @@
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
 | 
			
		||||
/* Log module */
 | 
			
		||||
GLOG_MODULE_DEFINE("gbinder");
 | 
			
		||||
#include <linux/ioctl.h>
 | 
			
		||||
 | 
			
		||||
/* BINDER_VM_SIZE copied from native/libs/binder/ProcessState.cpp */
 | 
			
		||||
#define BINDER_VM_SIZE ((1024*1024) - sysconf(_SC_PAGE_SIZE)*2)
 | 
			
		||||
@@ -87,10 +86,30 @@ struct gbinder_driver {
 | 
			
		||||
    const GBinderRpcProtocol* protocol;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_io_read_buf {
 | 
			
		||||
    GBinderIoBuf buf;
 | 
			
		||||
typedef struct gbinder_driver_read_buf {
 | 
			
		||||
    GBinderIoBuf io;
 | 
			
		||||
    gsize offset;
 | 
			
		||||
} GBinderDriverReadBuf;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_driver_read_data {
 | 
			
		||||
    GBinderDriverReadBuf buf;
 | 
			
		||||
    guint8 data[GBINDER_IO_READ_BUFFER_SIZE];
 | 
			
		||||
} GBinderIoReadBuf;
 | 
			
		||||
} GBinderDriverReadData;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_driver_context {
 | 
			
		||||
    GBinderDriverReadBuf* rbuf;
 | 
			
		||||
    GBinderObjectRegistry* reg;
 | 
			
		||||
    GBinderHandler* handler;
 | 
			
		||||
    GBinderCleanup* unrefs;
 | 
			
		||||
    GBinderBufferContentsList* bufs;
 | 
			
		||||
} GBinderDriverContext;
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
gbinder_driver_txstatus(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderDriverContext* context,
 | 
			
		||||
    GBinderRemoteReply* reply);
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Implementation
 | 
			
		||||
@@ -143,18 +162,38 @@ gbinder_driver_verbose_transaction_data(
 | 
			
		||||
            guint n = 0;
 | 
			
		||||
            while (tx->objects[n]) n++;
 | 
			
		||||
            if (tx->status) {
 | 
			
		||||
                GVERBOSE("> %s %d (%u bytes, %u objects)", name, tx->status,
 | 
			
		||||
                    (guint)tx->size, n);
 | 
			
		||||
                if (tx->target) {
 | 
			
		||||
                    GVERBOSE("> %s %p %d (%u bytes, %u objects)", name,
 | 
			
		||||
                             tx->target, tx->status, (guint)tx->size, n);
 | 
			
		||||
                } else {
 | 
			
		||||
                    GVERBOSE("> %s %d (%u bytes, %u objects)", name,
 | 
			
		||||
                        tx->status, (guint)tx->size, n);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                GVERBOSE("> %s (%u bytes, %u objects)", name,
 | 
			
		||||
                    (guint)tx->size, n);
 | 
			
		||||
                if (tx->target) {
 | 
			
		||||
                    GVERBOSE("> %s %p (%u bytes, %u objects)", name,
 | 
			
		||||
                        tx->target, (guint)tx->size, n);
 | 
			
		||||
                } else {
 | 
			
		||||
                    GVERBOSE("> %s (%u bytes, %u objects)", name, (guint)
 | 
			
		||||
                        tx->size, n);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            if (tx->status) {
 | 
			
		||||
                GVERBOSE("> %s %d (%u bytes)", name, tx->status,
 | 
			
		||||
                    (guint)tx->size);
 | 
			
		||||
                if (tx->target) {
 | 
			
		||||
                    GVERBOSE("> %s %p %d (%u bytes)", name, tx->target,
 | 
			
		||||
                        tx->status, (guint)tx->size);
 | 
			
		||||
                } else {
 | 
			
		||||
                    GVERBOSE("> %s %d (%u bytes)", name, tx->status, (guint)
 | 
			
		||||
                        tx->size);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                GVERBOSE("> %s (%u bytes)", name, (guint)tx->size);
 | 
			
		||||
                if (tx->target) {
 | 
			
		||||
                    GVERBOSE("> %s %p (%u bytes)", name, tx->target, (guint)
 | 
			
		||||
                        tx->size);
 | 
			
		||||
                } else {
 | 
			
		||||
                    GVERBOSE("> %s (%u bytes)", name, (guint)tx->size);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -178,9 +217,11 @@ gbinder_driver_write(
 | 
			
		||||
        gbinder_driver_verbose_dump('<',
 | 
			
		||||
            buf->ptr +  buf->consumed,
 | 
			
		||||
            buf->size - buf->consumed);
 | 
			
		||||
        GVERBOSE_("%u/%u", (guint)buf->consumed, (guint)buf->size);
 | 
			
		||||
        GVERBOSE("gbinder_driver_write(%d) %u/%u", self->fd,
 | 
			
		||||
            (guint)buf->consumed, (guint)buf->size);
 | 
			
		||||
        err = self->io->write_read(self->fd, buf, NULL);
 | 
			
		||||
        GVERBOSE_("%u/%u err %d", (guint)buf->consumed, (guint)buf->size, err);
 | 
			
		||||
        GVERBOSE("gbinder_driver_write(%d) %u/%u err %d", self->fd,
 | 
			
		||||
            (guint)buf->consumed, (guint)buf->size, err);
 | 
			
		||||
    }
 | 
			
		||||
    return err;
 | 
			
		||||
}
 | 
			
		||||
@@ -190,11 +231,24 @@ int
 | 
			
		||||
gbinder_driver_write_read(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderIoBuf* write,
 | 
			
		||||
    GBinderIoBuf* read)
 | 
			
		||||
    GBinderDriverReadBuf* rbuf)
 | 
			
		||||
{
 | 
			
		||||
    int err = (-EAGAIN);
 | 
			
		||||
    GBinderIoBuf rio;
 | 
			
		||||
    GBinderIoBuf* read;
 | 
			
		||||
 | 
			
		||||
    /* rbuf is never NULL */
 | 
			
		||||
    if (rbuf->offset) {
 | 
			
		||||
        rio.ptr = rbuf->io.ptr + rbuf->offset;
 | 
			
		||||
        rio.size = rbuf->io.size - rbuf->offset;
 | 
			
		||||
        rio.consumed = rbuf->io.consumed - rbuf->offset;
 | 
			
		||||
        read = &rio;
 | 
			
		||||
    } else {
 | 
			
		||||
        read = &rbuf->io;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    while (err == (-EAGAIN)) {
 | 
			
		||||
 | 
			
		||||
#if GUTIL_LOG_VERBOSE
 | 
			
		||||
        const gsize were_consumed = read ? read->consumed : 0;
 | 
			
		||||
        if (GLOG_ENABLED(GLOG_LEVEL_VERBOSE)) {
 | 
			
		||||
@@ -203,21 +257,23 @@ gbinder_driver_write_read(
 | 
			
		||||
                    write->ptr +  write->consumed,
 | 
			
		||||
                    write->size - write->consumed);
 | 
			
		||||
            }
 | 
			
		||||
            GVERBOSE_("write %u/%u read %u/%u",
 | 
			
		||||
              (guint)(write ? write->consumed : 0),
 | 
			
		||||
              (guint)(write ? write->size : 0),
 | 
			
		||||
              (guint)(read ? read->consumed : 0),
 | 
			
		||||
              (guint)(read ? read->size : 0));
 | 
			
		||||
            GVERBOSE("gbinder_driver_write_read(%d) "
 | 
			
		||||
                "write %u/%u read %u/%u", self->fd,
 | 
			
		||||
                (guint)(write ? write->consumed : 0),
 | 
			
		||||
                (guint)(write ? write->size : 0),
 | 
			
		||||
                (guint)(read ? read->consumed : 0),
 | 
			
		||||
                (guint)(read ? read->size : 0));
 | 
			
		||||
        }
 | 
			
		||||
#endif /* GUTIL_LOG_VERBOSE */
 | 
			
		||||
        err = self->io->write_read(self->fd, write, read);
 | 
			
		||||
#if GUTIL_LOG_VERBOSE
 | 
			
		||||
        if (GLOG_ENABLED(GLOG_LEVEL_VERBOSE)) {
 | 
			
		||||
            GVERBOSE_("write %u/%u read %u/%u err %d",
 | 
			
		||||
              (guint)(write ? write->consumed : 0),
 | 
			
		||||
              (guint)(write ? write->size : 0),
 | 
			
		||||
              (guint)(read ? read->consumed : 0),
 | 
			
		||||
              (guint)(read ? read->size : 0), err);
 | 
			
		||||
            GVERBOSE("gbinder_driver_write_read(%d) "
 | 
			
		||||
                "write %u/%u read %u/%u err %d", self->fd,
 | 
			
		||||
                (guint)(write ? write->consumed : 0),
 | 
			
		||||
                (guint)(write ? write->size : 0),
 | 
			
		||||
                (guint)(read ? read->consumed : 0),
 | 
			
		||||
                (guint)(read ? read->size : 0), err);
 | 
			
		||||
            if (read) {
 | 
			
		||||
                gbinder_driver_verbose_dump('>',
 | 
			
		||||
                    read->ptr + were_consumed,
 | 
			
		||||
@@ -226,6 +282,10 @@ gbinder_driver_write_read(
 | 
			
		||||
        }
 | 
			
		||||
#endif /* GUTIL_LOG_VERBOSE */
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (rbuf->offset) {
 | 
			
		||||
        rbuf->io.consumed = rio.consumed + rbuf->offset;
 | 
			
		||||
    }
 | 
			
		||||
    return err;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -283,55 +343,78 @@ gbinder_driver_cmd_data(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_death_notification(
 | 
			
		||||
gbinder_driver_handle_cookie(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    guint32 cmd,
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIoBuf write;
 | 
			
		||||
    guint8 buf[4 + GBINDER_MAX_DEATH_NOTIFICATION_SIZE];
 | 
			
		||||
    guint8 buf[4 + GBINDER_MAX_HANDLE_COOKIE_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);
 | 
			
		||||
    write.size = 4 + self->io->encode_handle_cookie(data + 1, obj);
 | 
			
		||||
    return gbinder_driver_write(self, &write) >= 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_read_init(
 | 
			
		||||
    GBinderIoReadBuf* rb)
 | 
			
		||||
    GBinderDriverReadData* read)
 | 
			
		||||
{
 | 
			
		||||
    rb->buf.ptr = (uintptr_t)(rb->data);
 | 
			
		||||
    rb->buf.size = sizeof(rb->data);
 | 
			
		||||
    rb->buf.consumed = 0;
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * It shouldn't be necessary to zero-initialize the buffer but
 | 
			
		||||
     * valgrind complains about access to uninitialised data if we
 | 
			
		||||
     * don't do so. Oh well...
 | 
			
		||||
     * It shouldn't be necessary to zero-initialize the whole buffer
 | 
			
		||||
     * but valgrind complains about access to uninitialised data if
 | 
			
		||||
     * we don't do so. Oh well...
 | 
			
		||||
     */
 | 
			
		||||
    memset(rb->data, 0, sizeof(rb->data));
 | 
			
		||||
    memset(read, 0, sizeof(*read));
 | 
			
		||||
    read->buf.io.ptr = GPOINTER_TO_SIZE(read->data);
 | 
			
		||||
    read->buf.io.size = sizeof(read->data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_context_init(
 | 
			
		||||
    GBinderDriverContext* context,
 | 
			
		||||
    GBinderDriverReadBuf* rbuf,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    GBinderHandler* handler)
 | 
			
		||||
{
 | 
			
		||||
    context->rbuf = rbuf;
 | 
			
		||||
    context->reg = reg;
 | 
			
		||||
    context->handler = handler;
 | 
			
		||||
    context->unrefs = NULL;
 | 
			
		||||
    context->bufs = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_context_cleanup(
 | 
			
		||||
    GBinderDriverContext* context)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_cleanup_free(context->unrefs);
 | 
			
		||||
    gbinder_buffer_contents_list_free(context->bufs);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
guint32
 | 
			
		||||
gbinder_driver_next_command(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    const GBinderIoBuf* buf)
 | 
			
		||||
    const GBinderDriverReadBuf* rbuf)
 | 
			
		||||
{
 | 
			
		||||
    const size_t remaining = buf->size - buf->consumed;
 | 
			
		||||
    guint32 cmd = 0;
 | 
			
		||||
    if (rbuf->io.consumed > rbuf->offset) {
 | 
			
		||||
        const gsize remaining = rbuf->io.consumed - rbuf->offset;
 | 
			
		||||
 | 
			
		||||
    if (remaining >= sizeof(cmd)) {
 | 
			
		||||
        int datalen;
 | 
			
		||||
        /* The size of the data to follow is encoded in the command code */
 | 
			
		||||
        cmd = *(guint32*)(buf->ptr + buf->consumed);
 | 
			
		||||
        datalen = _IOC_SIZE(cmd);
 | 
			
		||||
        if (remaining >= sizeof(cmd) + datalen) {
 | 
			
		||||
            return cmd;
 | 
			
		||||
        if (remaining >= 4) {
 | 
			
		||||
            /* The size of the data to follow is encoded in the command code */
 | 
			
		||||
            const guint32 cmd = *(guint32*)(rbuf->io.ptr + rbuf->offset);
 | 
			
		||||
            const guint datalen = _IOC_SIZE(cmd);
 | 
			
		||||
 | 
			
		||||
            if (remaining >= 4 + datalen) {
 | 
			
		||||
                return cmd;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
@@ -380,18 +463,18 @@ gbinder_driver_reply_data(
 | 
			
		||||
    GUtilIntArray* offsets = gbinder_output_data_offsets(data);
 | 
			
		||||
    void* offsets_buf = NULL;
 | 
			
		||||
 | 
			
		||||
    /* Build BC_TRANSACTION */
 | 
			
		||||
    /* Build BC_REPLY */
 | 
			
		||||
    if (extra_buffers) {
 | 
			
		||||
        GVERBOSE("< BC_REPLY_SG %u bytes", (guint)extra_buffers);
 | 
			
		||||
        gbinder_driver_verbose_dump_bytes(' ', data->bytes);
 | 
			
		||||
        *cmd = io->bc.reply_sg;
 | 
			
		||||
        len += io->encode_transaction_sg(buf + len, 0, 0, data->bytes, 0,
 | 
			
		||||
        len += io->encode_reply_sg(buf + len, 0, 0, data->bytes,
 | 
			
		||||
            offsets, &offsets_buf, extra_buffers);
 | 
			
		||||
    } else {
 | 
			
		||||
        GVERBOSE("< BC_REPLY");
 | 
			
		||||
        gbinder_driver_verbose_dump_bytes(' ', data->bytes);
 | 
			
		||||
        *cmd = io->bc.reply;
 | 
			
		||||
        len += io->encode_transaction(buf + len, 0, 0, data->bytes, 0,
 | 
			
		||||
        len += io->encode_reply(buf + len, 0, 0, data->bytes,
 | 
			
		||||
            offsets, &offsets_buf);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -416,16 +499,16 @@ static
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_handle_transaction(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    GBinderHandler* h,
 | 
			
		||||
    GBinderDriverContext* context,
 | 
			
		||||
    const void* data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalReply* reply = NULL;
 | 
			
		||||
    GBinderObjectRegistry* reg = context->reg;
 | 
			
		||||
    GBinderRemoteRequest* req;
 | 
			
		||||
    GBinderIoTxData tx;
 | 
			
		||||
    GBinderLocalObject* obj;
 | 
			
		||||
    const char* iface;
 | 
			
		||||
    int status = -EBADMSG;
 | 
			
		||||
    int txstatus = -EBADMSG;
 | 
			
		||||
 | 
			
		||||
    self->io->decode_transaction_data(data, &tx);
 | 
			
		||||
    gbinder_driver_verbose_transaction_data("BR_TRANSACTION", &tx);
 | 
			
		||||
@@ -434,9 +517,13 @@ gbinder_driver_handle_transaction(
 | 
			
		||||
 | 
			
		||||
    /* Transfer data ownership to the request */
 | 
			
		||||
    if (tx.data && tx.size) {
 | 
			
		||||
        GBinderBuffer* buf = gbinder_buffer_new(self,
 | 
			
		||||
            tx.data, tx.size, tx.objects);
 | 
			
		||||
 | 
			
		||||
        gbinder_driver_verbose_dump(' ', (uintptr_t)tx.data, tx.size);
 | 
			
		||||
        gbinder_remote_request_set_data(req, tx.code,
 | 
			
		||||
            gbinder_buffer_new(self, tx.data, tx.size, tx.objects));
 | 
			
		||||
        gbinder_remote_request_set_data(req, tx.code, buf);
 | 
			
		||||
        context->bufs = gbinder_buffer_contents_list_add(context->bufs,
 | 
			
		||||
            gbinder_buffer_contents(buf));
 | 
			
		||||
    } else {
 | 
			
		||||
        GASSERT(!tx.objects);
 | 
			
		||||
        gbinder_driver_free_buffer(self, tx.data);
 | 
			
		||||
@@ -447,11 +534,19 @@ gbinder_driver_handle_transaction(
 | 
			
		||||
    switch (gbinder_local_object_can_handle_transaction(obj, iface, tx.code)) {
 | 
			
		||||
    case GBINDER_LOCAL_TRANSACTION_LOOPER:
 | 
			
		||||
        reply = gbinder_local_object_handle_looper_transaction(obj, req,
 | 
			
		||||
            tx.code, tx.flags, &status);
 | 
			
		||||
            tx.code, tx.flags, &txstatus);
 | 
			
		||||
        break;
 | 
			
		||||
    case GBINDER_LOCAL_TRANSACTION_SUPPORTED:
 | 
			
		||||
        reply = gbinder_handler_transact(h, obj, req, tx.code, tx.flags,
 | 
			
		||||
            &status);
 | 
			
		||||
        /*
 | 
			
		||||
         * NULL GBinderHandler means that this is a synchronous call
 | 
			
		||||
         * executed on the main thread, meaning that we can call the
 | 
			
		||||
         * local object directly.
 | 
			
		||||
         */
 | 
			
		||||
        reply = context->handler ?
 | 
			
		||||
            gbinder_handler_transact(context->handler, obj, req, tx.code,
 | 
			
		||||
                tx.flags, &txstatus) :
 | 
			
		||||
            gbinder_local_object_handle_transaction(obj, req, tx.code,
 | 
			
		||||
                tx.flags, &txstatus);
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        GWARN("Unhandled transaction %s 0x%08x", iface, tx.code);
 | 
			
		||||
@@ -461,10 +556,20 @@ gbinder_driver_handle_transaction(
 | 
			
		||||
    /* No reply for one-way transactions */
 | 
			
		||||
    if (!(tx.flags & GBINDER_TX_FLAG_ONEWAY)) {
 | 
			
		||||
        if (reply) {
 | 
			
		||||
            context->bufs = gbinder_buffer_contents_list_add(context->bufs,
 | 
			
		||||
                gbinder_local_reply_contents(reply));
 | 
			
		||||
            gbinder_driver_reply_data(self, gbinder_local_reply_data(reply));
 | 
			
		||||
        } else {
 | 
			
		||||
            gbinder_driver_reply_status(self, status);
 | 
			
		||||
            gbinder_driver_reply_status(self, txstatus);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Wait until the reply is handled */
 | 
			
		||||
        do {
 | 
			
		||||
            txstatus = gbinder_driver_write_read(self, NULL, context->rbuf);
 | 
			
		||||
            if (txstatus >= 0) {
 | 
			
		||||
                txstatus = gbinder_driver_txstatus(self, context, NULL);
 | 
			
		||||
            }
 | 
			
		||||
        } while (txstatus == (-EAGAIN));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Free the data allocated for the transaction */
 | 
			
		||||
@@ -473,23 +578,45 @@ gbinder_driver_handle_transaction(
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_cleanup_decrefs(
 | 
			
		||||
    gpointer pointer)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObject* obj = GBINDER_LOCAL_OBJECT(pointer);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_object_handle_decrefs(obj);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_cleanup_release(
 | 
			
		||||
    gpointer pointer)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObject* obj = GBINDER_LOCAL_OBJECT(pointer);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_object_handle_release(obj);
 | 
			
		||||
    gbinder_local_object_unref(obj);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_handle_command(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    GBinderHandler* handler,
 | 
			
		||||
    GBinderDriverContext* context,
 | 
			
		||||
    guint32 cmd,
 | 
			
		||||
    const void* data)
 | 
			
		||||
{
 | 
			
		||||
    const GBinderIo* io = self->io;
 | 
			
		||||
    GBinderObjectRegistry* reg = context->reg;
 | 
			
		||||
 | 
			
		||||
    if (cmd == io->br.noop) {
 | 
			
		||||
        GVERBOSE("> BR_NOOP");
 | 
			
		||||
    } else if (cmd == io->br.ok) {
 | 
			
		||||
        GVERBOSE("> BR_OK");
 | 
			
		||||
    } else if (cmd == io->br.transaction_complete) {
 | 
			
		||||
        GVERBOSE("> BR_TRANSACTION_COMPLETE");
 | 
			
		||||
        GVERBOSE("> BR_TRANSACTION_COMPLETE (?)");
 | 
			
		||||
    } else if (cmd == io->br.spawn_looper) {
 | 
			
		||||
        GVERBOSE("> BR_SPAWN_LOOPER");
 | 
			
		||||
    } else if (cmd == io->br.finished) {
 | 
			
		||||
@@ -497,7 +624,7 @@ gbinder_driver_handle_command(
 | 
			
		||||
    } else if (cmd == io->br.increfs) {
 | 
			
		||||
        guint8 buf[4 + GBINDER_MAX_PTR_COOKIE_SIZE];
 | 
			
		||||
        GBinderLocalObject* obj = gbinder_object_registry_get_local
 | 
			
		||||
            (reg, io->decode_binder_ptr_cookie(data));
 | 
			
		||||
            (reg, io->decode_ptr_cookie(data));
 | 
			
		||||
 | 
			
		||||
        GVERBOSE("> BR_INCREFS %p", obj);
 | 
			
		||||
        gbinder_local_object_handle_increfs(obj);
 | 
			
		||||
@@ -506,114 +633,150 @@ gbinder_driver_handle_command(
 | 
			
		||||
        gbinder_driver_cmd_data(self, io->bc.increfs_done, data, buf);
 | 
			
		||||
    } else if (cmd == io->br.decrefs) {
 | 
			
		||||
        GBinderLocalObject* obj = gbinder_object_registry_get_local
 | 
			
		||||
            (reg, io->decode_binder_ptr_cookie(data));
 | 
			
		||||
            (reg, io->decode_ptr_cookie(data));
 | 
			
		||||
 | 
			
		||||
        GVERBOSE("> BR_DECREFS %p", obj);
 | 
			
		||||
        gbinder_local_object_handle_decrefs(obj);
 | 
			
		||||
        gbinder_local_object_unref(obj);
 | 
			
		||||
        if (obj) {
 | 
			
		||||
            /*
 | 
			
		||||
             * Unrefs must be processed only after clearing the incoming
 | 
			
		||||
             * command queue.
 | 
			
		||||
             */
 | 
			
		||||
            context->unrefs = gbinder_cleanup_add(context->unrefs,
 | 
			
		||||
                gbinder_driver_cleanup_decrefs, obj);
 | 
			
		||||
        }
 | 
			
		||||
    } else if (cmd == io->br.acquire) {
 | 
			
		||||
        guint8 buf[4 + GBINDER_MAX_PTR_COOKIE_SIZE];
 | 
			
		||||
        GBinderLocalObject* obj = gbinder_object_registry_get_local
 | 
			
		||||
            (reg, io->decode_binder_ptr_cookie(data));
 | 
			
		||||
            (reg, io->decode_ptr_cookie(data));
 | 
			
		||||
 | 
			
		||||
        GVERBOSE("> BR_ACQUIRE %p", obj);
 | 
			
		||||
        gbinder_local_object_handle_acquire(obj);
 | 
			
		||||
        gbinder_local_object_unref(obj);
 | 
			
		||||
        GVERBOSE("< BC_ACQUIRE_DONE %p", obj);
 | 
			
		||||
        gbinder_driver_cmd_data(self, io->bc.acquire_done, data, buf);
 | 
			
		||||
        if (obj) {
 | 
			
		||||
            /* BC_ACQUIRE_DONE will be sent after the request is handled */
 | 
			
		||||
            gbinder_local_object_handle_acquire(obj, context->bufs);
 | 
			
		||||
            gbinder_local_object_unref(obj);
 | 
			
		||||
        } else {
 | 
			
		||||
            /* This shouldn't normally happen. Just send the same data back. */
 | 
			
		||||
            GVERBOSE("< BC_ACQUIRE_DONE");
 | 
			
		||||
            gbinder_driver_cmd_data(self, io->bc.acquire_done, data, buf);
 | 
			
		||||
        }
 | 
			
		||||
    } else if (cmd == io->br.release) {
 | 
			
		||||
        GBinderLocalObject* obj = gbinder_object_registry_get_local
 | 
			
		||||
            (reg, io->decode_binder_ptr_cookie(data));
 | 
			
		||||
            (reg, io->decode_ptr_cookie(data));
 | 
			
		||||
 | 
			
		||||
        GVERBOSE("> BR_RELEASE %p", obj);
 | 
			
		||||
        gbinder_local_object_handle_release(obj);
 | 
			
		||||
        gbinder_local_object_unref(obj);
 | 
			
		||||
        if (obj) {
 | 
			
		||||
            /*
 | 
			
		||||
             * Unrefs must be processed only after clearing the incoming
 | 
			
		||||
             * command queue.
 | 
			
		||||
             */
 | 
			
		||||
            context->unrefs = gbinder_cleanup_add(context->unrefs,
 | 
			
		||||
                gbinder_driver_cleanup_release, obj);
 | 
			
		||||
        }
 | 
			
		||||
    } else if (cmd == io->br.transaction) {
 | 
			
		||||
        gbinder_driver_handle_transaction(self, reg, handler, data);
 | 
			
		||||
        gbinder_driver_handle_transaction(self, context, data);
 | 
			
		||||
    } else if (cmd == io->br.dead_binder) {
 | 
			
		||||
        guint8 buf[4 + GBINDER_MAX_PTR_COOKIE_SIZE];
 | 
			
		||||
        guint64 handle = 0;
 | 
			
		||||
        GBinderRemoteObject* obj;
 | 
			
		||||
 | 
			
		||||
        io->decode_cookie(data, &handle);
 | 
			
		||||
        GVERBOSE("> BR_DEAD_BINDER %llu", (long long unsigned int)handle);
 | 
			
		||||
        obj = gbinder_object_registry_get_remote(reg, (guint32)handle);
 | 
			
		||||
        GVERBOSE("> BR_DEAD_BINDER 0x%08llx", (long long unsigned int) handle);
 | 
			
		||||
        obj = gbinder_object_registry_get_remote(reg, (guint32)handle,
 | 
			
		||||
            REMOTE_REGISTRY_DONT_CREATE);
 | 
			
		||||
        if (obj) {
 | 
			
		||||
            /* BC_DEAD_BINDER_DONE will be sent after the request is handled */
 | 
			
		||||
            gbinder_remote_object_handle_death_notification(obj);
 | 
			
		||||
            gbinder_remote_object_unref(obj);
 | 
			
		||||
        } else {
 | 
			
		||||
            guint8 buf[4 + GBINDER_MAX_COOKIE_SIZE];
 | 
			
		||||
 | 
			
		||||
            /* This shouldn't normally happen. Just send the same data back. */
 | 
			
		||||
            GVERBOSE("< BC_DEAD_BINDER_DONE 0x%08llx", (long long unsigned int)
 | 
			
		||||
                handle);
 | 
			
		||||
            gbinder_driver_cmd_data(self, io->bc.dead_binder_done, data, buf);
 | 
			
		||||
        }
 | 
			
		||||
        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");
 | 
			
		||||
#if GUTIL_LOG_VERBOSE
 | 
			
		||||
        if (GLOG_ENABLED(GLOG_LEVEL_VERBOSE)) {
 | 
			
		||||
            guint64 handle = 0;
 | 
			
		||||
 | 
			
		||||
            io->decode_cookie(data, &handle);
 | 
			
		||||
            GVERBOSE("> BR_CLEAR_DEATH_NOTIFICATION_DONE 0x%08llx",
 | 
			
		||||
                (long long unsigned int) handle);
 | 
			
		||||
        }
 | 
			
		||||
#endif /* GUTIL_LOG_VERBOSE */
 | 
			
		||||
    } else {
 | 
			
		||||
#pragma message("TODO: handle more commands from the driver")
 | 
			
		||||
        GWARN("Unexpected command 0x%08x", cmd);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_compact_read_buf(
 | 
			
		||||
    GBinderDriverReadBuf* buf)
 | 
			
		||||
{
 | 
			
		||||
    /*
 | 
			
		||||
     * Move the data to the beginning of the buffer to make room for the
 | 
			
		||||
     * next portion of data (in case if we need one)
 | 
			
		||||
     */
 | 
			
		||||
    if (buf->io.consumed > buf->offset) {
 | 
			
		||||
        const gsize unprocessed = buf->io.consumed - buf->offset;
 | 
			
		||||
        guint8* data = GSIZE_TO_POINTER(buf->io.ptr);
 | 
			
		||||
 | 
			
		||||
        memmove(data, data + buf->offset, unprocessed);
 | 
			
		||||
        buf->io.consumed = unprocessed;
 | 
			
		||||
    } else {
 | 
			
		||||
        buf->io.consumed = 0;
 | 
			
		||||
    }
 | 
			
		||||
    buf->offset = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_handle_commands(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    GBinderHandler* handler,
 | 
			
		||||
    GBinderIoReadBuf* rb)
 | 
			
		||||
    GBinderDriverContext* context)
 | 
			
		||||
{
 | 
			
		||||
    GBinderDriverReadBuf* rbuf = context->rbuf;
 | 
			
		||||
    guint32 cmd;
 | 
			
		||||
    gsize unprocessed;
 | 
			
		||||
    GBinderIoBuf buf;
 | 
			
		||||
 | 
			
		||||
    buf.ptr = rb->buf.ptr;
 | 
			
		||||
    buf.size = rb->buf.consumed;
 | 
			
		||||
    buf.consumed = 0;
 | 
			
		||||
 | 
			
		||||
    while ((cmd = gbinder_driver_next_command(self, &buf)) != 0) {
 | 
			
		||||
        const size_t datalen = _IOC_SIZE(cmd);
 | 
			
		||||
        const size_t total = datalen + sizeof(cmd);
 | 
			
		||||
    while ((cmd = gbinder_driver_next_command(self, rbuf)) != 0) {
 | 
			
		||||
        const gsize datalen = _IOC_SIZE(cmd);
 | 
			
		||||
        const gsize total = datalen + sizeof(cmd);
 | 
			
		||||
        const void* data = GSIZE_TO_POINTER(rbuf->io.ptr + rbuf->offset + 4);
 | 
			
		||||
 | 
			
		||||
        /* Handle this command */
 | 
			
		||||
        gbinder_driver_handle_command(self, reg, handler, cmd,
 | 
			
		||||
            (void*)(buf.ptr + buf.consumed + sizeof(cmd)));
 | 
			
		||||
 | 
			
		||||
        /* Switch to the next packet in the buffer */
 | 
			
		||||
        buf.consumed += total;
 | 
			
		||||
        rbuf->offset += total;
 | 
			
		||||
        gbinder_driver_handle_command(self, context, cmd, data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Move the data to the beginning of the buffer to make room for the
 | 
			
		||||
     * next portion of data (in case if we need one) */
 | 
			
		||||
    unprocessed = buf.size - buf.consumed;
 | 
			
		||||
    memmove(rb->data, rb->data + buf.consumed, unprocessed);
 | 
			
		||||
    rb->buf.consumed = unprocessed;
 | 
			
		||||
    gbinder_driver_compact_read_buf(rbuf);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
gbinder_driver_txstatus(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    GBinderHandler* handler,
 | 
			
		||||
    GBinderIoReadBuf* rb,
 | 
			
		||||
    GBinderDriverContext* context,
 | 
			
		||||
    GBinderRemoteReply* reply)
 | 
			
		||||
{
 | 
			
		||||
    guint32 cmd;
 | 
			
		||||
    gsize unprocessed;
 | 
			
		||||
    int txstatus = (-EAGAIN);
 | 
			
		||||
    GBinderIoBuf buf;
 | 
			
		||||
    GBinderDriverReadBuf* rbuf = context->rbuf;
 | 
			
		||||
    const guint8* buf = GSIZE_TO_POINTER(rbuf->io.ptr);
 | 
			
		||||
    const GBinderIo* io = self->io;
 | 
			
		||||
 | 
			
		||||
    buf.ptr = rb->buf.ptr;
 | 
			
		||||
    buf.size = rb->buf.consumed;
 | 
			
		||||
    buf.consumed = 0;
 | 
			
		||||
 | 
			
		||||
    while (txstatus == (-EAGAIN) && (cmd =
 | 
			
		||||
        gbinder_driver_next_command(self, &buf)) != 0) {
 | 
			
		||||
        gbinder_driver_next_command(self, context->rbuf)) != 0) {
 | 
			
		||||
        /* The size of the data is encoded in the command code */
 | 
			
		||||
        const size_t datalen = _IOC_SIZE(cmd);
 | 
			
		||||
        const size_t total = datalen + sizeof(cmd);
 | 
			
		||||
        const void* data = (void*)(buf.ptr + buf.consumed + sizeof(cmd));
 | 
			
		||||
        const gsize datalen = _IOC_SIZE(cmd);
 | 
			
		||||
        const gsize total = datalen + sizeof(cmd);
 | 
			
		||||
        const void* data = buf + rbuf->offset + sizeof(cmd);
 | 
			
		||||
 | 
			
		||||
        /* Handle the packet */
 | 
			
		||||
        /* Swallow this packet */
 | 
			
		||||
        rbuf->offset += total;
 | 
			
		||||
 | 
			
		||||
        /* Handle the command */
 | 
			
		||||
        if (cmd == io->br.transaction_complete) {
 | 
			
		||||
            GVERBOSE("> BR_TRANSACTION_COMPLETE");
 | 
			
		||||
            if (!reply) {
 | 
			
		||||
@@ -631,32 +794,44 @@ gbinder_driver_txstatus(
 | 
			
		||||
            io->decode_transaction_data(data, &tx);
 | 
			
		||||
            gbinder_driver_verbose_transaction_data("BR_REPLY", &tx);
 | 
			
		||||
 | 
			
		||||
            /* Transfer data ownership to the request */
 | 
			
		||||
            /* Transfer data ownership to the reply */
 | 
			
		||||
            if (tx.data && tx.size) {
 | 
			
		||||
                GBinderBuffer* buf = gbinder_buffer_new(self,
 | 
			
		||||
                    tx.data, tx.size, tx.objects);
 | 
			
		||||
 | 
			
		||||
                gbinder_driver_verbose_dump(' ', (uintptr_t)tx.data, tx.size);
 | 
			
		||||
                gbinder_remote_reply_set_data(reply,
 | 
			
		||||
                    gbinder_buffer_new(self, tx.data, tx.size, tx.objects));
 | 
			
		||||
                gbinder_remote_reply_set_data(reply, buf);
 | 
			
		||||
                context->bufs = gbinder_buffer_contents_list_add(context->bufs,
 | 
			
		||||
                    gbinder_buffer_contents(buf));
 | 
			
		||||
            } else {
 | 
			
		||||
                GASSERT(!tx.objects);
 | 
			
		||||
                gbinder_driver_free_buffer(self, tx.data);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            txstatus = tx.status;
 | 
			
		||||
            GASSERT(txstatus != (-EAGAIN));
 | 
			
		||||
            if (txstatus == (-EAGAIN)) txstatus = (-EFAULT);
 | 
			
		||||
            /*
 | 
			
		||||
             * Filter out special cases. It's a bit unfortunate that
 | 
			
		||||
             * libgbinder API historically mixed TF_STATUS_CODE payload
 | 
			
		||||
             * with special delivery errors. It's not a bit deal though,
 | 
			
		||||
             * because in real life TF_STATUS_CODE transactions are not
 | 
			
		||||
             * being used that often, if at all.
 | 
			
		||||
             */
 | 
			
		||||
            switch (tx.status) {
 | 
			
		||||
            case (-EAGAIN):
 | 
			
		||||
            case GBINDER_STATUS_FAILED:
 | 
			
		||||
            case GBINDER_STATUS_DEAD_OBJECT:
 | 
			
		||||
                txstatus = (-EFAULT);
 | 
			
		||||
                GWARN("Replacing tx status %d with %d", tx.status, txstatus);
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                txstatus = tx.status;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            gbinder_driver_handle_command(self, reg, handler, cmd, data);
 | 
			
		||||
            gbinder_driver_handle_command(self, context, cmd, data);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Switch to the next packet in the buffer */
 | 
			
		||||
        buf.consumed += total;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Move the data to the beginning of the buffer to make room for the
 | 
			
		||||
     * next portion of data (in case if we need one) */
 | 
			
		||||
    unprocessed = buf.size - buf.consumed;
 | 
			
		||||
    memmove(rb->data, rb->data + buf.consumed, unprocessed);
 | 
			
		||||
    rb->buf.consumed = unprocessed;
 | 
			
		||||
    gbinder_driver_compact_read_buf(rbuf);
 | 
			
		||||
    return txstatus;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -710,7 +885,7 @@ gbinder_driver_new(
 | 
			
		||||
                            max_threads, strerror(errno));
 | 
			
		||||
                    }
 | 
			
		||||
                    /* Choose the protocol based on the device name
 | 
			
		||||
                     * if none is explicitely specified */
 | 
			
		||||
                     * if none is explicitly specified */
 | 
			
		||||
                    self->protocol = protocol ? protocol :
 | 
			
		||||
                        gbinder_rpc_protocol_for_device(dev);
 | 
			
		||||
                    return self;
 | 
			
		||||
@@ -743,11 +918,23 @@ gbinder_driver_unref(
 | 
			
		||||
{
 | 
			
		||||
    GASSERT(self->refcount > 0);
 | 
			
		||||
    if (g_atomic_int_dec_and_test(&self->refcount)) {
 | 
			
		||||
        gbinder_driver_close(self);
 | 
			
		||||
        g_free(self->dev);
 | 
			
		||||
        g_slice_free(GBinderDriver, self);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_close(
 | 
			
		||||
    GBinderDriver* self)
 | 
			
		||||
{
 | 
			
		||||
    if (self->vm) {
 | 
			
		||||
        GDEBUG("Closing %s", self->dev);
 | 
			
		||||
        gbinder_system_munmap(self->vm, self->vmsize);
 | 
			
		||||
        gbinder_system_close(self->fd);
 | 
			
		||||
        g_free(self->dev);
 | 
			
		||||
        g_slice_free(GBinderDriver, self);
 | 
			
		||||
        self->fd = -1;
 | 
			
		||||
        self->vm = NULL;
 | 
			
		||||
        self->vmsize = 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -806,6 +993,55 @@ gbinder_driver_io(
 | 
			
		||||
    return self->io;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const GBinderRpcProtocol*
 | 
			
		||||
gbinder_driver_protocol(
 | 
			
		||||
    GBinderDriver* self)
 | 
			
		||||
{
 | 
			
		||||
    return self->protocol;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_acquire_done(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIoBuf write;
 | 
			
		||||
    guint8 buf[4 + GBINDER_MAX_PTR_COOKIE_SIZE];
 | 
			
		||||
    guint32* data = (guint32*)buf;
 | 
			
		||||
    const GBinderIo* io = self->io;
 | 
			
		||||
 | 
			
		||||
    data[0] = io->bc.acquire_done;
 | 
			
		||||
    memset(&write, 0, sizeof(write));
 | 
			
		||||
    write.ptr = (uintptr_t)buf;
 | 
			
		||||
    write.size = 4 + io->encode_ptr_cookie(data + 1, obj);
 | 
			
		||||
 | 
			
		||||
    GVERBOSE("< BC_ACQUIRE_DONE %p", obj);
 | 
			
		||||
    return gbinder_driver_write(self, &write) >= 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_dead_binder_done(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(obj)) {
 | 
			
		||||
        GBinderIoBuf write;
 | 
			
		||||
        guint8 buf[4 + GBINDER_MAX_COOKIE_SIZE];
 | 
			
		||||
        guint32* data = (guint32*)buf;
 | 
			
		||||
        const GBinderIo* io = self->io;
 | 
			
		||||
 | 
			
		||||
        data[0] = io->bc.dead_binder_done;
 | 
			
		||||
        memset(&write, 0, sizeof(write));
 | 
			
		||||
        write.ptr = (uintptr_t)buf;
 | 
			
		||||
        write.size = 4 + io->encode_cookie(data + 1, obj->handle);
 | 
			
		||||
 | 
			
		||||
        GVERBOSE("< BC_DEAD_BINDER_DONE 0x%08x", obj->handle);
 | 
			
		||||
        return gbinder_driver_write(self, &write) >= 0;
 | 
			
		||||
    } else {
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_request_death_notification(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
@@ -813,7 +1049,7 @@ gbinder_driver_request_death_notification(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(obj)) {
 | 
			
		||||
        GVERBOSE("< BC_REQUEST_DEATH_NOTIFICATION 0x%08x", obj->handle);
 | 
			
		||||
        return gbinder_driver_death_notification(self,
 | 
			
		||||
        return gbinder_driver_handle_cookie(self,
 | 
			
		||||
            self->io->bc.request_death_notification, obj);
 | 
			
		||||
    } else {
 | 
			
		||||
        return FALSE;
 | 
			
		||||
@@ -827,7 +1063,7 @@ gbinder_driver_clear_death_notification(
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(obj)) {
 | 
			
		||||
        GVERBOSE("< BC_CLEAR_DEATH_NOTIFICATION 0x%08x", obj->handle);
 | 
			
		||||
        return gbinder_driver_death_notification(self,
 | 
			
		||||
        return gbinder_driver_handle_cookie(self,
 | 
			
		||||
            self->io->bc.clear_death_notification, obj);
 | 
			
		||||
    } else {
 | 
			
		||||
        return FALSE;
 | 
			
		||||
@@ -942,23 +1178,26 @@ gbinder_driver_read(
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    GBinderHandler* handler)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIoReadBuf rb;
 | 
			
		||||
    GBinderDriverReadData read;
 | 
			
		||||
    GBinderDriverContext context;
 | 
			
		||||
    int ret;
 | 
			
		||||
 | 
			
		||||
    gbinder_driver_read_init(&rb);
 | 
			
		||||
    ret = gbinder_driver_write_read(self, NULL, &rb.buf);
 | 
			
		||||
    gbinder_driver_read_init(&read);
 | 
			
		||||
    gbinder_driver_context_init(&context, &read.buf, reg, handler);
 | 
			
		||||
    ret = gbinder_driver_write_read(self, NULL, context.rbuf);
 | 
			
		||||
    if (ret >= 0) {
 | 
			
		||||
        /* Loop until we have handled all the incoming commands */
 | 
			
		||||
        gbinder_driver_handle_commands(self, reg, handler, &rb);
 | 
			
		||||
        while (rb.buf.consumed) {
 | 
			
		||||
            ret = gbinder_driver_write_read(self, NULL, &rb.buf);
 | 
			
		||||
        gbinder_driver_handle_commands(self, &context);
 | 
			
		||||
        while (read.buf.io.consumed && gbinder_handler_can_loop(handler)) {
 | 
			
		||||
            ret = gbinder_driver_write_read(self, NULL, context.rbuf);
 | 
			
		||||
            if (ret >= 0) {
 | 
			
		||||
                gbinder_driver_handle_commands(self, reg, handler, &rb);
 | 
			
		||||
                gbinder_driver_handle_commands(self, &context);
 | 
			
		||||
            } else {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_driver_context_cleanup(&context);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -966,13 +1205,16 @@ int
 | 
			
		||||
gbinder_driver_transact(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    GBinderHandler* handler,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    GBinderLocalRequest* req,
 | 
			
		||||
    GBinderRemoteReply* reply)
 | 
			
		||||
{
 | 
			
		||||
    GBinderDriverReadData read;
 | 
			
		||||
    GBinderDriverContext context;
 | 
			
		||||
    GBinderIoBuf write;
 | 
			
		||||
    GBinderIoReadBuf rb;
 | 
			
		||||
    GBinderDriverReadBuf* rbuf = &read.buf;
 | 
			
		||||
    const GBinderIo* io = self->io;
 | 
			
		||||
    const guint flags = reply ? 0 : GBINDER_TX_FLAG_ONEWAY;
 | 
			
		||||
    GBinderOutputData* data = gbinder_local_request_data(req);
 | 
			
		||||
@@ -984,7 +1226,8 @@ gbinder_driver_transact(
 | 
			
		||||
    guint len = sizeof(*cmd);
 | 
			
		||||
    int txstatus = (-EAGAIN);
 | 
			
		||||
 | 
			
		||||
    gbinder_driver_read_init(&rb);
 | 
			
		||||
    gbinder_driver_read_init(&read);
 | 
			
		||||
    gbinder_driver_context_init(&context, &read.buf, reg, handler);
 | 
			
		||||
 | 
			
		||||
    /* Build BC_TRANSACTION */
 | 
			
		||||
    if (extra_buffers) {
 | 
			
		||||
@@ -1018,11 +1261,11 @@ gbinder_driver_transact(
 | 
			
		||||
     * negative is a driver error (except for -EAGAIN meaning that there's
 | 
			
		||||
     * no status yet) */
 | 
			
		||||
    while (txstatus == (-EAGAIN)) {
 | 
			
		||||
        int err = gbinder_driver_write_read(self, &write, &rb.buf);
 | 
			
		||||
        int err = gbinder_driver_write_read(self, &write, rbuf);
 | 
			
		||||
        if (err < 0) {
 | 
			
		||||
            txstatus = err;
 | 
			
		||||
        } else {
 | 
			
		||||
            txstatus = gbinder_driver_txstatus(self, reg, NULL, &rb, reply);
 | 
			
		||||
            txstatus = gbinder_driver_txstatus(self, &context, reply);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -1031,54 +1274,40 @@ gbinder_driver_transact(
 | 
			
		||||
        GASSERT(write.consumed == write.size || txstatus > 0);
 | 
			
		||||
 | 
			
		||||
        /* Loop until we have handled all the incoming commands */
 | 
			
		||||
        gbinder_driver_handle_commands(self, reg, NULL, &rb);
 | 
			
		||||
        while (rb.buf.consumed) {
 | 
			
		||||
            int err = gbinder_driver_write_read(self, NULL, &rb.buf);
 | 
			
		||||
        gbinder_driver_handle_commands(self, &context);
 | 
			
		||||
        while (rbuf->io.consumed) {
 | 
			
		||||
            int err = gbinder_driver_write_read(self, NULL, rbuf);
 | 
			
		||||
            if (err < 0) {
 | 
			
		||||
                txstatus = err;
 | 
			
		||||
                break;
 | 
			
		||||
            } else {
 | 
			
		||||
                gbinder_driver_handle_commands(self, reg, NULL, &rb);
 | 
			
		||||
                gbinder_driver_handle_commands(self, &context);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    gbinder_driver_context_cleanup(&context);
 | 
			
		||||
    g_free(offsets_buf);
 | 
			
		||||
    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,
 | 
			
		||||
    const char* iface)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_local_request_new_iface(self->io, self->protocol, iface);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_driver_local_request_new_ping(
 | 
			
		||||
    GBinderDriver* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_local_request_new(self->io, NULL);
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_init_writer(req, &writer);
 | 
			
		||||
    self->protocol->write_rpc_header(&writer, iface);
 | 
			
		||||
    self->protocol->write_ping(&writer);
 | 
			
		||||
    return req;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -40,107 +40,149 @@ struct pollfd;
 | 
			
		||||
GBinderDriver*
 | 
			
		||||
gbinder_driver_new(
 | 
			
		||||
    const char* dev,
 | 
			
		||||
    const GBinderRpcProtocol* protocol);
 | 
			
		||||
    const GBinderRpcProtocol* protocol)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderDriver*
 | 
			
		||||
gbinder_driver_ref(
 | 
			
		||||
    GBinderDriver* driver);
 | 
			
		||||
    GBinderDriver* driver)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_unref(
 | 
			
		||||
    GBinderDriver* driver);
 | 
			
		||||
    GBinderDriver* driver)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_close(
 | 
			
		||||
    GBinderDriver* driver)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_driver_fd(
 | 
			
		||||
    GBinderDriver* driver);
 | 
			
		||||
    GBinderDriver* driver)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_driver_poll(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    struct pollfd* pollfd);
 | 
			
		||||
    struct pollfd* pollfd)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_driver_dev(
 | 
			
		||||
    GBinderDriver* driver);
 | 
			
		||||
    GBinderDriver* driver)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
const GBinderIo*
 | 
			
		||||
gbinder_driver_io(
 | 
			
		||||
    GBinderDriver* driver);
 | 
			
		||||
    GBinderDriver* driver)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
const GBinderRpcProtocol*
 | 
			
		||||
gbinder_driver_protocol(
 | 
			
		||||
    GBinderDriver* driver)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_acquire_done(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_dead_binder_done(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_request_death_notification(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    GBinderRemoteObject* obj);
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_clear_death_notification(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    GBinderRemoteObject* obj);
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_increfs(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    guint32 handle);
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_decrefs(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    guint32 handle);
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_acquire(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    guint32 handle);
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_release(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    guint32 handle);
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_close_fds(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    void** objects,
 | 
			
		||||
    const void* end);
 | 
			
		||||
    const void* end)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_driver_free_buffer(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    void* buffer);
 | 
			
		||||
    void* buffer)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_enter_looper(
 | 
			
		||||
    GBinderDriver* driver);
 | 
			
		||||
    GBinderDriver* driver)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_driver_exit_looper(
 | 
			
		||||
    GBinderDriver* driver);
 | 
			
		||||
    GBinderDriver* driver)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_driver_read(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    GBinderHandler* handler);
 | 
			
		||||
    GBinderHandler* handler)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_driver_transact(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    GBinderHandler* handler,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    GBinderLocalRequest* request,
 | 
			
		||||
    GBinderRemoteReply* reply);
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_driver_ping(
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    guint32 handle);
 | 
			
		||||
    GBinderRemoteReply* reply)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_driver_local_request_new(
 | 
			
		||||
    GBinderDriver* self,
 | 
			
		||||
    const char* iface);
 | 
			
		||||
    GBinderDriver* driver,
 | 
			
		||||
    const char* iface)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_driver_local_request_new_ping(
 | 
			
		||||
    GBinderDriver* self)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_DRIVER_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										405
									
								
								src/gbinder_eventloop.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										405
									
								
								src/gbinder_eventloop.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,405 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2020-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2020-2021 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_eventloop_p.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_macros.h>
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_idle_callback_data {
 | 
			
		||||
    GBinderEventLoopCallback* cb;
 | 
			
		||||
    GBinderEventLoopCallbackFunc func;
 | 
			
		||||
    GDestroyNotify destroy;
 | 
			
		||||
    gpointer data;
 | 
			
		||||
} GBinderIdleCallbackData;
 | 
			
		||||
 | 
			
		||||
#define GBINDER_DEFAULT_EVENTLOOP (&gbinder_eventloop_glib)
 | 
			
		||||
 | 
			
		||||
static const GBinderEventLoopIntegration gbinder_eventloop_glib;
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * GLib event loop integration
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_eventloop_glib_timeout {
 | 
			
		||||
    GBinderEventLoopTimeout timeout;
 | 
			
		||||
    guint id;
 | 
			
		||||
    GSourceFunc func;
 | 
			
		||||
    gpointer data;
 | 
			
		||||
} GBinderEventLoopTimeoutGLib;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_eventloop_glib_callback {
 | 
			
		||||
    GSource source;
 | 
			
		||||
    GBinderEventLoopCallback callback;
 | 
			
		||||
} GBinderEventLoopCallbackGLib;
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
inline
 | 
			
		||||
GBinderEventLoopTimeoutGLib*
 | 
			
		||||
gbinder_eventloop_glib_timeout_cast(
 | 
			
		||||
    GBinderEventLoopTimeout* timeout)
 | 
			
		||||
{
 | 
			
		||||
    return G_CAST(timeout,GBinderEventLoopTimeoutGLib,timeout);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
inline
 | 
			
		||||
GSource*
 | 
			
		||||
gbinder_eventloop_glib_callback_source(
 | 
			
		||||
    GBinderEventLoopCallback* callback)
 | 
			
		||||
{
 | 
			
		||||
    return &(G_CAST(callback,GBinderEventLoopCallbackGLib,callback)->source);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_eventloop_glib_timeout_callback(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderEventLoopTimeoutGLib* timeout = data;
 | 
			
		||||
 | 
			
		||||
    return timeout->func(timeout->data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_eventloop_glib_timeout_finalize(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    g_slice_free1(sizeof(GBinderEventLoopTimeoutGLib), data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderEventLoopTimeout*
 | 
			
		||||
gbinder_eventloop_glib_timeout_add(
 | 
			
		||||
    guint interval,
 | 
			
		||||
    GSourceFunc func,
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderEventLoopTimeoutGLib* impl =
 | 
			
		||||
        g_slice_new(GBinderEventLoopTimeoutGLib);
 | 
			
		||||
 | 
			
		||||
    impl->timeout.eventloop = &gbinder_eventloop_glib;
 | 
			
		||||
    impl->func = func;
 | 
			
		||||
    impl->data = data;
 | 
			
		||||
    impl->id = g_timeout_add_full(G_PRIORITY_DEFAULT, interval,
 | 
			
		||||
        gbinder_eventloop_glib_timeout_callback, impl,
 | 
			
		||||
        gbinder_eventloop_glib_timeout_finalize);
 | 
			
		||||
    return &impl->timeout;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_eventloop_glib_timeout_remove(
 | 
			
		||||
    GBinderEventLoopTimeout* timeout)
 | 
			
		||||
{
 | 
			
		||||
    g_source_remove(gbinder_eventloop_glib_timeout_cast(timeout)->id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_eventloop_glib_callback_prepare(
 | 
			
		||||
    GSource* source,
 | 
			
		||||
    gint* timeout)
 | 
			
		||||
{
 | 
			
		||||
    *timeout = 0;
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_eventloop_glib_callback_check(
 | 
			
		||||
    GSource* source)
 | 
			
		||||
{
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_eventloop_glib_callback_dispatch(
 | 
			
		||||
    GSource* source,
 | 
			
		||||
    GSourceFunc callback,
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    ((GBinderEventLoopCallbackFunc)callback)(user_data);
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderEventLoopCallback*
 | 
			
		||||
gbinder_eventloop_glib_callback_new(
 | 
			
		||||
    GBinderEventLoopCallbackFunc func,
 | 
			
		||||
    gpointer data,
 | 
			
		||||
    GDestroyNotify finalize)
 | 
			
		||||
{
 | 
			
		||||
    static GSourceFuncs callback_funcs = {
 | 
			
		||||
        gbinder_eventloop_glib_callback_prepare,
 | 
			
		||||
        gbinder_eventloop_glib_callback_check,
 | 
			
		||||
        gbinder_eventloop_glib_callback_dispatch
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    GBinderEventLoopCallbackGLib* impl = (GBinderEventLoopCallbackGLib*)
 | 
			
		||||
        g_source_new(&callback_funcs, sizeof(GBinderEventLoopCallbackGLib));
 | 
			
		||||
 | 
			
		||||
    impl->callback.eventloop = &gbinder_eventloop_glib;
 | 
			
		||||
    g_source_set_callback(&impl->source, (GSourceFunc) func, data, finalize);
 | 
			
		||||
    return &impl->callback;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_eventloop_glib_callback_ref(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
{
 | 
			
		||||
    g_source_ref(gbinder_eventloop_glib_callback_source(cb));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_eventloop_glib_callback_unref(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
{
 | 
			
		||||
    g_source_unref(gbinder_eventloop_glib_callback_source(cb));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_eventloop_glib_callback_schedule(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
{
 | 
			
		||||
    static GMainContext* context = NULL;
 | 
			
		||||
 | 
			
		||||
    if (!context) context = g_main_context_default();
 | 
			
		||||
    g_source_attach(gbinder_eventloop_glib_callback_source(cb), context);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_eventloop_glib_callback_cancel(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
{
 | 
			
		||||
    g_source_destroy(gbinder_eventloop_glib_callback_source(cb));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_eventloop_glib_cleanup(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const GBinderEventLoopIntegration gbinder_eventloop_glib = {
 | 
			
		||||
    gbinder_eventloop_glib_timeout_add,
 | 
			
		||||
    gbinder_eventloop_glib_timeout_remove,
 | 
			
		||||
    gbinder_eventloop_glib_callback_new,
 | 
			
		||||
    gbinder_eventloop_glib_callback_ref,
 | 
			
		||||
    gbinder_eventloop_glib_callback_unref,
 | 
			
		||||
    gbinder_eventloop_glib_callback_schedule,
 | 
			
		||||
    gbinder_eventloop_glib_callback_cancel,
 | 
			
		||||
    gbinder_eventloop_glib_cleanup
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Implementation
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_invoke_proc(
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIdleCallbackData* idle = user_data;
 | 
			
		||||
 | 
			
		||||
    if (idle->func) {
 | 
			
		||||
        idle->func(idle->data);
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_idle_callback_unref(idle->cb);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_invoke_done(
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIdleCallbackData* idle = user_data;
 | 
			
		||||
 | 
			
		||||
    if (idle->destroy) {
 | 
			
		||||
        idle->destroy(idle->data);
 | 
			
		||||
    }
 | 
			
		||||
    gutil_slice_free(idle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Internal interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static const GBinderEventLoopIntegration* gbinder_eventloop =
 | 
			
		||||
    GBINDER_DEFAULT_EVENTLOOP;
 | 
			
		||||
 | 
			
		||||
GBinderEventLoopTimeout*
 | 
			
		||||
gbinder_timeout_add(
 | 
			
		||||
    guint interval,
 | 
			
		||||
    GSourceFunc function,
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_eventloop->timeout_add(interval, function, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderEventLoopTimeout*
 | 
			
		||||
gbinder_idle_add(
 | 
			
		||||
    GSourceFunc function,
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_eventloop->timeout_add(0, function, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_timeout_remove(
 | 
			
		||||
    GBinderEventLoopTimeout* timeout)
 | 
			
		||||
{
 | 
			
		||||
    if (timeout) {
 | 
			
		||||
        timeout->eventloop->timeout_remove(timeout);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderEventLoopCallback*
 | 
			
		||||
gbinder_idle_callback_new(
 | 
			
		||||
    GBinderEventLoopCallbackFunc func,
 | 
			
		||||
    gpointer data,
 | 
			
		||||
    GDestroyNotify finalize)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_eventloop->callback_new(func, data, finalize);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderEventLoopCallback*
 | 
			
		||||
gbinder_idle_callback_schedule_new(
 | 
			
		||||
    GBinderEventLoopCallbackFunc func,
 | 
			
		||||
    gpointer data,
 | 
			
		||||
    GDestroyNotify finalize)
 | 
			
		||||
{
 | 
			
		||||
    GBinderEventLoopCallback* cb =
 | 
			
		||||
        gbinder_eventloop->callback_new(func, data, finalize);
 | 
			
		||||
 | 
			
		||||
    gbinder_idle_callback_schedule(cb);
 | 
			
		||||
    return cb;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderEventLoopCallback*
 | 
			
		||||
gbinder_idle_callback_ref(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
{
 | 
			
		||||
    if (cb) {
 | 
			
		||||
        cb->eventloop->callback_ref(cb);
 | 
			
		||||
        return cb;
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_unref(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
{
 | 
			
		||||
    if (cb) {
 | 
			
		||||
        cb->eventloop->callback_unref(cb);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_schedule(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
{
 | 
			
		||||
    if (cb) {
 | 
			
		||||
        cb->eventloop->callback_schedule(cb);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_cancel(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
{
 | 
			
		||||
    if (cb) {
 | 
			
		||||
        cb->eventloop->callback_cancel(cb);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_destroy(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
{
 | 
			
		||||
    if (cb) {
 | 
			
		||||
        const GBinderEventLoopIntegration* eventloop = cb->eventloop;
 | 
			
		||||
 | 
			
		||||
        eventloop->callback_cancel(cb);
 | 
			
		||||
        eventloop->callback_unref(cb);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Non-cancellable callback */
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_invoke_later(
 | 
			
		||||
    GBinderEventLoopCallbackFunc func,
 | 
			
		||||
    gpointer data,
 | 
			
		||||
    GDestroyNotify destroy)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIdleCallbackData* idle = g_slice_new(GBinderIdleCallbackData);
 | 
			
		||||
 | 
			
		||||
    idle->func = func;
 | 
			
		||||
    idle->data = data;
 | 
			
		||||
    idle->destroy = destroy;
 | 
			
		||||
    idle->cb = gbinder_idle_callback_new(gbinder_idle_callback_invoke_proc,
 | 
			
		||||
        idle, gbinder_idle_callback_invoke_done);
 | 
			
		||||
    gbinder_idle_callback_schedule(idle->cb);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Public interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_eventloop_set(
 | 
			
		||||
    const GBinderEventLoopIntegration* loop)
 | 
			
		||||
{
 | 
			
		||||
    if (!loop) loop = GBINDER_DEFAULT_EVENTLOOP;
 | 
			
		||||
    if (gbinder_eventloop != loop) {
 | 
			
		||||
        const GBinderEventLoopIntegration* prev = gbinder_eventloop;
 | 
			
		||||
 | 
			
		||||
        gbinder_eventloop = loop;
 | 
			
		||||
        prev->cleanup();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										115
									
								
								src/gbinder_eventloop_p.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								src/gbinder_eventloop_p.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,115 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2020-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2020-2021 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_EVENTLOOP_PRIVATE_H
 | 
			
		||||
#define GBINDER_EVENTLOOP_PRIVATE_H
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
#include "gbinder_eventloop.h"
 | 
			
		||||
 | 
			
		||||
GBinderEventLoopTimeout*
 | 
			
		||||
gbinder_timeout_add(
 | 
			
		||||
    guint millis,
 | 
			
		||||
    GSourceFunc func,
 | 
			
		||||
    gpointer data)
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderEventLoopTimeout*
 | 
			
		||||
gbinder_idle_add(
 | 
			
		||||
    GSourceFunc func,
 | 
			
		||||
    gpointer data)
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_timeout_remove(
 | 
			
		||||
    GBinderEventLoopTimeout* timeout)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderEventLoopCallback*
 | 
			
		||||
gbinder_idle_callback_new(
 | 
			
		||||
    GBinderEventLoopCallbackFunc func,
 | 
			
		||||
    gpointer data,
 | 
			
		||||
    GDestroyNotify destroy)
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderEventLoopCallback*
 | 
			
		||||
gbinder_idle_callback_schedule_new(
 | 
			
		||||
    GBinderEventLoopCallbackFunc func,
 | 
			
		||||
    gpointer data,
 | 
			
		||||
    GDestroyNotify destroy)
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderEventLoopCallback*
 | 
			
		||||
gbinder_idle_callback_ref(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_unref(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_schedule(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_cancel(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_destroy(
 | 
			
		||||
    GBinderEventLoopCallback* cb)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_idle_callback_invoke_later(
 | 
			
		||||
    GBinderEventLoopCallbackFunc func,
 | 
			
		||||
    gpointer data,
 | 
			
		||||
    GDestroyNotify destroy)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_EVENTLOOP_PRIVATE_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-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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -13,9 +13,9 @@
 | 
			
		||||
 *   2. Redistributions in binary form must reproduce the above copyright
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer in the
 | 
			
		||||
 *      documentation and/or other materials provided with the distribution.
 | 
			
		||||
 *   3. Neither the name of Jolla Ltd nor the names of its contributors may
 | 
			
		||||
 *      be used to endorse or promote products derived from this software
 | 
			
		||||
 *      without specific prior written permission.
 | 
			
		||||
 *   3. Neither the names of the copyright holders nor the names of its
 | 
			
		||||
 *      contributors may be used to endorse or promote products derived
 | 
			
		||||
 *      from this software without specific prior written permission.
 | 
			
		||||
 *
 | 
			
		||||
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 | 
			
		||||
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 | 
			
		||||
@@ -36,6 +36,7 @@
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_handler_functions {
 | 
			
		||||
    gboolean (*can_loop)(GBinderHandler* handler);
 | 
			
		||||
    GBinderLocalReply* (*transact)(GBinderHandler* handler,
 | 
			
		||||
        GBinderLocalObject* obj, GBinderRemoteRequest* req, guint code,
 | 
			
		||||
        guint flags, int* status);
 | 
			
		||||
@@ -47,6 +48,14 @@ struct gbinder_handler {
 | 
			
		||||
 | 
			
		||||
/* Inline wrappers */
 | 
			
		||||
 | 
			
		||||
GBINDER_INLINE_FUNC
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_handler_can_loop(
 | 
			
		||||
    GBinderHandler* self)
 | 
			
		||||
{
 | 
			
		||||
    return self && self->f->can_loop && self->f->can_loop(self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBINDER_INLINE_FUNC
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_handler_transact(
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										181
									
								
								src/gbinder_io.c
									
									
									
									
									
								
							
							
						
						
									
										181
									
								
								src/gbinder_io.c
									
									
									
									
									
								
							@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -90,19 +90,49 @@ GBINDER_IO_FN(write_read)(
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Returns size of the object */
 | 
			
		||||
static
 | 
			
		||||
gsize
 | 
			
		||||
GBINDER_IO_FN(object_size)(
 | 
			
		||||
    const void* obj)
 | 
			
		||||
{
 | 
			
		||||
    if (obj) {
 | 
			
		||||
        const struct binder_object_header* hdr = obj;
 | 
			
		||||
 | 
			
		||||
        switch (hdr->type) {
 | 
			
		||||
        case BINDER_TYPE_BINDER:
 | 
			
		||||
        case BINDER_TYPE_WEAK_BINDER:
 | 
			
		||||
        case BINDER_TYPE_HANDLE:
 | 
			
		||||
        case BINDER_TYPE_WEAK_HANDLE:
 | 
			
		||||
            return sizeof(struct flat_binder_object);
 | 
			
		||||
        case BINDER_TYPE_FD:
 | 
			
		||||
            return sizeof(struct binder_fd_object);
 | 
			
		||||
        case BINDER_TYPE_FDA:
 | 
			
		||||
            return sizeof(struct binder_fd_array_object);
 | 
			
		||||
        case BINDER_TYPE_PTR:
 | 
			
		||||
            return sizeof(struct binder_buffer_object);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Returns size of the object's extra data */
 | 
			
		||||
static
 | 
			
		||||
gsize
 | 
			
		||||
GBINDER_IO_FN(object_data_size)(
 | 
			
		||||
    const void* obj)
 | 
			
		||||
{
 | 
			
		||||
    const struct binder_buffer_object* buf = obj;
 | 
			
		||||
    if (obj) {
 | 
			
		||||
        const struct binder_object_header* hdr = obj;
 | 
			
		||||
 | 
			
		||||
    if (buf && buf->hdr.type == BINDER_TYPE_PTR) {
 | 
			
		||||
        return buf->length;
 | 
			
		||||
    } else {
 | 
			
		||||
        return 0;
 | 
			
		||||
        switch (hdr->type) {
 | 
			
		||||
        case BINDER_TYPE_PTR:
 | 
			
		||||
            return ((struct binder_buffer_object*)obj)->length;
 | 
			
		||||
        case BINDER_TYPE_FDA:
 | 
			
		||||
            return ((struct binder_fd_array_object*)obj)->num_fds * 4;
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Writes pointer to the buffer */
 | 
			
		||||
@@ -118,7 +148,20 @@ GBINDER_IO_FN(encode_pointer)(
 | 
			
		||||
    return sizeof(*dest);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Encodes flat_buffer_object */
 | 
			
		||||
/* Writes cookie to the buffer */
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
GBINDER_IO_FN(encode_cookie)(
 | 
			
		||||
    void* out,
 | 
			
		||||
    guint64 cookie)
 | 
			
		||||
{
 | 
			
		||||
    binder_uintptr_t* dest = out;
 | 
			
		||||
 | 
			
		||||
    *dest = (uintptr_t)cookie;
 | 
			
		||||
    return sizeof(*dest);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Encodes flat_binder_object */
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
GBINDER_IO_FN(encode_local_object)(
 | 
			
		||||
@@ -163,12 +206,12 @@ GBINDER_IO_FN(encode_fd_object)(
 | 
			
		||||
    void* out,
 | 
			
		||||
    int fd)
 | 
			
		||||
{
 | 
			
		||||
    struct flat_binder_object* dest = out;
 | 
			
		||||
    struct binder_fd_object* dest = out;
 | 
			
		||||
 | 
			
		||||
    memset(dest, 0, sizeof(*dest));
 | 
			
		||||
    dest->hdr.type = BINDER_TYPE_FD;
 | 
			
		||||
    dest->flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
 | 
			
		||||
    dest->handle = fd;
 | 
			
		||||
    dest->pad_flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
 | 
			
		||||
    dest->fd = fd;
 | 
			
		||||
    return sizeof(*dest);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -197,7 +240,7 @@ GBINDER_IO_FN(encode_buffer_object)(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
GBINDER_IO_FN(encode_death_notification)(
 | 
			
		||||
GBINDER_IO_FN(encode_handle_cookie)(
 | 
			
		||||
    void* out,
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
{
 | 
			
		||||
@@ -209,7 +252,21 @@ GBINDER_IO_FN(encode_death_notification)(
 | 
			
		||||
    return sizeof(*dest);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Encodes BC_TRANSACTION data */
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
GBINDER_IO_FN(encode_ptr_cookie)(
 | 
			
		||||
    void* out,
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    struct binder_ptr_cookie* dest = out;
 | 
			
		||||
 | 
			
		||||
    /* We never send these cookies and don't expect them back */
 | 
			
		||||
    dest->ptr = (uintptr_t)obj;
 | 
			
		||||
    dest->cookie = 0;
 | 
			
		||||
    return sizeof(dest);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Fills binder_transaction_data for BC_TRANSACTION/REPLY */
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
GBINDER_IO_FN(fill_transaction_data)(
 | 
			
		||||
@@ -217,7 +274,7 @@ GBINDER_IO_FN(fill_transaction_data)(
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* payload,
 | 
			
		||||
    guint flags,
 | 
			
		||||
    guint tx_flags,
 | 
			
		||||
    GUtilIntArray* offsets,
 | 
			
		||||
    void** offsets_buf)
 | 
			
		||||
{
 | 
			
		||||
@@ -226,9 +283,7 @@ GBINDER_IO_FN(fill_transaction_data)(
 | 
			
		||||
    tr->code = code;
 | 
			
		||||
    tr->data_size = payload->len;
 | 
			
		||||
    tr->data.ptr.buffer = (uintptr_t)payload->data;
 | 
			
		||||
    if (flags & GBINDER_TX_FLAG_ONEWAY) {
 | 
			
		||||
        tr->flags |= TF_ONE_WAY;
 | 
			
		||||
    }
 | 
			
		||||
    tr->flags = tx_flags;
 | 
			
		||||
    if (offsets && offsets->count) {
 | 
			
		||||
        guint i;
 | 
			
		||||
        binder_size_t* tx_offsets = g_new(binder_size_t, offsets->count);
 | 
			
		||||
@@ -244,6 +299,7 @@ GBINDER_IO_FN(fill_transaction_data)(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Encodes BC_TRANSACTION data */
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
GBINDER_IO_FN(encode_transaction)(
 | 
			
		||||
@@ -257,7 +313,8 @@ GBINDER_IO_FN(encode_transaction)(
 | 
			
		||||
{
 | 
			
		||||
    struct binder_transaction_data* tr = out;
 | 
			
		||||
 | 
			
		||||
    GBINDER_IO_FN(fill_transaction_data)(tr, handle, code, payload, flags,
 | 
			
		||||
    GBINDER_IO_FN(fill_transaction_data)(tr, handle, code, payload,
 | 
			
		||||
        (flags & GBINDER_TX_FLAG_ONEWAY) ? TF_ONE_WAY : TF_ACCEPT_FDS,
 | 
			
		||||
        offsets, offsets_buf);
 | 
			
		||||
    return sizeof(*tr);
 | 
			
		||||
}
 | 
			
		||||
@@ -278,13 +335,53 @@ GBINDER_IO_FN(encode_transaction_sg)(
 | 
			
		||||
    struct binder_transaction_data_sg* sg = out;
 | 
			
		||||
 | 
			
		||||
    GBINDER_IO_FN(fill_transaction_data)(&sg->transaction_data, handle, code,
 | 
			
		||||
        payload, flags, offsets, offsets_buf);
 | 
			
		||||
        payload, (flags & GBINDER_TX_FLAG_ONEWAY) ? TF_ONE_WAY : TF_ACCEPT_FDS,
 | 
			
		||||
        offsets, offsets_buf);
 | 
			
		||||
    /* The driver seems to require buffers to be 8-byte aligned */
 | 
			
		||||
    sg->buffers_size = G_ALIGN8(buffers_size);
 | 
			
		||||
    return sizeof(*sg);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Encode BC_REPLY */
 | 
			
		||||
/* Encodes BC_REPLY data */
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
GBINDER_IO_FN(encode_reply)(
 | 
			
		||||
    void* out,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* payload,
 | 
			
		||||
    GUtilIntArray* offsets,
 | 
			
		||||
    void** offsets_buf)
 | 
			
		||||
{
 | 
			
		||||
    struct binder_transaction_data* tr = out;
 | 
			
		||||
 | 
			
		||||
    GBINDER_IO_FN(fill_transaction_data)(tr, handle, code, payload, 0,
 | 
			
		||||
        offsets, offsets_buf);
 | 
			
		||||
    return sizeof(*tr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Encodes BC_REPLY_SG data */
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
GBINDER_IO_FN(encode_reply_sg)(
 | 
			
		||||
    void* out,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    const GByteArray* payload,
 | 
			
		||||
    GUtilIntArray* offsets,
 | 
			
		||||
    void** offsets_buf,
 | 
			
		||||
    gsize buffers_size)
 | 
			
		||||
{
 | 
			
		||||
    struct binder_transaction_data_sg* sg = out;
 | 
			
		||||
 | 
			
		||||
    GBINDER_IO_FN(fill_transaction_data)(&sg->transaction_data, handle, code,
 | 
			
		||||
        payload, 0, offsets, offsets_buf);
 | 
			
		||||
    /* The driver seems to require buffers to be 8-byte aligned */
 | 
			
		||||
    sg->buffers_size = G_ALIGN8(buffers_size);
 | 
			
		||||
    return sizeof(*sg);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Encode BC_REPLY with just status */
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
GBINDER_IO_FN(encode_status_reply)(
 | 
			
		||||
@@ -372,7 +469,7 @@ GBINDER_IO_FN(decode_cookie)(
 | 
			
		||||
/* Decode struct binder_ptr_cookie */
 | 
			
		||||
static
 | 
			
		||||
void*
 | 
			
		||||
GBINDER_IO_FN(decode_binder_ptr_cookie)(
 | 
			
		||||
GBINDER_IO_FN(decode_ptr_cookie)(
 | 
			
		||||
    const void* data)
 | 
			
		||||
{
 | 
			
		||||
    const struct binder_ptr_cookie* ptr = data;
 | 
			
		||||
@@ -382,6 +479,24 @@ GBINDER_IO_FN(decode_binder_ptr_cookie)(
 | 
			
		||||
    return (void*)(uintptr_t)ptr->ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
GBINDER_IO_FN(decode_binder_handle)(
 | 
			
		||||
    const void* data,
 | 
			
		||||
    guint32* handle)
 | 
			
		||||
{
 | 
			
		||||
    const struct flat_binder_object* obj = data;
 | 
			
		||||
 | 
			
		||||
    /* Caller guarantees that data points to an object */
 | 
			
		||||
    if (obj->hdr.type == BINDER_TYPE_HANDLE) {
 | 
			
		||||
        if (handle) {
 | 
			
		||||
            *handle = obj->handle;
 | 
			
		||||
        }
 | 
			
		||||
        return sizeof(*obj);
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
GBINDER_IO_FN(decode_binder_object)(
 | 
			
		||||
@@ -396,9 +511,19 @@ GBINDER_IO_FN(decode_binder_object)(
 | 
			
		||||
        switch (obj->hdr.type) {
 | 
			
		||||
        case BINDER_TYPE_HANDLE:
 | 
			
		||||
            if (out) {
 | 
			
		||||
                *out = gbinder_object_registry_get_remote(reg, obj->handle);
 | 
			
		||||
                *out = gbinder_object_registry_get_remote(reg, obj->handle,
 | 
			
		||||
                    REMOTE_REGISTRY_CAN_CREATE_AND_ACQUIRE);
 | 
			
		||||
            }
 | 
			
		||||
            return sizeof(*obj);
 | 
			
		||||
        case BINDER_TYPE_BINDER:
 | 
			
		||||
            if (!obj->binder) {
 | 
			
		||||
                /* That's a NULL reference */
 | 
			
		||||
                if (out) {
 | 
			
		||||
                    *out = NULL;
 | 
			
		||||
                }
 | 
			
		||||
                return sizeof(*obj);
 | 
			
		||||
            }
 | 
			
		||||
            /* fallthrough */
 | 
			
		||||
        default:
 | 
			
		||||
            GERR("Unsupported binder object type 0x%08x", obj->hdr.type);
 | 
			
		||||
            break;
 | 
			
		||||
@@ -503,23 +628,29 @@ const GBinderIo GBINDER_IO_PREFIX = {
 | 
			
		||||
        .failed_reply = BR_FAILED_REPLY
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    .object_size = GBINDER_IO_FN(object_size),
 | 
			
		||||
    .object_data_size = GBINDER_IO_FN(object_data_size),
 | 
			
		||||
 | 
			
		||||
    /* Encoders */
 | 
			
		||||
    .encode_pointer = GBINDER_IO_FN(encode_pointer),
 | 
			
		||||
    .encode_cookie = GBINDER_IO_FN(encode_cookie),
 | 
			
		||||
    .encode_local_object = GBINDER_IO_FN(encode_local_object),
 | 
			
		||||
    .encode_remote_object = GBINDER_IO_FN(encode_remote_object),
 | 
			
		||||
    .encode_fd_object = GBINDER_IO_FN(encode_fd_object),
 | 
			
		||||
    .encode_buffer_object = GBINDER_IO_FN(encode_buffer_object),
 | 
			
		||||
    .encode_death_notification = GBINDER_IO_FN(encode_death_notification),
 | 
			
		||||
    .encode_handle_cookie = GBINDER_IO_FN(encode_handle_cookie),
 | 
			
		||||
    .encode_ptr_cookie = GBINDER_IO_FN(encode_ptr_cookie),
 | 
			
		||||
    .encode_transaction = GBINDER_IO_FN(encode_transaction),
 | 
			
		||||
    .encode_transaction_sg = GBINDER_IO_FN(encode_transaction_sg),
 | 
			
		||||
    .encode_reply = GBINDER_IO_FN(encode_reply),
 | 
			
		||||
    .encode_reply_sg = GBINDER_IO_FN(encode_reply_sg),
 | 
			
		||||
    .encode_status_reply = GBINDER_IO_FN(encode_status_reply),
 | 
			
		||||
 | 
			
		||||
    /* Decoders */
 | 
			
		||||
    .decode_transaction_data = GBINDER_IO_FN(decode_transaction_data),
 | 
			
		||||
    .decode_cookie = GBINDER_IO_FN(decode_cookie),
 | 
			
		||||
    .decode_binder_ptr_cookie = GBINDER_IO_FN(decode_binder_ptr_cookie),
 | 
			
		||||
    .decode_ptr_cookie = GBINDER_IO_FN(decode_ptr_cookie),
 | 
			
		||||
    .decode_binder_handle = GBINDER_IO_FN(decode_binder_handle),
 | 
			
		||||
    .decode_binder_object = GBINDER_IO_FN(decode_binder_object),
 | 
			
		||||
    .decode_buffer_object = GBINDER_IO_FN(decode_buffer_object),
 | 
			
		||||
    .decode_fd_object = GBINDER_IO_FN(decode_fd_object),
 | 
			
		||||
@@ -535,7 +666,7 @@ G_STATIC_ASSERT(sizeof(struct flat_binder_object) <=
 | 
			
		||||
G_STATIC_ASSERT(sizeof(struct binder_buffer_object) <=
 | 
			
		||||
    GBINDER_MAX_BUFFER_OBJECT_SIZE);
 | 
			
		||||
G_STATIC_ASSERT(sizeof(struct binder_handle_cookie) <=
 | 
			
		||||
    GBINDER_MAX_DEATH_NOTIFICATION_SIZE);
 | 
			
		||||
    GBINDER_MAX_HANDLE_COOKIE_SIZE);
 | 
			
		||||
G_STATIC_ASSERT(sizeof(struct binder_transaction_data) <=
 | 
			
		||||
    GBINDER_MAX_BC_TRANSACTION_SIZE);
 | 
			
		||||
G_STATIC_ASSERT(sizeof(struct binder_transaction_data_sg) <=
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -125,7 +125,8 @@ struct gbinder_io {
 | 
			
		||||
        guint failed_reply;
 | 
			
		||||
    } br;
 | 
			
		||||
 | 
			
		||||
    /* Size of the object's extra data */
 | 
			
		||||
    /* Size of the object and its extra data */
 | 
			
		||||
    gsize (*object_size)(const void* obj);
 | 
			
		||||
    gsize (*object_data_size)(const void* obj);
 | 
			
		||||
 | 
			
		||||
    /* Writes pointer to the buffer. The destination buffer must have
 | 
			
		||||
@@ -134,6 +135,12 @@ struct gbinder_io {
 | 
			
		||||
#define GBINDER_MAX_POINTER_SIZE (8)
 | 
			
		||||
    guint (*encode_pointer)(void* out, const void* pointer);
 | 
			
		||||
 | 
			
		||||
    /* Writes cookie to the buffer. The destination buffer must have
 | 
			
		||||
     * at least GBINDER_IO_MAX_COOKIE_SIZE bytes available. The
 | 
			
		||||
     * actual size is returned. */
 | 
			
		||||
#define GBINDER_MAX_COOKIE_SIZE GBINDER_MAX_POINTER_SIZE
 | 
			
		||||
    guint (*encode_cookie)(void* out, guint64 cookie);
 | 
			
		||||
 | 
			
		||||
    /* Encode flat_buffer_object */
 | 
			
		||||
#define GBINDER_MAX_BINDER_OBJECT_SIZE (24)
 | 
			
		||||
    guint (*encode_local_object)(void* out, GBinderLocalObject* obj);
 | 
			
		||||
@@ -145,32 +152,42 @@ struct gbinder_io {
 | 
			
		||||
    guint (*encode_buffer_object)(void* out, const void* data, gsize size,
 | 
			
		||||
        const GBinderParent* parent);
 | 
			
		||||
 | 
			
		||||
    /* Encode death notification */
 | 
			
		||||
#define GBINDER_MAX_DEATH_NOTIFICATION_SIZE (12)
 | 
			
		||||
    guint (*encode_death_notification)(void* out, GBinderRemoteObject* obj);
 | 
			
		||||
    /* Encode binder_handle_cookie */
 | 
			
		||||
#define GBINDER_MAX_HANDLE_COOKIE_SIZE (12)
 | 
			
		||||
    guint (*encode_handle_cookie)(void* out, GBinderRemoteObject* obj);
 | 
			
		||||
 | 
			
		||||
    /* Encode BC_TRANSACTION/REPLY data */
 | 
			
		||||
    /* Encode binder_ptr_cookie */
 | 
			
		||||
#define GBINDER_MAX_PTR_COOKIE_SIZE (16)
 | 
			
		||||
    guint (*encode_ptr_cookie)(void* out, GBinderLocalObject* obj);
 | 
			
		||||
 | 
			
		||||
    /* Encode BC_TRANSACTION/BC_TRANSACTION_SG data */
 | 
			
		||||
#define GBINDER_MAX_BC_TRANSACTION_SIZE (64)
 | 
			
		||||
    guint (*encode_transaction)(void* out, guint32 handle, guint32 code,
 | 
			
		||||
        const GByteArray* data, guint flags /* See below */,
 | 
			
		||||
        GUtilIntArray* offsets, void** offsets_buf);
 | 
			
		||||
 | 
			
		||||
    /* Encode BC_TRANSACTION_SG/REPLY_SG data */
 | 
			
		||||
#define GBINDER_MAX_BC_TRANSACTION_SG_SIZE (72)
 | 
			
		||||
    guint (*encode_transaction_sg)(void* out, guint32 handle, guint32 code,
 | 
			
		||||
        const GByteArray* data, guint flags /* GBINDER_TX_FLAG_xxx */,
 | 
			
		||||
        GUtilIntArray* offsets, void** offsets_buf,
 | 
			
		||||
        gsize buffers_size);
 | 
			
		||||
 | 
			
		||||
    /* Encode BC_REPLY/REPLY_SG data */
 | 
			
		||||
#define GBINDER_MAX_BC_REPLY_SIZE GBINDER_MAX_BC_TRANSACTION_SIZE
 | 
			
		||||
    guint (*encode_reply)(void* out, guint32 handle, guint32 code,
 | 
			
		||||
        const GByteArray* data, GUtilIntArray* offsets, void** offsets_buf);
 | 
			
		||||
#define GBINDER_MAX_BC_REPLY_SG_SIZE GBINDER_MAX_BC_TRANSACTION_SG_SIZE
 | 
			
		||||
    guint (*encode_reply_sg)(void* out, guint32 handle, guint32 code,
 | 
			
		||||
        const GByteArray* data, GUtilIntArray* offsets, void** offsets_buf,
 | 
			
		||||
        gsize buffers_size);
 | 
			
		||||
 | 
			
		||||
    /* Encode BC_REPLY */
 | 
			
		||||
    guint (*encode_status_reply)(void* out, gint32* status);
 | 
			
		||||
 | 
			
		||||
    /* Decoders */
 | 
			
		||||
    void (*decode_transaction_data)(const void* data, GBinderIoTxData* tx);
 | 
			
		||||
 | 
			
		||||
#define GBINDER_MAX_PTR_COOKIE_SIZE (16)
 | 
			
		||||
    void* (*decode_binder_ptr_cookie)(const void* data);
 | 
			
		||||
    void* (*decode_ptr_cookie)(const void* data);
 | 
			
		||||
    guint (*decode_cookie)(const void* data, guint64* cookie);
 | 
			
		||||
    guint (*decode_binder_handle)(const void* obj, guint32* handle);
 | 
			
		||||
    guint (*decode_binder_object)(const void* data, gsize size,
 | 
			
		||||
        GBinderObjectRegistry* reg, GBinderRemoteObject** obj);
 | 
			
		||||
    guint (*decode_buffer_object)(GBinderBuffer* buf, gsize offset,
 | 
			
		||||
@@ -181,8 +198,8 @@ struct gbinder_io {
 | 
			
		||||
    int (*write_read)(int fd, GBinderIoBuf* write, GBinderIoBuf* read);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern const GBinderIo gbinder_io_32;
 | 
			
		||||
extern const GBinderIo gbinder_io_64;
 | 
			
		||||
extern const GBinderIo gbinder_io_32 GBINDER_INTERNAL;
 | 
			
		||||
extern const GBinderIo gbinder_io_64 GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_IO_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1149
									
								
								src/gbinder_ipc.c
									
									
									
									
									
								
							
							
						
						
									
										1149
									
								
								src/gbinder_ipc.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -42,7 +42,6 @@ struct gbinder_ipc {
 | 
			
		||||
    GObject object;
 | 
			
		||||
    GBinderIpcPriv* priv;
 | 
			
		||||
    GBinderDriver* driver;
 | 
			
		||||
    GUtilIdlePool* pool;
 | 
			
		||||
    const char* dev;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -60,6 +59,12 @@ struct gbinder_ipc_tx {
 | 
			
		||||
    void* user_data;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
gboolean
 | 
			
		||||
(*GBinderIpcLocalObjectCheckFunc)(
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
void
 | 
			
		||||
(*GBinderIpcReplyFunc)(
 | 
			
		||||
@@ -68,53 +73,99 @@ void
 | 
			
		||||
    int status,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
 | 
			
		||||
GBinderIpc*
 | 
			
		||||
gbinder_ipc_new(
 | 
			
		||||
   const char* dev,
 | 
			
		||||
   const GBinderRpcProtocol* protocol);
 | 
			
		||||
 | 
			
		||||
GBinderIpc*
 | 
			
		||||
gbinder_ipc_ref(
 | 
			
		||||
    GBinderIpc* ipc);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_unref(
 | 
			
		||||
    GBinderIpc* ipc);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_looper_check(
 | 
			
		||||
   GBinderIpc* ipc);
 | 
			
		||||
 | 
			
		||||
GBinderObjectRegistry*
 | 
			
		||||
gbinder_ipc_object_registry(
 | 
			
		||||
    GBinderIpc* ipc);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_register_local_object(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_ipc_get_remote_object(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    gboolean maybe_dead);
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
GBinderRemoteReply*
 | 
			
		||||
gbinder_ipc_transact_sync_reply(
 | 
			
		||||
(*GBinderIpcSyncReplyFunc)(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    GBinderLocalRequest* req,
 | 
			
		||||
    int* status);
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
int
 | 
			
		||||
gbinder_ipc_transact_sync_oneway(
 | 
			
		||||
(*GBinderIpcSyncOnewayFunc)(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    guint32 code,
 | 
			
		||||
    GBinderLocalRequest* req);
 | 
			
		||||
 | 
			
		||||
struct gbinder_ipc_sync_api {
 | 
			
		||||
    GBinderIpcSyncReplyFunc sync_reply;
 | 
			
		||||
    GBinderIpcSyncOnewayFunc sync_oneway;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern const GBinderIpcSyncApi gbinder_ipc_sync_main GBINDER_INTERNAL;
 | 
			
		||||
extern const GBinderIpcSyncApi gbinder_ipc_sync_worker GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderIpc*
 | 
			
		||||
gbinder_ipc_new(
 | 
			
		||||
    const char* dev)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderIpc*
 | 
			
		||||
gbinder_ipc_ref(
 | 
			
		||||
    GBinderIpc* ipc)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_unref(
 | 
			
		||||
    GBinderIpc* ipc)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_looper_check(
 | 
			
		||||
    GBinderIpc* ipc)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderObjectRegistry*
 | 
			
		||||
gbinder_ipc_object_registry(
 | 
			
		||||
    GBinderIpc* ipc)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
const GBinderIo*
 | 
			
		||||
gbinder_ipc_io(
 | 
			
		||||
    GBinderIpc* ipc)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
const GBinderRpcProtocol*
 | 
			
		||||
gbinder_ipc_protocol(
 | 
			
		||||
    GBinderIpc* ipc)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_ipc_find_local_object(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    GBinderIpcLocalObjectCheckFunc func,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
    GBINDER_INTERNAL
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_register_local_object(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_ipc_get_service_manager(
 | 
			
		||||
    GBinderIpc* self)
 | 
			
		||||
    GBINDER_INTERNAL
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_invalidate_remote_handle(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_ipc_ping_sync(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_ipc_transact(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
@@ -124,7 +175,8 @@ gbinder_ipc_transact(
 | 
			
		||||
    GBinderLocalRequest* req,
 | 
			
		||||
    GBinderIpcReplyFunc func,
 | 
			
		||||
    GDestroyNotify destroy,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
    void* user_data)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_ipc_transact_custom(
 | 
			
		||||
@@ -132,24 +184,42 @@ gbinder_ipc_transact_custom(
 | 
			
		||||
    GBinderIpcTxFunc exec,
 | 
			
		||||
    GBinderIpcTxFunc done,
 | 
			
		||||
    GDestroyNotify destroy,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
    void* user_data)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_cancel(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    gulong id);
 | 
			
		||||
    gulong id)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
/* Internal for GBinderLocalObject */
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_local_object_disposed(
 | 
			
		||||
    GBinderIpc* self,
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
/* Internal for GBinderRemoteObject */
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_remote_object_disposed(
 | 
			
		||||
    GBinderIpc* self,
 | 
			
		||||
    GBinderRemoteObject* obj);
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
/* Needed by unit tests */
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_ipc_set_max_threads(
 | 
			
		||||
    GBinderIpc* self,
 | 
			
		||||
    gint max_threads)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
/* Declared for unit tests */
 | 
			
		||||
void
 | 
			
		||||
gbinder_ipc_exit(
 | 
			
		||||
    void)
 | 
			
		||||
    GBINDER_INTERNAL
 | 
			
		||||
    GBINDER_DESTRUCTOR;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_IPC_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -30,27 +30,37 @@
 | 
			
		||||
 * THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define GLIB_DISABLE_DEPRECATION_WARNINGS
 | 
			
		||||
 | 
			
		||||
#include "gbinder_driver.h"
 | 
			
		||||
#include "gbinder_ipc.h"
 | 
			
		||||
#include "gbinder_buffer_p.h"
 | 
			
		||||
#include "gbinder_local_object_p.h"
 | 
			
		||||
#include "gbinder_local_reply_p.h"
 | 
			
		||||
#include "gbinder_remote_request.h"
 | 
			
		||||
#include "gbinder_eventloop_p.h"
 | 
			
		||||
#include "gbinder_writer.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_strv.h>
 | 
			
		||||
#include <gutil_macros.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
struct gbinder_local_object_priv {
 | 
			
		||||
    GMainContext* context;
 | 
			
		||||
    char** ifaces;
 | 
			
		||||
    GBinderLocalTransactFunc txproc;
 | 
			
		||||
    void* user_data;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_local_object_acquire_data {
 | 
			
		||||
    GBinderLocalObject* object;
 | 
			
		||||
    GBinderBufferContentsList* bufs;
 | 
			
		||||
} GBinderLocalObjectAcquireData;
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE(GBinderLocalObject, gbinder_local_object, G_TYPE_OBJECT)
 | 
			
		||||
 | 
			
		||||
#define PARENT_CLASS gbinder_local_object_parent_class
 | 
			
		||||
#define GBINDER_LOCAL_OBJECT_GET_CLASS(obj) \
 | 
			
		||||
    G_TYPE_INSTANCE_GET_CLASS((obj), GBINDER_TYPE_LOCAL_OBJECT, \
 | 
			
		||||
    GBinderLocalObjectClass)
 | 
			
		||||
@@ -254,73 +264,115 @@ gbinder_local_object_default_handle_looper_transaction(
 | 
			
		||||
    return handler(self, req, status);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_default_drop(
 | 
			
		||||
    GBinderLocalObject* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    /* Clear the transaction callback */
 | 
			
		||||
    priv->txproc = NULL;
 | 
			
		||||
    priv->user_data = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_handle_later(
 | 
			
		||||
    GBinderLocalObject* self,
 | 
			
		||||
    GSourceFunc function)
 | 
			
		||||
    GBinderEventLoopCallbackFunc function)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderLocalObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
        g_main_context_invoke_full(priv->context, G_PRIORITY_DEFAULT, function,
 | 
			
		||||
        gbinder_idle_callback_invoke_later(function,
 | 
			
		||||
            gbinder_local_object_ref(self), g_object_unref);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_local_object_handle_increfs_proc(
 | 
			
		||||
    gpointer local)
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_increfs_proc(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(local);
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(user_data);
 | 
			
		||||
 | 
			
		||||
    self->weak_refs++;
 | 
			
		||||
    g_signal_emit(self, gbinder_local_object_signals
 | 
			
		||||
        [SIGNAL_WEAK_REFS_CHANGED], 0);
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_local_object_handle_decrefs_proc(
 | 
			
		||||
    gpointer local)
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_decrefs_proc(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(local);
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(user_data);
 | 
			
		||||
 | 
			
		||||
    GASSERT(self->weak_refs > 0);
 | 
			
		||||
    self->weak_refs--;
 | 
			
		||||
    g_signal_emit(self, gbinder_local_object_signals
 | 
			
		||||
        [SIGNAL_WEAK_REFS_CHANGED], 0);
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_local_object_handle_acquire_proc(
 | 
			
		||||
    gpointer local)
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_default_acquire(
 | 
			
		||||
    GBinderLocalObject* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(local);
 | 
			
		||||
 | 
			
		||||
    self->strong_refs++;
 | 
			
		||||
    gbinder_local_object_ref(self);
 | 
			
		||||
    GVERBOSE_("%p => %d", self, self->strong_refs);
 | 
			
		||||
    g_signal_emit(self, gbinder_local_object_signals
 | 
			
		||||
        [SIGNAL_STRONG_REFS_CHANGED], 0);
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_local_object_handle_release_proc(
 | 
			
		||||
    gpointer local)
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_acquire_proc(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(local);
 | 
			
		||||
    GBinderLocalObjectAcquireData* data = user_data;
 | 
			
		||||
    GBinderLocalObject* self = data->object;
 | 
			
		||||
 | 
			
		||||
    GASSERT(self->strong_refs > 0);
 | 
			
		||||
    self->strong_refs--;
 | 
			
		||||
    g_signal_emit(self, gbinder_local_object_signals
 | 
			
		||||
        [SIGNAL_STRONG_REFS_CHANGED], 0);
 | 
			
		||||
    GBINDER_LOCAL_OBJECT_GET_CLASS(self)->acquire(self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_acquire_done(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObjectAcquireData* data = user_data;
 | 
			
		||||
    GBinderLocalObject* self = data->object;
 | 
			
		||||
 | 
			
		||||
    gbinder_driver_acquire_done(self->ipc->driver, self);
 | 
			
		||||
    gbinder_local_object_unref(self);
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
    gbinder_buffer_contents_list_free(data->bufs);
 | 
			
		||||
    return gutil_slice_free(data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_default_release(
 | 
			
		||||
    GBinderLocalObject* self)
 | 
			
		||||
{
 | 
			
		||||
    GASSERT(self->strong_refs > 0);
 | 
			
		||||
    if (self->strong_refs > 0) {
 | 
			
		||||
        self->strong_refs--;
 | 
			
		||||
        GVERBOSE_("%p => %d", self, self->strong_refs);
 | 
			
		||||
        g_signal_emit(self, gbinder_local_object_signals
 | 
			
		||||
            [SIGNAL_STRONG_REFS_CHANGED], 0);
 | 
			
		||||
        gbinder_local_object_unref(self);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_release_proc(
 | 
			
		||||
    gpointer obj)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(obj);
 | 
			
		||||
 | 
			
		||||
    GBINDER_LOCAL_OBJECT_GET_CLASS(self)->release(self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -333,42 +385,65 @@ gbinder_local_object_new(
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderLocalTransactFunc txproc,
 | 
			
		||||
    void* user_data) /* Since 1.0.30 */
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_local_object_new_with_type(GBINDER_TYPE_LOCAL_OBJECT,
 | 
			
		||||
        ipc, ifaces, txproc, user_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_local_object_new_with_type(
 | 
			
		||||
    GType type,
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderLocalTransactFunc txproc,
 | 
			
		||||
    void* arg)
 | 
			
		||||
{
 | 
			
		||||
    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;
 | 
			
		||||
        GBinderLocalObject* obj = g_object_new(type, NULL);
 | 
			
		||||
 | 
			
		||||
        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->ifaces = (const char**)priv->ifaces;
 | 
			
		||||
        priv->txproc = txproc;
 | 
			
		||||
        priv->user_data = user_data;
 | 
			
		||||
        gbinder_ipc_register_local_object(ipc, self);
 | 
			
		||||
        return self;
 | 
			
		||||
        gbinder_local_object_init_base(obj, ipc, ifaces, txproc, arg);
 | 
			
		||||
        gbinder_ipc_register_local_object(ipc, obj);
 | 
			
		||||
        return obj;
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_init_base(
 | 
			
		||||
    GBinderLocalObject* self,
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderLocalTransactFunc txproc,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    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->ifaces = (const char**)priv->ifaces;
 | 
			
		||||
    priv->txproc = txproc;
 | 
			
		||||
    priv->user_data = user_data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_local_object_ref(
 | 
			
		||||
    GBinderLocalObject* self)
 | 
			
		||||
@@ -395,11 +470,7 @@ gbinder_local_object_drop(
 | 
			
		||||
    GBinderLocalObject* self)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderLocalObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
        /* Clear the transaction callback */
 | 
			
		||||
        priv->txproc = NULL;
 | 
			
		||||
        priv->user_data = NULL;
 | 
			
		||||
        GBINDER_LOCAL_OBJECT_GET_CLASS(self)->drop(self);
 | 
			
		||||
        g_object_unref(GBINDER_LOCAL_OBJECT(self));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -493,33 +564,49 @@ void
 | 
			
		||||
gbinder_local_object_handle_increfs(
 | 
			
		||||
    GBinderLocalObject* self)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_local_object_handle_later(self,
 | 
			
		||||
        gbinder_local_object_handle_increfs_proc);
 | 
			
		||||
    gbinder_local_object_handle_later(self, gbinder_local_object_increfs_proc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_handle_decrefs(
 | 
			
		||||
    GBinderLocalObject* self)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_local_object_handle_later(self,
 | 
			
		||||
        gbinder_local_object_handle_decrefs_proc);
 | 
			
		||||
    gbinder_local_object_handle_later(self, gbinder_local_object_decrefs_proc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_handle_acquire(
 | 
			
		||||
    GBinderLocalObject* self)
 | 
			
		||||
    GBinderLocalObject* self,
 | 
			
		||||
    GBinderBufferContentsList* bufs)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_local_object_ref(self);
 | 
			
		||||
    gbinder_local_object_handle_later(self,
 | 
			
		||||
        gbinder_local_object_handle_acquire_proc);
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderLocalObjectAcquireData* data =
 | 
			
		||||
            g_slice_new(GBinderLocalObjectAcquireData);
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * This is a bit complicated :)
 | 
			
		||||
         * GBinderProxyObject derived from GBinderLocalObject acquires a
 | 
			
		||||
         * reference to the remote object in addition to performing the
 | 
			
		||||
         * default GBinderLocalObject action later on the main thread.
 | 
			
		||||
         * We must ensure that remote object doesn't go away before we
 | 
			
		||||
         * acquire our reference to it. One of the references to that
 | 
			
		||||
         * remote object (possibly the last one) may be associated with
 | 
			
		||||
         * the transaction buffer contained in GBinderBufferContentsList.
 | 
			
		||||
         * We don't know exactly which one we need, so we keep all those
 | 
			
		||||
         * buffers alive until we are done with BR_ACQUIRE.
 | 
			
		||||
         */
 | 
			
		||||
        data->object = gbinder_local_object_ref(self);
 | 
			
		||||
        data->bufs = gbinder_buffer_contents_list_dup(bufs);
 | 
			
		||||
        gbinder_idle_callback_invoke_later(gbinder_local_object_acquire_proc,
 | 
			
		||||
            data, gbinder_local_object_acquire_done);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_handle_release(
 | 
			
		||||
    GBinderLocalObject* self)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_local_object_handle_later(self,
 | 
			
		||||
        gbinder_local_object_handle_release_proc);
 | 
			
		||||
    gbinder_local_object_handle_later(self, gbinder_local_object_release_proc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -534,33 +621,32 @@ gbinder_local_object_init(
 | 
			
		||||
    GBinderLocalObjectPriv* priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
 | 
			
		||||
        GBINDER_TYPE_LOCAL_OBJECT, GBinderLocalObjectPriv);
 | 
			
		||||
 | 
			
		||||
    priv->context = g_main_context_default();
 | 
			
		||||
    self->priv = priv;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_dispose(
 | 
			
		||||
    GObject* local)
 | 
			
		||||
    GObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(local);
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(object);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_local_object_disposed(self->ipc, self);
 | 
			
		||||
    G_OBJECT_CLASS(gbinder_local_object_parent_class)->dispose(local);
 | 
			
		||||
    G_OBJECT_CLASS(PARENT_CLASS)->dispose(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_finalize(
 | 
			
		||||
    GObject* local)
 | 
			
		||||
    GObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(local);
 | 
			
		||||
    GBinderLocalObject* self = GBINDER_LOCAL_OBJECT(object);
 | 
			
		||||
    GBinderLocalObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    GASSERT(!self->strong_refs);
 | 
			
		||||
    gbinder_ipc_unref(self->ipc);
 | 
			
		||||
    g_strfreev(priv->ifaces);
 | 
			
		||||
    G_OBJECT_CLASS(gbinder_local_object_parent_class)->finalize(local);
 | 
			
		||||
    G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -580,6 +666,9 @@ gbinder_local_object_class_init(
 | 
			
		||||
        gbinder_local_object_default_handle_looper_transaction;
 | 
			
		||||
    klass->can_handle_transaction =
 | 
			
		||||
        gbinder_local_object_default_can_handle_transaction;
 | 
			
		||||
    klass->acquire = gbinder_local_object_default_acquire;
 | 
			
		||||
    klass->release = gbinder_local_object_default_release;
 | 
			
		||||
    klass->drop = gbinder_local_object_default_drop;
 | 
			
		||||
 | 
			
		||||
    gbinder_local_object_signals[SIGNAL_WEAK_REFS_CHANGED] =
 | 
			
		||||
        g_signal_new(SIGNAL_WEAK_REFS_CHANGED_NAME,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -40,8 +40,9 @@
 | 
			
		||||
#include <glib-object.h>
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Some if this stuff may become public if we decide to allow the clients
 | 
			
		||||
 * to derive their classes from GBinderLocalObject
 | 
			
		||||
 * Some of this stuff may become public if we decide to allow the clients
 | 
			
		||||
 * to derive their own classes from GBinderLocalObject. For now it's all
 | 
			
		||||
 * private.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
@@ -76,39 +77,66 @@ typedef struct gbinder_local_object_class {
 | 
			
		||||
    GBinderLocalReply* (*handle_looper_transaction)
 | 
			
		||||
        (GBinderLocalObject* self, GBinderRemoteRequest* req, guint code,
 | 
			
		||||
            guint flags, int* status);
 | 
			
		||||
    void (*acquire)(GBinderLocalObject* self);
 | 
			
		||||
    void (*release)(GBinderLocalObject* self);
 | 
			
		||||
    void (*drop)(GBinderLocalObject* self);
 | 
			
		||||
    /* Need to add some placeholders if this class becomes public */
 | 
			
		||||
} GBinderLocalObjectClass;
 | 
			
		||||
 | 
			
		||||
GType gbinder_local_object_get_type(void);
 | 
			
		||||
GType gbinder_local_object_get_type(void) GBINDER_INTERNAL;
 | 
			
		||||
#define GBINDER_TYPE_LOCAL_OBJECT (gbinder_local_object_get_type())
 | 
			
		||||
#define GBINDER_LOCAL_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
 | 
			
		||||
        GBINDER_TYPE_LOCAL_OBJECT, GBinderLocalObject))
 | 
			
		||||
#define GBINDER_LOCAL_OBJECT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \
 | 
			
		||||
        GBINDER_TYPE_LOCAL_OBJECT, GBinderLocalObjectClass)
 | 
			
		||||
 | 
			
		||||
#define gbinder_local_object_dev(obj) (gbinder_driver_dev((obj)->ipc->driver))
 | 
			
		||||
#define gbinder_local_object_io(obj) (gbinder_driver_io((obj)->ipc->driver))
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_local_object_new_with_type(
 | 
			
		||||
    GType type,
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderLocalTransactFunc txproc,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_init_base(
 | 
			
		||||
    GBinderLocalObject* self,
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    const char* const* ifaces,
 | 
			
		||||
    GBinderLocalTransactFunc txproc,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_local_object_add_weak_refs_changed_handler(
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    GBinderLocalObjectFunc func,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
    void* user_data)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_local_object_add_strong_refs_changed_handler(
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    GBinderLocalObjectFunc func,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
    void* user_data)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_remove_handler(
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    gulong id);
 | 
			
		||||
    gulong id)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBINDER_LOCAL_TRANSACTION_SUPPORT
 | 
			
		||||
gbinder_local_object_can_handle_transaction(
 | 
			
		||||
    GBinderLocalObject* self,
 | 
			
		||||
    const char* iface,
 | 
			
		||||
    guint code);
 | 
			
		||||
    guint code)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_local_object_handle_transaction(
 | 
			
		||||
@@ -116,7 +144,8 @@ gbinder_local_object_handle_transaction(
 | 
			
		||||
    GBinderRemoteRequest* req,
 | 
			
		||||
    guint code,
 | 
			
		||||
    guint flags,
 | 
			
		||||
    int* status);
 | 
			
		||||
    int* status)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_local_object_handle_looper_transaction(
 | 
			
		||||
@@ -124,23 +153,29 @@ gbinder_local_object_handle_looper_transaction(
 | 
			
		||||
    GBinderRemoteRequest* req,
 | 
			
		||||
    guint code,
 | 
			
		||||
    guint flags,
 | 
			
		||||
    int* status);
 | 
			
		||||
    int* status)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_handle_increfs(
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_handle_decrefs(
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_handle_acquire(
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    GBinderBufferContentsList* bufs)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_object_handle_release(
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_LOCAL_OBJECT_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -43,6 +43,7 @@ struct gbinder_local_reply {
 | 
			
		||||
    gint refcount;
 | 
			
		||||
    GBinderWriterData data;
 | 
			
		||||
    GBinderOutputData out;
 | 
			
		||||
    GBinderBufferContents* contents;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
GBINDER_INLINE_FUNC
 | 
			
		||||
@@ -94,14 +95,16 @@ gbinder_local_reply_new(
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_local_reply_new_from_data(
 | 
			
		||||
    GBinderBuffer* buffer)
 | 
			
		||||
gbinder_local_reply_set_contents(
 | 
			
		||||
    GBinderLocalReply* self,
 | 
			
		||||
    GBinderBuffer* buffer,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
{
 | 
			
		||||
    const GBinderIo* io = gbinder_buffer_io(buffer);
 | 
			
		||||
    GBinderLocalReply* self = gbinder_local_reply_new(io);
 | 
			
		||||
 | 
			
		||||
    if (self) {
 | 
			
		||||
        gbinder_writer_data_set_contents(&self->data, buffer);
 | 
			
		||||
        gbinder_writer_data_set_contents(&self->data, buffer, convert);
 | 
			
		||||
        gbinder_buffer_contents_unref(self->contents);
 | 
			
		||||
        self->contents = gbinder_buffer_contents_ref
 | 
			
		||||
            (gbinder_buffer_contents(buffer));
 | 
			
		||||
    }
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
@@ -116,7 +119,8 @@ gbinder_local_reply_free(
 | 
			
		||||
    gutil_int_array_free(data->offsets, TRUE);
 | 
			
		||||
    g_byte_array_free(data->bytes, TRUE);
 | 
			
		||||
    gbinder_cleanup_free(data->cleanup);
 | 
			
		||||
    g_slice_free(GBinderLocalReply, self);
 | 
			
		||||
    gbinder_buffer_contents_unref(self->contents);
 | 
			
		||||
    gutil_slice_free(self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
@@ -149,6 +153,13 @@ gbinder_local_reply_data(
 | 
			
		||||
    return G_LIKELY(self) ? &self->out :  NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderBufferContents*
 | 
			
		||||
gbinder_local_reply_contents(
 | 
			
		||||
    GBinderLocalReply* self)
 | 
			
		||||
{
 | 
			
		||||
    return G_LIKELY(self) ? self->contents :  NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_reply_cleanup(
 | 
			
		||||
    GBinderLocalReply* self,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -39,15 +39,25 @@
 | 
			
		||||
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_local_reply_new(
 | 
			
		||||
    const GBinderIo* io);
 | 
			
		||||
    const GBinderIo* io)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderOutputData*
 | 
			
		||||
gbinder_local_reply_data(
 | 
			
		||||
    GBinderLocalReply* reply);
 | 
			
		||||
    GBinderLocalReply* reply)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderBufferContents*
 | 
			
		||||
gbinder_local_reply_contents(
 | 
			
		||||
    GBinderLocalReply* reply)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_local_reply_new_from_data(
 | 
			
		||||
    GBinderBuffer* buffer);
 | 
			
		||||
gbinder_local_reply_set_contents(
 | 
			
		||||
    GBinderLocalReply* reply,
 | 
			
		||||
    GBinderBuffer* buffer,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_LOCAL_REPLY_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -31,6 +31,7 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "gbinder_local_request_p.h"
 | 
			
		||||
#include "gbinder_rpc_protocol.h"
 | 
			
		||||
#include "gbinder_output_data.h"
 | 
			
		||||
#include "gbinder_writer_p.h"
 | 
			
		||||
#include "gbinder_buffer_p.h"
 | 
			
		||||
@@ -91,6 +92,7 @@ gbinder_local_request_new(
 | 
			
		||||
        if (init) {
 | 
			
		||||
            gsize size;
 | 
			
		||||
            gconstpointer data = g_bytes_get_data(init, &size);
 | 
			
		||||
 | 
			
		||||
            writer->bytes = g_byte_array_sized_new(size);
 | 
			
		||||
            g_byte_array_append(writer->bytes, data, size);
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -103,19 +105,49 @@ gbinder_local_request_new(
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_local_request_new_iface(
 | 
			
		||||
    const GBinderIo* io,
 | 
			
		||||
    const GBinderRpcProtocol* protocol,
 | 
			
		||||
    const char* iface)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalRequest* self = gbinder_local_request_new(io, NULL);
 | 
			
		||||
 | 
			
		||||
    if (self && G_LIKELY(protocol) && G_LIKELY(iface)) {
 | 
			
		||||
        GBinderWriter writer;
 | 
			
		||||
 | 
			
		||||
        gbinder_local_request_init_writer(self, &writer);
 | 
			
		||||
        protocol->write_rpc_header(&writer, iface);
 | 
			
		||||
    }
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_local_request_new_from_data(
 | 
			
		||||
    GBinderBuffer* buffer)
 | 
			
		||||
    GBinderBuffer* buffer,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalRequest* self = gbinder_local_request_new
 | 
			
		||||
        (gbinder_buffer_io(buffer), NULL);
 | 
			
		||||
 | 
			
		||||
    if (self) {
 | 
			
		||||
        gbinder_writer_data_set_contents(&self->data, buffer);
 | 
			
		||||
        gbinder_writer_data_append_contents(&self->data, buffer, 0, convert);
 | 
			
		||||
    }
 | 
			
		||||
    return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_request_append_contents(
 | 
			
		||||
    GBinderLocalRequest* self,
 | 
			
		||||
    GBinderBuffer* buffer,
 | 
			
		||||
    gsize off,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
{
 | 
			
		||||
    if (self) {
 | 
			
		||||
        gbinder_writer_data_append_contents(&self->data, buffer, off, convert);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_request_free(
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -40,15 +40,34 @@
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_local_request_new(
 | 
			
		||||
    const GBinderIo* io,
 | 
			
		||||
    GBytes* init);
 | 
			
		||||
    GBytes* init)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderOutputData*
 | 
			
		||||
gbinder_local_request_data(
 | 
			
		||||
    GBinderLocalRequest* req);
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_local_request_new_iface(
 | 
			
		||||
    const GBinderIo* io,
 | 
			
		||||
    const GBinderRpcProtocol* protocol,
 | 
			
		||||
    const char* iface)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_local_request_new_from_data(
 | 
			
		||||
    GBinderBuffer* buffer);
 | 
			
		||||
    GBinderBuffer* buffer,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderOutputData*
 | 
			
		||||
gbinder_local_request_data(
 | 
			
		||||
    GBinderLocalRequest* req)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_local_request_append_contents(
 | 
			
		||||
    GBinderLocalRequest* req,
 | 
			
		||||
    GBinderBuffer* buffer,
 | 
			
		||||
    gsize offset,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_LOCAL_REQUEST_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										62
									
								
								src/gbinder_log.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								src/gbinder_log.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_misc.h>
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
/* Log module */
 | 
			
		||||
GLOG_MODULE_DEFINE("gbinder");
 | 
			
		||||
 | 
			
		||||
/* Initializes the default log level at startup */
 | 
			
		||||
void
 | 
			
		||||
gbinder_log_init(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    int level = GLOG_MODULE_NAME.level;
 | 
			
		||||
 | 
			
		||||
    if (gutil_parse_int(getenv("GBINDER_DEFAULT_LOG_LEVEL"), 0, &level) &&
 | 
			
		||||
        level >= GLOG_LEVEL_INHERIT && level <= GLOG_LEVEL_VERBOSE) {
 | 
			
		||||
        GINFO("Log level %d", level);
 | 
			
		||||
        GLOG_MODULE_NAME.level = level;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * 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-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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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,11 +33,18 @@
 | 
			
		||||
#ifndef GBINDER_LOG_H
 | 
			
		||||
#define GBINDER_LOG_H
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types.h"
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
 | 
			
		||||
#define GLOG_MODULE_NAME GBINDER_LOG_MODULE
 | 
			
		||||
#include <gutil_log.h>
 | 
			
		||||
 | 
			
		||||
/* Declared for unit tests */
 | 
			
		||||
__attribute__((constructor))
 | 
			
		||||
void
 | 
			
		||||
gbinder_log_init(
 | 
			
		||||
    void)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_LOG_H */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										67
									
								
								src/gbinder_object_converter.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								src/gbinder_object_converter.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,67 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2021 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_OBJECT_CONVERTER_H
 | 
			
		||||
#define GBINDER_OBJECT_CONVERTER_H
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_object_converter_functions {
 | 
			
		||||
    GBinderLocalObject* (*handle_to_local)(GBinderObjectConverter*, guint32);
 | 
			
		||||
} GBinderObjectConverterFunctions;
 | 
			
		||||
 | 
			
		||||
struct gbinder_object_converter {
 | 
			
		||||
    const GBinderObjectConverterFunctions* f;
 | 
			
		||||
    const GBinderIo* io;
 | 
			
		||||
    const GBinderRpcProtocol* protocol;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Inline wrappers */
 | 
			
		||||
 | 
			
		||||
GBINDER_INLINE_FUNC
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_object_converter_handle_to_local(
 | 
			
		||||
    GBinderObjectConverter* convert,
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
{
 | 
			
		||||
    return convert ? convert->f->handle_to_local(convert, handle) : NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_OBJECT_CONVERTER_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-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -13,9 +13,9 @@
 | 
			
		||||
 *   2. Redistributions in binary form must reproduce the above copyright
 | 
			
		||||
 *      notice, this list of conditions and the following disclaimer in the
 | 
			
		||||
 *      documentation and/or other materials provided with the distribution.
 | 
			
		||||
 *   3. Neither the name of Jolla Ltd nor the names of its contributors may
 | 
			
		||||
 *      be used to endorse or promote products derived from this software
 | 
			
		||||
 *      without specific prior written permission.
 | 
			
		||||
 *   3. Neither the names of the copyright holders nor the names of its
 | 
			
		||||
 *      contributors may be used to endorse or promote products derived
 | 
			
		||||
 *      from this software without specific prior written permission.
 | 
			
		||||
 *
 | 
			
		||||
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 | 
			
		||||
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 | 
			
		||||
@@ -35,13 +35,19 @@
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
 | 
			
		||||
typedef enum gbinder_remote_registry_create {
 | 
			
		||||
    REMOTE_REGISTRY_DONT_CREATE,
 | 
			
		||||
    REMOTE_REGISTRY_CAN_CREATE,
 | 
			
		||||
    REMOTE_REGISTRY_CAN_CREATE_AND_ACQUIRE
 | 
			
		||||
} REMOTE_REGISTRY_CREATE;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_object_registry_functions {
 | 
			
		||||
    void (*ref)(GBinderObjectRegistry* reg);
 | 
			
		||||
    void (*unref)(GBinderObjectRegistry* reg);
 | 
			
		||||
    GBinderLocalObject* (*get_local)(GBinderObjectRegistry* reg,
 | 
			
		||||
        void* pointer);
 | 
			
		||||
    GBinderRemoteObject* (*get_remote)(GBinderObjectRegistry* reg,
 | 
			
		||||
        guint32 handle);
 | 
			
		||||
        guint32 handle, REMOTE_REGISTRY_CREATE create);
 | 
			
		||||
} GBinderObjectRegistryFunctions;
 | 
			
		||||
 | 
			
		||||
struct gbinder_object_registry {
 | 
			
		||||
@@ -81,9 +87,10 @@ GBINDER_INLINE_FUNC
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_object_registry_get_remote(
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    REMOTE_REGISTRY_CREATE create)
 | 
			
		||||
{
 | 
			
		||||
    return reg ? reg->f->get_remote(reg, handle) : NULL;
 | 
			
		||||
    return reg ? reg->f->get_remote(reg, handle, create) : NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_OBJECT_REGISTRY_H */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										522
									
								
								src/gbinder_proxy_object.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										522
									
								
								src/gbinder_proxy_object.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,522 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2021 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.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define GLIB_DISABLE_DEPRECATION_WARNINGS
 | 
			
		||||
 | 
			
		||||
#include "gbinder_proxy_object.h"
 | 
			
		||||
#include "gbinder_local_object_p.h"
 | 
			
		||||
#include "gbinder_local_request.h"
 | 
			
		||||
#include "gbinder_local_reply.h"
 | 
			
		||||
#include "gbinder_remote_object_p.h"
 | 
			
		||||
#include "gbinder_remote_request_p.h"
 | 
			
		||||
#include "gbinder_remote_reply_p.h"
 | 
			
		||||
#include "gbinder_object_converter.h"
 | 
			
		||||
#include "gbinder_object_registry.h"
 | 
			
		||||
#include "gbinder_driver.h"
 | 
			
		||||
#include "gbinder_ipc.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_macros.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
typedef GBinderLocalObjectClass GBinderProxyObjectClass;
 | 
			
		||||
typedef struct gbinder_proxy_tx GBinderProxyTx;
 | 
			
		||||
 | 
			
		||||
struct gbinder_proxy_tx {
 | 
			
		||||
    GBinderProxyTx* next;
 | 
			
		||||
    GBinderRemoteRequest* req;
 | 
			
		||||
    GBinderProxyObject* proxy;
 | 
			
		||||
    gulong id;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct gbinder_proxy_object_priv {
 | 
			
		||||
    gulong remote_death_id;
 | 
			
		||||
    gboolean dropped;
 | 
			
		||||
    GBinderProxyTx* tx;
 | 
			
		||||
    GMutex mutex; /* Protects the hashtable below */
 | 
			
		||||
    GHashTable* subproxies;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE(GBinderProxyObject, gbinder_proxy_object, \
 | 
			
		||||
    GBINDER_TYPE_LOCAL_OBJECT)
 | 
			
		||||
#define GBINDER_IS_PROXY_OBJECT(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, \
 | 
			
		||||
    GBINDER_TYPE_PROXY_OBJECT)
 | 
			
		||||
 | 
			
		||||
#define THIS(obj) GBINDER_PROXY_OBJECT(obj)
 | 
			
		||||
#define THIS_TYPE GBINDER_TYPE_PROXY_OBJECT
 | 
			
		||||
#define PARENT_CLASS gbinder_proxy_object_parent_class
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_object_subproxy_gone(
 | 
			
		||||
    gpointer proxy,
 | 
			
		||||
    GObject* subproxy)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObject* self = THIS(proxy);
 | 
			
		||||
    GBinderProxyObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    /* Lock */
 | 
			
		||||
    g_mutex_lock(&priv->mutex);
 | 
			
		||||
    g_hash_table_remove(priv->subproxies, subproxy);
 | 
			
		||||
    if (g_hash_table_size(priv->subproxies) == 0) {
 | 
			
		||||
        g_hash_table_unref(priv->subproxies);
 | 
			
		||||
        priv->subproxies = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    g_mutex_unlock(&priv->mutex);
 | 
			
		||||
    /* Unlock */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_object_drop_subproxies(
 | 
			
		||||
    GBinderProxyObject* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObjectPriv* priv = self->priv;
 | 
			
		||||
    GSList* list = NULL;
 | 
			
		||||
 | 
			
		||||
    /* Lock */
 | 
			
		||||
    g_mutex_lock(&priv->mutex);
 | 
			
		||||
    if (priv->subproxies) {
 | 
			
		||||
        GHashTableIter it;
 | 
			
		||||
        gpointer value;
 | 
			
		||||
 | 
			
		||||
        g_hash_table_iter_init(&it, priv->subproxies);
 | 
			
		||||
        while (g_hash_table_iter_next(&it, NULL, &value)) {
 | 
			
		||||
            list = g_slist_append(list, gbinder_local_object_ref(value));
 | 
			
		||||
            g_object_weak_unref(G_OBJECT(value),
 | 
			
		||||
                gbinder_proxy_object_subproxy_gone, self);
 | 
			
		||||
        }
 | 
			
		||||
        g_hash_table_destroy(priv->subproxies);
 | 
			
		||||
        priv->subproxies = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    g_mutex_unlock(&priv->mutex);
 | 
			
		||||
    /* Unlock */
 | 
			
		||||
 | 
			
		||||
    /* Drop (and possibly destroy) the objects outside of the lock */
 | 
			
		||||
    g_slist_free_full(list, (GDestroyNotify) gbinder_local_object_drop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_remote_death_proc(
 | 
			
		||||
    GBinderRemoteObject* obj,
 | 
			
		||||
    void* proxy)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObject* self = THIS(proxy);
 | 
			
		||||
    GBinderProxyObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    GDEBUG("Remote object %u died on %s", obj->handle, obj->ipc->dev);
 | 
			
		||||
    gbinder_remote_object_remove_handler(obj, priv->remote_death_id);
 | 
			
		||||
    priv->remote_death_id = 0;
 | 
			
		||||
    /* Drop the implicit reference */
 | 
			
		||||
    gbinder_local_object_unref(&self->parent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Converter
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_proxy_object_converter {
 | 
			
		||||
    GBinderObjectConverter pub;
 | 
			
		||||
    GBinderProxyObject* proxy;
 | 
			
		||||
    GBinderIpc* remote;
 | 
			
		||||
    GBinderIpc* local;
 | 
			
		||||
} GBinderProxyObjectConverter;
 | 
			
		||||
 | 
			
		||||
GBINDER_INLINE_FUNC
 | 
			
		||||
GBinderProxyObjectConverter*
 | 
			
		||||
gbinder_proxy_object_converter_cast(
 | 
			
		||||
    GBinderObjectConverter* pub)
 | 
			
		||||
{
 | 
			
		||||
    return G_CAST(pub, GBinderProxyObjectConverter, pub);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_proxy_object_converter_check(
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    void* remote)
 | 
			
		||||
{
 | 
			
		||||
    if (GBINDER_IS_PROXY_OBJECT(obj) && THIS(obj)->remote == remote) {
 | 
			
		||||
        /* Found matching proxy object */
 | 
			
		||||
        return TRUE;
 | 
			
		||||
    }
 | 
			
		||||
    /* Keep looking */
 | 
			
		||||
    return FALSE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
gbinder_proxy_object_converter_handle_to_local(
 | 
			
		||||
    GBinderObjectConverter* pub,
 | 
			
		||||
    guint32 handle)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObjectConverter* c = gbinder_proxy_object_converter_cast(pub);
 | 
			
		||||
    GBinderProxyObject* proxy = c->proxy;
 | 
			
		||||
    GBinderProxyObjectPriv* priv = proxy->priv;
 | 
			
		||||
    GBinderObjectRegistry* reg = gbinder_ipc_object_registry(c->remote);
 | 
			
		||||
    GBinderRemoteObject* remote = gbinder_object_registry_get_remote(reg,
 | 
			
		||||
        handle, REMOTE_REGISTRY_CAN_CREATE /* but don't acquire */);
 | 
			
		||||
    GBinderLocalObject* local = gbinder_ipc_find_local_object(c->local,
 | 
			
		||||
        gbinder_proxy_object_converter_check, remote);
 | 
			
		||||
 | 
			
		||||
    if (!local && !remote->dead) {
 | 
			
		||||
        /* GBinderProxyObject will reference GBinderRemoteObject */
 | 
			
		||||
        GBinderProxyObject* subp = gbinder_proxy_object_new(c->local, remote);
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * Auto-created proxies may get spontaneously destroyed and
 | 
			
		||||
         * not necessarily on the UI thread.
 | 
			
		||||
         */
 | 
			
		||||
        subp->priv->remote_death_id = gbinder_remote_object_add_death_handler
 | 
			
		||||
            (remote, gbinder_proxy_remote_death_proc, subp);
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * Remote keeps an implicit reference to this auto-created
 | 
			
		||||
         * proxy. The reference gets released when the remote object
 | 
			
		||||
         * dies, i.e. by gbinder_proxy_remote_death_proc().
 | 
			
		||||
         */
 | 
			
		||||
        gbinder_local_object_ref(local = GBINDER_LOCAL_OBJECT(subp));
 | 
			
		||||
 | 
			
		||||
        /* Lock */
 | 
			
		||||
        g_mutex_lock(&priv->mutex);
 | 
			
		||||
        if (!priv->subproxies) {
 | 
			
		||||
            priv->subproxies = g_hash_table_new(g_direct_hash, g_direct_equal);
 | 
			
		||||
        }
 | 
			
		||||
        g_hash_table_insert(priv->subproxies, subp, subp);
 | 
			
		||||
        g_object_weak_ref(G_OBJECT(subp),
 | 
			
		||||
            gbinder_proxy_object_subproxy_gone, proxy);
 | 
			
		||||
        g_mutex_unlock(&priv->mutex);
 | 
			
		||||
        /* Unlock */
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Release the reference returned by gbinder_object_registry_get_remote */
 | 
			
		||||
    gbinder_remote_object_unref(remote);
 | 
			
		||||
    return local;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_object_converter_init(
 | 
			
		||||
    GBinderProxyObjectConverter* convert,
 | 
			
		||||
    GBinderProxyObject* proxy,
 | 
			
		||||
    GBinderIpc* remote,
 | 
			
		||||
    GBinderIpc* local)
 | 
			
		||||
{
 | 
			
		||||
    static const GBinderObjectConverterFunctions gbinder_converter_fn = {
 | 
			
		||||
        .handle_to_local = gbinder_proxy_object_converter_handle_to_local
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    GBinderObjectConverter* pub = &convert->pub;
 | 
			
		||||
    GBinderIpc* dest = proxy->parent.ipc;
 | 
			
		||||
 | 
			
		||||
    memset(convert, 0, sizeof(*convert));
 | 
			
		||||
    convert->proxy = proxy;
 | 
			
		||||
    convert->remote = remote;
 | 
			
		||||
    convert->local = local;
 | 
			
		||||
    pub->f = &gbinder_converter_fn;
 | 
			
		||||
    pub->io = gbinder_ipc_io(dest);
 | 
			
		||||
    pub->protocol = gbinder_ipc_protocol(dest);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Implementation
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_tx_dequeue(
 | 
			
		||||
    GBinderProxyTx* tx)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObject* proxy = tx->proxy;
 | 
			
		||||
 | 
			
		||||
    if (proxy) {
 | 
			
		||||
        GBinderProxyObjectPriv* priv = proxy->priv;
 | 
			
		||||
 | 
			
		||||
        if (priv->tx) {
 | 
			
		||||
            if (priv->tx == tx) {
 | 
			
		||||
                priv->tx = tx->next;
 | 
			
		||||
            } else {
 | 
			
		||||
                GBinderProxyTx* prev = priv->tx;
 | 
			
		||||
 | 
			
		||||
                while (prev->next) {
 | 
			
		||||
                    if (prev->next == tx) {
 | 
			
		||||
                        prev->next = tx->next;
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                    prev = prev->next;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        tx->next = NULL;
 | 
			
		||||
        tx->proxy = NULL;
 | 
			
		||||
        g_object_unref(proxy);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_tx_reply(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    GBinderRemoteReply* reply,
 | 
			
		||||
    int status,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyTx* tx = user_data;
 | 
			
		||||
    GBinderProxyObject* self = tx->proxy;
 | 
			
		||||
    GBinderProxyObjectConverter convert;
 | 
			
		||||
    GBinderLocalReply* fwd;
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * For proxy objects auto-created by the reply, the remote side (the
 | 
			
		||||
     * one sent the reply) will be the remote GBinderIpc and this object's
 | 
			
		||||
     * GBinderIpc will be the local, i.e. those proxies will work in the
 | 
			
		||||
     * same direction as the top level object. The direction gets inverted
 | 
			
		||||
     * twice.
 | 
			
		||||
     */
 | 
			
		||||
    gbinder_proxy_object_converter_init(&convert, self, ipc, self->parent.ipc);
 | 
			
		||||
    fwd = gbinder_remote_reply_convert_to_local(reply, &convert.pub);
 | 
			
		||||
    tx->id = 0;
 | 
			
		||||
    gbinder_proxy_tx_dequeue(tx);
 | 
			
		||||
    gbinder_remote_request_complete(tx->req, fwd,
 | 
			
		||||
        (status > 0) ? (-EFAULT) : status);
 | 
			
		||||
    if (status == GBINDER_STATUS_DEAD_OBJECT) {
 | 
			
		||||
        /*
 | 
			
		||||
         * Some kernels sometimes don't bother sending us death notifications.
 | 
			
		||||
         * Let's also interpret BR_DEAD_REPLY as an obituary to make sure that
 | 
			
		||||
         * we don't keep dead remote objects around.
 | 
			
		||||
         */
 | 
			
		||||
        gbinder_remote_object_commit_suicide(self->remote);
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_local_reply_unref(fwd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_tx_destroy(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyTx* tx = user_data;
 | 
			
		||||
 | 
			
		||||
    gbinder_proxy_tx_dequeue(tx);
 | 
			
		||||
    gbinder_remote_request_unref(tx->req);
 | 
			
		||||
    gutil_slice_free(tx);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_proxy_object_handle_transaction(
 | 
			
		||||
    GBinderLocalObject* object,
 | 
			
		||||
    GBinderRemoteRequest* req,
 | 
			
		||||
    guint code,
 | 
			
		||||
    guint flags,
 | 
			
		||||
    int* status)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObject* self = THIS(object);
 | 
			
		||||
    GBinderProxyObjectPriv* priv = self->priv;
 | 
			
		||||
    GBinderRemoteObject* remote = self->remote;
 | 
			
		||||
 | 
			
		||||
    if (!priv->dropped && !gbinder_remote_object_is_dead(remote)) {
 | 
			
		||||
        GBinderLocalRequest* fwd;
 | 
			
		||||
        GBinderProxyTx* tx = g_slice_new0(GBinderProxyTx);
 | 
			
		||||
        GBinderProxyObjectConverter convert;
 | 
			
		||||
 | 
			
		||||
        g_object_ref(tx->proxy = self);
 | 
			
		||||
        tx->req = gbinder_remote_request_ref(req);
 | 
			
		||||
        tx->next = priv->tx;
 | 
			
		||||
        priv->tx = tx;
 | 
			
		||||
 | 
			
		||||
        /* Mark the incoming request as pending */
 | 
			
		||||
        gbinder_remote_request_block(req);
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * For auto-created proxy objects, this object's GBinderIpc will
 | 
			
		||||
         * become a remote, and the remote's GBinderIpc will become local
 | 
			
		||||
         * because they work in the opposite direction.
 | 
			
		||||
         */
 | 
			
		||||
        gbinder_proxy_object_converter_init(&convert, self, object->ipc,
 | 
			
		||||
            remote->ipc);
 | 
			
		||||
 | 
			
		||||
        /* Forward the transaction */
 | 
			
		||||
        fwd = gbinder_remote_request_convert_to_local(req, &convert.pub);
 | 
			
		||||
        tx->id = gbinder_ipc_transact(remote->ipc, remote->handle, code, flags,
 | 
			
		||||
            fwd, gbinder_proxy_tx_reply, gbinder_proxy_tx_destroy, tx);
 | 
			
		||||
        gbinder_local_request_unref(fwd);
 | 
			
		||||
        *status = GBINDER_STATUS_OK;
 | 
			
		||||
    } else {
 | 
			
		||||
        *status = (-EBADMSG);
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBINDER_LOCAL_TRANSACTION_SUPPORT
 | 
			
		||||
gbinder_proxy_object_can_handle_transaction(
 | 
			
		||||
    GBinderLocalObject* self,
 | 
			
		||||
    const char* iface,
 | 
			
		||||
    guint code)
 | 
			
		||||
{
 | 
			
		||||
    /* Process all transactions on the main thread */
 | 
			
		||||
    return GBINDER_LOCAL_TRANSACTION_SUPPORTED;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_object_acquire(
 | 
			
		||||
    GBinderLocalObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObject* self = THIS(object);
 | 
			
		||||
    GBinderProxyObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    if (priv->remote_death_id && !object->strong_refs) {
 | 
			
		||||
        GBinderRemoteObject* remote = self->remote;
 | 
			
		||||
 | 
			
		||||
        /* First strong ref, acquire the attached remote object */
 | 
			
		||||
        gbinder_driver_acquire(remote->ipc->driver, remote->handle);
 | 
			
		||||
    }
 | 
			
		||||
    GBINDER_LOCAL_OBJECT_CLASS(PARENT_CLASS)->acquire(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_object_release(
 | 
			
		||||
    GBinderLocalObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObject* self = THIS(object);
 | 
			
		||||
    GBinderProxyObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    if (priv->remote_death_id && object->strong_refs == 1) {
 | 
			
		||||
        GBinderRemoteObject* remote = self->remote;
 | 
			
		||||
 | 
			
		||||
        /* Last strong ref, release the attached remote object */
 | 
			
		||||
        gbinder_driver_release(remote->ipc->driver, remote->handle);
 | 
			
		||||
    }
 | 
			
		||||
    GBINDER_LOCAL_OBJECT_CLASS(PARENT_CLASS)->release(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_object_drop(
 | 
			
		||||
    GBinderLocalObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObject* self = THIS(object);
 | 
			
		||||
    GBinderProxyObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    priv->dropped = TRUE;
 | 
			
		||||
    gbinder_proxy_object_drop_subproxies(self);
 | 
			
		||||
    GBINDER_LOCAL_OBJECT_CLASS(PARENT_CLASS)->drop(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
GBinderProxyObject*
 | 
			
		||||
gbinder_proxy_object_new(
 | 
			
		||||
    GBinderIpc* src,
 | 
			
		||||
    GBinderRemoteObject* remote)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(remote)) {
 | 
			
		||||
        /*
 | 
			
		||||
         * We don't need to specify the interface list because all
 | 
			
		||||
         * transactions (including HIDL_GET_DESCRIPTOR_TRANSACTION
 | 
			
		||||
         * and HIDL_DESCRIPTOR_CHAIN_TRANSACTION) are getting forwared
 | 
			
		||||
         * to the remote object.
 | 
			
		||||
         */
 | 
			
		||||
        GBinderLocalObject* object = gbinder_local_object_new_with_type
 | 
			
		||||
            (THIS_TYPE, src, NULL, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
        if (object) {
 | 
			
		||||
            GBinderProxyObject* self = THIS(object);
 | 
			
		||||
 | 
			
		||||
            self->remote = gbinder_remote_object_ref(remote);
 | 
			
		||||
            return self;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Internals
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_object_finalize(
 | 
			
		||||
    GObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObject* self = THIS(object);
 | 
			
		||||
    GBinderProxyObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    gbinder_proxy_object_drop_subproxies(self);
 | 
			
		||||
    gbinder_remote_object_remove_handler(self->remote, priv->remote_death_id);
 | 
			
		||||
    gbinder_remote_object_unref(self->remote);
 | 
			
		||||
    g_mutex_clear(&priv->mutex);
 | 
			
		||||
    G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_object_init(
 | 
			
		||||
    GBinderProxyObject* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderProxyObjectPriv* priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
 | 
			
		||||
        THIS_TYPE, GBinderProxyObjectPriv);
 | 
			
		||||
 | 
			
		||||
    self->priv = priv;
 | 
			
		||||
    g_mutex_init(&priv->mutex);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_proxy_object_class_init(
 | 
			
		||||
    GBinderProxyObjectClass* klass)
 | 
			
		||||
{
 | 
			
		||||
    GObjectClass* object_class = G_OBJECT_CLASS(klass);
 | 
			
		||||
 | 
			
		||||
    g_type_class_add_private(klass, sizeof(GBinderProxyObjectPriv));
 | 
			
		||||
    object_class->finalize = gbinder_proxy_object_finalize;
 | 
			
		||||
    klass->can_handle_transaction = gbinder_proxy_object_can_handle_transaction;
 | 
			
		||||
    klass->handle_transaction = gbinder_proxy_object_handle_transaction;
 | 
			
		||||
    klass->acquire = gbinder_proxy_object_acquire;
 | 
			
		||||
    klass->release = gbinder_proxy_object_release;
 | 
			
		||||
    klass->drop = gbinder_proxy_object_drop;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										66
									
								
								src/gbinder_proxy_object.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								src/gbinder_proxy_object.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2021 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_PROXY_OBJECT_H
 | 
			
		||||
#define GBINDER_PROXY_OBJECT_H
 | 
			
		||||
 | 
			
		||||
#include "gbinder_local_object_p.h"
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_proxy_object_priv GBinderProxyObjectPriv;
 | 
			
		||||
 | 
			
		||||
struct gbinder_proxy_object {
 | 
			
		||||
    GBinderLocalObject parent;
 | 
			
		||||
    GBinderProxyObjectPriv* priv;
 | 
			
		||||
    GBinderRemoteObject* remote;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
GType gbinder_proxy_object_get_type(void) GBINDER_INTERNAL;
 | 
			
		||||
#define GBINDER_TYPE_PROXY_OBJECT gbinder_proxy_object_get_type()
 | 
			
		||||
#define GBINDER_PROXY_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
 | 
			
		||||
        GBINDER_TYPE_PROXY_OBJECT, GBinderProxyObject))
 | 
			
		||||
 | 
			
		||||
/* Registers with src and forwards all transactions to the remote */
 | 
			
		||||
GBinderProxyObject*
 | 
			
		||||
gbinder_proxy_object_new(
 | 
			
		||||
    GBinderIpc* src,
 | 
			
		||||
    GBinderRemoteObject* remote)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_PROXY_OBJECT_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-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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -48,7 +48,8 @@ gbinder_reader_init(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    GBinderReaderData* data,
 | 
			
		||||
    gsize offset,
 | 
			
		||||
    gsize len);
 | 
			
		||||
    gsize len)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_READER_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -30,22 +30,26 @@
 | 
			
		||||
 * THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define GLIB_DISABLE_DEPRECATION_WARNINGS
 | 
			
		||||
 | 
			
		||||
#include "gbinder_driver.h"
 | 
			
		||||
#include "gbinder_ipc.h"
 | 
			
		||||
#include "gbinder_remote_object_p.h"
 | 
			
		||||
#include "gbinder_servicemanager_p.h"
 | 
			
		||||
#include "gbinder_eventloop_p.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
struct gbinder_remote_object_priv {
 | 
			
		||||
    GMainContext* context;
 | 
			
		||||
    gboolean acquired;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef GObjectClass GBinderRemoteObjectClass;
 | 
			
		||||
GType gbinder_remote_object_get_type(void) GBINDER_INTERNAL;
 | 
			
		||||
G_DEFINE_TYPE(GBinderRemoteObject, gbinder_remote_object, G_TYPE_OBJECT)
 | 
			
		||||
 | 
			
		||||
GType gbinder_remote_object_get_type(void);
 | 
			
		||||
#define GBINDER_TYPE_REMOTE_OBJECT (gbinder_remote_object_get_type())
 | 
			
		||||
#define GBINDER_REMOTE_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
 | 
			
		||||
        GBINDER_TYPE_REMOTE_OBJECT, GBinderRemoteObject))
 | 
			
		||||
#define PARENT_CLASS gbinder_remote_object_parent_class
 | 
			
		||||
#define THIS_TYPE (gbinder_remote_object_get_type())
 | 
			
		||||
#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj,THIS_TYPE,GBinderRemoteObject)
 | 
			
		||||
 | 
			
		||||
enum gbinder_remote_object_signal {
 | 
			
		||||
    SIGNAL_DEATH,
 | 
			
		||||
@@ -62,30 +66,31 @@ static guint gbinder_remote_object_signals[SIGNAL_COUNT] = { 0 };
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_object_died_on_main_thread(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
gbinder_remote_object_handle_death_on_main_thread(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderIpc* ipc = self->ipc;
 | 
			
		||||
    GBinderDriver* driver = ipc->driver;
 | 
			
		||||
    GBinderRemoteObject* self = THIS(user_data);
 | 
			
		||||
 | 
			
		||||
    GASSERT(!self->dead);
 | 
			
		||||
    if (!self->dead) {
 | 
			
		||||
        GBinderIpc* ipc = self->ipc;
 | 
			
		||||
        GBinderDriver* driver = ipc->driver;
 | 
			
		||||
        GBinderRemoteObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
        self->dead = TRUE;
 | 
			
		||||
        gbinder_driver_clear_death_notification(driver, self);
 | 
			
		||||
        gbinder_driver_release(driver, self->handle);
 | 
			
		||||
        if (priv->acquired) {
 | 
			
		||||
            priv->acquired = FALSE;
 | 
			
		||||
            /* Release the dead node */
 | 
			
		||||
            gbinder_driver_release(driver, self->handle);
 | 
			
		||||
        }
 | 
			
		||||
        /* ServiceManager always has the same handle, and can be reanimated. */
 | 
			
		||||
        if (self->handle != GBINDER_SERVICEMANAGER_HANDLE) {
 | 
			
		||||
            gbinder_ipc_invalidate_remote_handle(ipc, self->handle);
 | 
			
		||||
        }
 | 
			
		||||
        gbinder_driver_dead_binder_done(driver, self);
 | 
			
		||||
        g_signal_emit(self, gbinder_remote_object_signals[SIGNAL_DEATH], 0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_remote_object_died_handle(
 | 
			
		||||
    gpointer self)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_remote_object_died_on_main_thread(GBINDER_REMOTE_OBJECT(self));
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Internal interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -101,14 +106,20 @@ gbinder_remote_object_reanimate(
 | 
			
		||||
     */
 | 
			
		||||
    if (self->dead) {
 | 
			
		||||
        GBinderIpc* ipc = self->ipc;
 | 
			
		||||
        GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
 | 
			
		||||
        guint32 handle = self->handle;
 | 
			
		||||
 | 
			
		||||
        /* Kick the horse */
 | 
			
		||||
        if (gbinder_driver_ping(ipc->driver, reg, self->handle) == 0) {
 | 
			
		||||
        GASSERT(self->handle == GBINDER_SERVICEMANAGER_HANDLE);
 | 
			
		||||
        if (gbinder_ipc_ping_sync(ipc, handle, &gbinder_ipc_sync_main) == 0) {
 | 
			
		||||
            GBinderRemoteObjectPriv* priv = self->priv;
 | 
			
		||||
            GBinderDriver* driver = ipc->driver;
 | 
			
		||||
 | 
			
		||||
            /* Wow, it's alive! */
 | 
			
		||||
            self->dead = FALSE;
 | 
			
		||||
            gbinder_driver_acquire(ipc->driver, self->handle);
 | 
			
		||||
            gbinder_driver_request_death_notification(ipc->driver, self);
 | 
			
		||||
            priv->acquired = TRUE;
 | 
			
		||||
            gbinder_ipc_looper_check(ipc); /* For death notifications */
 | 
			
		||||
            gbinder_driver_acquire(driver, handle);
 | 
			
		||||
            gbinder_driver_request_death_notification(driver, self);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return !self->dead;
 | 
			
		||||
@@ -121,9 +132,33 @@ gbinder_remote_object_handle_death_notification(
 | 
			
		||||
    /* 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);
 | 
			
		||||
    gbinder_idle_callback_invoke_later
 | 
			
		||||
        (gbinder_remote_object_handle_death_on_main_thread,
 | 
			
		||||
            gbinder_remote_object_ref(self), g_object_unref);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_object_commit_suicide(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
{
 | 
			
		||||
    /* This function is only invoked by GBinderProxyObject in context of
 | 
			
		||||
     * the main thread, the object pointer is checked by the caller */
 | 
			
		||||
    if (!self->dead) {
 | 
			
		||||
        GBinderIpc* ipc = self->ipc;
 | 
			
		||||
        GBinderDriver* driver = ipc->driver;
 | 
			
		||||
        GBinderRemoteObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
        self->dead = TRUE;
 | 
			
		||||
        if (priv->acquired) {
 | 
			
		||||
            priv->acquired = FALSE;
 | 
			
		||||
            /* Release the dead node */
 | 
			
		||||
            gbinder_driver_release(driver, self->handle);
 | 
			
		||||
        }
 | 
			
		||||
        GVERBOSE_("%p %u", self, self->handle);
 | 
			
		||||
        gbinder_ipc_invalidate_remote_handle(self->ipc, self->handle);
 | 
			
		||||
        /* Don't submit BC_DEAD_BINDER_DONE because this is a suicide */
 | 
			
		||||
        g_signal_emit(self, gbinder_remote_object_signals[SIGNAL_DEATH], 0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
@@ -134,16 +169,29 @@ GBinderRemoteObject*
 | 
			
		||||
gbinder_remote_object_new(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    gboolean dead)
 | 
			
		||||
    REMOTE_OBJECT_CREATE create)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(ipc)) {
 | 
			
		||||
        GBinderRemoteObject* self = g_object_new
 | 
			
		||||
            (GBINDER_TYPE_REMOTE_OBJECT, NULL);
 | 
			
		||||
        GBinderRemoteObject* self = g_object_new(THIS_TYPE, NULL);
 | 
			
		||||
        GBinderRemoteObjectPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
        self->ipc = gbinder_ipc_ref(ipc);
 | 
			
		||||
        self->handle = handle;
 | 
			
		||||
        if (!(self->dead = dead)) {
 | 
			
		||||
            gbinder_driver_acquire(ipc->driver, handle);
 | 
			
		||||
        switch (create) {
 | 
			
		||||
        case REMOTE_OBJECT_CREATE_DEAD:
 | 
			
		||||
            self->dead = TRUE;
 | 
			
		||||
            break;
 | 
			
		||||
        case REMOTE_OBJECT_CREATE_ACQUIRED:
 | 
			
		||||
            priv->acquired = TRUE;
 | 
			
		||||
            /* fallthrough */
 | 
			
		||||
        case REMOTE_OBJECT_CREATE_ALIVE:
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        if (!self->dead) {
 | 
			
		||||
            gbinder_ipc_looper_check(self->ipc); /* For death notifications */
 | 
			
		||||
            if (priv->acquired) {
 | 
			
		||||
                gbinder_driver_acquire(ipc->driver, handle);
 | 
			
		||||
            }
 | 
			
		||||
            gbinder_driver_request_death_notification(ipc->driver, self);
 | 
			
		||||
        }
 | 
			
		||||
        return self;
 | 
			
		||||
@@ -156,7 +204,7 @@ gbinder_remote_object_ref(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        g_object_ref(GBINDER_REMOTE_OBJECT(self));
 | 
			
		||||
        g_object_ref(THIS(self));
 | 
			
		||||
        return self;
 | 
			
		||||
    } else {
 | 
			
		||||
        return NULL;
 | 
			
		||||
@@ -168,7 +216,7 @@ gbinder_remote_object_unref(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        g_object_unref(GBINDER_REMOTE_OBJECT(self));
 | 
			
		||||
        g_object_unref(THIS(self));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -220,38 +268,40 @@ gbinder_remote_object_init(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderRemoteObjectPriv* priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
 | 
			
		||||
        GBINDER_TYPE_REMOTE_OBJECT, GBinderRemoteObjectPriv);
 | 
			
		||||
        THIS_TYPE, GBinderRemoteObjectPriv);
 | 
			
		||||
 | 
			
		||||
    priv->context = g_main_context_default();
 | 
			
		||||
    self->priv = priv;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_object_dispose(
 | 
			
		||||
    GObject* remote)
 | 
			
		||||
    GObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderRemoteObject* self = GBINDER_REMOTE_OBJECT(remote);
 | 
			
		||||
    GBinderRemoteObject* self = THIS(object);
 | 
			
		||||
 | 
			
		||||
    gbinder_ipc_remote_object_disposed(self->ipc, self);
 | 
			
		||||
    G_OBJECT_CLASS(gbinder_remote_object_parent_class)->dispose(remote);
 | 
			
		||||
    G_OBJECT_CLASS(PARENT_CLASS)->dispose(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_object_finalize(
 | 
			
		||||
    GObject* remote)
 | 
			
		||||
    GObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderRemoteObject* self = GBINDER_REMOTE_OBJECT(remote);
 | 
			
		||||
    GBinderRemoteObject* self = THIS(object);
 | 
			
		||||
    GBinderRemoteObjectPriv* priv = self->priv;
 | 
			
		||||
    GBinderIpc* ipc = self->ipc;
 | 
			
		||||
    GBinderDriver* driver = ipc->driver;
 | 
			
		||||
 | 
			
		||||
    if (!self->dead) {
 | 
			
		||||
        gbinder_driver_clear_death_notification(driver, self);
 | 
			
		||||
    }
 | 
			
		||||
    if (priv->acquired) {
 | 
			
		||||
        gbinder_driver_release(driver, self->handle);
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_ipc_unref(ipc);
 | 
			
		||||
    G_OBJECT_CLASS(gbinder_remote_object_parent_class)->finalize(remote);
 | 
			
		||||
    G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -51,19 +51,33 @@ struct gbinder_remote_object {
 | 
			
		||||
#define gbinder_remote_object_dev(obj) (gbinder_driver_dev((obj)->ipc->driver))
 | 
			
		||||
#define gbinder_remote_object_io(obj) (gbinder_driver_io((obj)->ipc->driver))
 | 
			
		||||
 | 
			
		||||
typedef enum gbinder_remote_object_create {
 | 
			
		||||
    REMOTE_OBJECT_CREATE_DEAD,
 | 
			
		||||
    REMOTE_OBJECT_CREATE_ALIVE,
 | 
			
		||||
    REMOTE_OBJECT_CREATE_ACQUIRED
 | 
			
		||||
} REMOTE_OBJECT_CREATE;
 | 
			
		||||
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_remote_object_new(
 | 
			
		||||
    GBinderIpc* ipc,
 | 
			
		||||
    guint32 handle,
 | 
			
		||||
    gboolean maybe_dead);
 | 
			
		||||
    REMOTE_OBJECT_CREATE create)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_remote_object_reanimate(
 | 
			
		||||
    GBinderRemoteObject* obj);
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_object_handle_death_notification(
 | 
			
		||||
    GBinderRemoteObject* obj);
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_object_commit_suicide(
 | 
			
		||||
    GBinderRemoteObject* self)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_REMOTE_OBJECT_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -117,11 +117,23 @@ gbinder_remote_reply_is_empty(
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_remote_reply_copy_to_local(
 | 
			
		||||
    GBinderRemoteReply* self)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_remote_reply_convert_to_local(self, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_remote_reply_convert_to_local(
 | 
			
		||||
    GBinderRemoteReply* self,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderReaderData* d = &self->data;
 | 
			
		||||
        GBinderObjectRegistry* reg = d->reg;
 | 
			
		||||
 | 
			
		||||
        return gbinder_local_reply_new_from_data(d->buffer);
 | 
			
		||||
        if (reg) {
 | 
			
		||||
            return gbinder_local_reply_set_contents
 | 
			
		||||
                (gbinder_local_reply_new(reg->io), d->buffer, convert);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -39,16 +39,25 @@
 | 
			
		||||
 | 
			
		||||
GBinderRemoteReply*
 | 
			
		||||
gbinder_remote_reply_new(
 | 
			
		||||
    GBinderObjectRegistry* reg);
 | 
			
		||||
    GBinderObjectRegistry* reg)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_remote_reply_convert_to_local(
 | 
			
		||||
    GBinderRemoteReply* reply,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_reply_set_data(
 | 
			
		||||
    GBinderRemoteReply* reply,
 | 
			
		||||
    GBinderBuffer* buffer);
 | 
			
		||||
    GBinderBuffer* buffer)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_remote_reply_is_empty(
 | 
			
		||||
    GBinderRemoteReply* reply);
 | 
			
		||||
    GBinderRemoteReply* reply)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_REMOTE_REPLY_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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,8 +34,10 @@
 | 
			
		||||
#include "gbinder_reader_p.h"
 | 
			
		||||
#include "gbinder_rpc_protocol.h"
 | 
			
		||||
#include "gbinder_local_request_p.h"
 | 
			
		||||
#include "gbinder_object_converter.h"
 | 
			
		||||
#include "gbinder_object_registry.h"
 | 
			
		||||
#include "gbinder_buffer_p.h"
 | 
			
		||||
#include "gbinder_driver.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_macros.h>
 | 
			
		||||
@@ -85,7 +87,33 @@ gbinder_remote_request_copy_to_local(
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderReaderData* d = &self->data;
 | 
			
		||||
 | 
			
		||||
        return gbinder_local_request_new_from_data(d->buffer);
 | 
			
		||||
        return gbinder_local_request_new_from_data(d->buffer, NULL);
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_remote_request_convert_to_local(
 | 
			
		||||
    GBinderRemoteRequest* req,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
{
 | 
			
		||||
    GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
 | 
			
		||||
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        GBinderReaderData* data = &self->data;
 | 
			
		||||
 | 
			
		||||
        if (!convert || convert->protocol == self->protocol) {
 | 
			
		||||
            /* The same protocol, the same format of RPC header */
 | 
			
		||||
            return gbinder_local_request_new_from_data(data->buffer, convert);
 | 
			
		||||
        } else {
 | 
			
		||||
            /* Need to translate to another format */
 | 
			
		||||
            GBinderLocalRequest* local = gbinder_local_request_new_iface
 | 
			
		||||
                (convert->io, convert->protocol, self->iface);
 | 
			
		||||
 | 
			
		||||
            gbinder_local_request_append_contents(local, data->buffer,
 | 
			
		||||
                self->header_size, convert);
 | 
			
		||||
            return local;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -46,13 +46,21 @@ gbinder_remote_request_new(
 | 
			
		||||
    GBinderObjectRegistry* reg,
 | 
			
		||||
    const GBinderRpcProtocol* protocol,
 | 
			
		||||
    pid_t pid,
 | 
			
		||||
    uid_t euid);
 | 
			
		||||
    uid_t euid)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_remote_request_set_data(
 | 
			
		||||
    GBinderRemoteRequest* request,
 | 
			
		||||
    guint txcode,
 | 
			
		||||
    GBinderBuffer* buffer);
 | 
			
		||||
    GBinderBuffer* buffer)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_remote_request_convert_to_local(
 | 
			
		||||
    GBinderRemoteRequest* req,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_REMOTE_REQUEST_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -33,6 +33,12 @@
 | 
			
		||||
#include "gbinder_rpc_protocol.h"
 | 
			
		||||
#include "gbinder_reader.h"
 | 
			
		||||
#include "gbinder_writer.h"
 | 
			
		||||
#include "gbinder_config.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#define STRICT_MODE_PENALTY_GATHER (0x40 << 16)
 | 
			
		||||
#define BINDER_RPC_FLAGS (STRICT_MODE_PENALTY_GATHER)
 | 
			
		||||
#define UNSET_WORK_SOURCE (-1)
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * GBinderIpcProtocol callbacks (see Parcel::writeInterfaceToken in Android)
 | 
			
		||||
@@ -40,19 +46,39 @@
 | 
			
		||||
 *
 | 
			
		||||
 *   platform/system/libhwbinder/Parcel.cpp
 | 
			
		||||
 *   platform/frameworks/native/libs/binder/Parcel.cpp
 | 
			
		||||
 *
 | 
			
		||||
 * which mutate from version to version. Specific device => protocol
 | 
			
		||||
 * mapping can be optionally configured in /etc/gbinder.conf file.
 | 
			
		||||
 * The default protocol configuration looks like this:
 | 
			
		||||
 *
 | 
			
		||||
 *   [Protocol]
 | 
			
		||||
 *   Default = aidl
 | 
			
		||||
 *   /dev/binder = aidl
 | 
			
		||||
 *   /dev/hwbinder = hidl
 | 
			
		||||
 *
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
#define CONF_GROUP GBINDER_CONFIG_GROUP_PROTOCOL
 | 
			
		||||
#define CONF_DEFAULT GBINDER_CONFIG_VALUE_DEFAULT
 | 
			
		||||
 | 
			
		||||
static GHashTable* gbinder_rpc_protocol_map = NULL;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Default protocol for those binder devices which which haven't been
 | 
			
		||||
 * explicitely mapped.
 | 
			
		||||
 */
 | 
			
		||||
#define DEFAULT_PROTOCOL gbinder_rpc_protocol_aidl
 | 
			
		||||
static const GBinderRpcProtocol DEFAULT_PROTOCOL;
 | 
			
		||||
static const GBinderRpcProtocol* gbinder_rpc_protocol_default =
 | 
			
		||||
    &DEFAULT_PROTOCOL;
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * /dev/binder
 | 
			
		||||
 * The original AIDL protocol.
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
/* No idea what that is... */
 | 
			
		||||
#define STRICT_MODE_PENALTY_GATHER (0x40 << 16)
 | 
			
		||||
#define BINDER_RPC_FLAGS (STRICT_MODE_PENALTY_GATHER)
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_binder_write_ping(
 | 
			
		||||
gbinder_rpc_protocol_aidl_write_ping(
 | 
			
		||||
    GBinderWriter* writer)
 | 
			
		||||
{
 | 
			
		||||
    /* No payload */
 | 
			
		||||
@@ -60,7 +86,7 @@ gbinder_rpc_protocol_binder_write_ping(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_binder_write_rpc_header(
 | 
			
		||||
gbinder_rpc_protocol_aidl_write_rpc_header(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const char* iface)
 | 
			
		||||
{
 | 
			
		||||
@@ -75,7 +101,7 @@ gbinder_rpc_protocol_binder_write_rpc_header(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_rpc_protocol_binder_read_rpc_header(
 | 
			
		||||
gbinder_rpc_protocol_aidl_read_rpc_header(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    guint32 txcode,
 | 
			
		||||
    char** iface)
 | 
			
		||||
@@ -91,13 +117,69 @@ gbinder_rpc_protocol_binder_read_rpc_header(
 | 
			
		||||
    return *iface;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const GBinderRpcProtocol gbinder_rpc_protocol_aidl = {
 | 
			
		||||
    .name = "aidl",
 | 
			
		||||
    .ping_tx = GBINDER_PING_TRANSACTION,
 | 
			
		||||
    .write_ping = gbinder_rpc_protocol_aidl_write_ping,
 | 
			
		||||
    .write_rpc_header = gbinder_rpc_protocol_aidl_write_rpc_header,
 | 
			
		||||
    .read_rpc_header = gbinder_rpc_protocol_aidl_read_rpc_header
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * /dev/hwbinder
 | 
			
		||||
 * AIDL protocol appeared in Android 10 (API level 29)
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_hwbinder_write_rpc_header(
 | 
			
		||||
gbinder_rpc_protocol_aidl2_write_rpc_header(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const char* iface)
 | 
			
		||||
{
 | 
			
		||||
    /*
 | 
			
		||||
     * writeInt32(IPCThreadState::self()->getStrictModePolicy() |
 | 
			
		||||
     *               STRICT_MODE_PENALTY_GATHER);
 | 
			
		||||
     * writeInt32(IPCThreadState::kUnsetWorkSource);
 | 
			
		||||
     * writeString16(interface);
 | 
			
		||||
     */
 | 
			
		||||
    gbinder_writer_append_int32(writer, BINDER_RPC_FLAGS);
 | 
			
		||||
    gbinder_writer_append_int32(writer, UNSET_WORK_SOURCE);
 | 
			
		||||
    gbinder_writer_append_string16(writer, iface);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_rpc_protocol_aidl2_read_rpc_header(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    guint32 txcode,
 | 
			
		||||
    char** iface)
 | 
			
		||||
{
 | 
			
		||||
    if (txcode > GBINDER_TRANSACTION(0,0,0)) {
 | 
			
		||||
        /* Internal transaction e.g. GBINDER_DUMP_TRANSACTION etc. */
 | 
			
		||||
        *iface = NULL;
 | 
			
		||||
    } else if (gbinder_reader_read_int32(reader, NULL) /* flags */ &&
 | 
			
		||||
        gbinder_reader_read_int32(reader, NULL) /* work source */) {
 | 
			
		||||
        *iface = gbinder_reader_read_string16(reader);
 | 
			
		||||
    } else {
 | 
			
		||||
        *iface = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    return *iface;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const GBinderRpcProtocol gbinder_rpc_protocol_aidl2 = {
 | 
			
		||||
    .name = "aidl2",
 | 
			
		||||
    .ping_tx = GBINDER_PING_TRANSACTION,
 | 
			
		||||
    .write_ping = gbinder_rpc_protocol_aidl_write_ping, /* no payload */
 | 
			
		||||
    .write_rpc_header = gbinder_rpc_protocol_aidl2_write_rpc_header,
 | 
			
		||||
    .read_rpc_header = gbinder_rpc_protocol_aidl2_read_rpc_header
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * The original /dev/hwbinder protocol.
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_hidl_write_rpc_header(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const char* iface)
 | 
			
		||||
{
 | 
			
		||||
@@ -109,16 +191,16 @@ gbinder_rpc_protocol_hwbinder_write_rpc_header(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_hwbinder_write_ping(
 | 
			
		||||
gbinder_rpc_protocol_hidl_write_ping(
 | 
			
		||||
    GBinderWriter* writer)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_rpc_protocol_hwbinder_write_rpc_header(writer,
 | 
			
		||||
    gbinder_rpc_protocol_hidl_write_rpc_header(writer,
 | 
			
		||||
        "android.hidl.base@1.0::IBase");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
const char*
 | 
			
		||||
gbinder_rpc_protocol_hwbinder_read_rpc_header(
 | 
			
		||||
gbinder_rpc_protocol_hidl_read_rpc_header(
 | 
			
		||||
    GBinderReader* reader,
 | 
			
		||||
    guint32 txcode,
 | 
			
		||||
    char** iface)
 | 
			
		||||
@@ -127,30 +209,126 @@ gbinder_rpc_protocol_hwbinder_read_rpc_header(
 | 
			
		||||
    return gbinder_reader_read_string8(reader);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const GBinderRpcProtocol gbinder_rpc_protocol_hidl = {
 | 
			
		||||
    .name = "hidl",
 | 
			
		||||
    .ping_tx = HIDL_PING_TRANSACTION,
 | 
			
		||||
    .write_ping = gbinder_rpc_protocol_hidl_write_ping,
 | 
			
		||||
    .write_rpc_header = gbinder_rpc_protocol_hidl_write_rpc_header,
 | 
			
		||||
    .read_rpc_header = gbinder_rpc_protocol_hidl_read_rpc_header
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Implementation
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
/* All known protocols */
 | 
			
		||||
static const GBinderRpcProtocol* gbinder_rpc_protocol_list[] = {
 | 
			
		||||
    &gbinder_rpc_protocol_aidl,
 | 
			
		||||
    &gbinder_rpc_protocol_aidl2,
 | 
			
		||||
    &gbinder_rpc_protocol_hidl
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
const GBinderRpcProtocol*
 | 
			
		||||
gbinder_rpc_protocol_find(
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    guint i;
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < G_N_ELEMENTS(gbinder_rpc_protocol_list); i++) {
 | 
			
		||||
        if (!g_ascii_strcasecmp(gbinder_rpc_protocol_list[i]->name, name)) {
 | 
			
		||||
            return gbinder_rpc_protocol_list[i];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_map_add_default(
 | 
			
		||||
    GHashTable* map,
 | 
			
		||||
    const char* dev,
 | 
			
		||||
    const GBinderRpcProtocol* protocol)
 | 
			
		||||
{
 | 
			
		||||
    if (!g_hash_table_contains(map, dev)) {
 | 
			
		||||
        g_hash_table_insert(map, g_strdup(dev), (gpointer) protocol);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gconstpointer
 | 
			
		||||
gbinder_rpc_protocol_value_map(
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_rpc_protocol_find(name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GHashTable*
 | 
			
		||||
gbinder_rpc_protocol_load_config()
 | 
			
		||||
{
 | 
			
		||||
    GHashTable* map = gbinder_config_load(CONF_GROUP,
 | 
			
		||||
        gbinder_rpc_protocol_value_map);
 | 
			
		||||
 | 
			
		||||
    /* Add default configuration if it's not overridden */
 | 
			
		||||
    gbinder_rpc_protocol_map_add_default(map,
 | 
			
		||||
        GBINDER_DEFAULT_BINDER, &gbinder_rpc_protocol_aidl);
 | 
			
		||||
    gbinder_rpc_protocol_map_add_default(map,
 | 
			
		||||
        GBINDER_DEFAULT_HWBINDER, &gbinder_rpc_protocol_hidl);
 | 
			
		||||
 | 
			
		||||
    return map;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Runs at exit */
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_exit()
 | 
			
		||||
{
 | 
			
		||||
    if (gbinder_rpc_protocol_map) {
 | 
			
		||||
        g_hash_table_destroy(gbinder_rpc_protocol_map);
 | 
			
		||||
        gbinder_rpc_protocol_map = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    /* Reset the default too, mostly for unit testing */
 | 
			
		||||
    gbinder_rpc_protocol_default = &DEFAULT_PROTOCOL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
const GBinderRpcProtocol gbinder_rpc_protocol_binder = {
 | 
			
		||||
    .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 = {
 | 
			
		||||
    .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*
 | 
			
		||||
gbinder_rpc_protocol_for_device(
 | 
			
		||||
    const char* dev)
 | 
			
		||||
{
 | 
			
		||||
    return (dev && !strcmp(dev, GBINDER_DEFAULT_HWBINDER)) ?
 | 
			
		||||
        &gbinder_rpc_protocol_hwbinder : &gbinder_rpc_protocol_binder;
 | 
			
		||||
    if (dev) {
 | 
			
		||||
        const GBinderRpcProtocol* protocol;
 | 
			
		||||
 | 
			
		||||
        if (!gbinder_rpc_protocol_map) {
 | 
			
		||||
            const GBinderRpcProtocol* p;
 | 
			
		||||
 | 
			
		||||
            /* One-time initialization */
 | 
			
		||||
            gbinder_rpc_protocol_map = gbinder_rpc_protocol_load_config();
 | 
			
		||||
 | 
			
		||||
            /* "Default" is a special value stored in a special variable */
 | 
			
		||||
            p = g_hash_table_lookup(gbinder_rpc_protocol_map, CONF_DEFAULT);
 | 
			
		||||
            if (p) {
 | 
			
		||||
                g_hash_table_remove(gbinder_rpc_protocol_map, CONF_DEFAULT);
 | 
			
		||||
                gbinder_rpc_protocol_default = p;
 | 
			
		||||
            } else {
 | 
			
		||||
                gbinder_rpc_protocol_default = &DEFAULT_PROTOCOL;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        protocol = g_hash_table_lookup(gbinder_rpc_protocol_map, dev);
 | 
			
		||||
        if (protocol) {
 | 
			
		||||
            GDEBUG("Using %s protocol for %s", protocol->name, dev);
 | 
			
		||||
            return protocol;
 | 
			
		||||
        }
 | 
			
		||||
        GDEBUG("Using default protocol %s for %s",
 | 
			
		||||
            gbinder_rpc_protocol_default->name, dev);
 | 
			
		||||
    } else {
 | 
			
		||||
        GDEBUG("Using default protocol %s",
 | 
			
		||||
            gbinder_rpc_protocol_default->name);
 | 
			
		||||
    }
 | 
			
		||||
    return gbinder_rpc_protocol_default;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -13,10 +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.
 | 
			
		||||
 *      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
 | 
			
		||||
@@ -37,11 +36,12 @@
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * For whatever reason services communicating via /dev/binder
 | 
			
		||||
 * and /dev/hwbinder use slightly different RPC headers.
 | 
			
		||||
 * There are several versions of binder RPC protocol with diffferent
 | 
			
		||||
 * transaction headers and transaction codes.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
struct gbinder_rpc_protocol {
 | 
			
		||||
    const char* name;
 | 
			
		||||
    guint32 ping_tx;
 | 
			
		||||
    void (*write_ping)(GBinderWriter* writer);
 | 
			
		||||
    void (*write_rpc_header)(GBinderWriter* writer, const char* iface);
 | 
			
		||||
@@ -49,13 +49,18 @@ struct gbinder_rpc_protocol {
 | 
			
		||||
        char** iface);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern const GBinderRpcProtocol gbinder_rpc_protocol_binder;
 | 
			
		||||
extern const GBinderRpcProtocol gbinder_rpc_protocol_hwbinder;
 | 
			
		||||
 | 
			
		||||
/* Returns one of the above based on the device name */
 | 
			
		||||
const GBinderRpcProtocol*
 | 
			
		||||
gbinder_rpc_protocol_for_device(
 | 
			
		||||
    const char* dev);
 | 
			
		||||
    const char* dev)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
/* Runs at exit, declared here strictly for unit tests */
 | 
			
		||||
void
 | 
			
		||||
gbinder_rpc_protocol_exit(
 | 
			
		||||
    void)
 | 
			
		||||
    GBINDER_DESTRUCTOR
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_RPC_PROTOCOL_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -30,21 +30,69 @@
 | 
			
		||||
 * THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define GLIB_DISABLE_DEPRECATION_WARNINGS
 | 
			
		||||
 | 
			
		||||
#include "gbinder_servicemanager_p.h"
 | 
			
		||||
#include "gbinder_client_p.h"
 | 
			
		||||
#include "gbinder_config.h"
 | 
			
		||||
#include "gbinder_local_object_p.h"
 | 
			
		||||
#include "gbinder_remote_object_p.h"
 | 
			
		||||
#include "gbinder_eventloop_p.h"
 | 
			
		||||
#include "gbinder_driver.h"
 | 
			
		||||
#include "gbinder_ipc.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gbinder_client.h>
 | 
			
		||||
 | 
			
		||||
#include <gutil_idlepool.h>
 | 
			
		||||
#include <gutil_misc.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 *
 | 
			
		||||
 * Different versions of Android come with different flavors of service
 | 
			
		||||
 * managers. They are usually based on these two more or less independent
 | 
			
		||||
 * variants:
 | 
			
		||||
 *
 | 
			
		||||
 *   platform/frameworks/native/cmds/servicemanager/ServiceManager.cpp
 | 
			
		||||
 *   platform/system/hwservicemanager/ServiceManager.cpp
 | 
			
		||||
 *
 | 
			
		||||
 * They are talking slightly different protocols which slightly mutate
 | 
			
		||||
 * from version to version. If that's not complex enough, different
 | 
			
		||||
 * kinds of service managers can be running simultaneously, serving
 | 
			
		||||
 * different binder devices. Specific device => servicemanager mapping
 | 
			
		||||
 * can be optionally configured in /etc/gbinder.conf file. The default
 | 
			
		||||
 * service manager configuration looks like this:
 | 
			
		||||
 *
 | 
			
		||||
 *   [ServiceManager]
 | 
			
		||||
 *   Default = aidl
 | 
			
		||||
 *   /dev/binder = aidl
 | 
			
		||||
 *   /dev/hwbinder = hidl
 | 
			
		||||
 *
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
#define CONF_GROUP GBINDER_CONFIG_GROUP_SERVICEMANAGER
 | 
			
		||||
#define CONF_DEFAULT GBINDER_CONFIG_VALUE_DEFAULT
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_servicemanager_type {
 | 
			
		||||
    const char* name;
 | 
			
		||||
    GType (*get_type)(void);
 | 
			
		||||
} GBinderServiceManagerType;
 | 
			
		||||
 | 
			
		||||
static const GBinderServiceManagerType gbinder_servicemanager_types[] = {
 | 
			
		||||
    { "aidl", gbinder_servicemanager_aidl_get_type },
 | 
			
		||||
    { "aidl2", gbinder_servicemanager_aidl2_get_type },
 | 
			
		||||
    { "hidl", gbinder_servicemanager_hidl_get_type }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define SERVICEMANAGER_TYPE_AIDL (gbinder_servicemanager_types + 0)
 | 
			
		||||
#define SERVICEMANAGER_TYPE_HIDL (gbinder_servicemanager_types + 2)
 | 
			
		||||
#define SERVICEMANAGER_TYPE_DEFAULT SERVICEMANAGER_TYPE_AIDL
 | 
			
		||||
 | 
			
		||||
static GHashTable* gbinder_servicemanager_map = NULL;
 | 
			
		||||
static const GBinderServiceManagerType* gbinder_servicemanager_default =
 | 
			
		||||
    SERVICEMANAGER_TYPE_DEFAULT;
 | 
			
		||||
 | 
			
		||||
#define PRESENSE_WAIT_MS_MIN  (100)
 | 
			
		||||
#define PRESENSE_WAIT_MS_MAX  (1000)
 | 
			
		||||
#define PRESENSE_WAIT_MS_STEP (100)
 | 
			
		||||
@@ -60,8 +108,10 @@ struct gbinder_servicemanager_priv {
 | 
			
		||||
    GHashTable* watch_table;
 | 
			
		||||
    gulong death_id;
 | 
			
		||||
    gboolean present;
 | 
			
		||||
    guint presence_check_id;
 | 
			
		||||
    GBinderEventLoopTimeout* presence_check;
 | 
			
		||||
    guint presence_check_delay_ms;
 | 
			
		||||
    GBinderEventLoopCallback* autorelease_cb;
 | 
			
		||||
    GSList* autorelease;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_ABSTRACT_TYPE(GBinderServiceManager, gbinder_servicemanager,
 | 
			
		||||
@@ -71,9 +121,6 @@ G_DEFINE_ABSTRACT_TYPE(GBinderServiceManager, gbinder_servicemanager,
 | 
			
		||||
#define GBINDER_SERVICEMANAGER(obj) \
 | 
			
		||||
    G_TYPE_CHECK_INSTANCE_CAST((obj), GBINDER_TYPE_SERVICEMANAGER, \
 | 
			
		||||
    GBinderServiceManager)
 | 
			
		||||
#define GBINDER_SERVICEMANAGER_CLASS(klass) \
 | 
			
		||||
    G_TYPE_CHECK_CLASS_CAST((klass), GBINDER_TYPE_SERVICEMANAGER, \
 | 
			
		||||
    GBinderServiceManagerClass)
 | 
			
		||||
#define GBINDER_SERVICEMANAGER_GET_CLASS(obj) \
 | 
			
		||||
    G_TYPE_INSTANCE_GET_CLASS((obj), GBINDER_TYPE_SERVICEMANAGER, \
 | 
			
		||||
    GBinderServiceManagerClass)
 | 
			
		||||
@@ -152,7 +199,8 @@ gbinder_servicemanager_list_tx_exec(
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerListTxData* data = tx->user_data;
 | 
			
		||||
 | 
			
		||||
    data->result = GBINDER_SERVICEMANAGER_GET_CLASS(data->sm)->list(data->sm);
 | 
			
		||||
    data->result = GBINDER_SERVICEMANAGER_GET_CLASS(data->sm)->
 | 
			
		||||
        list(data->sm, &gbinder_ipc_sync_worker);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -165,6 +213,7 @@ gbinder_servicemanager_list_tx_done(
 | 
			
		||||
    if (!data->func(data->sm, data->result, data->user_data)) {
 | 
			
		||||
        g_strfreev(data->result);
 | 
			
		||||
    }
 | 
			
		||||
    data->result = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -174,6 +223,7 @@ gbinder_servicemanager_list_tx_free(
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerListTxData* data = user_data;
 | 
			
		||||
 | 
			
		||||
    g_strfreev(data->result);
 | 
			
		||||
    gbinder_servicemanager_unref(data->sm);
 | 
			
		||||
    g_slice_free(GBinderServiceManagerListTxData, data);
 | 
			
		||||
}
 | 
			
		||||
@@ -194,8 +244,9 @@ gbinder_servicemanager_get_service_tx_exec(
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerGetServiceTxData* data = tx->user_data;
 | 
			
		||||
 | 
			
		||||
    data->obj = GBINDER_SERVICEMANAGER_GET_CLASS(data->sm)->get_service
 | 
			
		||||
            (data->sm, data->name, &data->status);
 | 
			
		||||
    data->obj = GBINDER_SERVICEMANAGER_GET_CLASS(data->sm)->
 | 
			
		||||
        get_service(data->sm, data->name, &data->status,
 | 
			
		||||
            &gbinder_ipc_sync_worker);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -237,8 +288,8 @@ gbinder_servicemanager_add_service_tx_exec(
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerAddServiceTxData* data = tx->user_data;
 | 
			
		||||
 | 
			
		||||
    data->status = GBINDER_SERVICEMANAGER_GET_CLASS(data->sm)->add_service
 | 
			
		||||
            (data->sm, data->name, data->obj);
 | 
			
		||||
    data->status = GBINDER_SERVICEMANAGER_GET_CLASS(data->sm)->
 | 
			
		||||
        add_service(data->sm, data->name, data->obj, &gbinder_ipc_sync_worker);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
@@ -271,9 +322,9 @@ gbinder_servicemanager_reanimated(
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    if (priv->presence_check_id) {
 | 
			
		||||
        g_source_remove(priv->presence_check_id);
 | 
			
		||||
        priv->presence_check_id = 0;
 | 
			
		||||
    if (priv->presence_check) {
 | 
			
		||||
        gbinder_timeout_remove(priv->presence_check);
 | 
			
		||||
        priv->presence_check = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    GINFO("Service manager %s has appeared", self->dev);
 | 
			
		||||
    /* Re-arm the watches */
 | 
			
		||||
@@ -313,13 +364,14 @@ gbinder_servicemanager_presense_check_timer(
 | 
			
		||||
    gbinder_servicemanager_ref(self);
 | 
			
		||||
    if (gbinder_remote_object_reanimate(remote)) {
 | 
			
		||||
        /* Done */
 | 
			
		||||
        priv->presence_check_id = 0;
 | 
			
		||||
        priv->presence_check = NULL;
 | 
			
		||||
        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);
 | 
			
		||||
        priv->presence_check =
 | 
			
		||||
            gbinder_timeout_add(priv->presence_check_delay_ms,
 | 
			
		||||
                gbinder_servicemanager_presense_check_timer, self);
 | 
			
		||||
        result = G_SOURCE_REMOVE;
 | 
			
		||||
    } else {
 | 
			
		||||
        result = G_SOURCE_CONTINUE;
 | 
			
		||||
@@ -335,9 +387,9 @@ gbinder_servicemanager_presence_check_start(
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    GASSERT(!priv->presence_check_id);
 | 
			
		||||
    GASSERT(!priv->presence_check);
 | 
			
		||||
    priv->presence_check_delay_ms = PRESENSE_WAIT_MS_MIN;
 | 
			
		||||
    priv->presence_check_id = g_timeout_add(PRESENSE_WAIT_MS_MIN,
 | 
			
		||||
    priv->presence_check = gbinder_timeout_add(PRESENSE_WAIT_MS_MIN,
 | 
			
		||||
        gbinder_servicemanager_presense_check_timer, self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -387,6 +439,78 @@ gbinder_servicemanager_sleep_ms(
 | 
			
		||||
        (wait.tv_sec > 0 || wait.tv_nsec > 0));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_autorelease_cb(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManager* self = GBINDER_SERVICEMANAGER(data);
 | 
			
		||||
    GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
    GSList* list = priv->autorelease;
 | 
			
		||||
 | 
			
		||||
    priv->autorelease_cb = NULL;
 | 
			
		||||
    priv->autorelease = NULL;
 | 
			
		||||
    g_slist_free_full(list, g_object_unref);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_map_add_default(
 | 
			
		||||
    GHashTable* map,
 | 
			
		||||
    const char* dev,
 | 
			
		||||
    const GBinderServiceManagerType* type)
 | 
			
		||||
{
 | 
			
		||||
    if (!g_hash_table_contains(map, dev)) {
 | 
			
		||||
        g_hash_table_insert(map, g_strdup(dev), (gpointer) type);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gconstpointer
 | 
			
		||||
gbinder_servicemanager_value_map(
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    guint i;
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < G_N_ELEMENTS(gbinder_servicemanager_types); i++) {
 | 
			
		||||
        const GBinderServiceManagerType* t = gbinder_servicemanager_types + i;
 | 
			
		||||
 | 
			
		||||
        if (!g_strcmp0(name, t->name)) {
 | 
			
		||||
            return t;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GHashTable*
 | 
			
		||||
gbinder_servicemanager_load_config()
 | 
			
		||||
{
 | 
			
		||||
    GHashTable* map = gbinder_config_load(CONF_GROUP,
 | 
			
		||||
        gbinder_servicemanager_value_map);
 | 
			
		||||
 | 
			
		||||
    /* Add default configuration if it's not overridden */
 | 
			
		||||
    gbinder_servicemanager_map_add_default(map,
 | 
			
		||||
        GBINDER_DEFAULT_BINDER, SERVICEMANAGER_TYPE_AIDL);
 | 
			
		||||
    gbinder_servicemanager_map_add_default(map,
 | 
			
		||||
        GBINDER_DEFAULT_HWBINDER, SERVICEMANAGER_TYPE_HIDL);
 | 
			
		||||
 | 
			
		||||
    return map;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Runs at exit */
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_exit(
 | 
			
		||||
    void)
 | 
			
		||||
{
 | 
			
		||||
    if (gbinder_servicemanager_map) {
 | 
			
		||||
        g_hash_table_destroy(gbinder_servicemanager_map);
 | 
			
		||||
        gbinder_servicemanager_map = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    /* Reset the default too, mostly for unit testing */
 | 
			
		||||
    gbinder_servicemanager_default = SERVICEMANAGER_TYPE_DEFAULT;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Internal interface
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -403,11 +527,10 @@ gbinder_servicemanager_new_with_type(
 | 
			
		||||
        GBinderIpc* ipc;
 | 
			
		||||
 | 
			
		||||
        if (!dev) dev = klass->default_device;
 | 
			
		||||
        ipc = gbinder_ipc_new(dev, klass->rpc_protocol);
 | 
			
		||||
        ipc = gbinder_ipc_new(dev);
 | 
			
		||||
        if (ipc) {
 | 
			
		||||
            /* Create a possible dead remote object */
 | 
			
		||||
            GBinderRemoteObject* object = gbinder_ipc_get_remote_object
 | 
			
		||||
                (ipc, klass->handle, TRUE);
 | 
			
		||||
            /* Create a (possibly) dead service manager object */
 | 
			
		||||
            GBinderRemoteObject* object = gbinder_ipc_get_service_manager(ipc);
 | 
			
		||||
 | 
			
		||||
            if (object) {
 | 
			
		||||
                gboolean first_ref;
 | 
			
		||||
@@ -496,11 +619,35 @@ GBinderServiceManager*
 | 
			
		||||
gbinder_servicemanager_new(
 | 
			
		||||
    const char* dev)
 | 
			
		||||
{
 | 
			
		||||
    if (!g_strcmp0(dev, GBINDER_DEFAULT_HWBINDER)) {
 | 
			
		||||
        return gbinder_hwservicemanager_new(dev);
 | 
			
		||||
    } else {
 | 
			
		||||
        return gbinder_defaultservicemanager_new(dev);
 | 
			
		||||
    if (dev) {
 | 
			
		||||
        const GBinderServiceManagerType* type = NULL;
 | 
			
		||||
 | 
			
		||||
        if (!gbinder_servicemanager_map) {
 | 
			
		||||
            const GBinderServiceManagerType* t;
 | 
			
		||||
 | 
			
		||||
            /* One-time initialization */
 | 
			
		||||
            gbinder_servicemanager_map = gbinder_servicemanager_load_config();
 | 
			
		||||
 | 
			
		||||
            /* "Default" is a special value stored in a special variable */
 | 
			
		||||
            t = g_hash_table_lookup(gbinder_servicemanager_map, CONF_DEFAULT);
 | 
			
		||||
            if (t) {
 | 
			
		||||
                g_hash_table_remove(gbinder_servicemanager_map, CONF_DEFAULT);
 | 
			
		||||
                gbinder_servicemanager_default = t;
 | 
			
		||||
            } else {
 | 
			
		||||
                gbinder_servicemanager_default = SERVICEMANAGER_TYPE_DEFAULT;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        type = g_hash_table_lookup(gbinder_servicemanager_map, dev);
 | 
			
		||||
        if (type) {
 | 
			
		||||
            GDEBUG("Using %s service manager for %s", type->name, dev);
 | 
			
		||||
        } else {
 | 
			
		||||
            type = gbinder_servicemanager_default;
 | 
			
		||||
            GDEBUG("Using default service manager %s for %s", type->name, dev);
 | 
			
		||||
        }
 | 
			
		||||
        return gbinder_servicemanager_new_with_type(type->get_type(), dev);
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
@@ -630,7 +777,8 @@ gbinder_servicemanager_list_sync(
 | 
			
		||||
    GBinderServiceManager* self)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self)) {
 | 
			
		||||
        return GBINDER_SERVICEMANAGER_GET_CLASS(self)->list(self);
 | 
			
		||||
        return GBINDER_SERVICEMANAGER_GET_CLASS(self)->
 | 
			
		||||
            list(self, &gbinder_ipc_sync_main);
 | 
			
		||||
    }
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
@@ -669,12 +817,17 @@ gbinder_servicemanager_get_service_sync(
 | 
			
		||||
    GBinderRemoteObject* obj = NULL;
 | 
			
		||||
 | 
			
		||||
    if (G_LIKELY(self) && name) {
 | 
			
		||||
        obj = GBINDER_SERVICEMANAGER_GET_CLASS(self)->get_service
 | 
			
		||||
            (self, name, status);
 | 
			
		||||
        if (!self->pool) {
 | 
			
		||||
            self->pool = gutil_idle_pool_new();
 | 
			
		||||
        obj = GBINDER_SERVICEMANAGER_GET_CLASS(self)->
 | 
			
		||||
            get_service(self, name, status, &gbinder_ipc_sync_main);
 | 
			
		||||
        if (obj) {
 | 
			
		||||
            GBinderServiceManagerPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
            priv->autorelease = g_slist_prepend(priv->autorelease, obj);
 | 
			
		||||
            if (!priv->autorelease_cb) {
 | 
			
		||||
                priv->autorelease_cb = gbinder_idle_callback_schedule_new
 | 
			
		||||
                    (gbinder_servicemanager_autorelease_cb, self, NULL);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        gutil_idle_pool_add_object(self->pool, obj);
 | 
			
		||||
    } else if (status) {
 | 
			
		||||
        *status = (-EINVAL);
 | 
			
		||||
    }
 | 
			
		||||
@@ -715,8 +868,8 @@ gbinder_servicemanager_add_service_sync(
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    if (G_LIKELY(self) && name && obj) {
 | 
			
		||||
        return GBINDER_SERVICEMANAGER_GET_CLASS(self)->add_service
 | 
			
		||||
            (self, name, obj);
 | 
			
		||||
        return GBINDER_SERVICEMANAGER_GET_CLASS(self)->
 | 
			
		||||
            add_service(self, name, obj, &gbinder_ipc_sync_main);
 | 
			
		||||
    } else {
 | 
			
		||||
        return (-EINVAL);
 | 
			
		||||
    }
 | 
			
		||||
@@ -844,6 +997,28 @@ gbinder_servicemanager_remove_handlers(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * These two exist mostly for backward compatibility. Normally,
 | 
			
		||||
 * gbinder_servicemanager_new() should be used, to allow the type of
 | 
			
		||||
 * service manager to be configurable per device via /etc/gbinder.conf
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_defaultservicemanager_new(
 | 
			
		||||
    const char* dev)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_servicemanager_new_with_type
 | 
			
		||||
        (gbinder_servicemanager_aidl_get_type(), dev);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_hwservicemanager_new(
 | 
			
		||||
    const char* dev)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_servicemanager_new_with_type
 | 
			
		||||
        (gbinder_servicemanager_hidl_get_type(), dev);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*==========================================================================*
 | 
			
		||||
 * Internals
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
@@ -911,12 +1086,11 @@ 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_timeout_remove(priv->presence_check);
 | 
			
		||||
    gbinder_remote_object_remove_handler(self->client->remote, priv->death_id);
 | 
			
		||||
    gbinder_idle_callback_destroy(priv->autorelease_cb);
 | 
			
		||||
    g_slist_free_full(priv->autorelease, g_object_unref);
 | 
			
		||||
    g_hash_table_destroy(priv->watch_table);
 | 
			
		||||
    gutil_idle_pool_destroy(self->pool);
 | 
			
		||||
    gbinder_client_unref(self->client);
 | 
			
		||||
    G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										343
									
								
								src/gbinder_servicemanager_aidl.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										343
									
								
								src/gbinder_servicemanager_aidl.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,343 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
 * 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.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define GLIB_DISABLE_DEPRECATION_WARNINGS
 | 
			
		||||
 | 
			
		||||
#include "gbinder_servicemanager_aidl.h"
 | 
			
		||||
#include "gbinder_servicepoll.h"
 | 
			
		||||
#include "gbinder_eventloop_p.h"
 | 
			
		||||
#include "gbinder_client_p.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gbinder_local_request.h>
 | 
			
		||||
#include <gbinder_remote_reply.h>
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_servicemanager_aidl_watch {
 | 
			
		||||
    GBinderServicePoll* poll;
 | 
			
		||||
    char* name;
 | 
			
		||||
    gulong handler_id;
 | 
			
		||||
    GBinderEventLoopTimeout* notify;
 | 
			
		||||
} GBinderServiceManagerAidlWatch;
 | 
			
		||||
 | 
			
		||||
struct gbinder_servicemanager_aidl_priv {
 | 
			
		||||
    GBinderServicePoll* poll;
 | 
			
		||||
    GHashTable* watch_table;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE(GBinderServiceManagerAidl,
 | 
			
		||||
    gbinder_servicemanager_aidl,
 | 
			
		||||
    GBINDER_TYPE_SERVICEMANAGER)
 | 
			
		||||
 | 
			
		||||
#define PARENT_CLASS gbinder_servicemanager_aidl_parent_class
 | 
			
		||||
#define GBINDER_SERVICEMANAGER_AIDL(obj) \
 | 
			
		||||
    G_TYPE_CHECK_INSTANCE_CAST((obj), GBINDER_TYPE_SERVICEMANAGER_AIDL, \
 | 
			
		||||
    GBinderServiceManagerAidl)
 | 
			
		||||
#define GBINDER_SERVICEMANAGER_AIDL_GET_CLASS(obj) \
 | 
			
		||||
    G_TYPE_INSTANCE_GET_CLASS((obj), GBINDER_TYPE_SERVICEMANAGER_AIDL, \
 | 
			
		||||
    GBinderServiceManagerAidlClass)
 | 
			
		||||
 | 
			
		||||
enum gbinder_servicemanager_aidl_calls {
 | 
			
		||||
    GET_SERVICE_TRANSACTION = GBINDER_FIRST_CALL_TRANSACTION,
 | 
			
		||||
    CHECK_SERVICE_TRANSACTION,
 | 
			
		||||
    ADD_SERVICE_TRANSACTION,
 | 
			
		||||
    LIST_SERVICES_TRANSACTION
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define SERVICEMANAGER_AIDL_IFACE  "android.os.IServiceManager"
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_aidl_watch_proc(
 | 
			
		||||
    GBinderServicePoll* poll,
 | 
			
		||||
    const char* name_added,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerAidlWatch* watch = user_data;
 | 
			
		||||
 | 
			
		||||
    if (!g_strcmp0(name_added, watch->name)) {
 | 
			
		||||
        GBinderServiceManager* manager =
 | 
			
		||||
            gbinder_servicepoll_manager(watch->poll);
 | 
			
		||||
 | 
			
		||||
        if (watch->notify) {
 | 
			
		||||
            gbinder_timeout_remove(watch->notify);
 | 
			
		||||
            watch->notify = NULL;
 | 
			
		||||
        }
 | 
			
		||||
        gbinder_servicemanager_service_registered(manager, name_added);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_servicemanager_aidl_watch_notify(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerAidlWatch* watch = user_data;
 | 
			
		||||
    GBinderServiceManager* manager = gbinder_servicepoll_manager(watch->poll);
 | 
			
		||||
    char* name = g_strdup(watch->name);
 | 
			
		||||
 | 
			
		||||
    GASSERT(watch->notify);
 | 
			
		||||
    watch->notify = NULL;
 | 
			
		||||
    gbinder_servicemanager_service_registered(manager, name);
 | 
			
		||||
    g_free(name);
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_aidl_watch_free(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerAidlWatch* watch = user_data;
 | 
			
		||||
 | 
			
		||||
    gbinder_timeout_remove(watch->notify);
 | 
			
		||||
    gbinder_servicepoll_remove_handler(watch->poll, watch->handler_id);
 | 
			
		||||
    gbinder_servicepoll_unref(watch->poll);
 | 
			
		||||
    g_free(watch->name);
 | 
			
		||||
    g_slice_free(GBinderServiceManagerAidlWatch, watch);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderServiceManagerAidlWatch*
 | 
			
		||||
gbinder_servicemanager_aidl_watch_new(
 | 
			
		||||
    GBinderServiceManagerAidl* self,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerAidlPriv* priv = self->priv;
 | 
			
		||||
    GBinderServiceManagerAidlWatch* watch =
 | 
			
		||||
        g_slice_new0(GBinderServiceManagerAidlWatch);
 | 
			
		||||
 | 
			
		||||
    watch->name = g_strdup(name);
 | 
			
		||||
    watch->poll = gbinder_servicepoll_new(&self->manager, &priv->poll);
 | 
			
		||||
    watch->handler_id = gbinder_servicepoll_add_handler(priv->poll,
 | 
			
		||||
        gbinder_servicemanager_aidl_watch_proc, watch);
 | 
			
		||||
    return watch;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_servicemanager_aidl_list_services_req(
 | 
			
		||||
    GBinderClient* client,
 | 
			
		||||
    gint32 index)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_client_new_request(client);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_append_int32(req, index);
 | 
			
		||||
    return req;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_servicemanager_aidl_add_service_req(
 | 
			
		||||
    GBinderClient* client,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_client_new_request(client);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_append_string16(req, name);
 | 
			
		||||
    gbinder_local_request_append_local_object(req, obj);
 | 
			
		||||
    gbinder_local_request_append_int32(req, 0);
 | 
			
		||||
    return req;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
char**
 | 
			
		||||
gbinder_servicemanager_aidl_list(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
{
 | 
			
		||||
    GPtrArray* list = g_ptr_array_new();
 | 
			
		||||
    GBinderClient* client = manager->client;
 | 
			
		||||
    GBinderServiceManagerAidlClass* klass =
 | 
			
		||||
        GBINDER_SERVICEMANAGER_AIDL_GET_CLASS(manager);
 | 
			
		||||
    GBinderLocalRequest* req = klass->list_services_req(client, 0);
 | 
			
		||||
    GBinderRemoteReply* reply;
 | 
			
		||||
 | 
			
		||||
    while ((reply = gbinder_client_transact_sync_reply2(client,
 | 
			
		||||
        LIST_SERVICES_TRANSACTION, req, NULL, api)) != NULL) {
 | 
			
		||||
        char* service = gbinder_remote_reply_read_string16(reply);
 | 
			
		||||
 | 
			
		||||
        gbinder_remote_reply_unref(reply);
 | 
			
		||||
        if (service) {
 | 
			
		||||
            g_ptr_array_add(list, service);
 | 
			
		||||
            gbinder_local_request_unref(req);
 | 
			
		||||
            req = klass->list_services_req(client, list->len);
 | 
			
		||||
        } else {
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    g_ptr_array_add(list, NULL);
 | 
			
		||||
    return (char**)g_ptr_array_free(list, FALSE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_servicemanager_aidl_get_service(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    int* status,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
{
 | 
			
		||||
    GBinderRemoteObject* obj;
 | 
			
		||||
    GBinderRemoteReply* reply;
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_client_new_request(self->client);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_append_string16(req, name);
 | 
			
		||||
    reply = gbinder_client_transact_sync_reply2(self->client,
 | 
			
		||||
        CHECK_SERVICE_TRANSACTION, req, status, api);
 | 
			
		||||
 | 
			
		||||
    obj = gbinder_remote_reply_read_object(reply);
 | 
			
		||||
    gbinder_remote_reply_unref(reply);
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    return obj;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
gbinder_servicemanager_aidl_add_service(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
{
 | 
			
		||||
    int status;
 | 
			
		||||
    GBinderClient* client = manager->client;
 | 
			
		||||
    GBinderLocalRequest* req = GBINDER_SERVICEMANAGER_AIDL_GET_CLASS
 | 
			
		||||
        (manager)->add_service_req(client, name, obj);
 | 
			
		||||
    GBinderRemoteReply* reply = gbinder_client_transact_sync_reply2(client,
 | 
			
		||||
        ADD_SERVICE_TRANSACTION, req, &status, api);
 | 
			
		||||
 | 
			
		||||
    gbinder_remote_reply_unref(reply);
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    return status;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBINDER_SERVICEMANAGER_NAME_CHECK
 | 
			
		||||
gbinder_servicemanager_aidl_check_name(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    return GBINDER_SERVICEMANAGER_NAME_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_servicemanager_aidl_watch(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerAidl* self = GBINDER_SERVICEMANAGER_AIDL(manager);
 | 
			
		||||
    GBinderServiceManagerAidlPriv* priv = self->priv;
 | 
			
		||||
    GBinderServiceManagerAidlWatch* watch =
 | 
			
		||||
        gbinder_servicemanager_aidl_watch_new(self, name);
 | 
			
		||||
 | 
			
		||||
    g_hash_table_replace(priv->watch_table, watch->name, watch);
 | 
			
		||||
    if (gbinder_servicepoll_is_known_name(watch->poll, name)) {
 | 
			
		||||
        watch->notify = gbinder_idle_add
 | 
			
		||||
            (gbinder_servicemanager_aidl_watch_notify, watch);
 | 
			
		||||
    }
 | 
			
		||||
    return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_aidl_unwatch(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerAidl* self = GBINDER_SERVICEMANAGER_AIDL(manager);
 | 
			
		||||
    GBinderServiceManagerAidlPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    g_hash_table_remove(priv->watch_table, name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_aidl_init(
 | 
			
		||||
    GBinderServiceManagerAidl* self)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerAidlPriv* priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
 | 
			
		||||
        GBINDER_TYPE_SERVICEMANAGER_AIDL, GBinderServiceManagerAidlPriv);
 | 
			
		||||
 | 
			
		||||
    self->priv = priv;
 | 
			
		||||
    priv->watch_table = g_hash_table_new_full(g_str_hash, g_str_equal,
 | 
			
		||||
        NULL, gbinder_servicemanager_aidl_watch_free);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_aidl_finalize(
 | 
			
		||||
    GObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerAidl* self = GBINDER_SERVICEMANAGER_AIDL(object);
 | 
			
		||||
    GBinderServiceManagerAidlPriv* priv = self->priv;
 | 
			
		||||
 | 
			
		||||
    g_hash_table_destroy(priv->watch_table);
 | 
			
		||||
    G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_aidl_class_init(
 | 
			
		||||
    GBinderServiceManagerAidlClass* klass)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceManagerClass* manager = GBINDER_SERVICEMANAGER_CLASS(klass);
 | 
			
		||||
    GObjectClass* object = G_OBJECT_CLASS(klass);
 | 
			
		||||
 | 
			
		||||
    g_type_class_add_private(klass, sizeof(GBinderServiceManagerAidlPriv));
 | 
			
		||||
    klass->list_services_req = gbinder_servicemanager_aidl_list_services_req;
 | 
			
		||||
    klass->add_service_req = gbinder_servicemanager_aidl_add_service_req;
 | 
			
		||||
 | 
			
		||||
    manager->iface = SERVICEMANAGER_AIDL_IFACE;
 | 
			
		||||
    manager->default_device = GBINDER_DEFAULT_BINDER;
 | 
			
		||||
 | 
			
		||||
    manager->list = gbinder_servicemanager_aidl_list;
 | 
			
		||||
    manager->get_service = gbinder_servicemanager_aidl_get_service;
 | 
			
		||||
    manager->add_service = gbinder_servicemanager_aidl_add_service;
 | 
			
		||||
    manager->check_name = gbinder_servicemanager_aidl_check_name;
 | 
			
		||||
    /* normalize_name is not needed */
 | 
			
		||||
    manager->watch = gbinder_servicemanager_aidl_watch;
 | 
			
		||||
    manager->unwatch = gbinder_servicemanager_aidl_unwatch;
 | 
			
		||||
 | 
			
		||||
    object->finalize = gbinder_servicemanager_aidl_finalize;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										66
									
								
								src/gbinder_servicemanager_aidl.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								src/gbinder_servicemanager_aidl.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef GBINDER_SERVICEMANAGER_AIDL_H
 | 
			
		||||
#define GBINDER_SERVICEMANAGER_AIDL_H
 | 
			
		||||
 | 
			
		||||
#include "gbinder_servicemanager_p.h"
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_servicemanager_aidl_priv GBinderServiceManagerAidlPriv;
 | 
			
		||||
typedef struct gbinder_servicemanager_aidl {
 | 
			
		||||
    GBinderServiceManager manager;
 | 
			
		||||
    GBinderServiceManagerAidlPriv* priv;
 | 
			
		||||
} GBinderServiceManagerAidl;
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_servicemanager_aidl_class {
 | 
			
		||||
    GBinderServiceManagerClass parent;
 | 
			
		||||
    GBinderLocalRequest* (*list_services_req)
 | 
			
		||||
        (GBinderClient* client, gint32 index);
 | 
			
		||||
    GBinderLocalRequest* (*add_service_req)
 | 
			
		||||
        (GBinderClient* client, const char* name, GBinderLocalObject* obj);
 | 
			
		||||
} GBinderServiceManagerAidlClass;
 | 
			
		||||
 | 
			
		||||
#define GBINDER_TYPE_SERVICEMANAGER_AIDL \
 | 
			
		||||
    gbinder_servicemanager_aidl_get_type()
 | 
			
		||||
#define GBINDER_SERVICEMANAGER_AIDL_CLASS(klass) \
 | 
			
		||||
    G_TYPE_CHECK_CLASS_CAST((klass), GBINDER_TYPE_SERVICEMANAGER_AIDL, \
 | 
			
		||||
    GBinderServiceManagerAidlClass)
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_SERVICEMANAGER_AIDL_H */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										102
									
								
								src/gbinder_servicemanager_aidl2.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								src/gbinder_servicemanager_aidl2.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,102 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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_servicemanager_aidl.h"
 | 
			
		||||
 | 
			
		||||
#include <gbinder_client.h>
 | 
			
		||||
#include <gbinder_local_request.h>
 | 
			
		||||
 | 
			
		||||
/* Variant of AIDL servicemanager appeared in Android 9 (API level 28) */
 | 
			
		||||
 | 
			
		||||
typedef GBinderServiceManagerAidl GBinderServiceManagerAidl2;
 | 
			
		||||
typedef GBinderServiceManagerAidlClass GBinderServiceManagerAidl2Class;
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE(GBinderServiceManagerAidl2,
 | 
			
		||||
    gbinder_servicemanager_aidl2,
 | 
			
		||||
    GBINDER_TYPE_SERVICEMANAGER_AIDL)
 | 
			
		||||
 | 
			
		||||
#define PARENT_CLASS gbinder_servicemanager_aidl2_parent_class
 | 
			
		||||
#define DUMP_FLAG_PRIORITY_DEFAULT (0x08)
 | 
			
		||||
#define DUMP_FLAG_PRIORITY_ALL     (0x0f)
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_servicemanager_aidl2_list_services_req(
 | 
			
		||||
    GBinderClient* client,
 | 
			
		||||
    gint32 index)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_client_new_request(client);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_append_int32(req, index);
 | 
			
		||||
    gbinder_local_request_append_int32(req, DUMP_FLAG_PRIORITY_ALL);
 | 
			
		||||
    return req;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalRequest*
 | 
			
		||||
gbinder_servicemanager_aidl2_add_service_req(
 | 
			
		||||
    GBinderClient* client,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_client_new_request(client);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_append_string16(req, name);
 | 
			
		||||
    gbinder_local_request_append_local_object(req, obj);
 | 
			
		||||
    gbinder_local_request_append_int32(req, 0);
 | 
			
		||||
    gbinder_local_request_append_int32(req, DUMP_FLAG_PRIORITY_DEFAULT);
 | 
			
		||||
    return req;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_aidl2_init(
 | 
			
		||||
    GBinderServiceManagerAidl* self)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_aidl2_class_init(
 | 
			
		||||
    GBinderServiceManagerAidl2Class* cls)
 | 
			
		||||
{
 | 
			
		||||
    cls->list_services_req = gbinder_servicemanager_aidl2_list_services_req;
 | 
			
		||||
    cls->add_service_req = gbinder_servicemanager_aidl2_add_service_req;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * 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-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -31,10 +31,9 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "gbinder_servicemanager_p.h"
 | 
			
		||||
#include "gbinder_rpc_protocol.h"
 | 
			
		||||
#include "gbinder_client_p.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gbinder_client.h>
 | 
			
		||||
#include <gbinder_local_object.h>
 | 
			
		||||
#include <gbinder_local_request.h>
 | 
			
		||||
#include <gbinder_remote_reply.h>
 | 
			
		||||
@@ -42,30 +41,30 @@
 | 
			
		||||
#include <gbinder_reader.h>
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_hwservicemanager_watch {
 | 
			
		||||
typedef struct gbinder_servicemanager_hidl_watch {
 | 
			
		||||
    char* name;
 | 
			
		||||
    GBinderLocalObject* callback;
 | 
			
		||||
} GBinderHwServiceManagerWatch;
 | 
			
		||||
} GBinderServiceManagerHidlWatch;
 | 
			
		||||
 | 
			
		||||
typedef GBinderServiceManagerClass GBinderHwServiceManagerClass;
 | 
			
		||||
typedef struct gbinder_hwservicemanager {
 | 
			
		||||
typedef GBinderServiceManagerClass GBinderServiceManagerHidlClass;
 | 
			
		||||
typedef struct gbinder_servicemanager_hidl {
 | 
			
		||||
    GBinderServiceManager manager;
 | 
			
		||||
    GHashTable* watch_table;
 | 
			
		||||
} GBinderHwServiceManager;
 | 
			
		||||
} GBinderServiceManagerHidl;
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE(GBinderHwServiceManager,
 | 
			
		||||
    gbinder_hwservicemanager,
 | 
			
		||||
G_DEFINE_TYPE(GBinderServiceManagerHidl,
 | 
			
		||||
    gbinder_servicemanager_hidl,
 | 
			
		||||
    GBINDER_TYPE_SERVICEMANAGER)
 | 
			
		||||
 | 
			
		||||
#define PARENT_CLASS gbinder_hwservicemanager_parent_class
 | 
			
		||||
#define GBINDER_TYPE_HWSERVICEMANAGER (gbinder_hwservicemanager_get_type())
 | 
			
		||||
#define GBINDER_HWSERVICEMANAGER(obj) \
 | 
			
		||||
    G_TYPE_CHECK_INSTANCE_CAST((obj), GBINDER_TYPE_HWSERVICEMANAGER, \
 | 
			
		||||
    GBinderHwServiceManager)
 | 
			
		||||
#define PARENT_CLASS gbinder_servicemanager_hidl_parent_class
 | 
			
		||||
#define GBINDER_TYPE_SERVICEMANAGER_HIDL \
 | 
			
		||||
    gbinder_servicemanager_hidl_get_type()
 | 
			
		||||
#define GBINDER_SERVICEMANAGER_HIDL(obj) \
 | 
			
		||||
    G_TYPE_CHECK_INSTANCE_CAST((obj), GBINDER_TYPE_SERVICEMANAGER_HIDL, \
 | 
			
		||||
    GBinderServiceManagerHidl)
 | 
			
		||||
 | 
			
		||||
enum gbinder_hwservicemanager_calls {
 | 
			
		||||
enum gbinder_servicemanager_hidl_calls {
 | 
			
		||||
    GET_TRANSACTION = GBINDER_FIRST_CALL_TRANSACTION,
 | 
			
		||||
    ADD_TRANSACTION,
 | 
			
		||||
    GET_TRANSPORT_TRANSACTION,
 | 
			
		||||
@@ -76,20 +75,18 @@ enum gbinder_hwservicemanager_calls {
 | 
			
		||||
    REGISTER_PASSTHROUGH_CLIENT_TRANSACTION
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum gbinder_hwservicemanager_notifications {
 | 
			
		||||
enum gbinder_servicemanager_hidl_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 \
 | 
			
		||||
#define SERVICEMANAGER_HIDL_IFACE  "android.hidl.manager@1.0::IServiceManager"
 | 
			
		||||
#define SERVICEMANAGER_HIDL_NOTIFICATION_IFACE \
 | 
			
		||||
    "android.hidl.manager@1.0::IServiceNotification"
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_hwservicemanager_handle_registration(
 | 
			
		||||
    GBinderHwServiceManager* self,
 | 
			
		||||
gbinder_servicemanager_hidl_handle_registration(
 | 
			
		||||
    GBinderServiceManagerHidl* self,
 | 
			
		||||
    GBinderReader* reader)
 | 
			
		||||
{
 | 
			
		||||
    char* fqname = gbinder_reader_read_hidl_string(reader);
 | 
			
		||||
@@ -113,7 +110,7 @@ gbinder_hwservicemanager_handle_registration(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderLocalReply*
 | 
			
		||||
gbinder_hwservicemanager_notification(
 | 
			
		||||
gbinder_servicemanager_hidl_notification(
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    GBinderRemoteRequest* req,
 | 
			
		||||
    guint code,
 | 
			
		||||
@@ -121,22 +118,22 @@ gbinder_hwservicemanager_notification(
 | 
			
		||||
    int* status,
 | 
			
		||||
    void* user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderHwServiceManager* self = GBINDER_HWSERVICEMANAGER(user_data);
 | 
			
		||||
    GBinderServiceManagerHidl* self = GBINDER_SERVICEMANAGER_HIDL(user_data);
 | 
			
		||||
    const char* iface = gbinder_remote_request_interface(req);
 | 
			
		||||
 | 
			
		||||
    if (!g_strcmp0(iface, HWSERVICEMANAGER_NOTIFICATION_IFACE)) {
 | 
			
		||||
    if (!g_strcmp0(iface, SERVICEMANAGER_HIDL_NOTIFICATION_IFACE)) {
 | 
			
		||||
        GBinderReader reader;
 | 
			
		||||
 | 
			
		||||
        gbinder_remote_request_init_reader(req, &reader);
 | 
			
		||||
        switch (code) {
 | 
			
		||||
        case ON_REGISTRATION_TRANSACTION:
 | 
			
		||||
            GDEBUG(HWSERVICEMANAGER_NOTIFICATION_IFACE " %u onRegistration",
 | 
			
		||||
            GDEBUG(SERVICEMANAGER_HIDL_NOTIFICATION_IFACE " %u onRegistration",
 | 
			
		||||
                code);
 | 
			
		||||
            gbinder_hwservicemanager_handle_registration(self, &reader);
 | 
			
		||||
            gbinder_servicemanager_hidl_handle_registration(self, &reader);
 | 
			
		||||
            *status = GBINDER_STATUS_OK;
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            GDEBUG(HWSERVICEMANAGER_NOTIFICATION_IFACE " %u", code);
 | 
			
		||||
            GDEBUG(SERVICEMANAGER_HIDL_NOTIFICATION_IFACE " %u", code);
 | 
			
		||||
            *status = GBINDER_STATUS_FAILED;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
@@ -147,22 +144,15 @@ gbinder_hwservicemanager_notification(
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_hwservicemanager_new(
 | 
			
		||||
    const char* dev)
 | 
			
		||||
{
 | 
			
		||||
    return gbinder_servicemanager_new_with_type
 | 
			
		||||
        (gbinder_hwservicemanager_get_type(), dev);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
char**
 | 
			
		||||
gbinder_hwservicemanager_list(
 | 
			
		||||
    GBinderServiceManager* self)
 | 
			
		||||
gbinder_servicemanager_hidl_list(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_client_new_request(self->client);
 | 
			
		||||
    GBinderRemoteReply* reply = gbinder_client_transact_sync_reply
 | 
			
		||||
        (self->client, LIST_TRANSACTION, req, NULL);
 | 
			
		||||
    GBinderRemoteReply* reply = gbinder_client_transact_sync_reply2
 | 
			
		||||
        (self->client, LIST_TRANSACTION, req, NULL, api);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
    if (reply) {
 | 
			
		||||
@@ -186,10 +176,11 @@ gbinder_hwservicemanager_list(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBinderRemoteObject*
 | 
			
		||||
gbinder_hwservicemanager_get_service(
 | 
			
		||||
gbinder_servicemanager_hidl_get_service(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* fqinstance,
 | 
			
		||||
    int* status)
 | 
			
		||||
    int* status,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
{
 | 
			
		||||
    /* e.g. "android.hardware.radio@1.1::IRadio/slot1" */
 | 
			
		||||
    const char* sep = strchr(fqinstance, '/');
 | 
			
		||||
@@ -204,8 +195,8 @@ gbinder_hwservicemanager_get_service(
 | 
			
		||||
        gbinder_local_request_append_hidl_string(req, fqname);
 | 
			
		||||
        gbinder_local_request_append_hidl_string(req, name);
 | 
			
		||||
 | 
			
		||||
        reply = gbinder_client_transact_sync_reply(self->client,
 | 
			
		||||
            GET_TRANSACTION, req, status);
 | 
			
		||||
        reply = gbinder_client_transact_sync_reply2(self->client,
 | 
			
		||||
            GET_TRANSACTION, req, status, api);
 | 
			
		||||
 | 
			
		||||
        if (reply) {
 | 
			
		||||
            GBinderReader reader;
 | 
			
		||||
@@ -233,10 +224,11 @@ gbinder_hwservicemanager_get_service(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
gbinder_hwservicemanager_add_service(
 | 
			
		||||
gbinder_servicemanager_hidl_add_service(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* name,
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    const GBinderIpcSyncApi* api)
 | 
			
		||||
{
 | 
			
		||||
    int status;
 | 
			
		||||
    GBinderRemoteReply* reply;
 | 
			
		||||
@@ -246,8 +238,8 @@ gbinder_hwservicemanager_add_service(
 | 
			
		||||
    gbinder_local_request_append_hidl_string(req, name);
 | 
			
		||||
    gbinder_local_request_append_local_object(req, obj);
 | 
			
		||||
 | 
			
		||||
    reply = gbinder_client_transact_sync_reply(self->client,
 | 
			
		||||
        ADD_TRANSACTION, req, &status);
 | 
			
		||||
    reply = gbinder_client_transact_sync_reply2(self->client,
 | 
			
		||||
        ADD_TRANSACTION, req, &status, api);
 | 
			
		||||
 | 
			
		||||
    gbinder_remote_reply_unref(reply);
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
@@ -256,10 +248,10 @@ gbinder_hwservicemanager_add_service(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_hwservicemanager_watch_free(
 | 
			
		||||
gbinder_servicemanager_hidl_watch_free(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderHwServiceManagerWatch* watch = data;
 | 
			
		||||
    GBinderServiceManagerHidlWatch* watch = data;
 | 
			
		||||
 | 
			
		||||
    g_free(watch->name);
 | 
			
		||||
    gbinder_local_object_drop(watch->callback);
 | 
			
		||||
@@ -268,7 +260,7 @@ gbinder_hwservicemanager_watch_free(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
GBINDER_SERVICEMANAGER_NAME_CHECK
 | 
			
		||||
gbinder_hwservicemanager_check_name(
 | 
			
		||||
gbinder_servicemanager_hidl_check_name(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
@@ -289,32 +281,32 @@ gbinder_hwservicemanager_check_name(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
char*
 | 
			
		||||
gbinder_hwservicemanager_normalize_name(
 | 
			
		||||
gbinder_servicemanager_hidl_normalize_name(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    /* Slash must be there, see gbinder_hwservicemanager_check_name() above */
 | 
			
		||||
    /* Slash must be there, see gbinder_servicemanager_hidl_check_name() */
 | 
			
		||||
    return g_strndup(name, strchr(name, '/') - name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_hwservicemanager_watch(
 | 
			
		||||
gbinder_servicemanager_hidl_watch(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    GBinderHwServiceManager* self = GBINDER_HWSERVICEMANAGER(manager);
 | 
			
		||||
    GBinderServiceManagerHidl* self = GBINDER_SERVICEMANAGER_HIDL(manager);
 | 
			
		||||
    GBinderLocalRequest* req = gbinder_client_new_request(manager->client);
 | 
			
		||||
    GBinderRemoteReply* reply;
 | 
			
		||||
    GBinderHwServiceManagerWatch* watch =
 | 
			
		||||
        g_new0(GBinderHwServiceManagerWatch, 1);
 | 
			
		||||
    GBinderServiceManagerHidlWatch* watch =
 | 
			
		||||
        g_new0(GBinderServiceManagerHidlWatch, 1);
 | 
			
		||||
    gboolean success = FALSE;
 | 
			
		||||
    int status;
 | 
			
		||||
 | 
			
		||||
    watch->name = g_strdup(name);
 | 
			
		||||
    watch->callback = gbinder_servicemanager_new_local_object(manager,
 | 
			
		||||
        HWSERVICEMANAGER_NOTIFICATION_IFACE,
 | 
			
		||||
        gbinder_hwservicemanager_notification, self);
 | 
			
		||||
        SERVICEMANAGER_HIDL_NOTIFICATION_IFACE,
 | 
			
		||||
        gbinder_servicemanager_hidl_notification, self);
 | 
			
		||||
    g_hash_table_replace(self->watch_table, watch->name, watch);
 | 
			
		||||
 | 
			
		||||
    /* registerForNotifications(string fqName, string name,
 | 
			
		||||
@@ -346,28 +338,29 @@ gbinder_hwservicemanager_watch(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_hwservicemanager_unwatch(
 | 
			
		||||
gbinder_servicemanager_hidl_unwatch(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    const char* name)
 | 
			
		||||
{
 | 
			
		||||
    g_hash_table_remove(GBINDER_HWSERVICEMANAGER(manager)->watch_table, name);
 | 
			
		||||
    g_hash_table_remove(GBINDER_SERVICEMANAGER_HIDL(manager)->
 | 
			
		||||
        watch_table, name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_hwservicemanager_init(
 | 
			
		||||
    GBinderHwServiceManager* self)
 | 
			
		||||
gbinder_servicemanager_hidl_init(
 | 
			
		||||
    GBinderServiceManagerHidl* self)
 | 
			
		||||
{
 | 
			
		||||
    self->watch_table = g_hash_table_new_full(g_str_hash, g_str_equal,
 | 
			
		||||
        NULL, gbinder_hwservicemanager_watch_free);
 | 
			
		||||
        NULL, gbinder_servicemanager_hidl_watch_free);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_hwservicemanager_finalize(
 | 
			
		||||
gbinder_servicemanager_hidl_finalize(
 | 
			
		||||
    GObject* object)
 | 
			
		||||
{
 | 
			
		||||
    GBinderHwServiceManager* self = GBINDER_HWSERVICEMANAGER(object);
 | 
			
		||||
    GBinderServiceManagerHidl* self = GBINDER_SERVICEMANAGER_HIDL(object);
 | 
			
		||||
 | 
			
		||||
    g_hash_table_destroy(self->watch_table);
 | 
			
		||||
    G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
 | 
			
		||||
@@ -375,22 +368,20 @@ gbinder_hwservicemanager_finalize(
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_hwservicemanager_class_init(
 | 
			
		||||
    GBinderHwServiceManagerClass* klass)
 | 
			
		||||
gbinder_servicemanager_hidl_class_init(
 | 
			
		||||
    GBinderServiceManagerHidlClass* klass)
 | 
			
		||||
{
 | 
			
		||||
    klass->handle = HWSERVICEMANAGER_HANDLE;
 | 
			
		||||
    klass->iface = HWSERVICEMANAGER_IFACE;
 | 
			
		||||
    klass->iface = SERVICEMANAGER_HIDL_IFACE;
 | 
			
		||||
    klass->default_device = GBINDER_DEFAULT_HWBINDER;
 | 
			
		||||
    klass->rpc_protocol = &gbinder_rpc_protocol_hwbinder;
 | 
			
		||||
 | 
			
		||||
    klass->list = gbinder_hwservicemanager_list;
 | 
			
		||||
    klass->get_service = gbinder_hwservicemanager_get_service;
 | 
			
		||||
    klass->add_service = gbinder_hwservicemanager_add_service;
 | 
			
		||||
    klass->check_name = gbinder_hwservicemanager_check_name;
 | 
			
		||||
    klass->normalize_name = gbinder_hwservicemanager_normalize_name;
 | 
			
		||||
    klass->watch = gbinder_hwservicemanager_watch;
 | 
			
		||||
    klass->unwatch = gbinder_hwservicemanager_unwatch;
 | 
			
		||||
    G_OBJECT_CLASS(klass)->finalize = gbinder_hwservicemanager_finalize;
 | 
			
		||||
    klass->list = gbinder_servicemanager_hidl_list;
 | 
			
		||||
    klass->get_service = gbinder_servicemanager_hidl_get_service;
 | 
			
		||||
    klass->add_service = gbinder_servicemanager_hidl_add_service;
 | 
			
		||||
    klass->check_name = gbinder_servicemanager_hidl_check_name;
 | 
			
		||||
    klass->normalize_name = gbinder_servicemanager_hidl_normalize_name;
 | 
			
		||||
    klass->watch = gbinder_servicemanager_hidl_watch;
 | 
			
		||||
    klass->unwatch = gbinder_servicemanager_hidl_unwatch;
 | 
			
		||||
    G_OBJECT_CLASS(klass)->finalize = gbinder_servicemanager_hidl_finalize;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -46,7 +46,6 @@ typedef struct gbinder_servicemanager {
 | 
			
		||||
    GBinderServiceManagerPriv* priv;
 | 
			
		||||
    const char* dev;
 | 
			
		||||
    GBinderClient* client;
 | 
			
		||||
    GUtilIdlePool* pool;
 | 
			
		||||
} GBinderServiceManager;
 | 
			
		||||
 | 
			
		||||
typedef enum gbinder_servicemanager_name_check {
 | 
			
		||||
@@ -60,18 +59,15 @@ typedef struct gbinder_servicemanager_class {
 | 
			
		||||
    GMutex mutex;
 | 
			
		||||
    GHashTable* table;
 | 
			
		||||
 | 
			
		||||
    guint32 handle;
 | 
			
		||||
    const char* iface;
 | 
			
		||||
    const char* default_device;
 | 
			
		||||
    const GBinderRpcProtocol* rpc_protocol;
 | 
			
		||||
 | 
			
		||||
    /* Methods (synchronous) */
 | 
			
		||||
    char** (*list)(GBinderServiceManager* self);
 | 
			
		||||
    GBinderRemoteObject* (*get_service)
 | 
			
		||||
        (GBinderServiceManager* self, const char* name, int* status);
 | 
			
		||||
    int (*add_service)
 | 
			
		||||
        (GBinderServiceManager* self, const char* name,
 | 
			
		||||
            GBinderLocalObject* obj);
 | 
			
		||||
    char** (*list)(GBinderServiceManager* self, const GBinderIpcSyncApi* api);
 | 
			
		||||
    GBinderRemoteObject* (*get_service)(GBinderServiceManager* self,
 | 
			
		||||
        const char* name, int* status, const GBinderIpcSyncApi* api);
 | 
			
		||||
    int (*add_service)(GBinderServiceManager* self, const char* name,
 | 
			
		||||
        GBinderLocalObject* obj, const GBinderIpcSyncApi* api);
 | 
			
		||||
 | 
			
		||||
    /* Checking/normalizing watch names */
 | 
			
		||||
    GBINDER_SERVICEMANAGER_NAME_CHECK (*check_name)
 | 
			
		||||
@@ -83,18 +79,38 @@ typedef struct gbinder_servicemanager_class {
 | 
			
		||||
    void (*unwatch)(GBinderServiceManager* self, const char* name);
 | 
			
		||||
} GBinderServiceManagerClass;
 | 
			
		||||
 | 
			
		||||
GType gbinder_servicemanager_get_type(void);
 | 
			
		||||
GType gbinder_servicemanager_get_type(void) GBINDER_INTERNAL;
 | 
			
		||||
#define GBINDER_TYPE_SERVICEMANAGER (gbinder_servicemanager_get_type())
 | 
			
		||||
#define GBINDER_SERVICEMANAGER_CLASS(klass) \
 | 
			
		||||
    G_TYPE_CHECK_CLASS_CAST((klass), GBINDER_TYPE_SERVICEMANAGER, \
 | 
			
		||||
    GBinderServiceManagerClass)
 | 
			
		||||
 | 
			
		||||
#define gbinder_servicemanager_ipc(sm) gbinder_client_ipc(sm->client)
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_servicemanager_new_with_type(
 | 
			
		||||
    GType type,
 | 
			
		||||
    const char* dev);
 | 
			
		||||
    const char* dev)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_service_registered(
 | 
			
		||||
    GBinderServiceManager* self,
 | 
			
		||||
    const char* name);
 | 
			
		||||
    const char* name)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
/* Declared for unit tests */
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicemanager_exit(
 | 
			
		||||
    void)
 | 
			
		||||
    GBINDER_INTERNAL
 | 
			
		||||
    GBINDER_DESTRUCTOR;
 | 
			
		||||
 | 
			
		||||
/* Derived types */
 | 
			
		||||
 | 
			
		||||
GType gbinder_servicemanager_aidl_get_type(void) GBINDER_INTERNAL;
 | 
			
		||||
GType gbinder_servicemanager_aidl2_get_type(void) GBINDER_INTERNAL;
 | 
			
		||||
GType gbinder_servicemanager_hidl_get_type(void) GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_SERVICEMANAGER_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2019-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -31,6 +31,7 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
#include "gbinder_eventloop_p.h"
 | 
			
		||||
#include "gbinder_servicename.h"
 | 
			
		||||
#include "gbinder_servicemanager.h"
 | 
			
		||||
#include "gbinder_local_object.h"
 | 
			
		||||
@@ -40,16 +41,24 @@
 | 
			
		||||
 | 
			
		||||
/* Since 1.0.26 */
 | 
			
		||||
 | 
			
		||||
#define GBINDER_SERVICENAME_RETRY_INTERVAL_MS (500)
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_servicename_priv {
 | 
			
		||||
    GBinderServiceName pub;
 | 
			
		||||
    gint refcount;
 | 
			
		||||
    char* name;
 | 
			
		||||
    GBinderLocalObject* object;
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    GBinderEventLoopTimeout* retry_timer;
 | 
			
		||||
    gulong presence_id;
 | 
			
		||||
    gulong add_call_id;
 | 
			
		||||
} GBinderServiceNamePriv;
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicename_add_service(
 | 
			
		||||
    GBinderServiceNamePriv* priv);
 | 
			
		||||
 | 
			
		||||
GBINDER_INLINE_FUNC GBinderServiceNamePriv*
 | 
			
		||||
gbinder_servicename_cast(GBinderServiceName* pub)
 | 
			
		||||
    { return G_CAST(pub, GBinderServiceNamePriv, pub); }
 | 
			
		||||
@@ -58,6 +67,18 @@ gbinder_servicename_cast(GBinderServiceName* pub)
 | 
			
		||||
 * Implementation
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_servicename_add_service_retry(
 | 
			
		||||
    gpointer user_data)
 | 
			
		||||
{
 | 
			
		||||
    GBinderServiceNamePriv* priv = user_data;
 | 
			
		||||
 | 
			
		||||
    priv->retry_timer = NULL;
 | 
			
		||||
    gbinder_servicename_add_service(priv);
 | 
			
		||||
    return G_SOURCE_REMOVE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicename_add_service_done(
 | 
			
		||||
@@ -71,6 +92,10 @@ gbinder_servicename_add_service_done(
 | 
			
		||||
    priv->add_call_id = 0;
 | 
			
		||||
    if (status) {
 | 
			
		||||
        GWARN("Error %d adding name \"%s\"", status, priv->name);
 | 
			
		||||
        gbinder_timeout_remove(priv->retry_timer);
 | 
			
		||||
        priv->retry_timer =
 | 
			
		||||
            gbinder_timeout_add(GBINDER_SERVICENAME_RETRY_INTERVAL_MS,
 | 
			
		||||
                gbinder_servicename_add_service_retry, priv);
 | 
			
		||||
    } else {
 | 
			
		||||
        GDEBUG("Service \"%s\" has been registered", priv->name);
 | 
			
		||||
    }
 | 
			
		||||
@@ -97,9 +122,15 @@ gbinder_servicename_presence_handler(
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
    } else {
 | 
			
		||||
        if (priv->add_call_id) {
 | 
			
		||||
            gbinder_servicemanager_cancel(priv->sm, priv->add_call_id);
 | 
			
		||||
            priv->add_call_id = 0;
 | 
			
		||||
        }
 | 
			
		||||
        if (priv->retry_timer) {
 | 
			
		||||
            gbinder_timeout_remove(priv->retry_timer);
 | 
			
		||||
            priv->retry_timer = NULL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -158,8 +189,9 @@ gbinder_servicename_unref(
 | 
			
		||||
            gbinder_servicemanager_remove_handler(priv->sm, priv->presence_id);
 | 
			
		||||
            gbinder_servicemanager_unref(priv->sm);
 | 
			
		||||
            gbinder_local_object_unref(priv->object);
 | 
			
		||||
            gbinder_timeout_remove(priv->retry_timer);
 | 
			
		||||
            g_free(priv->name);
 | 
			
		||||
            g_slice_free(GBinderServiceName, self);
 | 
			
		||||
            gutil_slice_free(priv);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -32,6 +32,7 @@
 | 
			
		||||
 | 
			
		||||
#include "gbinder_servicepoll.h"
 | 
			
		||||
#include "gbinder_servicemanager.h"
 | 
			
		||||
#include "gbinder_eventloop_p.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_strv.h>
 | 
			
		||||
 | 
			
		||||
@@ -46,7 +47,7 @@ struct gbinder_servicepoll {
 | 
			
		||||
    GBinderServiceManager* manager;
 | 
			
		||||
    char** list;
 | 
			
		||||
    gulong list_id;
 | 
			
		||||
    guint timer_id;
 | 
			
		||||
    GBinderEventLoopTimeout* timer;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE(GBinderServicePoll, gbinder_servicepoll, G_TYPE_OBJECT)
 | 
			
		||||
@@ -230,7 +231,7 @@ void
 | 
			
		||||
gbinder_servicepoll_init(
 | 
			
		||||
    GBinderServicePoll* self)
 | 
			
		||||
{
 | 
			
		||||
    self->timer_id = g_timeout_add(gbinder_servicepoll_interval_ms,
 | 
			
		||||
    self->timer = gbinder_timeout_add(gbinder_servicepoll_interval_ms,
 | 
			
		||||
        gbinder_servicepoll_timer, self);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -241,7 +242,7 @@ gbinder_servicepoll_finalize(
 | 
			
		||||
{
 | 
			
		||||
    GBinderServicePoll* self = GBINDER_SERVICEPOLL(object);
 | 
			
		||||
 | 
			
		||||
    g_source_remove(self->timer_id);
 | 
			
		||||
    gbinder_timeout_remove(self->timer);
 | 
			
		||||
    gbinder_servicemanager_cancel(self->manager, self->list_id);
 | 
			
		||||
    gbinder_servicemanager_unref(self->manager);
 | 
			
		||||
    g_strfreev(self->list);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -35,7 +35,7 @@
 | 
			
		||||
 | 
			
		||||
#include "gbinder_types_p.h"
 | 
			
		||||
 | 
			
		||||
extern guint gbinder_servicepoll_interval_ms;
 | 
			
		||||
extern guint gbinder_servicepoll_interval_ms GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
typedef
 | 
			
		||||
void
 | 
			
		||||
@@ -47,35 +47,42 @@ void
 | 
			
		||||
GBinderServicePoll*
 | 
			
		||||
gbinder_servicepoll_new(
 | 
			
		||||
    GBinderServiceManager* manager,
 | 
			
		||||
    GBinderServicePoll** weakptr);
 | 
			
		||||
    GBinderServicePoll** weakptr)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderServicePoll*
 | 
			
		||||
gbinder_servicepoll_ref(
 | 
			
		||||
    GBinderServicePoll* poll);
 | 
			
		||||
    GBinderServicePoll* poll)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicepoll_unref(
 | 
			
		||||
    GBinderServicePoll* poll);
 | 
			
		||||
    GBinderServicePoll* poll)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
GBinderServiceManager*
 | 
			
		||||
gbinder_servicepoll_manager(
 | 
			
		||||
    GBinderServicePoll* poll);
 | 
			
		||||
    GBinderServicePoll* poll)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
gbinder_servicepoll_is_known_name(
 | 
			
		||||
    GBinderServicePoll* poll,
 | 
			
		||||
    const char* name);
 | 
			
		||||
    const char* name)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
gulong
 | 
			
		||||
gbinder_servicepoll_add_handler(
 | 
			
		||||
    GBinderServicePoll* poll,
 | 
			
		||||
    GBinderServicePollFunc func,
 | 
			
		||||
    void* user_data);
 | 
			
		||||
    void* user_data)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_servicepoll_remove_handler(
 | 
			
		||||
    GBinderServicePoll* poll,
 | 
			
		||||
    gulong id);
 | 
			
		||||
    gulong id)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_SERVICEPOLL_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Contact: Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -34,6 +34,7 @@
 | 
			
		||||
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <sys/ioctl.h>
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
 | 
			
		||||
@@ -58,7 +59,10 @@ gbinder_system_ioctl(
 | 
			
		||||
    int request,
 | 
			
		||||
    void* data)
 | 
			
		||||
{
 | 
			
		||||
    return ioctl(fd, request, data);
 | 
			
		||||
    int ret;
 | 
			
		||||
 | 
			
		||||
    while ((ret = ioctl(fd, request, data)) < 0 && errno == EINTR);
 | 
			
		||||
    return ret >= 0 ? 0 : -errno;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void*
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Contact: 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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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,29 +38,34 @@
 | 
			
		||||
int
 | 
			
		||||
gbinder_system_open(
 | 
			
		||||
    const char* path,
 | 
			
		||||
    int flags);
 | 
			
		||||
    int flags)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_system_close(
 | 
			
		||||
    int fd);
 | 
			
		||||
    int fd)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_system_ioctl(
 | 
			
		||||
    int fd,
 | 
			
		||||
    int request,
 | 
			
		||||
    void* data);
 | 
			
		||||
    void* data)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void*
 | 
			
		||||
gbinder_system_mmap(
 | 
			
		||||
   size_t length,
 | 
			
		||||
   int prot,
 | 
			
		||||
   int flags,
 | 
			
		||||
   int fd);
 | 
			
		||||
   int fd)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
gbinder_system_munmap(
 | 
			
		||||
    void* addr,
 | 
			
		||||
    size_t length);
 | 
			
		||||
    size_t length)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_SYSTEM_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -36,17 +36,23 @@
 | 
			
		||||
#include <gbinder_types.h>
 | 
			
		||||
 | 
			
		||||
typedef struct gbinder_buffer_contents GBinderBufferContents;
 | 
			
		||||
typedef struct gbinder_buffer_contents_list GBinderBufferContentsList;
 | 
			
		||||
typedef struct gbinder_cleanup GBinderCleanup;
 | 
			
		||||
typedef struct gbinder_driver GBinderDriver;
 | 
			
		||||
typedef struct gbinder_handler GBinderHandler;
 | 
			
		||||
typedef struct gbinder_io GBinderIo;
 | 
			
		||||
typedef struct gbinder_object_converter GBinderObjectConverter;
 | 
			
		||||
typedef struct gbinder_object_registry GBinderObjectRegistry;
 | 
			
		||||
typedef struct gbinder_output_data GBinderOutputData;
 | 
			
		||||
typedef struct gbinder_proxy_object GBinderProxyObject;
 | 
			
		||||
typedef struct gbinder_rpc_protocol GBinderRpcProtocol;
 | 
			
		||||
typedef struct gbinder_servicepoll GBinderServicePoll;
 | 
			
		||||
typedef struct gbinder_ipc_looper_tx GBinderIpcLooperTx;
 | 
			
		||||
typedef struct gbinder_ipc_sync_api GBinderIpcSyncApi;
 | 
			
		||||
 | 
			
		||||
#define GBINDER_INLINE_FUNC static inline
 | 
			
		||||
#define GBINDER_INTERNAL G_GNUC_INTERNAL
 | 
			
		||||
#define GBINDER_DESTRUCTOR __attribute__((destructor))
 | 
			
		||||
 | 
			
		||||
#define GBINDER_TRANSACTION(c2,c3,c4)     GBINDER_FOURCC('_',c2,c3,c4)
 | 
			
		||||
#define GBINDER_PING_TRANSACTION          GBINDER_TRANSACTION('P','N','G')
 | 
			
		||||
@@ -68,6 +74,9 @@ typedef struct gbinder_ipc_looper_tx GBinderIpcLooperTx;
 | 
			
		||||
#define HIDL_DEBUG_TRANSACTION                    HIDL_FOURCC('D','B','G')
 | 
			
		||||
#define HIDL_HASH_CHAIN_TRANSACTION               HIDL_FOURCC('H','S','H')
 | 
			
		||||
 | 
			
		||||
/* As a special case, ServiceManager's handle is zero */
 | 
			
		||||
#define GBINDER_SERVICEMANAGER_HANDLE (0)
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_TYPES_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -32,12 +32,15 @@
 | 
			
		||||
 | 
			
		||||
#include "gbinder_writer_p.h"
 | 
			
		||||
#include "gbinder_buffer_p.h"
 | 
			
		||||
#include "gbinder_local_object.h"
 | 
			
		||||
#include "gbinder_object_converter.h"
 | 
			
		||||
#include "gbinder_io.h"
 | 
			
		||||
#include "gbinder_log.h"
 | 
			
		||||
 | 
			
		||||
#include <gutil_intarray.h>
 | 
			
		||||
#include <gutil_macros.h>
 | 
			
		||||
#include <gutil_strv.h>
 | 
			
		||||
#include <gutil_misc.h>
 | 
			
		||||
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
@@ -55,52 +58,88 @@ GBINDER_INLINE_FUNC GBinderWriterPriv* gbinder_writer_cast(GBinderWriter* pub)
 | 
			
		||||
GBINDER_INLINE_FUNC GBinderWriterData* gbinder_writer_data(GBinderWriter* pub)
 | 
			
		||||
    { return G_LIKELY(pub) ? gbinder_writer_cast(pub)->data : NULL; }
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_buffer_cleanup(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    gbinder_buffer_contents_unref((GBinderBufferContents*)data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_set_contents(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    GBinderBuffer* buffer)
 | 
			
		||||
    GBinderBuffer* buffer,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
{
 | 
			
		||||
    gsize bufsize;
 | 
			
		||||
    const guint8* bufdata = gbinder_buffer_data(buffer, &bufsize);
 | 
			
		||||
    const GBinderIo* io = gbinder_buffer_io(buffer);
 | 
			
		||||
    GBinderBufferContents* contents = gbinder_buffer_contents(buffer);
 | 
			
		||||
 | 
			
		||||
    GASSERT(data->io == io);
 | 
			
		||||
    g_byte_array_set_size(data->bytes, 0);
 | 
			
		||||
    gutil_int_array_set_count(data->offsets, 0);
 | 
			
		||||
    data->buffers_size = 0;
 | 
			
		||||
    gbinder_cleanup_reset(data->cleanup);
 | 
			
		||||
    gbinder_writer_data_append_contents(data, buffer, 0, convert);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_contents(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    GBinderBuffer* buffer,
 | 
			
		||||
    gsize off,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
{
 | 
			
		||||
    GBinderBufferContents* contents = gbinder_buffer_contents(buffer);
 | 
			
		||||
 | 
			
		||||
    g_byte_array_append(data->bytes, bufdata, bufsize);
 | 
			
		||||
    if (contents) {
 | 
			
		||||
        gsize bufsize;
 | 
			
		||||
        GByteArray* dest = data->bytes;
 | 
			
		||||
        const guint8* bufdata = gbinder_buffer_data(buffer, &bufsize);
 | 
			
		||||
        void** objects = gbinder_buffer_objects(buffer);
 | 
			
		||||
 | 
			
		||||
        data->cleanup = gbinder_cleanup_add(data->cleanup,
 | 
			
		||||
            gbinder_writer_data_buffer_cleanup,
 | 
			
		||||
        data->cleanup = gbinder_cleanup_add(data->cleanup, (GDestroyNotify)
 | 
			
		||||
            gbinder_buffer_contents_unref,
 | 
			
		||||
            gbinder_buffer_contents_ref(contents));
 | 
			
		||||
        if (objects && *objects) {
 | 
			
		||||
            const GBinderIo* io = gbinder_buffer_io(buffer);
 | 
			
		||||
 | 
			
		||||
            /* GBinderIo must be the same because it's defined by the kernel */
 | 
			
		||||
            GASSERT(io == data->io);
 | 
			
		||||
            if (!data->offsets) {
 | 
			
		||||
                data->offsets = gutil_int_array_new();
 | 
			
		||||
            }
 | 
			
		||||
            while (*objects) {
 | 
			
		||||
                const guint8* obj = *objects++;
 | 
			
		||||
                gsize offset = obj - bufdata;
 | 
			
		||||
                gsize objsize = io->object_data_size(obj);
 | 
			
		||||
                gsize objsize, offset = obj - bufdata;
 | 
			
		||||
                GBinderLocalObject* local;
 | 
			
		||||
                guint32 handle;
 | 
			
		||||
 | 
			
		||||
                GASSERT(offset >= off && offset < bufsize);
 | 
			
		||||
                if (offset > off) {
 | 
			
		||||
                    /* Copy serialized data preceeding this object */
 | 
			
		||||
                    g_byte_array_append(dest, bufdata + off, offset - off);
 | 
			
		||||
                    off = offset;
 | 
			
		||||
                }
 | 
			
		||||
                /* Offset in the destination buffer */
 | 
			
		||||
                gutil_int_array_append(data->offsets, dest->len);
 | 
			
		||||
 | 
			
		||||
                /* Convert remote object into local if necessary */
 | 
			
		||||
                if (convert && io->decode_binder_handle(obj, &handle) &&
 | 
			
		||||
                    (local = gbinder_object_converter_handle_to_local
 | 
			
		||||
                    (convert, handle))) {
 | 
			
		||||
                    const guint pos = dest->len;
 | 
			
		||||
 | 
			
		||||
                    g_byte_array_set_size(dest, pos +
 | 
			
		||||
                        GBINDER_MAX_BINDER_OBJECT_SIZE);
 | 
			
		||||
                    objsize = io->encode_local_object(dest->data + pos, local);
 | 
			
		||||
                    g_byte_array_set_size(dest, pos + objsize);
 | 
			
		||||
 | 
			
		||||
                    /* Keep the reference */
 | 
			
		||||
                    data->cleanup = gbinder_cleanup_add(data->cleanup,
 | 
			
		||||
                        (GDestroyNotify) gbinder_local_object_unref, local);
 | 
			
		||||
                } else {
 | 
			
		||||
                    objsize = io->object_size(obj);
 | 
			
		||||
                    g_byte_array_append(dest, obj, objsize);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                GASSERT(offset > 0 && offset < bufsize);
 | 
			
		||||
                gutil_int_array_append(data->offsets, (int)offset);
 | 
			
		||||
                /* Size of each buffer has to be 8-byte aligned */
 | 
			
		||||
                data->buffers_size += G_ALIGN8(objsize);
 | 
			
		||||
                data->buffers_size += G_ALIGN8(io->object_data_size(obj));
 | 
			
		||||
                off += objsize;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (off < bufsize) {
 | 
			
		||||
            /* Copy remaining data */
 | 
			
		||||
            g_byte_array_append(dest, bufdata + off, bufsize - off);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -116,30 +155,6 @@ gbinder_writer_data_record_offset(
 | 
			
		||||
    gutil_int_array_append(data->offsets, offset);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_write_buffer_object(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    const void* ptr,
 | 
			
		||||
    gsize size,
 | 
			
		||||
    const GBinderParent* parent)
 | 
			
		||||
{
 | 
			
		||||
    GByteArray* buf = data->bytes;
 | 
			
		||||
    const guint offset = buf->len;
 | 
			
		||||
    guint n;
 | 
			
		||||
 | 
			
		||||
    /* Preallocate enough space */
 | 
			
		||||
    g_byte_array_set_size(buf, offset + GBINDER_MAX_BUFFER_OBJECT_SIZE);
 | 
			
		||||
    /* Write the object */
 | 
			
		||||
    n = data->io->encode_buffer_object(buf->data + offset, ptr, size, parent);
 | 
			
		||||
    /* Fix the data size */
 | 
			
		||||
    g_byte_array_set_size(buf, offset + n);
 | 
			
		||||
    /* Record the offset */
 | 
			
		||||
    gbinder_writer_data_record_offset(data, offset);
 | 
			
		||||
    /* The driver seems to require each buffer to be 8-byte aligned */
 | 
			
		||||
    data->buffers_size += G_ALIGN8(size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_init(
 | 
			
		||||
    GBinderWriter* self,
 | 
			
		||||
@@ -542,17 +557,6 @@ gbinder_writer_append_bytes(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
guint
 | 
			
		||||
gbinder_writer_data_prepare(
 | 
			
		||||
    GBinderWriterData* data)
 | 
			
		||||
{
 | 
			
		||||
    if (!data->offsets) {
 | 
			
		||||
        data->offsets = gutil_int_array_new();
 | 
			
		||||
    }
 | 
			
		||||
    return data->offsets->count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_close_fd(
 | 
			
		||||
@@ -643,9 +647,21 @@ gbinder_writer_data_append_buffer_object(
 | 
			
		||||
    gsize size,
 | 
			
		||||
    const GBinderParent* parent)
 | 
			
		||||
{
 | 
			
		||||
    guint index = gbinder_writer_data_prepare(data);
 | 
			
		||||
    const guint index = data->offsets ? data->offsets->count : 0;
 | 
			
		||||
    GByteArray* buf = data->bytes;
 | 
			
		||||
    const guint offset = buf->len;
 | 
			
		||||
    guint n;
 | 
			
		||||
 | 
			
		||||
    gbinder_writer_data_write_buffer_object(data, ptr, size, parent);
 | 
			
		||||
    /* Preallocate enough space */
 | 
			
		||||
    g_byte_array_set_size(buf, offset + GBINDER_MAX_BUFFER_OBJECT_SIZE);
 | 
			
		||||
    /* Write the object */
 | 
			
		||||
    n = data->io->encode_buffer_object(buf->data + offset, ptr, size, parent);
 | 
			
		||||
    /* Fix the data size */
 | 
			
		||||
    g_byte_array_set_size(buf, offset + n);
 | 
			
		||||
    /* Record the offset */
 | 
			
		||||
    gbinder_writer_data_record_offset(data, offset);
 | 
			
		||||
    /* The driver seems to require each buffer to be 8-byte aligned */
 | 
			
		||||
    data->buffers_size += G_ALIGN8(size);
 | 
			
		||||
    return index;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -661,6 +677,21 @@ gbinder_writer_append_hidl_string(
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_append_hidl_string_copy(
 | 
			
		||||
    GBinderWriter* self,
 | 
			
		||||
    const char* str) /* Since 1.1.13 */
 | 
			
		||||
{
 | 
			
		||||
    GBinderWriterData* data = gbinder_writer_data(self);
 | 
			
		||||
 | 
			
		||||
    if (G_LIKELY(data)) {
 | 
			
		||||
        static const char empty[] = "";
 | 
			
		||||
 | 
			
		||||
        gbinder_writer_data_append_hidl_string(data, str ? (str[0] ?
 | 
			
		||||
            gbinder_writer_strdup(self, str) : empty) : NULL);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_hidl_vec(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
@@ -671,11 +702,7 @@ gbinder_writer_data_append_hidl_vec(
 | 
			
		||||
    GBinderParent vec_parent;
 | 
			
		||||
    GBinderHidlVec* vec = g_new0(GBinderHidlVec, 1);
 | 
			
		||||
    const gsize total = count * elemsize;
 | 
			
		||||
    void* buf = g_memdup(base, total);
 | 
			
		||||
 | 
			
		||||
    /* Prepare parent descriptor for the string data */
 | 
			
		||||
    vec_parent.index = gbinder_writer_data_prepare(data);
 | 
			
		||||
    vec_parent.offset = GBINDER_HIDL_VEC_BUFFER_OFFSET;
 | 
			
		||||
    void* buf = gutil_memdup(base, total);
 | 
			
		||||
 | 
			
		||||
    /* Fill in the vector descriptor */
 | 
			
		||||
    if (buf) {
 | 
			
		||||
@@ -686,13 +713,11 @@ gbinder_writer_data_append_hidl_vec(
 | 
			
		||||
    vec->owns_buffer = TRUE;
 | 
			
		||||
    data->cleanup = gbinder_cleanup_add(data->cleanup, g_free, vec);
 | 
			
		||||
 | 
			
		||||
    /* Write the buffer object pointing to the vector descriptor */
 | 
			
		||||
    gbinder_writer_data_write_buffer_object(data, vec, sizeof(*vec), NULL);
 | 
			
		||||
 | 
			
		||||
    /* Not sure what's the right way to deal with NULL vectors... */
 | 
			
		||||
    if (buf) {
 | 
			
		||||
        gbinder_writer_data_write_buffer_object(data, buf, total, &vec_parent);
 | 
			
		||||
    }
 | 
			
		||||
    /* Every vector, even the one without data, requires two buffer objects */
 | 
			
		||||
    vec_parent.offset = GBINDER_HIDL_VEC_BUFFER_OFFSET;
 | 
			
		||||
    vec_parent.index = gbinder_writer_data_append_buffer_object(data,
 | 
			
		||||
        vec, sizeof(*vec), NULL);
 | 
			
		||||
    gbinder_writer_data_append_buffer_object(data, buf, total, &vec_parent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
@@ -718,10 +743,6 @@ gbinder_writer_data_append_hidl_string(
 | 
			
		||||
    GBinderHidlString* hidl_string = g_new0(GBinderHidlString, 1);
 | 
			
		||||
    const gsize len = str ? strlen(str) : 0;
 | 
			
		||||
 | 
			
		||||
    /* Prepare parent descriptor for the string data */
 | 
			
		||||
    str_parent.index = gbinder_writer_data_prepare(data);
 | 
			
		||||
    str_parent.offset = GBINDER_HIDL_STRING_BUFFER_OFFSET;
 | 
			
		||||
 | 
			
		||||
    /* Fill in the string descriptor and store it */
 | 
			
		||||
    hidl_string->data.str = str;
 | 
			
		||||
    hidl_string->len = len;
 | 
			
		||||
@@ -729,16 +750,18 @@ gbinder_writer_data_append_hidl_string(
 | 
			
		||||
    data->cleanup = gbinder_cleanup_add(data->cleanup, g_free, hidl_string);
 | 
			
		||||
 | 
			
		||||
    /* Write the buffer object pointing to the string descriptor */
 | 
			
		||||
    gbinder_writer_data_write_buffer_object(data, hidl_string,
 | 
			
		||||
        sizeof(*hidl_string), NULL);
 | 
			
		||||
    str_parent.offset = GBINDER_HIDL_STRING_BUFFER_OFFSET;
 | 
			
		||||
    str_parent.index = gbinder_writer_data_append_buffer_object(data,
 | 
			
		||||
        hidl_string, sizeof(*hidl_string), NULL);
 | 
			
		||||
 | 
			
		||||
    /* Not sure what's the right way to deal with NULL strings... */
 | 
			
		||||
    if (str) {
 | 
			
		||||
        /* Write the buffer pointing to the string data including the
 | 
			
		||||
         * NULL terminator, referencing string descriptor as a parent. */
 | 
			
		||||
        gbinder_writer_data_write_buffer_object(data, str, len+1, &str_parent);
 | 
			
		||||
        gbinder_writer_data_append_buffer_object(data, str, len+1, &str_parent);
 | 
			
		||||
        GVERBOSE_("\"%s\" %u %u %u", str, (guint)len, (guint)str_parent.index,
 | 
			
		||||
            (guint)data->buffers_size);
 | 
			
		||||
    } else {
 | 
			
		||||
        gbinder_writer_data_append_buffer_object(data, NULL, 0, &str_parent);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -771,10 +794,6 @@ gbinder_writer_data_append_hidl_string_vec(
 | 
			
		||||
        count = gutil_strv_length((char**)strv);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Prepare parent descriptor for the vector data */
 | 
			
		||||
    vec_parent.index = gbinder_writer_data_prepare(data);
 | 
			
		||||
    vec_parent.offset = GBINDER_HIDL_VEC_BUFFER_OFFSET;
 | 
			
		||||
 | 
			
		||||
    /* Fill in the vector descriptor */
 | 
			
		||||
    if (count > 0) {
 | 
			
		||||
        strings = g_new0(GBinderHidlString, count);
 | 
			
		||||
@@ -797,7 +816,10 @@ gbinder_writer_data_append_hidl_string_vec(
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Write the vector object */
 | 
			
		||||
    gbinder_writer_data_write_buffer_object(data, vec, sizeof(*vec), NULL);
 | 
			
		||||
    vec_parent.offset = GBINDER_HIDL_VEC_BUFFER_OFFSET;
 | 
			
		||||
    vec_parent.index = gbinder_writer_data_append_buffer_object(data,
 | 
			
		||||
        vec, sizeof(*vec), NULL);
 | 
			
		||||
 | 
			
		||||
    if (strings) {
 | 
			
		||||
        GBinderParent str_parent;
 | 
			
		||||
 | 
			
		||||
@@ -806,7 +828,7 @@ gbinder_writer_data_append_hidl_string_vec(
 | 
			
		||||
        str_parent.offset = GBINDER_HIDL_STRING_BUFFER_OFFSET;
 | 
			
		||||
 | 
			
		||||
        /* Write the vector data (it's parent for the string data) */
 | 
			
		||||
        gbinder_writer_data_write_buffer_object(data, strings,
 | 
			
		||||
        gbinder_writer_data_append_buffer_object(data, strings,
 | 
			
		||||
            sizeof(*strings) * count, &vec_parent);
 | 
			
		||||
 | 
			
		||||
        /* Write the string data */
 | 
			
		||||
@@ -814,14 +836,21 @@ gbinder_writer_data_append_hidl_string_vec(
 | 
			
		||||
            GBinderHidlString* hidl_str = strings + i;
 | 
			
		||||
 | 
			
		||||
            if (hidl_str->data.str) {
 | 
			
		||||
                gbinder_writer_data_write_buffer_object(data,
 | 
			
		||||
                gbinder_writer_data_append_buffer_object(data,
 | 
			
		||||
                    hidl_str->data.str, hidl_str->len + 1, &str_parent);
 | 
			
		||||
                GVERBOSE_("%d. \"%s\" %u %u %u", i + 1, hidl_str->data.str,
 | 
			
		||||
                    (guint)hidl_str->len, (guint)str_parent.index,
 | 
			
		||||
                    (guint)data->buffers_size);
 | 
			
		||||
            } else {
 | 
			
		||||
                GVERBOSE_("%d. NULL %u %u %u", i + 1, (guint)hidl_str->len,
 | 
			
		||||
                    (guint)str_parent.index, (guint)data->buffers_size);
 | 
			
		||||
                gbinder_writer_data_append_buffer_object(data, NULL, 0,
 | 
			
		||||
                    &str_parent);
 | 
			
		||||
            }
 | 
			
		||||
            str_parent.offset += sizeof(GBinderHidlString);
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        gbinder_writer_data_append_buffer_object(data, NULL, 0, &vec_parent);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -952,6 +981,14 @@ gbinder_writer_malloc0(
 | 
			
		||||
    return gbinder_writer_alloc(self, size, g_malloc0, g_free);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char*
 | 
			
		||||
gbinder_writer_strdup(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    const char* str) /* since 1.1.13 */
 | 
			
		||||
{
 | 
			
		||||
    return str ? gbinder_writer_memdup(writer, str, strlen(str) + 1) : NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void*
 | 
			
		||||
gbinder_writer_memdup(
 | 
			
		||||
    GBinderWriter* self,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -48,94 +48,120 @@ typedef struct gbinder_writer_data {
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_init(
 | 
			
		||||
    GBinderWriter* writer,
 | 
			
		||||
    GBinderWriterData* data);
 | 
			
		||||
    GBinderWriterData* data)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_set_contents(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    GBinderBuffer* buffer);
 | 
			
		||||
    GBinderBuffer* buffer,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_contents(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    GBinderBuffer* buffer,
 | 
			
		||||
    gsize data_offset,
 | 
			
		||||
    GBinderObjectConverter* convert)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_bool(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    gboolean value);
 | 
			
		||||
    gboolean value)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_int32(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    guint32 value);
 | 
			
		||||
    guint32 value)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_int64(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    guint64 value);
 | 
			
		||||
    guint64 value)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_float(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    gfloat value);
 | 
			
		||||
    gfloat value)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_double(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    gdouble value);
 | 
			
		||||
    gdouble value)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_string8(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    const char* str);
 | 
			
		||||
    const char* str)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_string8_len(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    const char* str,
 | 
			
		||||
    gsize len);
 | 
			
		||||
    gsize len)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_string16(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    const char* utf8);
 | 
			
		||||
    const char* utf8)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_string16_len(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    const char* utf8,
 | 
			
		||||
    gssize num_bytes);
 | 
			
		||||
    gssize num_bytes)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
guint
 | 
			
		||||
gbinder_writer_data_append_buffer_object(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    const void* ptr,
 | 
			
		||||
    gsize size,
 | 
			
		||||
    const GBinderParent* parent);
 | 
			
		||||
    const GBinderParent* parent)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_hidl_vec(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    const void* base,
 | 
			
		||||
    guint count,
 | 
			
		||||
    guint elemsize);
 | 
			
		||||
    guint elemsize)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_hidl_string(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    const char* str);
 | 
			
		||||
    const char* str)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_hidl_string_vec(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    const char* strv[],
 | 
			
		||||
    gssize count);
 | 
			
		||||
    gssize count)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_local_object(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
    GBinderLocalObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
gbinder_writer_data_append_remote_object(
 | 
			
		||||
    GBinderWriterData* data,
 | 
			
		||||
    GBinderRemoteObject* obj);
 | 
			
		||||
    GBinderRemoteObject* obj)
 | 
			
		||||
    GBINDER_INTERNAL;
 | 
			
		||||
 | 
			
		||||
#endif /* GBINDER_WRITER_PRIVATE_H */
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,11 @@
 | 
			
		||||
 | 
			
		||||
all:
 | 
			
		||||
%:
 | 
			
		||||
	@$(MAKE) -C binder-bridge $*
 | 
			
		||||
	@$(MAKE) -C binder-client $*
 | 
			
		||||
	@$(MAKE) -C binder-dump $*
 | 
			
		||||
	@$(MAKE) -C binder-list $*
 | 
			
		||||
	@$(MAKE) -C binder-ping $*
 | 
			
		||||
	@$(MAKE) -C binder-service $*
 | 
			
		||||
	@$(MAKE) -C binder-call $*
 | 
			
		||||
	@$(MAKE) -C rild-card-status $*
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										140
									
								
								test/ashmem-test/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								test/ashmem-test/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 = ashmem-test
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# 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)
 | 
			
		||||
							
								
								
									
										260
									
								
								test/ashmem-test/ashmem-test.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										260
									
								
								test/ashmem-test/ashmem-test.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,260 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2021 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_misc.h>
 | 
			
		||||
#include <gutil_log.h>
 | 
			
		||||
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
 | 
			
		||||
#define RET_OK          (0)
 | 
			
		||||
#define RET_NOTFOUND    (1)
 | 
			
		||||
#define RET_INVARG      (2)
 | 
			
		||||
#define RET_ERR         (3)
 | 
			
		||||
 | 
			
		||||
#define DEFAULT_BINDER  GBINDER_DEFAULT_HWBINDER
 | 
			
		||||
#define ALLOCATOR_IFACE "android.hidl.allocator@1.0::IAllocator"
 | 
			
		||||
#define DEFAULT_FQNAME  ALLOCATOR_IFACE "/ashmem"
 | 
			
		||||
#define TX_ALLOCATE     GBINDER_FIRST_CALL_TRANSACTION
 | 
			
		||||
 | 
			
		||||
typedef struct app_options {
 | 
			
		||||
    const char* fqname;
 | 
			
		||||
    char* dev;
 | 
			
		||||
    gsize size;
 | 
			
		||||
} AppOptions;
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
app_dumpmem(
 | 
			
		||||
    const GBinderHidlMemory* mem)
 | 
			
		||||
{
 | 
			
		||||
    const GBinderFds* fds = mem->data.fds;
 | 
			
		||||
 | 
			
		||||
    GDEBUG("Name: %s", mem->name.data.str);
 | 
			
		||||
    GDEBUG("Size: %" G_GUINT64_FORMAT " bytes", mem->size);
 | 
			
		||||
 | 
			
		||||
    GASSERT(fds->version == GBINDER_HIDL_FDS_VERSION);
 | 
			
		||||
    GDEBUG("Contains %u fd(s)", fds->num_fds);
 | 
			
		||||
    if (fds->num_fds) {
 | 
			
		||||
        guint i;
 | 
			
		||||
 | 
			
		||||
        for (i = 0; i < fds->num_fds; i++) {
 | 
			
		||||
            int fd = gbinder_fds_get_fd(fds, i);
 | 
			
		||||
            guint8* ptr = mmap(NULL, mem->size, PROT_READ | PROT_WRITE,
 | 
			
		||||
                MAP_SHARED, fd, 0);
 | 
			
		||||
 | 
			
		||||
            if (ptr) {
 | 
			
		||||
                gsize off = 0;
 | 
			
		||||
 | 
			
		||||
                GDEBUG("fd %d => %p", fd, ptr);
 | 
			
		||||
                while (off < mem->size) {
 | 
			
		||||
                    char line[GUTIL_HEXDUMP_BUFSIZE];
 | 
			
		||||
                    guint n = gutil_hexdump(line, ptr + off, mem->size - off);
 | 
			
		||||
 | 
			
		||||
                    GDEBUG("%04X: %s", (uint) off, line);
 | 
			
		||||
                    off += n;
 | 
			
		||||
                }
 | 
			
		||||
                munmap(ptr, mem->size);
 | 
			
		||||
            } else {
 | 
			
		||||
                GDEBUG("fd %d", fd);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
app_allocate(
 | 
			
		||||
    const AppOptions* opt,
 | 
			
		||||
    GBinderClient* client)
 | 
			
		||||
{
 | 
			
		||||
    GBinderLocalRequest* request = gbinder_client_new_request(client);
 | 
			
		||||
    GBinderRemoteReply* reply;
 | 
			
		||||
    int status, ret;
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_append_int64(request, opt->size);
 | 
			
		||||
    reply = gbinder_client_transact_sync_reply(client, TX_ALLOCATE,
 | 
			
		||||
        request, &status);
 | 
			
		||||
                             
 | 
			
		||||
    if (reply) {
 | 
			
		||||
        GBinderReader reader;
 | 
			
		||||
        gint32 tx_status;
 | 
			
		||||
        gboolean success;
 | 
			
		||||
 | 
			
		||||
        gbinder_remote_reply_init_reader(reply, &reader);
 | 
			
		||||
        if (gbinder_reader_read_int32(&reader, &tx_status) &&
 | 
			
		||||
            gbinder_reader_read_bool(&reader, &success) &&
 | 
			
		||||
            tx_status == GBINDER_STATUS_OK &&
 | 
			
		||||
            success) {
 | 
			
		||||
            const GBinderHidlMemory* mem = gbinder_reader_read_hidl_struct
 | 
			
		||||
                (&reader, GBinderHidlMemory);
 | 
			
		||||
 | 
			
		||||
            if (mem) {
 | 
			
		||||
                GINFO("OK");
 | 
			
		||||
                app_dumpmem(mem);
 | 
			
		||||
            } else {
 | 
			
		||||
                GINFO("OOPS");
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            GINFO("FAILED");
 | 
			
		||||
        }
 | 
			
		||||
        ret = RET_OK;
 | 
			
		||||
    } else {
 | 
			
		||||
        GERR("Call failed (%d)", status);
 | 
			
		||||
        ret = RET_ERR;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_unref(request);
 | 
			
		||||
    gbinder_remote_reply_unref(reply);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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) {
 | 
			
		||||
            GBinderClient* client = gbinder_client_new(remote, ALLOCATOR_IFACE);
 | 
			
		||||
 | 
			
		||||
            ret = app_allocate(opt, client);
 | 
			
		||||
            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 < 3) {
 | 
			
		||||
            opt->fqname = ((argc == 2) ? argv[1] : DEFAULT_FQNAME);
 | 
			
		||||
            opt->size = 64;
 | 
			
		||||
            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:
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										154
									
								
								test/binder-bridge/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										154
									
								
								test/binder-bridge/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,154 @@
 | 
			
		||||
# -*- 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-bridge
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# 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)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Install
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
INSTALL = install
 | 
			
		||||
 | 
			
		||||
INSTALL_BIN_DIR = $(DESTDIR)/usr/bin
 | 
			
		||||
 | 
			
		||||
install: release $(INSTALL_BIN_DIR)
 | 
			
		||||
	$(INSTALL) -m 755 $(RELEASE_EXE) $(INSTALL_BIN_DIR)
 | 
			
		||||
 | 
			
		||||
$(INSTALL_BIN_DIR):
 | 
			
		||||
	$(INSTALL) -d $@
 | 
			
		||||
							
								
								
									
										196
									
								
								test/binder-bridge/binder-bridge.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										196
									
								
								test/binder-bridge/binder-bridge.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,196 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2021 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>
 | 
			
		||||
 | 
			
		||||
#include <glib-unix.h>
 | 
			
		||||
 | 
			
		||||
#define RET_OK      (0)
 | 
			
		||||
#define RET_NODEV   (1)
 | 
			
		||||
#define RET_INVARG  (2)
 | 
			
		||||
 | 
			
		||||
typedef struct app_options {
 | 
			
		||||
    const char* src;
 | 
			
		||||
    const char* dest;
 | 
			
		||||
    char* src_name;
 | 
			
		||||
    const char* dest_name;
 | 
			
		||||
    const char** ifaces;
 | 
			
		||||
} AppOptions;
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
app_signal(
 | 
			
		||||
    gpointer loop)
 | 
			
		||||
{
 | 
			
		||||
    GINFO("Caught signal, shutting down...");
 | 
			
		||||
    g_main_loop_quit(loop);
 | 
			
		||||
    return G_SOURCE_CONTINUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
app_run(
 | 
			
		||||
    const AppOptions* opt)
 | 
			
		||||
{
 | 
			
		||||
    int ret = RET_NODEV;
 | 
			
		||||
    GBinderServiceManager* src = gbinder_servicemanager_new(opt->src);
 | 
			
		||||
 | 
			
		||||
    if (src) {
 | 
			
		||||
        GBinderServiceManager* dest = gbinder_servicemanager_new(opt->dest);
 | 
			
		||||
 | 
			
		||||
        if (dest) {
 | 
			
		||||
            GMainLoop* loop = g_main_loop_new(NULL, TRUE);
 | 
			
		||||
            guint sigtrm = g_unix_signal_add(SIGTERM, app_signal, loop);
 | 
			
		||||
            guint sigint = g_unix_signal_add(SIGINT, app_signal, loop);
 | 
			
		||||
            GBinderBridge* bridge = gbinder_bridge_new2
 | 
			
		||||
                (opt->src_name, opt->dest_name, opt->ifaces, src, dest);
 | 
			
		||||
 | 
			
		||||
            g_main_loop_run(loop);
 | 
			
		||||
 | 
			
		||||
            if (sigtrm) g_source_remove(sigtrm);
 | 
			
		||||
            if (sigint) g_source_remove(sigint);
 | 
			
		||||
            g_main_loop_unref(loop);
 | 
			
		||||
            gbinder_bridge_free(bridge);
 | 
			
		||||
            gbinder_servicemanager_unref(dest);
 | 
			
		||||
            ret = RET_OK;
 | 
			
		||||
        } else {
 | 
			
		||||
            GERR("No servicemanager at %s", opt->dest);
 | 
			
		||||
        }
 | 
			
		||||
        gbinder_servicemanager_unref(src);
 | 
			
		||||
    } else {
 | 
			
		||||
        GERR("No servicemanager at %s", opt->src);
 | 
			
		||||
    }
 | 
			
		||||
    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[] = {
 | 
			
		||||
        { "source", 's', 0, G_OPTION_ARG_STRING, &opt->src_name,
 | 
			
		||||
          "Register a different name on source", "NAME" },
 | 
			
		||||
        { "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 },
 | 
			
		||||
        { NULL }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    GError* error = NULL;
 | 
			
		||||
    GOptionContext* options = g_option_context_new("SRC DST NAME IFACES...");
 | 
			
		||||
 | 
			
		||||
    gutil_log_default.level = GLOG_LEVEL_DEFAULT;
 | 
			
		||||
 | 
			
		||||
    g_option_context_add_main_entries(options, entries, NULL);
 | 
			
		||||
    g_option_context_set_summary(options,
 | 
			
		||||
        "Forwards calls from device SRC to device DST.");
 | 
			
		||||
 | 
			
		||||
    if (g_option_context_parse(options, &argc, &argv, &error)) {
 | 
			
		||||
        if (argc >= 5) {
 | 
			
		||||
            int i;
 | 
			
		||||
            const int first_iface = 4;
 | 
			
		||||
 | 
			
		||||
            opt->src = argv[1];
 | 
			
		||||
            opt->dest = argv[2];
 | 
			
		||||
            opt->dest_name = argv[3];
 | 
			
		||||
            opt->ifaces = g_new(const char*, argc - first_iface + 1);
 | 
			
		||||
            for (i = first_iface; i < argc; i++) {
 | 
			
		||||
                opt->ifaces[i - first_iface] = argv[i];
 | 
			
		||||
            }
 | 
			
		||||
            opt->ifaces[i - first_iface] = NULL;
 | 
			
		||||
            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.src_name);
 | 
			
		||||
    g_free(opt.ifaces);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										178
									
								
								test/binder-call/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										178
									
								
								test/binder-call/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,178 @@
 | 
			
		||||
# -*- Mode: makefile-gmake -*-
 | 
			
		||||
 | 
			
		||||
.PHONY: all debug release install 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-call
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Sources
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
SRC = $(EXE).c
 | 
			
		||||
GEN_SRC = \
 | 
			
		||||
  cmdline.tab.c \
 | 
			
		||||
  lex.cmdline.c
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Directories
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
SRC_DIR = .
 | 
			
		||||
BUILD_DIR = build
 | 
			
		||||
GEN_DIR = $(BUILD_DIR)
 | 
			
		||||
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 -I$(GEN_DIR) -I$(SRC_DIR)
 | 
			
		||||
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 =
 | 
			
		||||
 | 
			
		||||
KEEP_SYMBOLS ?= 0
 | 
			
		||||
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 = \
 | 
			
		||||
  $(GEN_SRC:%.c=$(DEBUG_BUILD_DIR)/%.o) \
 | 
			
		||||
  $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
 | 
			
		||||
RELEASE_OBJS = \
 | 
			
		||||
  $(GEN_SRC:%.c=$(RELEASE_BUILD_DIR)/%.o) \
 | 
			
		||||
  $(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)
 | 
			
		||||
GEN_FILES = $(GEN_SRC:%=$(GEN_DIR)/%)
 | 
			
		||||
.PRECIOUS: $(GEN_FILES)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Dependencies
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d)
 | 
			
		||||
ifneq ($(MAKECMDGOALS),clean)
 | 
			
		||||
ifneq ($(strip $(DEPS)),)
 | 
			
		||||
-include $(DEPS)
 | 
			
		||||
endif
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
$(GEN_FILES): | $(GEN_DIR)
 | 
			
		||||
$(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 $@
 | 
			
		||||
 | 
			
		||||
$(GEN_DIR):
 | 
			
		||||
	mkdir -p $@
 | 
			
		||||
 | 
			
		||||
$(GEN_DIR)/%.tab.c : $(SRC_DIR)/%.y
 | 
			
		||||
	bison -pcmdline -bcmdline -d -o $@ $<
 | 
			
		||||
 | 
			
		||||
$(GEN_DIR)/lex.%.c : $(SRC_DIR)/%.l
 | 
			
		||||
	flex -o $@ $<
 | 
			
		||||
 | 
			
		||||
$(DEBUG_BUILD_DIR)/%.o : $(GEN_DIR)/%.c
 | 
			
		||||
	$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
 | 
			
		||||
 | 
			
		||||
$(RELEASE_BUILD_DIR)/%.o : $(GEN_DIR)/%.c
 | 
			
		||||
	$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
 | 
			
		||||
 | 
			
		||||
$(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)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Install
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
INSTALL = install
 | 
			
		||||
 | 
			
		||||
INSTALL_BIN_DIR = $(DESTDIR)/usr/bin
 | 
			
		||||
 | 
			
		||||
install: release $(INSTALL_BIN_DIR)
 | 
			
		||||
	$(INSTALL) -m 755 $(RELEASE_EXE) $(INSTALL_BIN_DIR)
 | 
			
		||||
 | 
			
		||||
$(INSTALL_BIN_DIR):
 | 
			
		||||
	$(INSTALL) -d $@
 | 
			
		||||
							
								
								
									
										814
									
								
								test/binder-call/binder-call.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										814
									
								
								test/binder-call/binder-call.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,814 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2021 Franz-Josef Haider <franz.haider@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>
 | 
			
		||||
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <binder-call.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#define RET_OK          (0)
 | 
			
		||||
#define RET_NOTFOUND    (1)
 | 
			
		||||
#define RET_INVARG      (2)
 | 
			
		||||
#define RET_ERR         (3)
 | 
			
		||||
 | 
			
		||||
#define DEFAULT_DEVICE     GBINDER_DEFAULT_BINDER
 | 
			
		||||
 | 
			
		||||
#define GBINDER_TRANSACTION(c2,c3,c4)     GBINDER_FOURCC('_',c2,c3,c4)
 | 
			
		||||
#define GBINDER_INTERFACE_TRANSACTION     GBINDER_TRANSACTION('N','T','F')
 | 
			
		||||
 | 
			
		||||
static const char pname[] = "binder-call";
 | 
			
		||||
 | 
			
		||||
struct transaction_and_reply* ast;
 | 
			
		||||
 | 
			
		||||
enum transaction_pass {
 | 
			
		||||
    COMPUTE_SIZES = 0,
 | 
			
		||||
    FILL_BUFFERS,
 | 
			
		||||
    BUILD_TRANSACTION
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum reply_pass {
 | 
			
		||||
    PRINT_REPLY = 0,
 | 
			
		||||
    COMPUTE_SIZES_REPLY
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
go_through_transaction_ast(
 | 
			
		||||
    App* app,
 | 
			
		||||
    GList* node_list,
 | 
			
		||||
    int parent_idx,
 | 
			
		||||
    void* buf,
 | 
			
		||||
    enum transaction_pass cur_pass,
 | 
			
		||||
    int cont_offset)
 | 
			
		||||
{
 | 
			
		||||
    GList* l;
 | 
			
		||||
    int offset = cont_offset;
 | 
			
		||||
 | 
			
		||||
    for (l = node_list; l; l = l->next) {
 | 
			
		||||
        struct value_info* v = l->data;
 | 
			
		||||
 | 
			
		||||
        switch(v->type) {
 | 
			
		||||
        case INT8_TYPE:
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("int8");
 | 
			
		||||
            if (parent_idx == -1) {
 | 
			
		||||
                gbinder_writer_append_int32(&app->writer, *((int*)v->value));
 | 
			
		||||
            } else if (cur_pass == FILL_BUFFERS) {
 | 
			
		||||
                *((unsigned char*)(((char*)buf)+offset)) =
 | 
			
		||||
                    *((unsigned char*)v->value);
 | 
			
		||||
            }
 | 
			
		||||
            offset++;
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case INT32_TYPE:
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("int32");
 | 
			
		||||
            if (parent_idx == -1) {
 | 
			
		||||
                gbinder_writer_append_int32(&app->writer, *((int*)v->value));
 | 
			
		||||
            } else if (cur_pass == FILL_BUFFERS) {
 | 
			
		||||
                *((int*)(((char*)buf)+offset)) = *((int*)v->value);
 | 
			
		||||
            }
 | 
			
		||||
            offset += sizeof(gint32);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case INT64_TYPE:
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("int64");
 | 
			
		||||
            if (parent_idx == -1) {
 | 
			
		||||
                gbinder_writer_append_int64(&app->writer, *((gint64*)v->value));
 | 
			
		||||
            } else if (cur_pass == FILL_BUFFERS) {
 | 
			
		||||
                *((gint64*)(((char*)buf)+offset)) = *((gint64*)v->value);
 | 
			
		||||
            }
 | 
			
		||||
            offset += sizeof(gint64);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case FLOAT_TYPE:
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("float");
 | 
			
		||||
            if (parent_idx == -1) {
 | 
			
		||||
                gbinder_writer_append_float(&app->writer, *((float*)v->value));
 | 
			
		||||
            } else if (cur_pass == FILL_BUFFERS) {
 | 
			
		||||
                *((float*)(((char*)buf)+offset)) = *((float*)v->value);
 | 
			
		||||
            }
 | 
			
		||||
            offset += sizeof(float);
 | 
			
		||||
            break;
 | 
			
		||||
        case DOUBLE_TYPE:
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("double");
 | 
			
		||||
            if (parent_idx == -1) {
 | 
			
		||||
                gbinder_writer_append_double(&app->writer,*((double*)v->value));
 | 
			
		||||
            } else if (cur_pass == FILL_BUFFERS) {
 | 
			
		||||
                *((double*)(((char*)buf)+offset)) = *((double*)v->value);
 | 
			
		||||
            }
 | 
			
		||||
            offset += sizeof(double);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case STRING8_TYPE:
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("string8");
 | 
			
		||||
            gbinder_writer_append_string8(&app->writer, v->value);
 | 
			
		||||
            /* offset not incremented since it only makes sense for hidl */
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case STRING16_TYPE:
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("string16");
 | 
			
		||||
            gbinder_writer_append_string16(&app->writer, v->value);
 | 
			
		||||
            /* offset not incremented since it only makes sense for hidl */
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case HSTRING_TYPE:
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("hstring");
 | 
			
		||||
            if (parent_idx == -1) {
 | 
			
		||||
                gbinder_writer_append_hidl_string(&app->writer, v->value);
 | 
			
		||||
            } else {
 | 
			
		||||
                GBinderHidlString* hidl_str = (GBinderHidlString*)
 | 
			
		||||
                    (((char*)buf)+offset);
 | 
			
		||||
 | 
			
		||||
                if (cur_pass == FILL_BUFFERS) {
 | 
			
		||||
                    hidl_str->data.str = v->value;
 | 
			
		||||
                    hidl_str->len = strlen(v->value);
 | 
			
		||||
                    hidl_str->owns_buffer = TRUE;
 | 
			
		||||
                } else if (cur_pass == BUILD_TRANSACTION) {
 | 
			
		||||
                    GBinderParent p;
 | 
			
		||||
 | 
			
		||||
                    p.index = parent_idx;
 | 
			
		||||
                    p.offset = offset;
 | 
			
		||||
                    gbinder_writer_append_buffer_object_with_parent
 | 
			
		||||
                        (&app->writer, hidl_str->data.str, hidl_str->len+1, &p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            offset += sizeof(GBinderHidlString);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case STRUCT_TYPE:
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("struct");
 | 
			
		||||
            if (!app->opt->aidl) {
 | 
			
		||||
                if (parent_idx == -1) {
 | 
			
		||||
                    int s = go_through_transaction_ast(app, v->value, 0,
 | 
			
		||||
                        NULL, COMPUTE_SIZES, 0);
 | 
			
		||||
                    void* new_buf = gbinder_writer_malloc(&app->writer, s);
 | 
			
		||||
                    int new_parent_idx;
 | 
			
		||||
 | 
			
		||||
                    go_through_transaction_ast(app, v->value, 0, new_buf,
 | 
			
		||||
                        FILL_BUFFERS, 0);
 | 
			
		||||
                    new_parent_idx = gbinder_writer_append_buffer_object
 | 
			
		||||
                        (&app->writer, new_buf, s);
 | 
			
		||||
                    /*
 | 
			
		||||
                     * if parent_idx == -1 there is no need to update the
 | 
			
		||||
                     * offset, since we are processing the argument list
 | 
			
		||||
                     *  and are not inside an argument.
 | 
			
		||||
                     */
 | 
			
		||||
                    go_through_transaction_ast(app, v->value,
 | 
			
		||||
                        new_parent_idx, new_buf, BUILD_TRANSACTION, 0);
 | 
			
		||||
                } else {
 | 
			
		||||
                    if (cur_pass == FILL_BUFFERS) {
 | 
			
		||||
                        /* fill struct mode */
 | 
			
		||||
                        offset += go_through_transaction_ast(app,
 | 
			
		||||
                            v->value, 0, ((char*)buf)+offset, cur_pass, 0);
 | 
			
		||||
                    } else if (cur_pass == BUILD_TRANSACTION) {
 | 
			
		||||
                        int s = go_through_transaction_ast(app,
 | 
			
		||||
                            v->value, 0, NULL, COMPUTE_SIZES, 0);
 | 
			
		||||
 | 
			
		||||
                        go_through_transaction_ast(app, v->value, 0,
 | 
			
		||||
                            buf, FILL_BUFFERS, offset);
 | 
			
		||||
                        go_through_transaction_ast(app, v->value,  parent_idx,
 | 
			
		||||
                            buf, BUILD_TRANSACTION, offset);
 | 
			
		||||
                        offset += s;
 | 
			
		||||
                    } else if (cur_pass == COMPUTE_SIZES) {
 | 
			
		||||
                        offset += go_through_transaction_ast(app,
 | 
			
		||||
                            v->value, 0, NULL, cur_pass, 0);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                go_through_transaction_ast(app, v->value, -1, NULL,
 | 
			
		||||
                    cur_pass, 0);
 | 
			
		||||
            }
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("structend");
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case VECTOR_TYPE:
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("vector");
 | 
			
		||||
            if (!app->opt->aidl) {
 | 
			
		||||
                if (parent_idx == -1) {
 | 
			
		||||
                    GBinderHidlVec* vec;
 | 
			
		||||
                    int vs = go_through_transaction_ast(app,
 | 
			
		||||
                        v->value, 0, NULL, COMPUTE_SIZES, 0);
 | 
			
		||||
                    int es = go_through_transaction_ast(app,
 | 
			
		||||
                        g_list_last(v->value), 0, NULL, COMPUTE_SIZES, 0);
 | 
			
		||||
                    void* new_buf = gbinder_writer_malloc(&app->writer, vs);
 | 
			
		||||
                    int new_parent_idx;
 | 
			
		||||
                    GBinderParent vec_parent;
 | 
			
		||||
 | 
			
		||||
                    go_through_transaction_ast(app, v->value, 0, new_buf,
 | 
			
		||||
                        FILL_BUFFERS, 0);
 | 
			
		||||
                    vec = gbinder_writer_new0(&app->writer, GBinderHidlVec);
 | 
			
		||||
                    vec->data.ptr = new_buf;
 | 
			
		||||
                    vec->count = vs / es;
 | 
			
		||||
                    if (vec->count != g_list_length(v->value)) {
 | 
			
		||||
                        GERR("SEMANTIC ERROR VECTOR");
 | 
			
		||||
                        abort();
 | 
			
		||||
                    }
 | 
			
		||||
                    vec_parent.index = gbinder_writer_append_buffer_object
 | 
			
		||||
                        (&app->writer, vec, sizeof(*vec));
 | 
			
		||||
                    vec_parent.offset = GBINDER_HIDL_VEC_BUFFER_OFFSET;
 | 
			
		||||
                    new_parent_idx =
 | 
			
		||||
                        gbinder_writer_append_buffer_object_with_parent
 | 
			
		||||
                            (&app->writer, new_buf, vs, &vec_parent);
 | 
			
		||||
                    go_through_transaction_ast(app, v->value,
 | 
			
		||||
                        new_parent_idx, new_buf, BUILD_TRANSACTION, 0);
 | 
			
		||||
                } else {
 | 
			
		||||
                    if (cur_pass == FILL_BUFFERS) {
 | 
			
		||||
                        /* fill struct mode */
 | 
			
		||||
                        int sl = go_through_transaction_ast(app,
 | 
			
		||||
                            v->value, 0, NULL, COMPUTE_SIZES, 0);
 | 
			
		||||
                        int es = go_through_transaction_ast(app,
 | 
			
		||||
                            g_list_last(v->value), 0, NULL, COMPUTE_SIZES, 0);
 | 
			
		||||
                        void* new_buf = gbinder_writer_malloc(&app->writer, sl);
 | 
			
		||||
                        GBinderHidlVec* vec = (GBinderHidlVec*)
 | 
			
		||||
                            (((char*)buf)+offset);
 | 
			
		||||
 | 
			
		||||
                        vec->data.ptr = new_buf;
 | 
			
		||||
                        vec->count = sl / es;
 | 
			
		||||
                    } else if (cur_pass == BUILD_TRANSACTION) {
 | 
			
		||||
                        int new_parent_idx;
 | 
			
		||||
                        int sl = go_through_transaction_ast(app,
 | 
			
		||||
                            v->value, 0, NULL, COMPUTE_SIZES, 0);
 | 
			
		||||
                        GBinderHidlVec* vec = (GBinderHidlVec*)
 | 
			
		||||
                            (((char*)buf)+offset);
 | 
			
		||||
                        GBinderParent p;
 | 
			
		||||
                        void* new_buf = (void*)vec->data.ptr;
 | 
			
		||||
 | 
			
		||||
                        go_through_transaction_ast(app, v->value, 0,
 | 
			
		||||
                            new_buf, FILL_BUFFERS, 0);
 | 
			
		||||
                        if (vec->count != g_list_length(v->value)) {
 | 
			
		||||
                            GERR("SEMANTIC ERROR VECTOR");
 | 
			
		||||
                            abort();
 | 
			
		||||
                        }
 | 
			
		||||
                        p.index = parent_idx;
 | 
			
		||||
                        p.offset = offset;
 | 
			
		||||
                        new_parent_idx =
 | 
			
		||||
                            gbinder_writer_append_buffer_object_with_parent
 | 
			
		||||
                                (&app->writer, new_buf, sl, &p);
 | 
			
		||||
                        go_through_transaction_ast(app, v->value,
 | 
			
		||||
                            new_parent_idx, new_buf, BUILD_TRANSACTION, 0);
 | 
			
		||||
                    }
 | 
			
		||||
                    offset += sizeof(GBinderHidlVec);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                int vl = g_list_length(v->value);
 | 
			
		||||
 | 
			
		||||
                gbinder_writer_append_int32(&app->writer, vl);
 | 
			
		||||
                go_through_transaction_ast(app, v->value, -1, NULL,
 | 
			
		||||
                    cur_pass, 0);
 | 
			
		||||
            }
 | 
			
		||||
            if (cur_pass == BUILD_TRANSACTION) GDEBUG("vectorend");
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            GERR("unknown type: %d\n", v->type);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return offset;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
int
 | 
			
		||||
go_through_reply_ast(
 | 
			
		||||
    App* app,
 | 
			
		||||
    GList* node_list,
 | 
			
		||||
    struct type_info* tt,
 | 
			
		||||
    const void* buf,
 | 
			
		||||
    enum reply_pass cur_pass)
 | 
			
		||||
{
 | 
			
		||||
    GList* l;
 | 
			
		||||
    int offset = 0;
 | 
			
		||||
 | 
			
		||||
    for (l = node_list; l || tt; l = l->next) {
 | 
			
		||||
        struct type_info* t = node_list ? l->data : tt;
 | 
			
		||||
 | 
			
		||||
        switch(t->type) {
 | 
			
		||||
        case INT8_TYPE:
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("int8");
 | 
			
		||||
            if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                int val;
 | 
			
		||||
 | 
			
		||||
                if (!buf) {
 | 
			
		||||
                    gbinder_reader_read_int32(&app->reader, &val);
 | 
			
		||||
                } else if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                    val = *((unsigned char*)(((char*)buf)+offset));
 | 
			
		||||
                }
 | 
			
		||||
                printf("%d:8 ", val);
 | 
			
		||||
            }
 | 
			
		||||
            offset += 1;
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case INT32_TYPE:
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("int32");
 | 
			
		||||
            if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                gint32 val;
 | 
			
		||||
 | 
			
		||||
                if (!buf) {
 | 
			
		||||
                    gbinder_reader_read_int32(&app->reader, &val);
 | 
			
		||||
                } else if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                    val = *((gint32*)(((char*)buf)+offset));
 | 
			
		||||
                }
 | 
			
		||||
                printf("%" G_GINT32_FORMAT " ", val);
 | 
			
		||||
            }
 | 
			
		||||
            offset += sizeof(gint32);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case INT64_TYPE:
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("int64");
 | 
			
		||||
            if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                gint64 val;
 | 
			
		||||
 | 
			
		||||
                if (!buf) {
 | 
			
		||||
                    gbinder_reader_read_int64(&app->reader, &val);
 | 
			
		||||
                } else if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                    val = *((gint64*)(((char*)buf)+offset));
 | 
			
		||||
                }
 | 
			
		||||
                printf("%" G_GINT64_FORMAT " ", val);
 | 
			
		||||
            }
 | 
			
		||||
            offset += sizeof(gint64);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case FLOAT_TYPE:
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("float");
 | 
			
		||||
            if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                float val;
 | 
			
		||||
 | 
			
		||||
                if (!buf) {
 | 
			
		||||
                    gbinder_reader_read_float(&app->reader, &val);
 | 
			
		||||
                } else if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                    val = *((float*)(((char*)buf)+offset));
 | 
			
		||||
                }
 | 
			
		||||
                printf("%f ", val);
 | 
			
		||||
            }
 | 
			
		||||
            offset += sizeof(float);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case DOUBLE_TYPE:
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("double");
 | 
			
		||||
            if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                double val;
 | 
			
		||||
 | 
			
		||||
                if (!buf) {
 | 
			
		||||
                    gbinder_reader_read_double(&app->reader, &val);
 | 
			
		||||
                } else if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                    val = *((double*)(((char*)buf)+offset));
 | 
			
		||||
                }
 | 
			
		||||
                printf("%lfL ", val);
 | 
			
		||||
            }
 | 
			
		||||
            offset += sizeof(double);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case STRING8_TYPE:
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("string8");
 | 
			
		||||
            printf("\"%s\" ", gbinder_reader_read_string8(&app->reader));
 | 
			
		||||
            /* offset not incremented since it only makes sense for hidl */
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case STRING16_TYPE: {
 | 
			
		||||
            char* val = gbinder_reader_read_string16(&app->reader);
 | 
			
		||||
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("string16");
 | 
			
		||||
            printf("\"%s\"U ", val);
 | 
			
		||||
            g_free(val);
 | 
			
		||||
            /* offset not incremented since it only makes sense for hidl */
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        case HSTRING_TYPE:
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("hstring");
 | 
			
		||||
            if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                char* val = NULL;
 | 
			
		||||
 | 
			
		||||
                if (!buf) {
 | 
			
		||||
                    val = gbinder_reader_read_hidl_string(&app->reader);
 | 
			
		||||
                } else {
 | 
			
		||||
                    GBinderHidlString* hidl_str = (GBinderHidlString*)
 | 
			
		||||
                        (((char*)buf)+offset);
 | 
			
		||||
 | 
			
		||||
                    val = strdup(hidl_str->data.str);
 | 
			
		||||
                }
 | 
			
		||||
                printf("\"%s\"H ", val);
 | 
			
		||||
                g_free(val);
 | 
			
		||||
            }
 | 
			
		||||
            offset += sizeof(GBinderHidlString);
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case STRUCT_TYPE:
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("struct");
 | 
			
		||||
            if (!app->opt->aidl) {
 | 
			
		||||
                if (cur_pass == COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                    offset += go_through_reply_ast(app, t->data, NULL, NULL,
 | 
			
		||||
                        COMPUTE_SIZES_REPLY);
 | 
			
		||||
                } else {
 | 
			
		||||
                    printf("{ ");
 | 
			
		||||
                    if (!buf) {
 | 
			
		||||
                        int sl = go_through_reply_ast(app, t->data, NULL, NULL,
 | 
			
		||||
                            COMPUTE_SIZES_REPLY);
 | 
			
		||||
 | 
			
		||||
                        offset += go_through_reply_ast(app, t->data, NULL,
 | 
			
		||||
                            gbinder_reader_read_hidl_struct1(&app->reader, sl),
 | 
			
		||||
                            PRINT_REPLY);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        offset += go_through_reply_ast(app, t->data, NULL,
 | 
			
		||||
                            ((char*)buf) + offset, PRINT_REPLY);
 | 
			
		||||
                    }
 | 
			
		||||
                    printf("} ");
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                go_through_reply_ast(app, t->data, NULL, NULL, cur_pass);
 | 
			
		||||
            }
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("structend");
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case VECTOR_TYPE:
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("vector");
 | 
			
		||||
            if (!app->opt->aidl) {
 | 
			
		||||
                if (cur_pass != COMPUTE_SIZES_REPLY) {
 | 
			
		||||
                    if (!buf) {
 | 
			
		||||
                        guint i;
 | 
			
		||||
                        gsize count, elemsize;
 | 
			
		||||
                        const void* new_buf = gbinder_reader_read_hidl_vec
 | 
			
		||||
                            (&app->reader, &count, &elemsize);
 | 
			
		||||
 | 
			
		||||
                        printf("[ ");
 | 
			
		||||
                        for (i = 0; i < count; i++) {
 | 
			
		||||
                            /* TODO: validate elemsize somehow? */
 | 
			
		||||
                            go_through_reply_ast(app, NULL, t->data,
 | 
			
		||||
                                new_buf + elemsize*i, cur_pass);
 | 
			
		||||
                        }
 | 
			
		||||
                        printf("] ");
 | 
			
		||||
                    } else {
 | 
			
		||||
                        guint i;
 | 
			
		||||
                        gsize count;
 | 
			
		||||
                        GBinderHidlVec* vec = (GBinderHidlVec*)
 | 
			
		||||
                            (((char*)buf) + offset);
 | 
			
		||||
                        int off;
 | 
			
		||||
 | 
			
		||||
                        count = vec->count;
 | 
			
		||||
                        printf("[ ");
 | 
			
		||||
                        off = 0;
 | 
			
		||||
                        for (i = 0; i < count; i++) {
 | 
			
		||||
                            off += go_through_reply_ast(app, NULL, t->data,
 | 
			
		||||
                                vec->data.ptr + off, cur_pass);
 | 
			
		||||
                        }
 | 
			
		||||
                        printf("] ");
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                offset += sizeof(GBinderHidlVec);
 | 
			
		||||
            } else {
 | 
			
		||||
                guint i;
 | 
			
		||||
                gint32 vl;
 | 
			
		||||
 | 
			
		||||
                gbinder_reader_read_int32(&app->reader, &vl);
 | 
			
		||||
                printf("[ ");
 | 
			
		||||
                for (i = 0; i < vl; i++) {
 | 
			
		||||
                    go_through_reply_ast(app, NULL, t->data, NULL, cur_pass);
 | 
			
		||||
                }
 | 
			
		||||
                printf("] ");
 | 
			
		||||
            }
 | 
			
		||||
            if (cur_pass == PRINT_REPLY) GDEBUG("vectorend");
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        default:
 | 
			
		||||
            GERR("unknown type: %d\n", t->type);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (tt) break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return offset;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
go_through_ast(
 | 
			
		||||
    App* app,
 | 
			
		||||
    struct transaction_and_reply* ast,
 | 
			
		||||
    gboolean transaction)
 | 
			
		||||
{
 | 
			
		||||
    if (ast) {
 | 
			
		||||
        if (transaction && ast->tree_transaction) {
 | 
			
		||||
            go_through_transaction_ast(app, ast->tree_transaction, -1, NULL,
 | 
			
		||||
                BUILD_TRANSACTION, 0);
 | 
			
		||||
        } else if (!transaction && ast->tree_reply) {
 | 
			
		||||
            GDEBUG("REPLY:");
 | 
			
		||||
            go_through_reply_ast(app, ast->tree_reply, NULL, NULL, PRINT_REPLY);
 | 
			
		||||
            printf("\n");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
free_ast_transaction_tree(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = data;
 | 
			
		||||
 | 
			
		||||
    if (v->type == STRUCT_TYPE || v->type == VECTOR_TYPE) {
 | 
			
		||||
        g_list_free_full(v->value, free_ast_transaction_tree);
 | 
			
		||||
    } else {
 | 
			
		||||
        g_free(v->value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    g_free(v);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
free_ast_reply_tree(
 | 
			
		||||
    gpointer data)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* t = data;
 | 
			
		||||
 | 
			
		||||
    if (t->type == VECTOR_TYPE) {
 | 
			
		||||
        free_ast_reply_tree(t->data);
 | 
			
		||||
    } else if (t->type == STRUCT_TYPE) {
 | 
			
		||||
        g_list_free_full(t->data, free_ast_reply_tree);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    g_free(t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
free_ast(
 | 
			
		||||
    struct transaction_and_reply* ast)
 | 
			
		||||
{
 | 
			
		||||
    if (ast) {
 | 
			
		||||
        g_list_free_full(ast->tree_transaction, free_ast_transaction_tree);
 | 
			
		||||
        g_list_free_full(ast->tree_reply, free_ast_reply_tree);
 | 
			
		||||
        g_free(ast);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
void
 | 
			
		||||
app_run(
 | 
			
		||||
    App* app)
 | 
			
		||||
{
 | 
			
		||||
    const AppOptions* opt = app->opt;
 | 
			
		||||
    char* iface = opt->iface ? g_strdup(opt->iface) : NULL;
 | 
			
		||||
    int status = 0;
 | 
			
		||||
    int rargc = 1;
 | 
			
		||||
    char* service = opt->argv[rargc++];
 | 
			
		||||
    int code = atoi(opt->argv[rargc++]);
 | 
			
		||||
    GBinderClient* client;
 | 
			
		||||
    GBinderLocalRequest* req;
 | 
			
		||||
    GBinderRemoteReply* reply;
 | 
			
		||||
    GBinderRemoteObject* obj;
 | 
			
		||||
 | 
			
		||||
    if (!code) {
 | 
			
		||||
        GERR("Transaction code must be > GBINDER_FIRST_CALL_TRANSACTION(=1).");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    obj = gbinder_servicemanager_get_service_sync(app->sm,
 | 
			
		||||
        service, &status);
 | 
			
		||||
    if (!obj) {
 | 
			
		||||
        GERR("No such service: %s", service);
 | 
			
		||||
        g_free(iface);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (strstr(service, "/") != NULL) {
 | 
			
		||||
        iface = g_strndup(service, strchr(service, '/') - service);
 | 
			
		||||
    } else {
 | 
			
		||||
        GBinderReader reader;
 | 
			
		||||
 | 
			
		||||
        client = gbinder_client_new(obj, NULL);
 | 
			
		||||
        req = gbinder_client_new_request(client);
 | 
			
		||||
        reply = gbinder_client_transact_sync_reply(client,
 | 
			
		||||
            GBINDER_INTERFACE_TRANSACTION, req, &status);
 | 
			
		||||
        gbinder_remote_reply_init_reader(reply, &reader);
 | 
			
		||||
        iface = gbinder_reader_read_string16(&reader);
 | 
			
		||||
        gbinder_local_request_unref(req);
 | 
			
		||||
        gbinder_remote_reply_unref(reply);
 | 
			
		||||
        gbinder_client_unref(client);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!iface) {
 | 
			
		||||
        GERR("Failed to get interface");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    GDEBUG("Got iface: %s", iface);
 | 
			
		||||
 | 
			
		||||
    client = gbinder_client_new(obj, iface);
 | 
			
		||||
    g_free(iface);
 | 
			
		||||
 | 
			
		||||
    req = gbinder_client_new_request(client);
 | 
			
		||||
 | 
			
		||||
    app->rargc = rargc;
 | 
			
		||||
    app->code = code;
 | 
			
		||||
 | 
			
		||||
    cmdline_parse(app);
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_init_writer(req, &app->writer);
 | 
			
		||||
    go_through_ast(app, ast, TRUE);
 | 
			
		||||
 | 
			
		||||
    if (opt->oneway) {
 | 
			
		||||
        gbinder_client_transact_sync_oneway(client, code, req);
 | 
			
		||||
        reply = NULL;
 | 
			
		||||
    } else {
 | 
			
		||||
        reply = gbinder_client_transact_sync_reply(client, code, req, &status);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    gbinder_local_request_unref(req);
 | 
			
		||||
 | 
			
		||||
    if (!reply) {
 | 
			
		||||
        printf("NO REPLY\n");
 | 
			
		||||
    } else {
 | 
			
		||||
        if (ast && !ast->tree_reply) {
 | 
			
		||||
            guchar b;
 | 
			
		||||
 | 
			
		||||
            gbinder_remote_reply_init_reader(reply, &app->reader);
 | 
			
		||||
            printf("TRANSACTION BUFFER: 0x");
 | 
			
		||||
            while (gbinder_reader_read_byte(&app->reader, &b)) {
 | 
			
		||||
                printf("%02X", b);
 | 
			
		||||
            }
 | 
			
		||||
            printf("\n");
 | 
			
		||||
        } else {
 | 
			
		||||
            gbinder_remote_reply_init_reader(reply, &app->reader);
 | 
			
		||||
            go_through_ast(app, ast, FALSE);
 | 
			
		||||
        }
 | 
			
		||||
        gbinder_remote_reply_unref(reply);
 | 
			
		||||
    }
 | 
			
		||||
    gbinder_client_unref(client);
 | 
			
		||||
    free_ast(ast);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static
 | 
			
		||||
gboolean
 | 
			
		||||
app_log_verbose(
 | 
			
		||||
    const gchar* name,
 | 
			
		||||
    const gchar* value,
 | 
			
		||||
    gpointer data,
 | 
			
		||||
    GError** error)
 | 
			
		||||
{
 | 
			
		||||
    gutil_log_default.level = (gutil_log_default.level < GLOG_LEVEL_DEBUG) ?
 | 
			
		||||
        GLOG_LEVEL_DEBUG : 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_ERR;
 | 
			
		||||
    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_DEVICE "]", "DEVICE" },
 | 
			
		||||
        { "oneway", 'o', 0, G_OPTION_ARG_NONE, &opt->oneway,
 | 
			
		||||
          "Use a oneway transaction", NULL },
 | 
			
		||||
        { "aidl", 'a', 0, G_OPTION_ARG_NONE, &opt->aidl,
 | 
			
		||||
          "Treat types as aidl types (default: hidl)", NULL },
 | 
			
		||||
        { NULL }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    GError* error = NULL;
 | 
			
		||||
    GOptionContext* options = g_option_context_new("NAME CODE [[VALUE1] [VALUE2] ...] [reply [TYPE1] [TYPE2] ...]");
 | 
			
		||||
    g_option_context_set_description(options,
 | 
			
		||||
    "Performs binder transactions from the command line.\n\n"
 | 
			
		||||
    "NAME is the name of the object to call, registered with servicemanager.\n"
 | 
			
		||||
    "For example \"android.hardware.sensors@1.0::ISensors/default\".\n\n"
 | 
			
		||||
    "CODE is the transaction id (must be >=1).\n\n"
 | 
			
		||||
    "Optional transaction arguments follow the transaction code.\n"
 | 
			
		||||
    "Possible arguments are:\n\n"
 | 
			
		||||
    "\t[0-9]*:8 for an 8-bit integer\n"
 | 
			
		||||
    "\t[0-9]* for a 32-bit integer\n"
 | 
			
		||||
    "\t[0-9]*L for an 64-bit integer\n"
 | 
			
		||||
    "\t[0-9]*.[0-9]* for a 32-bit float\n"
 | 
			
		||||
    "\t[0-9]*.[0-9]*L for a 64-bit double\n"
 | 
			
		||||
    "\t\"[.*]\" for an 8-bit aidl string\n"
 | 
			
		||||
    "\t\"[.*]\"L for an utf16 aidl string\n"
 | 
			
		||||
    "\t\"[.*]\"h for an 8-bit hidl string\n"
 | 
			
		||||
    "\t{ VALUE1 VALUE2 ... VALUEN } for a struct containing VALUE1, VALUE2, etc., where\n"
 | 
			
		||||
    "\t all of these values can be any of the possible values described here.\n"
 | 
			
		||||
    "\t[ VALUE1 VALUE2 ... VALUEN ] for a vector of length N containing VALUE1, VALUE2, etc., where\n"
 | 
			
		||||
    "\t all of these values can be one of the possible VALUES described here.\n"
 | 
			
		||||
    "\t They must be of the same type.\n\n"
 | 
			
		||||
    "The structure of the reply follows the \"reply\" keyword.\n"
 | 
			
		||||
    "The following types are accepted:\n\n"
 | 
			
		||||
    "\ti8 for an 8-bit integer\n"
 | 
			
		||||
    "\ti32 for a 32-bit integer\n"
 | 
			
		||||
    "\ti64 for a 64-bit integer\n"
 | 
			
		||||
    "\ts8 for an 8-bit aidl string\n"
 | 
			
		||||
    "\ts16 for an utf16 aidl string\n"
 | 
			
		||||
    "\thstr for an 8-bit hidl string\n"
 | 
			
		||||
    "\tf|float for a 32-bit float\n"
 | 
			
		||||
    "\td|double for a 64-bit double\n"
 | 
			
		||||
    "\t[ TYPE ] for a vector<TYPE> where TYPE can be any of the possible types decribed here\n"
 | 
			
		||||
    "\t{ TYPE1 TYPE2 ... TYPEN } for a struct containing TYPE1, TYPE2, etc. where\n"
 | 
			
		||||
    "\t all of the types can be any of the possible types decribed here.\n\n"
 | 
			
		||||
    "The following example calls getSensorsList method on \"android.hardware.sensors@1.0::ISensors/default\"\n"
 | 
			
		||||
    "service:\n\n"
 | 
			
		||||
    "\tbinder-call -d /dev/hwbinder android.hardware.sensors@1.0::ISensors/default 1 reply i32 \"[ { i32 i32 hstr hstr i32 i32 hstr f f f i32 i32 i32 hstr i32 i32 } ]\"\n");
 | 
			
		||||
 | 
			
		||||
    g_option_context_add_main_entries(options, entries, NULL);
 | 
			
		||||
 | 
			
		||||
    memset(opt, 0, sizeof(*opt));
 | 
			
		||||
 | 
			
		||||
    gutil_log_timestamp = FALSE;
 | 
			
		||||
    gutil_log_set_type(GLOG_TYPE_STDERR, pname);
 | 
			
		||||
    gutil_log_default.level = GLOG_LEVEL_DEFAULT;
 | 
			
		||||
 | 
			
		||||
    if (g_option_context_parse(options, &argc, &argv, &error)) {
 | 
			
		||||
        char* help;
 | 
			
		||||
 | 
			
		||||
        if (argc > 2) {
 | 
			
		||||
            opt->argc = argc;
 | 
			
		||||
            opt->argv = argv;
 | 
			
		||||
            ok = TRUE;
 | 
			
		||||
        } else {
 | 
			
		||||
            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[])
 | 
			
		||||
{
 | 
			
		||||
    App app;
 | 
			
		||||
    AppOptions opt;
 | 
			
		||||
 | 
			
		||||
    memset(&app, 0, sizeof(app));
 | 
			
		||||
    app.ret = RET_INVARG;
 | 
			
		||||
    app.opt = &opt;
 | 
			
		||||
    if (app_init(&opt, argc, argv)) {
 | 
			
		||||
        app.sm = gbinder_servicemanager_new(opt.dev);
 | 
			
		||||
        if (app.sm) {
 | 
			
		||||
            app_run(&app);
 | 
			
		||||
            gbinder_servicemanager_unref(app.sm);
 | 
			
		||||
        } else {
 | 
			
		||||
            GERR("servicemanager seems to be missing");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    g_free(opt.iface);
 | 
			
		||||
    g_free(opt.dev);
 | 
			
		||||
    return app.ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local Variables:
 | 
			
		||||
 * mode: C
 | 
			
		||||
 * c-basic-offset: 4
 | 
			
		||||
 * indent-tabs-mode: nil
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										97
									
								
								test/binder-call/binder-call.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								test/binder-call/binder-call.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,97 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2021 Jolla Ltd.
 | 
			
		||||
 *
 | 
			
		||||
 * 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 BINDER_CALL_H__
 | 
			
		||||
#define BINDER_CALL_H__
 | 
			
		||||
 | 
			
		||||
#include <gbinder.h>
 | 
			
		||||
 | 
			
		||||
typedef struct app_options {
 | 
			
		||||
    char* dev;
 | 
			
		||||
    char* iface;
 | 
			
		||||
    gboolean oneway;
 | 
			
		||||
    gboolean aidl;
 | 
			
		||||
    gint transaction;
 | 
			
		||||
    int argc;
 | 
			
		||||
    char** argv;
 | 
			
		||||
} AppOptions;
 | 
			
		||||
 | 
			
		||||
typedef struct app {
 | 
			
		||||
    const AppOptions* opt;
 | 
			
		||||
    GMainLoop* loop;
 | 
			
		||||
    GBinderServiceManager* sm;
 | 
			
		||||
    GBinderWriter writer;
 | 
			
		||||
    GBinderReader reader;
 | 
			
		||||
    int code;
 | 
			
		||||
    int rargc;
 | 
			
		||||
    int ret;
 | 
			
		||||
} App;
 | 
			
		||||
 | 
			
		||||
enum TYPE_INFO {
 | 
			
		||||
    INT8_TYPE = 0,
 | 
			
		||||
    INT32_TYPE,
 | 
			
		||||
    INT64_TYPE,
 | 
			
		||||
    FLOAT_TYPE,
 | 
			
		||||
    DOUBLE_TYPE,
 | 
			
		||||
    STRING8_TYPE,
 | 
			
		||||
    STRING16_TYPE,
 | 
			
		||||
    HSTRING_TYPE,
 | 
			
		||||
    STRUCT_TYPE,
 | 
			
		||||
    VECTOR_TYPE
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct type_info {
 | 
			
		||||
    enum TYPE_INFO type;
 | 
			
		||||
    void* data;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct value_info {
 | 
			
		||||
    enum TYPE_INFO type;
 | 
			
		||||
    void* value;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct transaction_and_reply {
 | 
			
		||||
    GList* tree_transaction;
 | 
			
		||||
    GList* tree_reply;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
cmdline_parse(
 | 
			
		||||
    App* app);
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
cmdlinelex(
 | 
			
		||||
    void* args);
 | 
			
		||||
 | 
			
		||||
extern struct transaction_and_reply* ast;
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										98
									
								
								test/binder-call/cmdline.l
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								test/binder-call/cmdline.l
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,98 @@
 | 
			
		||||
D              [0-9]
 | 
			
		||||
l              "l"
 | 
			
		||||
L              "L"
 | 
			
		||||
u              "u"
 | 
			
		||||
U              "U"
 | 
			
		||||
h              "h"
 | 
			
		||||
H              "H"
 | 
			
		||||
COLON          ":"
 | 
			
		||||
EIGHT          "8"
 | 
			
		||||
 | 
			
		||||
INT8_SUFFIX    {COLON}{EIGHT}
 | 
			
		||||
INT64_SUFFIX   [lL]
 | 
			
		||||
UTF16_SUFFIX   [uU]
 | 
			
		||||
HSTRING_SUFFIX [hH]
 | 
			
		||||
 | 
			
		||||
%{
 | 
			
		||||
#include <glib.h>
 | 
			
		||||
#include "cmdline.tab.h"
 | 
			
		||||
#include "binder-call.h"
 | 
			
		||||
 | 
			
		||||
#define YY_SKIP_YYWRAP
 | 
			
		||||
int cmdlinewrap(App* app);
 | 
			
		||||
#undef yywrap
 | 
			
		||||
#define yywrap() cmdlinewrap( (App*) args )
 | 
			
		||||
#define YY_DECL int cmdlinelex( void* args )
 | 
			
		||||
 | 
			
		||||
char* handle_str(char* text) {
 | 
			
		||||
    // extract str from "str"X
 | 
			
		||||
    char* str = g_strndup(text + 1, strlen(text) - 3);
 | 
			
		||||
    return str;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char* handle_str8(char* text) {
 | 
			
		||||
    // extract str from "str"
 | 
			
		||||
    char* str = g_strndup(text + 1, strlen(text) - 2);
 | 
			
		||||
    return str;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
%}
 | 
			
		||||
 | 
			
		||||
%option never-interactive noinput nounput
 | 
			
		||||
 | 
			
		||||
%%
 | 
			
		||||
"i8"                                { return(INT8); }
 | 
			
		||||
"i32"                               { return(INT32); }
 | 
			
		||||
"i64"                               { return(INT64); }
 | 
			
		||||
"s8"                                { return(STRING8); }
 | 
			
		||||
"s16"                               { return(STRING16); }
 | 
			
		||||
"float"                             { return(FLOAT); }
 | 
			
		||||
"double"                            { return(DOUBLE); }
 | 
			
		||||
"f"                                 { return(FLOAT); }
 | 
			
		||||
"d"                                 { return(DOUBLE); }
 | 
			
		||||
"hstr"                              { return(HSTRING); }
 | 
			
		||||
"{"                                 { return('{'); }
 | 
			
		||||
"}"                                 { return('}'); }
 | 
			
		||||
"["                                 { return('['); }
 | 
			
		||||
"]"                                 { return(']'); }
 | 
			
		||||
{D}*{INT8_SUFFIX}                   { cmdlinelval.int8_value = atoi(yytext); return(INT8_VALUE); }
 | 
			
		||||
{D}*{INT64_SUFFIX}                  { cmdlinelval.int64_value = atol(yytext); return(INT64_VALUE); }
 | 
			
		||||
{D}*                                { cmdlinelval.int32_value = atoi(yytext); return(INT32_VALUE); }
 | 
			
		||||
{D}+"."{D}*{INT64_SUFFIX}           { cmdlinelval.double_value = atof(yytext); return(DOUBLE_VALUE); }
 | 
			
		||||
{D}+"."{D}*                         { cmdlinelval.float_value = atof(yytext); return(FLOAT_VALUE); }
 | 
			
		||||
"reply"                             { return(REPLY); }
 | 
			
		||||
\".*\"{HSTRING_SUFFIX}              { cmdlinelval.hstring_value = handle_str(yytext); return(HSTRING_VALUE); }
 | 
			
		||||
\".*\"{UTF16_SUFFIX}                { cmdlinelval.string16_value = handle_str(yytext); return(STRING16_VALUE); }
 | 
			
		||||
\".*\"                              { cmdlinelval.string8_value = handle_str8(yytext); return(STRING8_VALUE); }
 | 
			
		||||
" "                                 { /* eat */ }
 | 
			
		||||
.                                   { fprintf(stderr, "Unrecognized character: '%c'\n", yytext[0]); }
 | 
			
		||||
 | 
			
		||||
%%
 | 
			
		||||
 | 
			
		||||
#include "binder-call.h"
 | 
			
		||||
 | 
			
		||||
int cmdlinewrap(App* app)
 | 
			
		||||
{
 | 
			
		||||
    if (YY_CURRENT_BUFFER) {
 | 
			
		||||
        yy_delete_buffer( YY_CURRENT_BUFFER );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (app->rargc == app->opt->argc) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    yy_scan_string(app->opt->argv[app->rargc++]);
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int cmdline_parse(App* app) {
 | 
			
		||||
    if (app->opt->argc > app->rargc) {
 | 
			
		||||
        cmdlinewrap(app);
 | 
			
		||||
    } else {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return cmdlineparse (app);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										399
									
								
								test/binder-call/cmdline.y
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										399
									
								
								test/binder-call/cmdline.y
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,399 @@
 | 
			
		||||
%{
 | 
			
		||||
#include <glib.h>
 | 
			
		||||
#include "binder-call.h"
 | 
			
		||||
 | 
			
		||||
struct transaction_and_reply* make_transaction_and_reply(GList* transaction, GList* reply);
 | 
			
		||||
struct value_info* handle_int8(App* app, int value);
 | 
			
		||||
struct value_info* handle_int32(App* app, int value);
 | 
			
		||||
struct value_info* handle_int64(App* app, long value);
 | 
			
		||||
struct value_info* handle_float(App* app, float value);
 | 
			
		||||
struct value_info* handle_double(App* app, double value);
 | 
			
		||||
struct value_info* handle_string8(App* app, char* value);
 | 
			
		||||
struct value_info* handle_string16(App* app, char* value);
 | 
			
		||||
struct value_info* handle_hstring(App* app, char* value);
 | 
			
		||||
struct value_info* handle_vector(App* app, GList* values);
 | 
			
		||||
struct value_info* handle_struct(App* app, GList* values);
 | 
			
		||||
 | 
			
		||||
void cmdlineerror(App* app, char const* s);
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_int8(App* app);
 | 
			
		||||
struct type_info* handle_type_int32(App* app);
 | 
			
		||||
struct type_info* handle_type_int64(App* app);
 | 
			
		||||
struct type_info* handle_type_float(App* app);
 | 
			
		||||
struct type_info* handle_type_double(App* app);
 | 
			
		||||
struct type_info* handle_type_string8(App* app);
 | 
			
		||||
struct type_info* handle_type_string16(App* app);
 | 
			
		||||
struct type_info* handle_type_hstring(App* app);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_vector(App* app, struct type_info* t);
 | 
			
		||||
struct type_info* handle_type_struct(App* app, GList* l);
 | 
			
		||||
 | 
			
		||||
%}
 | 
			
		||||
 | 
			
		||||
%union {
 | 
			
		||||
    union {
 | 
			
		||||
        int int8_value;
 | 
			
		||||
        int int32_value;
 | 
			
		||||
        long int64_value;
 | 
			
		||||
        float float_value;
 | 
			
		||||
        double double_value;
 | 
			
		||||
        char* string8_value;
 | 
			
		||||
        char* string16_value;
 | 
			
		||||
        char* hstring_value;
 | 
			
		||||
    };
 | 
			
		||||
    struct value_info* value;
 | 
			
		||||
    struct type_info* type;
 | 
			
		||||
    GList* value_list;
 | 
			
		||||
    GList* type_list;
 | 
			
		||||
    GList* struct_type_list;
 | 
			
		||||
    struct transaction_and_reply* trans_and_reply;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
%parse-param { void* args }
 | 
			
		||||
%lex-param { void* args }
 | 
			
		||||
 | 
			
		||||
%token INT8 INT32 INT64 FLOAT DOUBLE STRING8 STRING16 HSTRING
 | 
			
		||||
 | 
			
		||||
%token INT8_VALUE INT32_VALUE INT64_VALUE FLOAT_VALUE DOUBLE_VALUE STRING8_VALUE STRING16_VALUE HSTRING_VALUE
 | 
			
		||||
%type <value> values
 | 
			
		||||
 | 
			
		||||
%type <value> struct_values
 | 
			
		||||
%type <value> vec_values
 | 
			
		||||
%type <value> value_specifiers
 | 
			
		||||
%type <trans_and_reply> translation_unit
 | 
			
		||||
 | 
			
		||||
%type <value_list> values_list
 | 
			
		||||
%type <type_list> specifiers_list
 | 
			
		||||
 | 
			
		||||
%type <type> specifiers
 | 
			
		||||
%type <type> type_specifier
 | 
			
		||||
%type <type> vec_specifier
 | 
			
		||||
%type <type> struct_specifier
 | 
			
		||||
%type <struct_type_list> struct_declaration_list
 | 
			
		||||
 | 
			
		||||
%token REPLY
 | 
			
		||||
 | 
			
		||||
%start translation_unit
 | 
			
		||||
%%
 | 
			
		||||
 | 
			
		||||
type_specifier
 | 
			
		||||
    : INT8 { $$ = handle_type_int8(args); }
 | 
			
		||||
    | INT32 { $$ = handle_type_int32(args); }
 | 
			
		||||
    | INT64 { $$ = handle_type_int64(args); }
 | 
			
		||||
    | STRING8 { $$ = handle_type_string8(args); }
 | 
			
		||||
    | STRING16 { $$ = handle_type_string16(args); }
 | 
			
		||||
    | FLOAT { $$ = handle_type_float(args); }
 | 
			
		||||
    | DOUBLE { $$ = handle_type_double(args); }
 | 
			
		||||
    | HSTRING { $$ = handle_type_hstring(args); }
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
values
 | 
			
		||||
    : INT8_VALUE { $$ = handle_int8(args, cmdlinelval.int8_value); }
 | 
			
		||||
    | INT32_VALUE { $$ = handle_int32(args, cmdlinelval.int32_value); }
 | 
			
		||||
    | INT64_VALUE { $$ = handle_int64(args, cmdlinelval.int64_value); }
 | 
			
		||||
    | STRING8_VALUE { $$ = handle_string8(args, cmdlinelval.string8_value); }
 | 
			
		||||
    | STRING16_VALUE { $$ = handle_string16(args, cmdlinelval.string16_value); }
 | 
			
		||||
    | HSTRING_VALUE { $$ = handle_hstring(args, cmdlinelval.hstring_value); }
 | 
			
		||||
    | FLOAT_VALUE { $$ = handle_float(args, cmdlinelval.float_value); }
 | 
			
		||||
    | DOUBLE_VALUE { $$ = handle_double(args, cmdlinelval.double_value); }
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
struct
 | 
			
		||||
    : '{'
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
struct_end
 | 
			
		||||
    : '}'
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
vec
 | 
			
		||||
    : '['
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
vec_end
 | 
			
		||||
    : ']'
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
struct_specifier
 | 
			
		||||
    : struct struct_declaration_list struct_end { $$ = handle_type_struct(args, $2); }
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
vec_specifier
 | 
			
		||||
    : vec specifiers vec_end { $$ = handle_type_vector(args, $2); }
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
struct_declaration_list
 | 
			
		||||
    : specifiers { $$ = NULL; $$ = g_list_append($$, $1); }
 | 
			
		||||
    | struct_declaration_list specifiers { $$ = g_list_append($$, $2); }
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
specifiers
 | 
			
		||||
    : type_specifier
 | 
			
		||||
    | struct_specifier
 | 
			
		||||
    | vec_specifier
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
specifiers_list
 | 
			
		||||
    : specifiers { $$ = NULL; $$ = g_list_append($$, $1); }
 | 
			
		||||
    | specifiers_list specifiers { $$ = g_list_append($$, $2); }
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
struct_values
 | 
			
		||||
    : struct values_list struct_end { $$ = handle_struct(args, $2); }
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
vec_values
 | 
			
		||||
    : vec values_list vec_end { $$ = handle_vector(args, $2); }
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
value_specifiers
 | 
			
		||||
    : values
 | 
			
		||||
    | struct_values
 | 
			
		||||
    | vec_values
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
values_list
 | 
			
		||||
    : value_specifiers { $$ = NULL;  $$ = g_list_append($$, $1); }
 | 
			
		||||
    | values_list value_specifiers { $$ = g_list_append($$, $2); }
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
reply
 | 
			
		||||
    : REPLY
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
translation_unit
 | 
			
		||||
    : values_list reply specifiers_list { $$ = make_transaction_and_reply($1, $3); ast = $$; }
 | 
			
		||||
    | values_list { $$ = make_transaction_and_reply($1, 0); ast = $$; }
 | 
			
		||||
    | reply specifiers_list { $$ = make_transaction_and_reply(0, $2); ast = $$; }
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
%%
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <glib.h>
 | 
			
		||||
#include <gutil_log.h>
 | 
			
		||||
#include <binder-call.h>
 | 
			
		||||
 | 
			
		||||
extern char yytext[];
 | 
			
		||||
 | 
			
		||||
struct value_info* handle_int8(App* app, int value)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = g_new0(struct value_info, 1);
 | 
			
		||||
 | 
			
		||||
    v->type = INT8_TYPE;
 | 
			
		||||
    v->value = g_new0(unsigned char, 1);
 | 
			
		||||
   * ((unsigned char*)v->value) = value;
 | 
			
		||||
 | 
			
		||||
    return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct value_info* handle_int32(App* app, int value)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = g_new0(struct value_info, 1);
 | 
			
		||||
 | 
			
		||||
    v->type = INT32_TYPE;
 | 
			
		||||
    v->value = g_new0(int, 1);
 | 
			
		||||
   * ((int*)v->value) = value;
 | 
			
		||||
 | 
			
		||||
    return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct value_info* handle_int64(App* app, long value)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = g_new0(struct value_info, 1);
 | 
			
		||||
 | 
			
		||||
    v->type = INT64_TYPE;
 | 
			
		||||
    v->value = g_new0(long, 1);
 | 
			
		||||
   * ((long*)v->value) = value;
 | 
			
		||||
 | 
			
		||||
    return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct value_info* handle_float(App* app, float value)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = g_new0(struct value_info, 1);
 | 
			
		||||
 | 
			
		||||
    v->type = FLOAT_TYPE;
 | 
			
		||||
    v->value = g_new0(float, 1);
 | 
			
		||||
   * ((float*)v->value) = value;
 | 
			
		||||
 | 
			
		||||
    return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct value_info* handle_double(App* app, double value)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = g_new0(struct value_info, 1);
 | 
			
		||||
 | 
			
		||||
    v->type = DOUBLE_TYPE;
 | 
			
		||||
    v->value = g_new0(double, 1);
 | 
			
		||||
   * ((double*)v->value) = value;
 | 
			
		||||
 | 
			
		||||
    return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct value_info* handle_string8(App* app, char* value)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = g_new0(struct value_info, 1);
 | 
			
		||||
 | 
			
		||||
    v->type = STRING8_TYPE;
 | 
			
		||||
    v->value = value;
 | 
			
		||||
 | 
			
		||||
    return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct value_info* handle_string16(App* app, char* value)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = g_new0(struct value_info, 1);
 | 
			
		||||
 | 
			
		||||
    v->type = STRING16_TYPE;
 | 
			
		||||
    v->value = value;
 | 
			
		||||
 | 
			
		||||
    return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct value_info* handle_hstring(App* app, char* value)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = g_new0(struct value_info, 1);
 | 
			
		||||
 | 
			
		||||
    v->type = HSTRING_TYPE;
 | 
			
		||||
    v->value = value;
 | 
			
		||||
 | 
			
		||||
    return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct value_info* handle_vector(App* app, GList* values)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = g_new0(struct value_info, 1);
 | 
			
		||||
 | 
			
		||||
    v->type = VECTOR_TYPE;
 | 
			
		||||
    v->value = values;
 | 
			
		||||
 | 
			
		||||
    return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct value_info* handle_struct(App* app, GList* values)
 | 
			
		||||
{
 | 
			
		||||
    struct value_info* v = g_new0(struct value_info, 1);
 | 
			
		||||
 | 
			
		||||
    v->type = STRUCT_TYPE;
 | 
			
		||||
    v->value = values;
 | 
			
		||||
 | 
			
		||||
    return v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_int8(App* app)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* info = g_new0(struct type_info, 1);
 | 
			
		||||
 | 
			
		||||
    info->type = INT8_TYPE;
 | 
			
		||||
    info->data = 0;
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_int32(App* app)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* info = g_new0(struct type_info, 1);
 | 
			
		||||
 | 
			
		||||
    info->type = INT32_TYPE;
 | 
			
		||||
    info->data = 0;
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_int64(App* app)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* info = g_new0(struct type_info, 1);
 | 
			
		||||
 | 
			
		||||
    info->type = INT64_TYPE;
 | 
			
		||||
    info->data = 0;
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_float(App* app)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* info = g_new0(struct type_info, 1);
 | 
			
		||||
 | 
			
		||||
    info->type = FLOAT_TYPE;
 | 
			
		||||
    info->data = 0;
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_double(App* app)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* info = g_new0(struct type_info, 1);
 | 
			
		||||
 | 
			
		||||
    info->type = DOUBLE_TYPE;
 | 
			
		||||
    info->data = 0;
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_string8(App* app)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* info = g_new0(struct type_info, 1);
 | 
			
		||||
 | 
			
		||||
    info->type = STRING8_TYPE;
 | 
			
		||||
    info->data = 0;
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_string16(App* app)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* info = g_new0(struct type_info, 1);
 | 
			
		||||
 | 
			
		||||
    info->type = STRING16_TYPE;
 | 
			
		||||
    info->data = 0;
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_hstring(App* app)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* info = g_new0(struct type_info, 1);
 | 
			
		||||
 | 
			
		||||
    info->type = HSTRING_TYPE;
 | 
			
		||||
    info->data = 0;
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_vector(App* app, struct type_info* t)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* info = g_new0(struct type_info, 1);
 | 
			
		||||
 | 
			
		||||
    info->type = VECTOR_TYPE;
 | 
			
		||||
    info->data = t;
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct type_info* handle_type_struct(App* app, GList* l)
 | 
			
		||||
{
 | 
			
		||||
    struct type_info* info = g_new0(struct type_info, 1);
 | 
			
		||||
 | 
			
		||||
    info->type = STRUCT_TYPE;
 | 
			
		||||
    info->data = l;
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct transaction_and_reply* make_transaction_and_reply(GList* transaction, GList* reply)
 | 
			
		||||
{
 | 
			
		||||
    struct transaction_and_reply* tar = g_new0(struct transaction_and_reply, 1);
 | 
			
		||||
 | 
			
		||||
    tar->tree_transaction = transaction;
 | 
			
		||||
    tar->tree_reply = reply;
 | 
			
		||||
 | 
			
		||||
    return tar;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void cmdlineerror(App* app, char const* s)
 | 
			
		||||
{
 | 
			
		||||
    fprintf(stderr, "@%d %s: %s\n", app->rargc - 1, s, app->opt->argv[app->rargc - 1]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -41,7 +41,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release
 | 
			
		||||
# Tools and flags
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
CC = $(CROSS_COMPILE)gcc
 | 
			
		||||
CC ?= $(CROSS_COMPILE)gcc
 | 
			
		||||
LD = $(CC)
 | 
			
		||||
WARNINGS = -Wall
 | 
			
		||||
INCLUDES = -I$(LIB_DIR)/include
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release
 | 
			
		||||
# Tools and flags
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
CC = $(CROSS_COMPILE)gcc
 | 
			
		||||
CC ?= $(CROSS_COMPILE)gcc
 | 
			
		||||
LD = $(CC)
 | 
			
		||||
WARNINGS = -Wall
 | 
			
		||||
INCLUDES = -I$(LIB_DIR)/include
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release
 | 
			
		||||
# Tools and flags
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
CC = $(CROSS_COMPILE)gcc
 | 
			
		||||
CC ?= $(CROSS_COMPILE)gcc
 | 
			
		||||
LD = $(CC)
 | 
			
		||||
WARNINGS = -Wall
 | 
			
		||||
INCLUDES = -I$(LIB_DIR)/include
 | 
			
		||||
@@ -138,3 +138,17 @@ libgbinder-debug:
 | 
			
		||||
 | 
			
		||||
libgbinder-release:
 | 
			
		||||
	@make $(SUBMAKE_OPTS) -C $(LIB_DIR) $(RELEASE_SO_FILE) $(RELEASE_LINK_FILE)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Install
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
INSTALL = install
 | 
			
		||||
 | 
			
		||||
INSTALL_BIN_DIR = $(DESTDIR)/usr/bin
 | 
			
		||||
 | 
			
		||||
install: release $(INSTALL_BIN_DIR)
 | 
			
		||||
	$(INSTALL) -m 755 $(RELEASE_EXE) $(INSTALL_BIN_DIR)
 | 
			
		||||
 | 
			
		||||
$(INSTALL_BIN_DIR):
 | 
			
		||||
	$(INSTALL) -d $@
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 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:
 | 
			
		||||
 *
 | 
			
		||||
@@ -39,7 +39,7 @@
 | 
			
		||||
#define RET_INVARG      (2)
 | 
			
		||||
#define RET_ERR         (3)
 | 
			
		||||
 | 
			
		||||
#define DEV_DEFAULT     "/dev/binder"
 | 
			
		||||
#define DEV_DEFAULT     GBINDER_DEFAULT_HWBINDER
 | 
			
		||||
 | 
			
		||||
typedef struct app_options {
 | 
			
		||||
    char* dev;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										154
									
								
								test/binder-ping/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										154
									
								
								test/binder-ping/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,154 @@
 | 
			
		||||
# -*- 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)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Install
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
INSTALL = install
 | 
			
		||||
 | 
			
		||||
INSTALL_BIN_DIR = $(DESTDIR)/usr/bin
 | 
			
		||||
 | 
			
		||||
install: release $(INSTALL_BIN_DIR)
 | 
			
		||||
	$(INSTALL) -m 755 $(RELEASE_EXE) $(INSTALL_BIN_DIR)
 | 
			
		||||
 | 
			
		||||
$(INSTALL_BIN_DIR):
 | 
			
		||||
	$(INSTALL) -d $@
 | 
			
		||||
							
								
								
									
										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:
 | 
			
		||||
 */
 | 
			
		||||
@@ -41,7 +41,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release
 | 
			
		||||
# Tools and flags
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
CC = $(CROSS_COMPILE)gcc
 | 
			
		||||
CC ?= $(CROSS_COMPILE)gcc
 | 
			
		||||
LD = $(CC)
 | 
			
		||||
WARNINGS = -Wall
 | 
			
		||||
INCLUDES = -I$(LIB_DIR)/include
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release
 | 
			
		||||
# Tools and flags
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
CC = $(CROSS_COMPILE)gcc
 | 
			
		||||
CC ?= $(CROSS_COMPILE)gcc
 | 
			
		||||
LD = $(CC)
 | 
			
		||||
WARNINGS = -Wall
 | 
			
		||||
INCLUDES = -I$(LIB_DIR)/include
 | 
			
		||||
 
 | 
			
		||||
@@ -2,20 +2,28 @@
 | 
			
		||||
 | 
			
		||||
all:
 | 
			
		||||
%:
 | 
			
		||||
	@$(MAKE) -C unit_bridge $*
 | 
			
		||||
	@$(MAKE) -C unit_buffer $*
 | 
			
		||||
	@$(MAKE) -C unit_cleanup $*
 | 
			
		||||
	@$(MAKE) -C unit_client $*
 | 
			
		||||
	@$(MAKE) -C unit_config $*
 | 
			
		||||
	@$(MAKE) -C unit_driver $*
 | 
			
		||||
	@$(MAKE) -C unit_eventloop $*
 | 
			
		||||
	@$(MAKE) -C unit_ipc $*
 | 
			
		||||
	@$(MAKE) -C unit_local_object $*
 | 
			
		||||
	@$(MAKE) -C unit_local_reply $*
 | 
			
		||||
	@$(MAKE) -C unit_local_request $*
 | 
			
		||||
	@$(MAKE) -C unit_log $*
 | 
			
		||||
	@$(MAKE) -C unit_protocol $*
 | 
			
		||||
	@$(MAKE) -C unit_proxy_object $*
 | 
			
		||||
	@$(MAKE) -C unit_reader $*
 | 
			
		||||
	@$(MAKE) -C unit_remote_object $*
 | 
			
		||||
	@$(MAKE) -C unit_remote_reply $*
 | 
			
		||||
	@$(MAKE) -C unit_remote_request $*
 | 
			
		||||
	@$(MAKE) -C unit_servicemanager $*
 | 
			
		||||
	@$(MAKE) -C unit_servicemanager_aidl $*
 | 
			
		||||
	@$(MAKE) -C unit_servicemanager_aidl2 $*
 | 
			
		||||
	@$(MAKE) -C unit_servicemanager_hidl $*
 | 
			
		||||
	@$(MAKE) -C unit_servicename $*
 | 
			
		||||
	@$(MAKE) -C unit_servicepoll $*
 | 
			
		||||
	@$(MAKE) -C unit_writer $*
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,31 @@ COMMON_SRC ?= test_binder.c test_main.c
 | 
			
		||||
# Required packages
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
PKGS += libglibutil glib-2.0 gobject-2.0
 | 
			
		||||
PKGS += glib-2.0 gobject-2.0
 | 
			
		||||
 | 
			
		||||
ifeq ($(LIBGLIBUTIL_PATH),)
 | 
			
		||||
 | 
			
		||||
# Assume that libglibutil devel package is installed
 | 
			
		||||
PKGS += libglibutil
 | 
			
		||||
 | 
			
		||||
else
 | 
			
		||||
 | 
			
		||||
# Side-by-side build
 | 
			
		||||
INCLUDES += -I$(LIBGLIBUTIL_PATH)/include
 | 
			
		||||
DEBUG_LIBS = -L$(LIBGLIBUTIL_PATH)/build/debug -lglibutil
 | 
			
		||||
RELEASE_LIBS = -L$(LIBGLIBUTIL_PATH)/build/release -lglibutil
 | 
			
		||||
DEBUG_DEPS = libglibutil_debug
 | 
			
		||||
RELEASE_DEPS = libglibutil_release
 | 
			
		||||
 | 
			
		||||
.PHONY: libglibutil_debug libglibutil_release
 | 
			
		||||
 | 
			
		||||
libglibutil_debug:
 | 
			
		||||
	make -C $(LIBGLIBUTIL_PATH) debug
 | 
			
		||||
 | 
			
		||||
libglibutil_release:
 | 
			
		||||
	make -C $(LIBGLIBUTIL_PATH) release
 | 
			
		||||
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Default target
 | 
			
		||||
@@ -42,9 +66,9 @@ COVERAGE_BUILD_DIR = $(BUILD_DIR)/coverage
 | 
			
		||||
# Tools and flags
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
CC = $(CROSS_COMPILE)gcc
 | 
			
		||||
CC ?= $(CROSS_COMPILE)gcc
 | 
			
		||||
LD = $(CC)
 | 
			
		||||
WARNINGS += -Wall
 | 
			
		||||
WARNINGS += -Wall -Wno-deprecated-declarations
 | 
			
		||||
INCLUDES += -I$(COMMON_DIR) -I$(LIB_DIR)/src -I$(LIB_DIR)/include
 | 
			
		||||
BASE_FLAGS = -fPIC
 | 
			
		||||
BASE_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS)
 | 
			
		||||
@@ -52,7 +76,7 @@ BASE_CFLAGS = $(BASE_FLAGS) $(CFLAGS)
 | 
			
		||||
FULL_CFLAGS = $(BASE_CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \
 | 
			
		||||
  $(shell pkg-config --cflags $(PKGS))
 | 
			
		||||
FULL_LDFLAGS = $(BASE_LDFLAGS)
 | 
			
		||||
LIBS = $(shell pkg-config --libs $(PKGS))
 | 
			
		||||
LIBS = $(shell pkg-config --libs $(PKGS)) -lpthread
 | 
			
		||||
QUIET_MAKE = make --no-print-directory
 | 
			
		||||
DEBUG_FLAGS = -g
 | 
			
		||||
RELEASE_FLAGS =
 | 
			
		||||
@@ -74,9 +98,9 @@ DEBUG_LIB = $(LIB_DIR)/$(DEBUG_LIB_FILE)
 | 
			
		||||
RELEASE_LIB = $(LIB_DIR)/$(RELEASE_LIB_FILE)
 | 
			
		||||
COVERAGE_LIB = $(LIB_DIR)/$(COVERAGE_LIB_FILE)
 | 
			
		||||
 | 
			
		||||
DEBUG_LIBS = $(DEBUG_LIB) $(LIBS)
 | 
			
		||||
RELEASE_LIBS = $(RELEASE_LIB) $(LIBS)
 | 
			
		||||
COVERAGE_LIBS = $(COVERAGE_LIB) $(LIBS)
 | 
			
		||||
DEBUG_LIBS += $(DEBUG_LIB) $(LIBS)
 | 
			
		||||
RELEASE_LIBS += $(RELEASE_LIB) $(LIBS)
 | 
			
		||||
COVERAGE_LIBS += $(COVERAGE_LIB) $(LIBS)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Files
 | 
			
		||||
@@ -107,8 +131,8 @@ $(DEBUG_LIB): | debug_lib
 | 
			
		||||
$(RELEASE_LIB): | release_lib
 | 
			
		||||
$(COVERAGE_LIB): | coverage_lib
 | 
			
		||||
 | 
			
		||||
$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
 | 
			
		||||
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
 | 
			
		||||
$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR) $(DEBUG_DEPS)
 | 
			
		||||
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR) $(RELEASE_DEPS)
 | 
			
		||||
$(COVERAGE_OBJS): | $(COVERAGE_BUILD_DIR)
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
@@ -138,10 +162,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 $@
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018-2019 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -35,6 +35,8 @@
 | 
			
		||||
 | 
			
		||||
#include "test_common.h"
 | 
			
		||||
 | 
			
		||||
typedef struct test_binder TestBinder;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_br_noop(
 | 
			
		||||
    int fd);
 | 
			
		||||
@@ -111,10 +113,44 @@ test_binder_br_reply_status_later(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gint32 status);
 | 
			
		||||
 | 
			
		||||
typedef enum test_looper {
 | 
			
		||||
    TEST_LOOPER_DISABLE,
 | 
			
		||||
    TEST_LOOPER_ENABLE,
 | 
			
		||||
    TEST_LOOPER_ENABLE_ONE
 | 
			
		||||
} TEST_LOOPER;
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_set_looper_enabled(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gboolean enabled);
 | 
			
		||||
    TEST_LOOPER value);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_set_passthrough(
 | 
			
		||||
    int fd,
 | 
			
		||||
    gboolean passthrough);
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
test_binder_handle(
 | 
			
		||||
    int fd,
 | 
			
		||||
    GBinderLocalObject* obj);
 | 
			
		||||
 | 
			
		||||
GBinderLocalObject*
 | 
			
		||||
test_binder_object(
 | 
			
		||||
    int fd,
 | 
			
		||||
    guint handle)
 | 
			
		||||
    G_GNUC_WARN_UNUSED_RESULT; /* Need to unref */
 | 
			
		||||
 | 
			
		||||
guint
 | 
			
		||||
test_binder_register_object(
 | 
			
		||||
    int fd,
 | 
			
		||||
    GBinderLocalObject* obj,
 | 
			
		||||
    guint handle);
 | 
			
		||||
 | 
			
		||||
#define AUTO_HANDLE ((guint)-1)
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_unregister_objects(
 | 
			
		||||
    int fd);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_set_destroy(
 | 
			
		||||
@@ -122,6 +158,11 @@ test_binder_set_destroy(
 | 
			
		||||
    gpointer ptr,
 | 
			
		||||
    GDestroyNotify destroy);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
test_binder_exit_wait(
 | 
			
		||||
    const TestOpt* opt,
 | 
			
		||||
    GMainLoop* loop);
 | 
			
		||||
 | 
			
		||||
#endif /* TEST_BINDER_H */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2018 Jolla Ltd.
 | 
			
		||||
 * Contact: Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 * Copyright (C) 2018-2021 Jolla Ltd.
 | 
			
		||||
 * Copyright (C) 2018-2021 Slava Monich <slava.monich@jolla.com>
 | 
			
		||||
 *
 | 
			
		||||
 * You may use this file under the terms of BSD license as follows:
 | 
			
		||||
 *
 | 
			
		||||
@@ -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,23 @@ void
 | 
			
		||||
test_quit_later(
 | 
			
		||||
    GMainLoop* loop);
 | 
			
		||||
 | 
			
		||||
/* Quits the event loop after n iterations */
 | 
			
		||||
void
 | 
			
		||||
test_quit_later_n(
 | 
			
		||||
    GMainLoop* loop,
 | 
			
		||||
    guint n);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Makes sure that we own the context for the entire duration of the test.
 | 
			
		||||
 * That prevents many race conditions - all callbacks that are supposed to
 | 
			
		||||
 * be invoked on the main thread, are actually invoked on the main thread
 | 
			
		||||
 * (rather than a random worker thread which happens to acquire the context).
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
test_run_in_context(
 | 
			
		||||
    const TestOpt* opt,
 | 
			
		||||
    GTestFunc func);
 | 
			
		||||
 | 
			
		||||
#define TEST_TIMEOUT_SEC (20)
 | 
			
		||||
 | 
			
		||||
/* Helper macros */
 | 
			
		||||
 
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user