Compare commits
145 Commits
upgrade-3.
...
1.0.45
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82ea37ead9 | ||
|
|
882ef93084 | ||
|
|
881469ab7f | ||
|
|
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 | ||
|
|
141bda151b | ||
|
|
e952380ce6 | ||
|
|
721f5dc469 | ||
|
|
434b17eefe | ||
|
|
af6a1c84ef | ||
|
|
a0ce447a1f | ||
|
|
f24145f407 | ||
|
|
11c173b2e4 | ||
|
|
aff816d10c | ||
|
|
e1acaa3bdb | ||
|
|
c63743ac51 | ||
|
|
6832d9bf46 | ||
|
|
4c3ccbc06f | ||
|
|
f82596c372 | ||
|
|
4921a6ab8d | ||
|
|
ef9c242a59 | ||
|
|
a83c9937a5 | ||
|
|
cfa3ad4d9e | ||
|
|
ffc9638ebb | ||
|
|
000534654d | ||
|
|
68e9358d02 | ||
|
|
37e3859f8f | ||
|
|
e79b940b0d | ||
|
|
d8dfe3f289 | ||
|
|
394c286ee5 | ||
|
|
307bd6942c | ||
|
|
148b53e862 | ||
|
|
5c8cb0a013 | ||
|
|
4d644e0584 | ||
|
|
dce9c8b3d1 | ||
|
|
b117ee6404 | ||
|
|
c3f783bf7e | ||
|
|
4c65a6eded | ||
|
|
c382cab922 | ||
|
|
199fd4ed61 | ||
|
|
f86d62fbf8 | ||
|
|
3ea82dc384 | ||
|
|
03ae5834ee | ||
|
|
e39b5c20ee | ||
|
|
d6e131eb6e | ||
|
|
1c36b5f142 | ||
|
|
827bd0b59f | ||
|
|
2dab057652 | ||
|
|
488fbc5b63 | ||
|
|
17f511d7a3 | ||
|
|
63e633c0ec | ||
|
|
f46448c236 | ||
|
|
43023be32d | ||
|
|
4811d51c5d | ||
|
|
821dabca3d | ||
|
|
587f4ebb50 | ||
|
|
0c0b25fcd1 | ||
|
|
bdf07d04d4 | ||
|
|
6936675eb9 | ||
|
|
c39bf4b802 | ||
|
|
5a43b1b091 | ||
|
|
3e039e033c | ||
|
|
6a2af83ea3 | ||
|
|
5a12df240b | ||
|
|
2ea7d91fc7 | ||
|
|
d9903e7398 | ||
|
|
39b69f27ee | ||
|
|
31a1d19b4e | ||
|
|
f4a923c3dc | ||
|
|
171ff7d1e4 | ||
|
|
5cfbf22b81 | ||
|
|
5a35ed5ea1 | ||
|
|
1978359f15 | ||
|
|
fef6543f1a | ||
|
|
b1a9200803 | ||
|
|
fada30868a | ||
|
|
8414e9485f | ||
|
|
f6d8d485bc | ||
|
|
6ea0d6c631 | ||
|
|
31c6c05c1e | ||
|
|
d855d695db | ||
|
|
922cc82029 | ||
|
|
80498378f2 | ||
|
|
51856865df | ||
|
|
d26dcca37e | ||
|
|
5ac02fcb2e | ||
|
|
110cd65779 |
10
.gitignore
vendored
10
.gitignore
vendored
@@ -1,13 +1,11 @@
|
|||||||
*~
|
*~
|
||||||
debian/files
|
debian/files
|
||||||
debian/libgbinder-dev.debhelper.log
|
|
||||||
debian/libgbinder-dev.substvars
|
|
||||||
debian/libgbinder-dev
|
debian/libgbinder-dev
|
||||||
debian/libgbinder.debhelper.log
|
|
||||||
debian/libgbinder.postinst.debhelper
|
|
||||||
debian/libgbinder.postrm.debhelper
|
|
||||||
debian/libgbinder.substvars
|
|
||||||
debian/libgbinder
|
debian/libgbinder
|
||||||
|
debian/*.debhelper.log
|
||||||
|
debian/*.debhelper
|
||||||
|
debian/*.substvars
|
||||||
|
debian/*.install
|
||||||
debian/tmp
|
debian/tmp
|
||||||
documentation.list
|
documentation.list
|
||||||
installroot
|
installroot
|
||||||
|
|||||||
1
AUTHORS
1
AUTHORS
@@ -2,3 +2,4 @@ Slava Monich <slava.monich@jolla.com>
|
|||||||
Matti Lehtimäki <matti.lehtimaki@gmail.com>
|
Matti Lehtimäki <matti.lehtimaki@gmail.com>
|
||||||
Franz-Josef Haider <franz.haider@jolla.com>
|
Franz-Josef Haider <franz.haider@jolla.com>
|
||||||
Juho Hämäläinen <juho.hamalainen@jolla.com>
|
Juho Hämäläinen <juho.hamalainen@jolla.com>
|
||||||
|
Andrew Branson <andrew.branson@jolla.com>
|
||||||
|
|||||||
10
LICENSE
10
LICENSE
@@ -1,5 +1,5 @@
|
|||||||
Copyright (C) 2018 Jolla Ltd.
|
Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
|
|
||||||
You may use this file under the terms of BSD license as follows:
|
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
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
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 name of Jolla Ltd nor the names of its contributors may
|
3. Neither the names of the copyright holders nor the names of its
|
||||||
be used to endorse or promote products derived from this software
|
contributors may be used to endorse or promote products derived
|
||||||
without specific prior written permission.
|
from this software without specific prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
|||||||
110
Makefile
110
Makefile
@@ -1,16 +1,25 @@
|
|||||||
# -*- Mode: makefile-gmake -*-
|
# -*- 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: clean all debug release test
|
||||||
.PHONY: print_debug_so print_release_so
|
.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_link print_release_link
|
||||||
.PHONY: print_debug_path print_release_path
|
.PHONY: print_debug_path print_release_path
|
||||||
|
|
||||||
#
|
#
|
||||||
# Required packages
|
# Library version
|
||||||
#
|
#
|
||||||
|
|
||||||
PKGS = libglibutil glib-2.0 gobject-2.0
|
VERSION_MAJOR = 1
|
||||||
|
VERSION_MINOR = 0
|
||||||
|
VERSION_RELEASE = 45
|
||||||
|
|
||||||
|
# Version for pkg-config
|
||||||
|
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Default target
|
# Default target
|
||||||
@@ -19,15 +28,34 @@ PKGS = libglibutil glib-2.0 gobject-2.0
|
|||||||
all: debug release pkgconfig
|
all: debug release pkgconfig
|
||||||
|
|
||||||
#
|
#
|
||||||
# Library version
|
# Required packages
|
||||||
#
|
#
|
||||||
|
|
||||||
VERSION_MAJOR = 1
|
PKGS = glib-2.0 gobject-2.0
|
||||||
VERSION_MINOR = 0
|
|
||||||
VERSION_RELEASE = 12
|
|
||||||
|
|
||||||
# Version for pkg-config
|
ifeq ($(LIBGLIBUTIL_PATH),)
|
||||||
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
|
|
||||||
|
# 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
|
# Library name
|
||||||
@@ -51,17 +79,21 @@ SRC = \
|
|||||||
gbinder_cleanup.c \
|
gbinder_cleanup.c \
|
||||||
gbinder_client.c \
|
gbinder_client.c \
|
||||||
gbinder_driver.c \
|
gbinder_driver.c \
|
||||||
|
gbinder_eventloop.c \
|
||||||
gbinder_io_32.c \
|
gbinder_io_32.c \
|
||||||
gbinder_io_64.c \
|
gbinder_io_64.c \
|
||||||
gbinder_ipc.c \
|
gbinder_ipc.c \
|
||||||
gbinder_local_object.c \
|
gbinder_local_object.c \
|
||||||
gbinder_local_reply.c \
|
gbinder_local_reply.c \
|
||||||
gbinder_local_request.c \
|
gbinder_local_request.c \
|
||||||
|
gbinder_log.c \
|
||||||
gbinder_reader.c \
|
gbinder_reader.c \
|
||||||
gbinder_remote_object.c \
|
gbinder_remote_object.c \
|
||||||
gbinder_remote_reply.c \
|
gbinder_remote_reply.c \
|
||||||
gbinder_remote_request.c \
|
gbinder_remote_request.c \
|
||||||
gbinder_rpc_protocol.c \
|
gbinder_rpc_protocol.c \
|
||||||
|
gbinder_servicename.c \
|
||||||
|
gbinder_servicepoll.c \
|
||||||
gbinder_writer.c
|
gbinder_writer.c
|
||||||
|
|
||||||
SRC += \
|
SRC += \
|
||||||
@@ -87,10 +119,11 @@ COVERAGE_BUILD_DIR = $(BUILD_DIR)/coverage
|
|||||||
# Tools and flags
|
# Tools and flags
|
||||||
#
|
#
|
||||||
|
|
||||||
CC = $(CROSS_COMPILE)gcc
|
CC ?= $(CROSS_COMPILE)gcc
|
||||||
|
STRIP ?= strip
|
||||||
LD = $(CC)
|
LD = $(CC)
|
||||||
WARNINGS = -Wall -Wstrict-aliasing -Wunused-result
|
WARNINGS = -Wall -Wstrict-aliasing -Wunused-result
|
||||||
INCLUDES = -I$(INCLUDE_DIR)
|
INCLUDES += -I$(INCLUDE_DIR)
|
||||||
BASE_FLAGS = -fPIC
|
BASE_FLAGS = -fPIC
|
||||||
FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
|
FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
|
||||||
-MMD -MP $(shell pkg-config --cflags $(PKGS))
|
-MMD -MP $(shell pkg-config --cflags $(PKGS))
|
||||||
@@ -100,16 +133,13 @@ DEBUG_FLAGS = -g
|
|||||||
RELEASE_FLAGS =
|
RELEASE_FLAGS =
|
||||||
COVERAGE_FLAGS = -g
|
COVERAGE_FLAGS = -g
|
||||||
|
|
||||||
ifndef KEEP_SYMBOLS
|
KEEP_SYMBOLS ?= 0
|
||||||
KEEP_SYMBOLS = 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq ($(KEEP_SYMBOLS),0)
|
ifneq ($(KEEP_SYMBOLS),0)
|
||||||
RELEASE_FLAGS += -g
|
RELEASE_FLAGS += -g
|
||||||
endif
|
endif
|
||||||
|
|
||||||
DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_FLAGS)
|
DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_LIBS) $(DEBUG_FLAGS)
|
||||||
RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS)
|
RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_LIBS) $(RELEASE_FLAGS)
|
||||||
DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG
|
DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG
|
||||||
RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2
|
RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2
|
||||||
COVERAGE_CFLAGS = $(FULL_CFLAGS) $(COVERAGE_FLAGS) --coverage
|
COVERAGE_CFLAGS = $(FULL_CFLAGS) $(COVERAGE_FLAGS) --coverage
|
||||||
@@ -135,8 +165,8 @@ endif
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
$(PKGCONFIG): | $(BUILD_DIR)
|
$(PKGCONFIG): | $(BUILD_DIR)
|
||||||
$(DEBUG_OBJS) $(DEBUG_SO): | $(DEBUG_BUILD_DIR)
|
$(DEBUG_OBJS) $(DEBUG_SO): | $(DEBUG_BUILD_DIR) $(DEBUG_DEPS)
|
||||||
$(RELEASE_OBJS) $(RELEASE_SO): | $(RELEASE_BUILD_DIR)
|
$(RELEASE_OBJS) $(RELEASE_SO): | $(RELEASE_BUILD_DIR) $(RELEASE_DEPS)
|
||||||
$(COVERAGE_OBJS) $(COVERAGE_LIB): | $(COVERAGE_BUILD_DIR)
|
$(COVERAGE_OBJS) $(COVERAGE_LIB): | $(COVERAGE_BUILD_DIR)
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -147,13 +177,15 @@ DEBUG_SO = $(DEBUG_BUILD_DIR)/$(LIB_SO)
|
|||||||
RELEASE_SO = $(RELEASE_BUILD_DIR)/$(LIB_SO)
|
RELEASE_SO = $(RELEASE_BUILD_DIR)/$(LIB_SO)
|
||||||
DEBUG_LINK = $(DEBUG_BUILD_DIR)/$(LIB_SYMLINK1)
|
DEBUG_LINK = $(DEBUG_BUILD_DIR)/$(LIB_SYMLINK1)
|
||||||
RELEASE_LINK = $(RELEASE_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)
|
DEBUG_LIB = $(DEBUG_BUILD_DIR)/$(LIB)
|
||||||
RELEASE_LIB = $(RELEASE_BUILD_DIR)/$(LIB)
|
RELEASE_LIB = $(RELEASE_BUILD_DIR)/$(LIB)
|
||||||
COVERAGE_LIB = $(COVERAGE_BUILD_DIR)/$(LIB)
|
COVERAGE_LIB = $(COVERAGE_BUILD_DIR)/$(LIB)
|
||||||
|
|
||||||
debug: $(DEBUG_SO)
|
debug: $(DEBUG_SO) $(DEBUG_LINK) $(DEBUG_DEV_LINK)
|
||||||
|
|
||||||
release: $(RELEASE_SO)
|
release: $(RELEASE_SO) $(RELEASE_LINK) $(RELEASE_DEV_LINK)
|
||||||
|
|
||||||
debug_lib: $(DEBUG_LIB)
|
debug_lib: $(DEBUG_LIB)
|
||||||
|
|
||||||
@@ -199,6 +231,7 @@ clean:
|
|||||||
rm -fr debian/tmp debian/libgbinder debian/libgbinder-dev
|
rm -fr debian/tmp debian/libgbinder debian/libgbinder-dev
|
||||||
rm -f documentation.list debian/files debian/*.substvars
|
rm -f documentation.list debian/files debian/*.substvars
|
||||||
rm -f debian/*.debhelper.log debian/*.debhelper debian/*~
|
rm -f debian/*.debhelper.log debian/*.debhelper debian/*~
|
||||||
|
rm -f debian/*.install
|
||||||
|
|
||||||
test:
|
test:
|
||||||
make -C unit test
|
make -C unit test
|
||||||
@@ -226,13 +259,11 @@ $(COVERAGE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
|
|||||||
|
|
||||||
$(DEBUG_SO): $(DEBUG_OBJS)
|
$(DEBUG_SO): $(DEBUG_OBJS)
|
||||||
$(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) -o $@
|
$(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) -o $@
|
||||||
ln -sf $(LIB_SO) $(DEBUG_LINK)
|
|
||||||
|
|
||||||
$(RELEASE_SO): $(RELEASE_OBJS)
|
$(RELEASE_SO): $(RELEASE_OBJS)
|
||||||
$(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) -o $@
|
$(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) -o $@
|
||||||
ln -sf $(LIB_SO) $(RELEASE_LINK)
|
|
||||||
ifeq ($(KEEP_SYMBOLS),0)
|
ifeq ($(KEEP_SYMBOLS),0)
|
||||||
strip $@
|
$(STRIP) $@
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(DEBUG_LIB): $(DEBUG_OBJS)
|
$(DEBUG_LIB): $(DEBUG_OBJS)
|
||||||
@@ -243,12 +274,35 @@ $(RELEASE_LIB): $(RELEASE_OBJS)
|
|||||||
$(AR) rc $@ $?
|
$(AR) rc $@ $?
|
||||||
ranlib $@
|
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)
|
$(COVERAGE_LIB): $(COVERAGE_OBJS)
|
||||||
$(AR) rc $@ $?
|
$(AR) rc $@ $?
|
||||||
ranlib $@
|
ranlib $@
|
||||||
|
|
||||||
$(PKGCONFIG): $(LIB_NAME).pc.in
|
#
|
||||||
sed -e 's/\[version\]/'$(PCVERSION)/g $< > $@
|
# 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' -e 's|@libdir@|$(ABS_LIBDIR)|g' $< > $@
|
||||||
|
|
||||||
|
debian/%.install: debian/%.install.in
|
||||||
|
sed 's|@LIBDIR@|$(LIBDIR)|g' $< > $@
|
||||||
|
|
||||||
#
|
#
|
||||||
# Install
|
# Install
|
||||||
@@ -260,9 +314,9 @@ INSTALL = install
|
|||||||
INSTALL_DIRS = $(INSTALL) -d
|
INSTALL_DIRS = $(INSTALL) -d
|
||||||
INSTALL_FILES = $(INSTALL) -m $(INSTALL_PERM)
|
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_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: $(INSTALL_LIB_DIR)
|
||||||
$(INSTALL_FILES) $(RELEASE_SO) $(INSTALL_LIB_DIR)
|
$(INSTALL_FILES) $(RELEASE_SO) $(INSTALL_LIB_DIR)
|
||||||
|
|||||||
215
debian/changelog
vendored
215
debian/changelog
vendored
@@ -1,3 +1,218 @@
|
|||||||
|
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()
|
||||||
|
* Added gbinder_remote_object_ipc()
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Wed, 20 Feb 2019 11:59:08 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.29) unstable; urgency=low
|
||||||
|
|
||||||
|
* Added gbinder_servicemanager_new_local_object2()
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Thu, 14 Feb 2019 18:17:53 +0300
|
||||||
|
|
||||||
|
libgbinder (1.0.28) unstable; urgency=low
|
||||||
|
|
||||||
|
* Set type for local nulls to BINDER_TYPE_WEAK_BINDER
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Tue, 29 Jan 2019 02:49:10 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.27) unstable; urgency=low
|
||||||
|
|
||||||
|
* Fixed outgoing oneway transactions
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Thu, 24 Jan 2019 18:55:16 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.26) unstable; urgency=low
|
||||||
|
|
||||||
|
* Implement PING and INTERFACE transactions
|
||||||
|
* Add GBinderServiceName API
|
||||||
|
* Added gbinder_reader_read_string16_utf16()
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Wed, 23 Jan 2019 17:43:41 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.25) unstable; urgency=low
|
||||||
|
|
||||||
|
* Added ServiceManager presence API
|
||||||
|
|
||||||
|
gbinder_servicemanager_wait()
|
||||||
|
gbinder_servicemanager_is_present()
|
||||||
|
gbinder_servicemanager_add_presence_handler()
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Tue, 22 Jan 2019 16:03:57 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.24) unstable; urgency=low
|
||||||
|
|
||||||
|
* Revert "Make sure NULL objects are passed as BINDER_TYPE_WEAK_HANDLE"
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Fri, 18 Jan 2019 21:36:32 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.23) unstable; urgency=low
|
||||||
|
|
||||||
|
* Added gbinder_reader_read_hidl_string_c()
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Tue, 15 Jan 2019 15:16:41 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.22) unstable; urgency=low
|
||||||
|
|
||||||
|
* Added gbinder_client_interface()
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Thu, 10 Jan 2019 14:09:44 +0300
|
||||||
|
|
||||||
|
libgbinder (1.0.21) unstable; urgency=low
|
||||||
|
|
||||||
|
* Added API to overwrite prefix length
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Tue, 18 Dec 2018 14:05:14 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.20) unstable; urgency=low
|
||||||
|
|
||||||
|
* Added API to block incoming requests
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Mon, 17 Dec 2018 16:06:43 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.19) unstable; urgency=low
|
||||||
|
|
||||||
|
* Added GBinderWriter memory allocation and cleanup API
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Fri, 14 Dec 2018 16:27:51 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.18) unstable; urgency=low
|
||||||
|
|
||||||
|
* Implemented support for file descritors
|
||||||
|
* Allow GBinderClient without RPC header
|
||||||
|
* Added binder-dump test
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Mon, 10 Dec 2018 13:17:22 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.17) unstable; urgency=low
|
||||||
|
|
||||||
|
* Added gbinder_writer_append_string16_utf16()
|
||||||
|
* Added gbinder_reader_read_nullable_string16_utf16()
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Fri, 07 Dec 2018 02:54:07 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.16) unstable; urgency=low
|
||||||
|
|
||||||
|
* Added GBinderHidlVec and GBinderHidlString types
|
||||||
|
* Added gbinder_reader_copy()
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Thu, 06 Dec 2018 19:03:32 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.15) unstable; urgency=low
|
||||||
|
|
||||||
|
* Implemented service polling for old servicemanager
|
||||||
|
* Added new tests and improved coverage for existing ones
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Wed, 05 Dec 2018 12:11:34 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.14) unstable; urgency=low
|
||||||
|
|
||||||
|
* Changed bool padding from 0xff to 0x00
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Tue, 27 Nov 2018 17:20:18 +0200
|
||||||
|
|
||||||
|
libgbinder (1.0.13) unstable; urgency=low
|
||||||
|
|
||||||
|
* Support for service registration notifications
|
||||||
|
* Make sure looper is started before gbinder_ipc_looper_new() returns
|
||||||
|
|
||||||
|
-- Slava Monich <slava.monich@jolla.com> Sat, 17 Nov 2018 01:52:28 +0200
|
||||||
|
|
||||||
libgbinder (1.0.12) unstable; urgency=low
|
libgbinder (1.0.12) unstable; urgency=low
|
||||||
|
|
||||||
* Add byte array reader and writer
|
* Add byte array reader and writer
|
||||||
|
|||||||
4
debian/control
vendored
4
debian/control
vendored
@@ -2,13 +2,13 @@ Source: libgbinder
|
|||||||
Section: libs
|
Section: libs
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Maintainer: Slava Monich <slava.monich@jolla.com>
|
Maintainer: Slava Monich <slava.monich@jolla.com>
|
||||||
Build-Depends: debhelper (>= 7), libglib2.0-dev (>= 2.0), libglibutil (>= 1.0.29)
|
Build-Depends: debhelper (>= 8.1.3), libglib2.0-dev (>= 2.0), libglibutil (>= 1.0.35)
|
||||||
Standards-Version: 3.8.4
|
Standards-Version: 3.8.4
|
||||||
|
|
||||||
Package: libgbinder
|
Package: libgbinder
|
||||||
Section: libs
|
Section: libs
|
||||||
Architecture: any
|
Architecture: any
|
||||||
Depends: libglibutil (>= 1.0.29), ${shlibs:Depends}, ${misc:Depends}
|
Depends: libglibutil (>= 1.0.35), ${shlibs:Depends}, ${misc:Depends}
|
||||||
Description: Binder client library
|
Description: Binder client library
|
||||||
|
|
||||||
Package: libgbinder-dev
|
Package: libgbinder-dev
|
||||||
|
|||||||
10
debian/copyright
vendored
10
debian/copyright
vendored
@@ -1,5 +1,5 @@
|
|||||||
Copyright (C) 2018 Jolla Ltd.
|
Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
|
|
||||||
You may use this file under the terms of BSD license as follows:
|
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
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
notice, this list of conditions and the following disclaimer in the
|
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 name of Jolla Ltd nor the names of its contributors may
|
3. Neither the names of the copyright holders nor the names of its
|
||||||
be used to endorse or promote products derived from this software
|
contributors may be used to endorse or promote products derived
|
||||||
without specific prior written permission.
|
from this software without specific prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
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.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@
|
||||||
7
debian/rules
vendored
7
debian/rules
vendored
@@ -4,8 +4,13 @@
|
|||||||
# Uncomment this to turn on verbose mode.
|
# Uncomment this to turn on verbose mode.
|
||||||
#export DH_VERBOSE=1
|
#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
|
||||||
|
|
||||||
override_dh_auto_install:
|
override_dh_auto_install:
|
||||||
dh_auto_install -- install-dev
|
dh_auto_install -- LIBDIR=$(LIBDIR) install-dev
|
||||||
|
|
||||||
%:
|
%:
|
||||||
dh $@
|
dh $@
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -44,6 +44,7 @@
|
|||||||
#include "gbinder_remote_object.h"
|
#include "gbinder_remote_object.h"
|
||||||
#include "gbinder_remote_reply.h"
|
#include "gbinder_remote_reply.h"
|
||||||
#include "gbinder_remote_request.h"
|
#include "gbinder_remote_request.h"
|
||||||
|
#include "gbinder_servicename.h"
|
||||||
#include "gbinder_servicemanager.h"
|
#include "gbinder_servicemanager.h"
|
||||||
#include "gbinder_writer.h"
|
#include "gbinder_writer.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -37,6 +37,11 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
typedef struct gbinder_client_iface_info {
|
||||||
|
const char* iface;
|
||||||
|
guint32 last_code;
|
||||||
|
} GBinderClientIfaceInfo;
|
||||||
|
|
||||||
typedef
|
typedef
|
||||||
void
|
void
|
||||||
(*GBinderClientReplyFunc)(
|
(*GBinderClientReplyFunc)(
|
||||||
@@ -50,6 +55,12 @@ gbinder_client_new(
|
|||||||
GBinderRemoteObject* object,
|
GBinderRemoteObject* object,
|
||||||
const char* iface);
|
const char* iface);
|
||||||
|
|
||||||
|
GBinderClient*
|
||||||
|
gbinder_client_new2(
|
||||||
|
GBinderRemoteObject* object,
|
||||||
|
const GBinderClientIfaceInfo* ifaces,
|
||||||
|
gsize count); /* since 1.0.42 */
|
||||||
|
|
||||||
GBinderClient*
|
GBinderClient*
|
||||||
gbinder_client_ref(
|
gbinder_client_ref(
|
||||||
GBinderClient* client);
|
GBinderClient* client);
|
||||||
@@ -58,10 +69,24 @@ void
|
|||||||
gbinder_client_unref(
|
gbinder_client_unref(
|
||||||
GBinderClient* client);
|
GBinderClient* client);
|
||||||
|
|
||||||
|
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*
|
GBinderLocalRequest*
|
||||||
gbinder_client_new_request(
|
gbinder_client_new_request(
|
||||||
GBinderClient* client);
|
GBinderClient* client);
|
||||||
|
|
||||||
|
GBinderLocalRequest*
|
||||||
|
gbinder_client_new_request2(
|
||||||
|
GBinderClient* client,
|
||||||
|
guint32 code); /* since 1.0.42 */
|
||||||
|
|
||||||
GBinderRemoteReply*
|
GBinderRemoteReply*
|
||||||
gbinder_client_transact_sync_reply(
|
gbinder_client_transact_sync_reply(
|
||||||
GBinderClient* client,
|
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 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -37,6 +37,14 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
GBinderLocalObject*
|
||||||
|
gbinder_local_object_new(
|
||||||
|
GBinderIpc* ipc,
|
||||||
|
const char* const* ifaces,
|
||||||
|
GBinderLocalTransactFunc handler,
|
||||||
|
void* user_data) /* Since 1.0.30 */
|
||||||
|
G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
GBinderLocalObject*
|
GBinderLocalObject*
|
||||||
gbinder_local_object_ref(
|
gbinder_local_object_ref(
|
||||||
GBinderLocalObject* obj);
|
GBinderLocalObject* obj);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -53,7 +53,7 @@ struct gbinder_reader {
|
|||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_reader_at_end(
|
gbinder_reader_at_end(
|
||||||
GBinderReader* reader);
|
const GBinderReader* reader);
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_reader_read_byte(
|
gbinder_reader_read_byte(
|
||||||
@@ -95,6 +95,15 @@ gbinder_reader_read_double(
|
|||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
gdouble* value);
|
gdouble* value);
|
||||||
|
|
||||||
|
int
|
||||||
|
gbinder_reader_read_fd(
|
||||||
|
GBinderReader* reader); /* Since 1.0.18 */
|
||||||
|
|
||||||
|
int
|
||||||
|
gbinder_reader_read_dup_fd(
|
||||||
|
GBinderReader* reader) /* Since 1.0.18 */
|
||||||
|
G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_reader_read_nullable_object(
|
gbinder_reader_read_nullable_object(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
@@ -116,7 +125,7 @@ gbinder_reader_read_buffer(
|
|||||||
const void*
|
const void*
|
||||||
gbinder_reader_read_hidl_struct1(
|
gbinder_reader_read_hidl_struct1(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
gsize size); /* since 1.0.9 */
|
gsize size); /* Since 1.0.9 */
|
||||||
|
|
||||||
#define gbinder_reader_read_hidl_struct(reader,type) \
|
#define gbinder_reader_read_hidl_struct(reader,type) \
|
||||||
((const type*)gbinder_reader_read_hidl_struct1(reader, sizeof(type)))
|
((const type*)gbinder_reader_read_hidl_struct1(reader, sizeof(type)))
|
||||||
@@ -131,7 +140,7 @@ const void*
|
|||||||
gbinder_reader_read_hidl_vec1(
|
gbinder_reader_read_hidl_vec1(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
gsize* count,
|
gsize* count,
|
||||||
guint expected_elemsize); /* since 1.0.9 */
|
guint expected_elemsize); /* Since 1.0.9 */
|
||||||
|
|
||||||
#define gbinder_reader_read_hidl_type_vec(reader,type,count) \
|
#define gbinder_reader_read_hidl_type_vec(reader,type,count) \
|
||||||
((const type*)gbinder_reader_read_hidl_vec1(reader, count, sizeof(type)))
|
((const type*)gbinder_reader_read_hidl_vec1(reader, count, sizeof(type)))
|
||||||
@@ -143,6 +152,13 @@ gbinder_reader_read_hidl_string(
|
|||||||
GBinderReader* reader)
|
GBinderReader* reader)
|
||||||
G_GNUC_WARN_UNUSED_RESULT;
|
G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
const char*
|
||||||
|
gbinder_reader_read_hidl_string_c(
|
||||||
|
GBinderReader* reader); /* Since 1.0.23 */
|
||||||
|
|
||||||
|
#define gbinder_reader_skip_hidl_string(reader) \
|
||||||
|
(gbinder_reader_read_hidl_string_c(reader) != NULL)
|
||||||
|
|
||||||
char**
|
char**
|
||||||
gbinder_reader_read_hidl_string_vec(
|
gbinder_reader_read_hidl_string_vec(
|
||||||
GBinderReader* reader);
|
GBinderReader* reader);
|
||||||
@@ -165,6 +181,17 @@ gbinder_reader_read_nullable_string16(
|
|||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
char** out);
|
char** out);
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gbinder_reader_read_nullable_string16_utf16(
|
||||||
|
GBinderReader* reader,
|
||||||
|
const gunichar2** out,
|
||||||
|
gsize* len); /* Since 1.0.17 */
|
||||||
|
|
||||||
|
const gunichar2*
|
||||||
|
gbinder_reader_read_string16_utf16(
|
||||||
|
GBinderReader* reader,
|
||||||
|
gsize* len); /* Since 1.0.26 */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_reader_skip_string16(
|
gbinder_reader_skip_string16(
|
||||||
GBinderReader* reader);
|
GBinderReader* reader);
|
||||||
@@ -172,15 +199,20 @@ gbinder_reader_skip_string16(
|
|||||||
const void*
|
const void*
|
||||||
gbinder_reader_read_byte_array(
|
gbinder_reader_read_byte_array(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
gsize* len); /* since 1.0.12 */
|
gsize* len); /* Since 1.0.12 */
|
||||||
|
|
||||||
gsize
|
gsize
|
||||||
gbinder_reader_bytes_read(
|
gbinder_reader_bytes_read(
|
||||||
GBinderReader* reader);
|
const GBinderReader* reader);
|
||||||
|
|
||||||
gsize
|
gsize
|
||||||
gbinder_reader_bytes_remaining(
|
gbinder_reader_bytes_remaining(
|
||||||
GBinderReader* reader);
|
const GBinderReader* reader);
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_reader_copy(
|
||||||
|
GBinderReader* dest,
|
||||||
|
const GBinderReader* src); /* Since 1.0.16 */
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -51,6 +51,10 @@ void
|
|||||||
gbinder_remote_object_unref(
|
gbinder_remote_object_unref(
|
||||||
GBinderRemoteObject* obj);
|
GBinderRemoteObject* obj);
|
||||||
|
|
||||||
|
GBinderIpc*
|
||||||
|
gbinder_remote_object_ipc(
|
||||||
|
GBinderRemoteObject* obj); /* Since 1.0.30 */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_remote_object_is_dead(
|
gbinder_remote_object_is_dead(
|
||||||
GBinderRemoteObject* obj);
|
GBinderRemoteObject* obj);
|
||||||
|
|||||||
@@ -67,6 +67,16 @@ gbinder_remote_request_copy_to_local(
|
|||||||
GBinderRemoteRequest* req) /* since 1.0.6 */
|
GBinderRemoteRequest* req) /* since 1.0.6 */
|
||||||
G_GNUC_WARN_UNUSED_RESULT;
|
G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_remote_request_block(
|
||||||
|
GBinderRemoteRequest* req); /* Since 1.0.20 */
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_remote_request_complete(
|
||||||
|
GBinderRemoteRequest* req,
|
||||||
|
GBinderLocalReply* reply,
|
||||||
|
int status); /* Since 1.0.20 */
|
||||||
|
|
||||||
/* Convenience function to decode requests with just one data item */
|
/* Convenience function to decode requests with just one data item */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived from
|
||||||
* without specific prior written permission.
|
* this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -37,6 +37,12 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
typedef
|
||||||
|
void
|
||||||
|
(*GBinderServiceManagerFunc)(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
void* user_data);
|
||||||
|
|
||||||
/* GBinderServiceManagerListFunc callback returns TRUE to keep the services
|
/* GBinderServiceManagerListFunc callback returns TRUE to keep the services
|
||||||
* list, otherwise the caller will deallocate it. */
|
* list, otherwise the caller will deallocate it. */
|
||||||
typedef
|
typedef
|
||||||
@@ -61,6 +67,13 @@ void
|
|||||||
int status,
|
int status,
|
||||||
void* user_data);
|
void* user_data);
|
||||||
|
|
||||||
|
typedef
|
||||||
|
void
|
||||||
|
(*GBinderServiceManagerRegistrationFunc)(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
const char* name,
|
||||||
|
void* user_data);
|
||||||
|
|
||||||
GBinderServiceManager*
|
GBinderServiceManager*
|
||||||
gbinder_servicemanager_new(
|
gbinder_servicemanager_new(
|
||||||
const char* dev);
|
const char* dev);
|
||||||
@@ -80,6 +93,13 @@ gbinder_servicemanager_new_local_object(
|
|||||||
GBinderLocalTransactFunc handler,
|
GBinderLocalTransactFunc handler,
|
||||||
void* user_data);
|
void* user_data);
|
||||||
|
|
||||||
|
GBinderLocalObject*
|
||||||
|
gbinder_servicemanager_new_local_object2(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
const char* const* ifaces,
|
||||||
|
GBinderLocalTransactFunc handler,
|
||||||
|
void* user_data); /* Since 1.0.29 */
|
||||||
|
|
||||||
GBinderServiceManager*
|
GBinderServiceManager*
|
||||||
gbinder_servicemanager_ref(
|
gbinder_servicemanager_ref(
|
||||||
GBinderServiceManager* sm);
|
GBinderServiceManager* sm);
|
||||||
@@ -88,6 +108,15 @@ void
|
|||||||
gbinder_servicemanager_unref(
|
gbinder_servicemanager_unref(
|
||||||
GBinderServiceManager* sm);
|
GBinderServiceManager* sm);
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gbinder_servicemanager_is_present(
|
||||||
|
GBinderServiceManager* sm); /* Since 1.0.25 */
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gbinder_servicemanager_wait(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
long max_wait_ms); /* Since 1.0.25 */
|
||||||
|
|
||||||
gulong
|
gulong
|
||||||
gbinder_servicemanager_list(
|
gbinder_servicemanager_list(
|
||||||
GBinderServiceManager* sm,
|
GBinderServiceManager* sm,
|
||||||
@@ -130,6 +159,33 @@ gbinder_servicemanager_cancel(
|
|||||||
GBinderServiceManager* sm,
|
GBinderServiceManager* sm,
|
||||||
gulong id);
|
gulong id);
|
||||||
|
|
||||||
|
gulong
|
||||||
|
gbinder_servicemanager_add_presence_handler(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
GBinderServiceManagerFunc func,
|
||||||
|
void* user_data); /* Since 1.0.25 */
|
||||||
|
|
||||||
|
gulong
|
||||||
|
gbinder_servicemanager_add_registration_handler(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
const char* name,
|
||||||
|
GBinderServiceManagerRegistrationFunc func,
|
||||||
|
void* user_data); /* Since 1.0.13 */
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicemanager_remove_handler(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
gulong id); /* Since 1.0.13 */
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicemanager_remove_handlers(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
gulong* ids,
|
||||||
|
guint count); /* Since 1.0.25 */
|
||||||
|
|
||||||
|
#define gbinder_servicemanager_remove_all_handlers(r,ids) \
|
||||||
|
gbinder_servicemanager_remove_handlers(sm, ids, G_N_ELEMENTS(ids))
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* GBINDER_SERVICEMANAGER_H */
|
#endif /* GBINDER_SERVICEMANAGER_H */
|
||||||
|
|||||||
70
include/gbinder_servicename.h
Normal file
70
include/gbinder_servicename.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Jolla Ltd.
|
||||||
|
* Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
|
||||||
|
*
|
||||||
|
* You may use this file under the terms of BSD license as follows:
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GBINDER_SERVICENAME_H
|
||||||
|
#define GBINDER_SERVICENAME_H
|
||||||
|
|
||||||
|
#include "gbinder_types.h"
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
/* Since 1.0.26 */
|
||||||
|
|
||||||
|
struct gbinder_servicename {
|
||||||
|
const char* name;
|
||||||
|
};
|
||||||
|
|
||||||
|
GBinderServiceName*
|
||||||
|
gbinder_servicename_new(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
GBinderLocalObject* object,
|
||||||
|
const char* name);
|
||||||
|
|
||||||
|
GBinderServiceName*
|
||||||
|
gbinder_servicename_ref(
|
||||||
|
GBinderServiceName* name);
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicename_unref(
|
||||||
|
GBinderServiceName* name);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* GBINDER_SERVICENAME_H */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local Variables:
|
||||||
|
* mode: C
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* indent-tabs-mode: nil
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -61,6 +61,7 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
typedef struct gbinder_buffer GBinderBuffer;
|
typedef struct gbinder_buffer GBinderBuffer;
|
||||||
typedef struct gbinder_client GBinderClient;
|
typedef struct gbinder_client GBinderClient;
|
||||||
|
typedef struct gbinder_ipc GBinderIpc;
|
||||||
typedef struct gbinder_local_object GBinderLocalObject;
|
typedef struct gbinder_local_object GBinderLocalObject;
|
||||||
typedef struct gbinder_local_reply GBinderLocalReply;
|
typedef struct gbinder_local_reply GBinderLocalReply;
|
||||||
typedef struct gbinder_local_request GBinderLocalRequest;
|
typedef struct gbinder_local_request GBinderLocalRequest;
|
||||||
@@ -68,10 +69,35 @@ typedef struct gbinder_reader GBinderReader;
|
|||||||
typedef struct gbinder_remote_object GBinderRemoteObject;
|
typedef struct gbinder_remote_object GBinderRemoteObject;
|
||||||
typedef struct gbinder_remote_reply GBinderRemoteReply;
|
typedef struct gbinder_remote_reply GBinderRemoteReply;
|
||||||
typedef struct gbinder_remote_request GBinderRemoteRequest;
|
typedef struct gbinder_remote_request GBinderRemoteRequest;
|
||||||
|
typedef struct gbinder_servicename GBinderServiceName;
|
||||||
typedef struct gbinder_servicemanager GBinderServiceManager;
|
typedef struct gbinder_servicemanager GBinderServiceManager;
|
||||||
typedef struct gbinder_writer GBinderWriter;
|
typedef struct gbinder_writer GBinderWriter;
|
||||||
typedef struct gbinder_parent GBinderParent;
|
typedef struct gbinder_parent GBinderParent;
|
||||||
|
|
||||||
|
/* Basic HIDL types */
|
||||||
|
|
||||||
|
typedef struct gbinder_hidl_vec {
|
||||||
|
union {
|
||||||
|
guint64 value;
|
||||||
|
const void* ptr;
|
||||||
|
} data;
|
||||||
|
guint32 count;
|
||||||
|
guint32 owns_buffer;
|
||||||
|
} GBinderHidlVec;
|
||||||
|
|
||||||
|
#define GBINDER_HIDL_VEC_BUFFER_OFFSET (0)
|
||||||
|
|
||||||
|
typedef struct gbinder_hidl_string {
|
||||||
|
union {
|
||||||
|
guint64 value;
|
||||||
|
const char* str;
|
||||||
|
} data;
|
||||||
|
guint32 len;
|
||||||
|
guint32 owns_buffer;
|
||||||
|
} GBinderHidlString;
|
||||||
|
|
||||||
|
#define GBINDER_HIDL_STRING_BUFFER_OFFSET (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Each RPC call is identified by the interface name returned
|
* Each RPC call is identified by the interface name returned
|
||||||
* by gbinder_remote_request_interface() the transaction code.
|
* by gbinder_remote_request_interface() the transaction code.
|
||||||
|
|||||||
@@ -86,6 +86,12 @@ gbinder_writer_append_string16_len(
|
|||||||
const char* utf8,
|
const char* utf8,
|
||||||
gssize num_bytes);
|
gssize num_bytes);
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_writer_append_string16_utf16(
|
||||||
|
GBinderWriter* writer,
|
||||||
|
const gunichar2* utf16,
|
||||||
|
gssize length); /* Since 1.0.17 */
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_append_string8(
|
gbinder_writer_append_string8(
|
||||||
GBinderWriter* writer,
|
GBinderWriter* writer,
|
||||||
@@ -108,6 +114,21 @@ gbinder_writer_append_bytes(
|
|||||||
const void* data,
|
const void* data,
|
||||||
gsize size);
|
gsize size);
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_writer_append_fd(
|
||||||
|
GBinderWriter* writer,
|
||||||
|
int fd); /* Since 1.0.18 */
|
||||||
|
|
||||||
|
gsize
|
||||||
|
gbinder_writer_bytes_written(
|
||||||
|
GBinderWriter* writer); /* since 1.0.21 */
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_writer_overwrite_int32(
|
||||||
|
GBinderWriter* writer,
|
||||||
|
gsize offset,
|
||||||
|
gint32 value); /* since 1.0.21 */
|
||||||
|
|
||||||
guint
|
guint
|
||||||
gbinder_writer_append_buffer_object_with_parent(
|
gbinder_writer_append_buffer_object_with_parent(
|
||||||
GBinderWriter* writer,
|
GBinderWriter* writer,
|
||||||
@@ -151,10 +172,38 @@ gbinder_writer_append_remote_object(
|
|||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_append_byte_array(
|
gbinder_writer_append_byte_array(
|
||||||
GBinderWriter* self,
|
GBinderWriter* writer,
|
||||||
const void* byte_array,
|
const void* byte_array,
|
||||||
gint32 len); /* since 1.0.12 */
|
gint32 len); /* since 1.0.12 */
|
||||||
|
|
||||||
|
void*
|
||||||
|
gbinder_writer_malloc(
|
||||||
|
GBinderWriter* writer,
|
||||||
|
gsize size); /* since 1.0.19 */
|
||||||
|
|
||||||
|
void*
|
||||||
|
gbinder_writer_malloc0(
|
||||||
|
GBinderWriter* writer,
|
||||||
|
gsize size); /* since 1.0.19 */
|
||||||
|
|
||||||
|
#define gbinder_writer_new(writer,type) \
|
||||||
|
((type*) gbinder_writer_malloc(writer, sizeof(type)))
|
||||||
|
|
||||||
|
#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 */
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* GBINDER_WRITER_H */
|
#endif /* GBINDER_WRITER_H */
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
name=gbinder
|
name=gbinder
|
||||||
libdir=/usr/lib
|
libdir=@libdir@
|
||||||
includedir=/usr/include
|
includedir=/usr/include
|
||||||
|
|
||||||
Name: libgbinder
|
Name: libgbinder
|
||||||
Description: Binder client library
|
Description: Binder client library
|
||||||
Version: [version]
|
Version: @version@
|
||||||
Requires: glib-2.0 libglibutil
|
Requires.private: glib-2.0 libglibutil
|
||||||
Libs: -L${libdir} -l${name}
|
Libs: -L${libdir} -l${name}
|
||||||
Cflags: -I${includedir} -I${includedir}/${name}
|
Cflags: -I${includedir} -I${includedir}/${name}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
Name: libgbinder
|
Name: libgbinder
|
||||||
Version: 1.0.12
|
Version: 1.0.45
|
||||||
Release: 0
|
Release: 0
|
||||||
Summary: Binder client library
|
Summary: Binder client library
|
||||||
Group: Development/Libraries
|
|
||||||
License: BSD
|
License: BSD
|
||||||
URL: https://github.com/mer-hybris/libgbinder
|
URL: https://github.com/mer-hybris/libgbinder
|
||||||
Source: %{name}-%{version}.tar.bz2
|
Source: %{name}-%{version}.tar.bz2
|
||||||
Requires: libglibutil >= 1.0.29
|
|
||||||
|
%define libglibutil_version 1.0.35
|
||||||
|
|
||||||
BuildRequires: pkgconfig(glib-2.0)
|
BuildRequires: pkgconfig(glib-2.0)
|
||||||
BuildRequires: pkgconfig(libglibutil) >= 1.0.29
|
BuildRequires: pkgconfig(libglibutil) >= %{libglibutil_version}
|
||||||
|
Requires: libglibutil >= %{libglibutil_version}
|
||||||
Requires(post): /sbin/ldconfig
|
Requires(post): /sbin/ldconfig
|
||||||
Requires(postun): /sbin/ldconfig
|
Requires(postun): /sbin/ldconfig
|
||||||
|
|
||||||
@@ -27,11 +29,11 @@ This package contains the development library for %{name}.
|
|||||||
%setup -q
|
%setup -q
|
||||||
|
|
||||||
%build
|
%build
|
||||||
make KEEP_SYMBOLS=1 release pkgconfig
|
make LIBDIR=%{_libdir} KEEP_SYMBOLS=1 release pkgconfig
|
||||||
|
|
||||||
%install
|
%install
|
||||||
rm -rf %{buildroot}
|
rm -rf %{buildroot}
|
||||||
make install-dev DESTDIR=%{buildroot}
|
make LIBDIR=%{_libdir} DESTDIR=%{buildroot} install-dev
|
||||||
|
|
||||||
%check
|
%check
|
||||||
make -C unit test
|
make -C unit test
|
||||||
|
|||||||
@@ -36,54 +36,62 @@
|
|||||||
|
|
||||||
#include <gutil_macros.h>
|
#include <gutil_macros.h>
|
||||||
|
|
||||||
struct gbinder_buffer_memory {
|
struct gbinder_buffer_contents {
|
||||||
gint refcount;
|
gint refcount;
|
||||||
void* buffer;
|
void* buffer;
|
||||||
gsize size;
|
gsize size;
|
||||||
|
void** objects;
|
||||||
GBinderDriver* driver;
|
GBinderDriver* driver;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct gbinder_buffer_priv {
|
typedef struct gbinder_buffer_priv {
|
||||||
GBinderBuffer pub;
|
GBinderBuffer pub;
|
||||||
GBinderBufferMemory* memory;
|
GBinderBufferContents* contents;
|
||||||
} GBinderBufferPriv;
|
} GBinderBufferPriv;
|
||||||
|
|
||||||
static inline GBinderBufferPriv* gbinder_buffer_cast(GBinderBuffer* buf)
|
static inline GBinderBufferPriv* gbinder_buffer_cast(GBinderBuffer* buf)
|
||||||
{ return G_CAST(buf, GBinderBufferPriv, pub); }
|
{ return G_CAST(buf, GBinderBufferPriv, pub); }
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* GBinderBufferMemory
|
* GBinderBufferContents
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
|
|
||||||
static
|
static
|
||||||
GBinderBufferMemory*
|
GBinderBufferContents*
|
||||||
gbinder_buffer_memory_new(
|
gbinder_buffer_contents_new(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
void* buffer,
|
void* buffer,
|
||||||
gsize size)
|
gsize size,
|
||||||
|
void** objects)
|
||||||
{
|
{
|
||||||
GBinderBufferMemory* self = g_slice_new0(GBinderBufferMemory);
|
GBinderBufferContents* self = g_slice_new0(GBinderBufferContents);
|
||||||
|
|
||||||
g_atomic_int_set(&self->refcount, 1);
|
g_atomic_int_set(&self->refcount, 1);
|
||||||
self->buffer = buffer;
|
self->buffer = buffer;
|
||||||
self->size = size;
|
self->size = size;
|
||||||
|
self->objects = objects;
|
||||||
self->driver = gbinder_driver_ref(driver);
|
self->driver = gbinder_driver_ref(driver);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
gbinder_buffer_memory_free(
|
gbinder_buffer_contents_free(
|
||||||
GBinderBufferMemory* self)
|
GBinderBufferContents* self)
|
||||||
{
|
{
|
||||||
|
if (self->objects) {
|
||||||
|
gbinder_driver_close_fds(self->driver, self->objects,
|
||||||
|
((guint8*)self->buffer) + self->size);
|
||||||
|
g_free(self->objects);
|
||||||
|
}
|
||||||
gbinder_driver_free_buffer(self->driver, self->buffer);
|
gbinder_driver_free_buffer(self->driver, self->buffer);
|
||||||
gbinder_driver_unref(self->driver);
|
gbinder_driver_unref(self->driver);
|
||||||
g_slice_free(GBinderBufferMemory, self);
|
g_slice_free(GBinderBufferContents, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
GBinderBufferMemory*
|
GBinderBufferContents*
|
||||||
gbinder_buffer_memory_ref(
|
gbinder_buffer_contents_ref(
|
||||||
GBinderBufferMemory* self)
|
GBinderBufferContents* self)
|
||||||
{
|
{
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GASSERT(self->refcount > 0);
|
GASSERT(self->refcount > 0);
|
||||||
@@ -93,13 +101,13 @@ gbinder_buffer_memory_ref(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_buffer_memory_unref(
|
gbinder_buffer_contents_unref(
|
||||||
GBinderBufferMemory* self)
|
GBinderBufferContents* self)
|
||||||
{
|
{
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GASSERT(self->refcount > 0);
|
GASSERT(self->refcount > 0);
|
||||||
if (g_atomic_int_dec_and_test(&self->refcount)) {
|
if (g_atomic_int_dec_and_test(&self->refcount)) {
|
||||||
gbinder_buffer_memory_free(self);
|
gbinder_buffer_contents_free(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,14 +119,14 @@ gbinder_buffer_memory_unref(
|
|||||||
static
|
static
|
||||||
GBinderBuffer*
|
GBinderBuffer*
|
||||||
gbinder_buffer_alloc(
|
gbinder_buffer_alloc(
|
||||||
GBinderBufferMemory* memory,
|
GBinderBufferContents* contents,
|
||||||
void* data,
|
void* data,
|
||||||
gsize size)
|
gsize size)
|
||||||
{
|
{
|
||||||
GBinderBufferPriv* priv = g_slice_new0(GBinderBufferPriv);
|
GBinderBufferPriv* priv = g_slice_new0(GBinderBufferPriv);
|
||||||
GBinderBuffer* self = &priv->pub;
|
GBinderBuffer* self = &priv->pub;
|
||||||
|
|
||||||
priv->memory = memory;
|
priv->contents = contents;
|
||||||
self->data = data;
|
self->data = data;
|
||||||
self->size = size;
|
self->size = size;
|
||||||
return self;
|
return self;
|
||||||
@@ -131,7 +139,7 @@ gbinder_buffer_free(
|
|||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderBufferPriv* priv = gbinder_buffer_cast(self);
|
GBinderBufferPriv* priv = gbinder_buffer_cast(self);
|
||||||
|
|
||||||
gbinder_buffer_memory_unref(priv->memory);
|
gbinder_buffer_contents_unref(priv->contents);
|
||||||
g_slice_free(GBinderBufferPriv, priv);
|
g_slice_free(GBinderBufferPriv, priv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,10 +148,12 @@ GBinderBuffer*
|
|||||||
gbinder_buffer_new(
|
gbinder_buffer_new(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
void* data,
|
void* data,
|
||||||
gsize size)
|
gsize size,
|
||||||
|
void** objects)
|
||||||
{
|
{
|
||||||
return gbinder_buffer_alloc((driver && data) ?
|
return gbinder_buffer_alloc((driver && data) ?
|
||||||
gbinder_buffer_memory_new(driver, data, size) : NULL, data, size);
|
gbinder_buffer_contents_new(driver, data, size, objects) : NULL,
|
||||||
|
data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
GBinderBuffer*
|
GBinderBuffer*
|
||||||
@@ -153,7 +163,7 @@ gbinder_buffer_new_with_parent(
|
|||||||
gsize size)
|
gsize size)
|
||||||
{
|
{
|
||||||
return gbinder_buffer_alloc(parent ?
|
return gbinder_buffer_alloc(parent ?
|
||||||
gbinder_buffer_memory_ref(gbinder_buffer_memory(parent)) : NULL,
|
gbinder_buffer_contents_ref(gbinder_buffer_contents(parent)) : NULL,
|
||||||
data, size);
|
data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,13 +172,13 @@ gbinder_buffer_data(
|
|||||||
GBinderBuffer* self,
|
GBinderBuffer* self,
|
||||||
gsize* size)
|
gsize* size)
|
||||||
{
|
{
|
||||||
GBinderBufferMemory* memory = gbinder_buffer_memory(self);
|
GBinderBufferContents* contents = gbinder_buffer_contents(self);
|
||||||
|
|
||||||
if (G_LIKELY(memory)) {
|
if (G_LIKELY(contents)) {
|
||||||
if (size) {
|
if (size) {
|
||||||
*size = memory->size;
|
*size = contents->size;
|
||||||
}
|
}
|
||||||
return memory->buffer;
|
return contents->buffer;
|
||||||
} else {
|
} else {
|
||||||
if (size) {
|
if (size) {
|
||||||
*size = 0;
|
*size = 0;
|
||||||
@@ -184,8 +194,8 @@ gbinder_buffer_driver(
|
|||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderBufferPriv* priv = gbinder_buffer_cast(self);
|
GBinderBufferPriv* priv = gbinder_buffer_cast(self);
|
||||||
|
|
||||||
if (priv->memory) {
|
if (priv->contents) {
|
||||||
return priv->memory->driver;
|
return priv->contents->driver;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -200,11 +210,25 @@ gbinder_buffer_io(
|
|||||||
return driver ? gbinder_driver_io(driver) : NULL;
|
return driver ? gbinder_driver_io(driver) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GBinderBufferMemory*
|
void**
|
||||||
gbinder_buffer_memory(
|
gbinder_buffer_objects(
|
||||||
GBinderBuffer* self)
|
GBinderBuffer* self)
|
||||||
{
|
{
|
||||||
return G_LIKELY(self) ? gbinder_buffer_cast(self)->memory : NULL;
|
if (G_LIKELY(self)) {
|
||||||
|
GBinderBufferPriv* priv = gbinder_buffer_cast(self);
|
||||||
|
|
||||||
|
if (priv->contents) {
|
||||||
|
return priv->contents->objects;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GBinderBufferContents*
|
||||||
|
gbinder_buffer_contents(
|
||||||
|
GBinderBuffer* self)
|
||||||
|
{
|
||||||
|
return G_LIKELY(self) ? gbinder_buffer_cast(self)->contents : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -41,38 +41,52 @@ GBinderBuffer*
|
|||||||
gbinder_buffer_new(
|
gbinder_buffer_new(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
void* data,
|
void* data,
|
||||||
gsize size);
|
gsize size,
|
||||||
|
void** objects)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderBuffer*
|
GBinderBuffer*
|
||||||
gbinder_buffer_new_with_parent(
|
gbinder_buffer_new_with_parent(
|
||||||
GBinderBuffer* parent,
|
GBinderBuffer* parent,
|
||||||
void* data,
|
void* data,
|
||||||
gsize size);
|
gsize size)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderDriver*
|
GBinderDriver*
|
||||||
gbinder_buffer_driver(
|
gbinder_buffer_driver(
|
||||||
GBinderBuffer* buf);
|
GBinderBuffer* buf)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderBufferMemory*
|
GBinderBufferContents*
|
||||||
gbinder_buffer_memory(
|
gbinder_buffer_contents(
|
||||||
GBinderBuffer* buf);
|
GBinderBuffer* buf)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gconstpointer
|
gconstpointer
|
||||||
gbinder_buffer_data(
|
gbinder_buffer_data(
|
||||||
GBinderBuffer* buf,
|
GBinderBuffer* buf,
|
||||||
gsize* size);
|
gsize* size)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
const GBinderIo*
|
const GBinderIo*
|
||||||
gbinder_buffer_io(
|
gbinder_buffer_io(
|
||||||
GBinderBuffer* buf);
|
GBinderBuffer* buf)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderBufferMemory*
|
void**
|
||||||
gbinder_buffer_memory_ref(
|
gbinder_buffer_objects(
|
||||||
GBinderBufferMemory* mem);
|
GBinderBuffer* buffer)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
GBinderBufferContents*
|
||||||
|
gbinder_buffer_contents_ref(
|
||||||
|
GBinderBufferContents* contents)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_buffer_memory_unref(
|
gbinder_buffer_contents_unref(
|
||||||
GBinderBufferMemory* mem);
|
GBinderBufferContents* contents)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_BUFFER_PRIVATE_H */
|
#endif /* GBINDER_BUFFER_PRIVATE_H */
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -48,11 +48,33 @@ struct gbinder_cleanup {
|
|||||||
G_STATIC_ASSERT(sizeof(GBinderCleanup) == sizeof(GArray));
|
G_STATIC_ASSERT(sizeof(GBinderCleanup) == sizeof(GArray));
|
||||||
#define ELEMENT_SIZE (sizeof(GBinderCleanupItem))
|
#define ELEMENT_SIZE (sizeof(GBinderCleanupItem))
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_cleanup_destroy_func(
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
GBinderCleanupItem* item = data;
|
||||||
|
|
||||||
|
item->destroy(item->pointer);
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
GBinderCleanup*
|
GBinderCleanup*
|
||||||
gbinder_cleanup_new()
|
gbinder_cleanup_new()
|
||||||
{
|
{
|
||||||
return (GBinderCleanup*)g_array_sized_new(FALSE, FALSE, ELEMENT_SIZE, 0);
|
GArray* array = g_array_sized_new(FALSE, FALSE, ELEMENT_SIZE, 0);
|
||||||
|
|
||||||
|
g_array_set_clear_func(array, gbinder_cleanup_destroy_func);
|
||||||
|
return (GBinderCleanup*)array;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_cleanup_reset(
|
||||||
|
GBinderCleanup* self)
|
||||||
|
{
|
||||||
|
if (G_LIKELY(self)) {
|
||||||
|
g_array_set_size((GArray*)self, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -60,11 +82,6 @@ gbinder_cleanup_free(
|
|||||||
GBinderCleanup* self)
|
GBinderCleanup* self)
|
||||||
{
|
{
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
guint i;
|
|
||||||
|
|
||||||
for (i = 0; i < self->count; i++) {
|
|
||||||
self->items[i].destroy(self->items[i].pointer);
|
|
||||||
}
|
|
||||||
g_array_free((GArray*)self, TRUE);
|
g_array_free((GArray*)self, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -37,13 +37,20 @@
|
|||||||
|
|
||||||
void
|
void
|
||||||
gbinder_cleanup_free(
|
gbinder_cleanup_free(
|
||||||
GBinderCleanup* cleanup);
|
GBinderCleanup* cleanup)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_cleanup_reset(
|
||||||
|
GBinderCleanup* cleanup)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderCleanup*
|
GBinderCleanup*
|
||||||
gbinder_cleanup_add(
|
gbinder_cleanup_add(
|
||||||
GBinderCleanup* cleanup,
|
GBinderCleanup* cleanup,
|
||||||
GDestroyNotify destroy,
|
GDestroyNotify destroy,
|
||||||
gpointer pointer);
|
gpointer pointer)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_CLEANUP_H */
|
#endif /* GBINDER_CLEANUP_H */
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -41,14 +41,22 @@
|
|||||||
|
|
||||||
#include <gutil_macros.h>
|
#include <gutil_macros.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <errno.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 {
|
typedef struct gbinder_client_priv {
|
||||||
GBinderClient pub;
|
GBinderClient pub;
|
||||||
guint32 refcount;
|
guint32 refcount;
|
||||||
char* iface;
|
GBinderClientIfaceRange* ranges;
|
||||||
GBytes* rpc_header;
|
guint nr;
|
||||||
GBinderLocalRequest* basic_req;
|
|
||||||
} GBinderClientPriv;
|
} GBinderClientPriv;
|
||||||
|
|
||||||
typedef struct gbinder_client_tx {
|
typedef struct gbinder_client_tx {
|
||||||
@@ -65,17 +73,79 @@ static inline GBinderClientPriv* gbinder_client_cast(GBinderClient* client)
|
|||||||
* Implementation
|
* 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
|
static
|
||||||
void
|
void
|
||||||
gbinder_client_free(
|
gbinder_client_free(
|
||||||
GBinderClientPriv* priv)
|
GBinderClientPriv* priv)
|
||||||
{
|
{
|
||||||
GBinderClient* self = &priv->pub;
|
GBinderClient* self = &priv->pub;
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
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);
|
gbinder_remote_object_unref(self->remote);
|
||||||
gbinder_local_request_unref(priv->basic_req);
|
|
||||||
g_free(priv->iface);
|
|
||||||
g_bytes_unref(priv->rpc_header);
|
|
||||||
g_slice_free(GBinderClientPriv, priv);
|
g_slice_free(GBinderClientPriv, priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,34 +182,52 @@ gbinder_client_transact_destroy(
|
|||||||
* Interface
|
* Interface
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
|
|
||||||
|
GBinderClient*
|
||||||
|
gbinder_client_new2(
|
||||||
|
GBinderRemoteObject* remote,
|
||||||
|
const GBinderClientIfaceInfo* ifaces,
|
||||||
|
gsize count)
|
||||||
|
{
|
||||||
|
if (G_LIKELY(remote)) {
|
||||||
|
GBinderClientPriv* priv = g_slice_new0(GBinderClientPriv);
|
||||||
|
GBinderClient* self = &priv->pub;
|
||||||
|
GBinderDriver* driver = remote->ipc->driver;
|
||||||
|
|
||||||
|
g_atomic_int_set(&priv->refcount, 1);
|
||||||
|
self->remote = gbinder_remote_object_ref(remote);
|
||||||
|
if (count > 0) {
|
||||||
|
gsize i;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
GBinderClient*
|
GBinderClient*
|
||||||
gbinder_client_new(
|
gbinder_client_new(
|
||||||
GBinderRemoteObject* remote,
|
GBinderRemoteObject* remote,
|
||||||
const char* iface)
|
const char* iface)
|
||||||
{
|
{
|
||||||
if (G_LIKELY(remote) && G_LIKELY(iface)) {
|
GBinderClientIfaceInfo info;
|
||||||
GBinderClientPriv* priv = g_slice_new0(GBinderClientPriv);
|
|
||||||
GBinderClient* self = &priv->pub;
|
|
||||||
GBinderIpc* ipc = remote->ipc;
|
|
||||||
GBinderOutputData* hdr;
|
|
||||||
|
|
||||||
g_atomic_int_set(&priv->refcount, 1);
|
info.iface = iface;
|
||||||
|
info.last_code = UINT_MAX;
|
||||||
/*
|
return gbinder_client_new2(remote, &info, 1);
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
priv->basic_req = gbinder_driver_local_request_new(ipc->driver, iface);
|
|
||||||
hdr = gbinder_local_request_data(priv->basic_req);
|
|
||||||
priv->rpc_header = g_bytes_new(hdr->bytes->data, hdr->bytes->len);
|
|
||||||
|
|
||||||
self->remote = gbinder_remote_object_ref(remote);
|
|
||||||
self->iface = priv->iface = g_strdup(iface);
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GBinderClient*
|
GBinderClient*
|
||||||
@@ -169,6 +257,29 @@ gbinder_client_unref(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char*
|
||||||
|
gbinder_client_interface(
|
||||||
|
GBinderClient* self) /* since 1.0.22 */
|
||||||
|
{
|
||||||
|
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*
|
GBinderLocalRequest*
|
||||||
gbinder_client_new_request(
|
gbinder_client_new_request(
|
||||||
GBinderClient* self)
|
GBinderClient* self)
|
||||||
@@ -176,7 +287,27 @@ gbinder_client_new_request(
|
|||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderClientPriv* priv = gbinder_client_cast(self);
|
GBinderClientPriv* priv = gbinder_client_cast(self);
|
||||||
const GBinderIo* io = gbinder_driver_io(self->remote->ipc->driver);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -191,12 +322,20 @@ gbinder_client_transact_sync_reply(
|
|||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderRemoteObject* obj = self->remote;
|
GBinderRemoteObject* obj = self->remote;
|
||||||
|
|
||||||
if (!req) {
|
if (G_LIKELY(!obj->dead)) {
|
||||||
/* Default empty request (just the header, no parameters) */
|
if (!req) {
|
||||||
req = gbinder_client_cast(self)->basic_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gbinder_ipc_transact_sync_reply(obj->ipc, obj->handle,
|
||||||
|
code, req, status);
|
||||||
}
|
}
|
||||||
return gbinder_ipc_transact_sync_reply(obj->ipc, obj->handle,
|
GDEBUG("Refusing to perform transaction with a dead object");
|
||||||
code, req, status);
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -210,15 +349,23 @@ gbinder_client_transact_sync_oneway(
|
|||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderRemoteObject* obj = self->remote;
|
GBinderRemoteObject* obj = self->remote;
|
||||||
|
|
||||||
if (!req) {
|
if (G_LIKELY(!obj->dead)) {
|
||||||
/* Default empty request (just the header, no parameters) */
|
if (!req) {
|
||||||
req = gbinder_client_cast(self)->basic_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gbinder_ipc_transact_sync_oneway(obj->ipc, obj->handle,
|
||||||
|
code, req);
|
||||||
}
|
}
|
||||||
return gbinder_ipc_transact_sync_oneway(obj->ipc, obj->handle,
|
GDEBUG("Refusing to perform transaction with a dead object");
|
||||||
code, req);
|
return (-ESTALE);
|
||||||
} else {
|
|
||||||
return (-EINVAL);
|
|
||||||
}
|
}
|
||||||
|
return (-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
gulong
|
gulong
|
||||||
@@ -233,23 +380,32 @@ gbinder_client_transact(
|
|||||||
{
|
{
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderRemoteObject* obj = self->remote;
|
GBinderRemoteObject* obj = self->remote;
|
||||||
GBinderClientTx* tx = g_slice_new0(GBinderClientTx);
|
|
||||||
|
|
||||||
tx->client = gbinder_client_ref(self);
|
if (G_LIKELY(!obj->dead)) {
|
||||||
tx->reply = reply;
|
GBinderClientTx* tx = g_slice_new0(GBinderClientTx);
|
||||||
tx->destroy = destroy;
|
|
||||||
tx->user_data = user_data;
|
|
||||||
|
|
||||||
if (!req) {
|
tx->client = gbinder_client_ref(self);
|
||||||
/* Default empty request (just the header, no parameters) */
|
tx->reply = reply;
|
||||||
req = gbinder_client_cast(self)->basic_req;
|
tx->destroy = destroy;
|
||||||
|
tx->user_data = user_data;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return gbinder_ipc_transact(obj->ipc, obj->handle, code,
|
||||||
|
flags, req, gbinder_client_transact_reply,
|
||||||
|
gbinder_client_transact_destroy, tx);
|
||||||
}
|
}
|
||||||
|
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
|
void
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -38,7 +38,6 @@
|
|||||||
#include "gbinder_types_p.h"
|
#include "gbinder_types_p.h"
|
||||||
|
|
||||||
struct gbinder_client {
|
struct gbinder_client {
|
||||||
const char* iface;
|
|
||||||
GBinderRemoteObject* remote;
|
GBinderRemoteObject* remote;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
#include "gbinder_servicemanager_p.h"
|
#include "gbinder_servicemanager_p.h"
|
||||||
#include "gbinder_rpc_protocol.h"
|
#include "gbinder_rpc_protocol.h"
|
||||||
|
#include "gbinder_servicepoll.h"
|
||||||
|
#include "gbinder_eventloop_p.h"
|
||||||
#include "gbinder_log.h"
|
#include "gbinder_log.h"
|
||||||
|
|
||||||
#include <gbinder_client.h>
|
#include <gbinder_client.h>
|
||||||
@@ -43,13 +45,31 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
typedef GBinderServiceManager GBinderDefaultServiceManager;
|
typedef struct gbinder_defaultservicemanager_watch {
|
||||||
|
GBinderServicePoll* poll;
|
||||||
|
char* name;
|
||||||
|
gulong handler_id;
|
||||||
|
GBinderEventLoopTimeout* notify;
|
||||||
|
} GBinderDefaultServiceManagerWatch;
|
||||||
|
|
||||||
typedef GBinderServiceManagerClass GBinderDefaultServiceManagerClass;
|
typedef GBinderServiceManagerClass GBinderDefaultServiceManagerClass;
|
||||||
|
typedef struct gbinder_defaultservicemanager {
|
||||||
|
GBinderServiceManager manager;
|
||||||
|
GBinderServicePoll* poll;
|
||||||
|
GHashTable* watch_table;
|
||||||
|
} GBinderDefaultServiceManager;
|
||||||
|
|
||||||
G_DEFINE_TYPE(GBinderDefaultServiceManager,
|
G_DEFINE_TYPE(GBinderDefaultServiceManager,
|
||||||
gbinder_defaultservicemanager,
|
gbinder_defaultservicemanager,
|
||||||
GBINDER_TYPE_SERVICEMANAGER)
|
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 {
|
enum gbinder_defaultservicemanager_calls {
|
||||||
GET_SERVICE_TRANSACTION = GBINDER_FIRST_CALL_TRANSACTION,
|
GET_SERVICE_TRANSACTION = GBINDER_FIRST_CALL_TRANSACTION,
|
||||||
CHECK_SERVICE_TRANSACTION,
|
CHECK_SERVICE_TRANSACTION,
|
||||||
@@ -57,8 +77,6 @@ enum gbinder_defaultservicemanager_calls {
|
|||||||
LIST_SERVICES_TRANSACTION
|
LIST_SERVICES_TRANSACTION
|
||||||
};
|
};
|
||||||
|
|
||||||
/* As a special case, ServiceManager's handle is zero */
|
|
||||||
#define DEFAULTSERVICEMANAGER_HANDLE (0)
|
|
||||||
#define DEFAULTSERVICEMANAGER_IFACE "android.os.IServiceManager"
|
#define DEFAULTSERVICEMANAGER_IFACE "android.os.IServiceManager"
|
||||||
|
|
||||||
GBinderServiceManager*
|
GBinderServiceManager*
|
||||||
@@ -66,7 +84,74 @@ gbinder_defaultservicemanager_new(
|
|||||||
const char* dev)
|
const char* dev)
|
||||||
{
|
{
|
||||||
return gbinder_servicemanager_new_with_type
|
return gbinder_servicemanager_new_with_type
|
||||||
(gbinder_defaultservicemanager_get_type(), dev);
|
(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) {
|
||||||
|
gbinder_timeout_remove(watch->notify);
|
||||||
|
watch->notify = NULL;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
watch->notify = NULL;
|
||||||
|
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;
|
||||||
|
|
||||||
|
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(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
|
static
|
||||||
@@ -151,11 +236,61 @@ gbinder_defaultservicemanager_add_service(
|
|||||||
return status;
|
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 = gbinder_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
|
static
|
||||||
void
|
void
|
||||||
gbinder_defaultservicemanager_init(
|
gbinder_defaultservicemanager_init(
|
||||||
GBinderDefaultServiceManager* self)
|
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
|
static
|
||||||
@@ -163,7 +298,6 @@ void
|
|||||||
gbinder_defaultservicemanager_class_init(
|
gbinder_defaultservicemanager_class_init(
|
||||||
GBinderDefaultServiceManagerClass* klass)
|
GBinderDefaultServiceManagerClass* klass)
|
||||||
{
|
{
|
||||||
klass->handle = DEFAULTSERVICEMANAGER_HANDLE;
|
|
||||||
klass->iface = DEFAULTSERVICEMANAGER_IFACE;
|
klass->iface = DEFAULTSERVICEMANAGER_IFACE;
|
||||||
klass->default_device = GBINDER_DEFAULT_BINDER;
|
klass->default_device = GBINDER_DEFAULT_BINDER;
|
||||||
klass->rpc_protocol = &gbinder_rpc_protocol_binder;
|
klass->rpc_protocol = &gbinder_rpc_protocol_binder;
|
||||||
@@ -171,6 +305,11 @@ gbinder_defaultservicemanager_class_init(
|
|||||||
klass->list = gbinder_defaultservicemanager_list;
|
klass->list = gbinder_defaultservicemanager_list;
|
||||||
klass->get_service = gbinder_defaultservicemanager_get_service;
|
klass->get_service = gbinder_defaultservicemanager_get_service;
|
||||||
klass->add_service = gbinder_defaultservicemanager_add_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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -61,9 +61,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
/* Log module */
|
|
||||||
GLOG_MODULE_DEFINE("gbinder");
|
|
||||||
|
|
||||||
/* BINDER_VM_SIZE copied from native/libs/binder/ProcessState.cpp */
|
/* BINDER_VM_SIZE copied from native/libs/binder/ProcessState.cpp */
|
||||||
#define BINDER_VM_SIZE ((1024*1024) - sysconf(_SC_PAGE_SIZE)*2)
|
#define BINDER_VM_SIZE ((1024*1024) - sysconf(_SC_PAGE_SIZE)*2)
|
||||||
|
|
||||||
@@ -288,19 +285,15 @@ gbinder_driver_death_notification(
|
|||||||
guint32 cmd,
|
guint32 cmd,
|
||||||
GBinderRemoteObject* obj)
|
GBinderRemoteObject* obj)
|
||||||
{
|
{
|
||||||
if (G_LIKELY(obj)) {
|
GBinderIoBuf write;
|
||||||
GBinderIoBuf write;
|
guint8 buf[4 + GBINDER_MAX_DEATH_NOTIFICATION_SIZE];
|
||||||
guint8 buf[4 + GBINDER_MAX_DEATH_NOTIFICATION_SIZE];
|
guint32* data = (guint32*)buf;
|
||||||
guint32* data = (guint32*)buf;
|
|
||||||
|
|
||||||
data[0] = cmd;
|
data[0] = cmd;
|
||||||
memset(&write, 0, sizeof(write));
|
memset(&write, 0, sizeof(write));
|
||||||
write.ptr = (uintptr_t)buf;
|
write.ptr = (uintptr_t)buf;
|
||||||
write.size = 4 + self->io->encode_death_notification(data + 1, obj);
|
write.size = 4 + self->io->encode_death_notification(data + 1, obj);
|
||||||
|
return gbinder_driver_write(self, &write) >= 0;
|
||||||
return gbinder_driver_write(self, &write) >= 0;
|
|
||||||
}
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -439,11 +432,10 @@ gbinder_driver_handle_transaction(
|
|||||||
/* Transfer data ownership to the request */
|
/* Transfer data ownership to the request */
|
||||||
if (tx.data && tx.size) {
|
if (tx.data && tx.size) {
|
||||||
gbinder_driver_verbose_dump(' ', (uintptr_t)tx.data, tx.size);
|
gbinder_driver_verbose_dump(' ', (uintptr_t)tx.data, tx.size);
|
||||||
gbinder_remote_request_set_data(req,
|
gbinder_remote_request_set_data(req, tx.code,
|
||||||
gbinder_buffer_new(self, tx.data, tx.size),
|
gbinder_buffer_new(self, tx.data, tx.size, tx.objects));
|
||||||
tx.objects);
|
|
||||||
} else {
|
} else {
|
||||||
g_free(tx.objects);
|
GASSERT(!tx.objects);
|
||||||
gbinder_driver_free_buffer(self, tx.data);
|
gbinder_driver_free_buffer(self, tx.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,11 +447,17 @@ gbinder_driver_handle_transaction(
|
|||||||
tx.code, tx.flags, &status);
|
tx.code, tx.flags, &status);
|
||||||
break;
|
break;
|
||||||
case GBINDER_LOCAL_TRANSACTION_SUPPORTED:
|
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 = h ? gbinder_handler_transact(h, obj, req, tx.code, tx.flags,
|
||||||
|
&status) : gbinder_local_object_handle_transaction(obj, req,
|
||||||
|
tx.code, tx.flags, &status);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
GWARN("Unhandled transaction 0x%08x", tx.code);
|
GWARN("Unhandled transaction %s 0x%08x", iface, tx.code);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,6 +534,7 @@ gbinder_driver_handle_command(
|
|||||||
} else if (cmd == io->br.transaction) {
|
} else if (cmd == io->br.transaction) {
|
||||||
gbinder_driver_handle_transaction(self, reg, handler, data);
|
gbinder_driver_handle_transaction(self, reg, handler, data);
|
||||||
} else if (cmd == io->br.dead_binder) {
|
} else if (cmd == io->br.dead_binder) {
|
||||||
|
guint8 buf[4 + GBINDER_MAX_PTR_COOKIE_SIZE];
|
||||||
guint64 handle = 0;
|
guint64 handle = 0;
|
||||||
GBinderRemoteObject* obj;
|
GBinderRemoteObject* obj;
|
||||||
|
|
||||||
@@ -546,6 +545,8 @@ gbinder_driver_handle_command(
|
|||||||
gbinder_remote_object_handle_death_notification(obj);
|
gbinder_remote_object_handle_death_notification(obj);
|
||||||
gbinder_remote_object_unref(obj);
|
gbinder_remote_object_unref(obj);
|
||||||
}
|
}
|
||||||
|
GVERBOSE("< BC_DEAD_BINDER_DONE %llu", (long long unsigned int)handle);
|
||||||
|
gbinder_driver_cmd_data(self, io->bc.dead_binder_done, data, buf);
|
||||||
} else if (cmd == io->br.clear_death_notification_done) {
|
} else if (cmd == io->br.clear_death_notification_done) {
|
||||||
GVERBOSE("> BR_CLEAR_DEATH_NOTIFICATION_DONE");
|
GVERBOSE("> BR_CLEAR_DEATH_NOTIFICATION_DONE");
|
||||||
} else {
|
} else {
|
||||||
@@ -637,10 +638,9 @@ gbinder_driver_txstatus(
|
|||||||
if (tx.data && tx.size) {
|
if (tx.data && tx.size) {
|
||||||
gbinder_driver_verbose_dump(' ', (uintptr_t)tx.data, tx.size);
|
gbinder_driver_verbose_dump(' ', (uintptr_t)tx.data, tx.size);
|
||||||
gbinder_remote_reply_set_data(reply,
|
gbinder_remote_reply_set_data(reply,
|
||||||
gbinder_buffer_new(self, tx.data, tx.size),
|
gbinder_buffer_new(self, tx.data, tx.size, tx.objects));
|
||||||
tx.objects);
|
|
||||||
} else {
|
} else {
|
||||||
g_free(tx.objects);
|
GASSERT(!tx.objects);
|
||||||
gbinder_driver_free_buffer(self, tx.data);
|
gbinder_driver_free_buffer(self, tx.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -814,8 +814,13 @@ gbinder_driver_request_death_notification(
|
|||||||
GBinderDriver* self,
|
GBinderDriver* self,
|
||||||
GBinderRemoteObject* obj)
|
GBinderRemoteObject* obj)
|
||||||
{
|
{
|
||||||
return gbinder_driver_death_notification
|
if (G_LIKELY(obj)) {
|
||||||
(self, self->io->bc.request_death_notification, obj);
|
GVERBOSE("< BC_REQUEST_DEATH_NOTIFICATION 0x%08x", obj->handle);
|
||||||
|
return gbinder_driver_death_notification(self,
|
||||||
|
self->io->bc.request_death_notification, obj);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@@ -823,8 +828,13 @@ gbinder_driver_clear_death_notification(
|
|||||||
GBinderDriver* self,
|
GBinderDriver* self,
|
||||||
GBinderRemoteObject* obj)
|
GBinderRemoteObject* obj)
|
||||||
{
|
{
|
||||||
return gbinder_driver_death_notification
|
if (G_LIKELY(obj)) {
|
||||||
(self, self->io->bc.clear_death_notification, obj);
|
GVERBOSE("< BC_CLEAR_DEATH_NOTIFICATION 0x%08x", obj->handle);
|
||||||
|
return gbinder_driver_death_notification(self,
|
||||||
|
self->io->bc.clear_death_notification, obj);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@@ -863,6 +873,32 @@ gbinder_driver_release(
|
|||||||
return gbinder_driver_cmd_int32(self, self->io->bc.release, handle);
|
return gbinder_driver_cmd_int32(self, self->io->bc.release, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_driver_close_fds(
|
||||||
|
GBinderDriver* self,
|
||||||
|
void** objects,
|
||||||
|
const void* end)
|
||||||
|
{
|
||||||
|
const GBinderIo* io = self->io;
|
||||||
|
void** ptr;
|
||||||
|
|
||||||
|
/* Caller checks objects for NULL */
|
||||||
|
for (ptr = objects; *ptr; ptr++) {
|
||||||
|
void* obj = *ptr;
|
||||||
|
|
||||||
|
GASSERT(obj < end);
|
||||||
|
if (obj < end) {
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (io->decode_fd_object(obj, (guint8*)end - (guint8*)obj, &fd)) {
|
||||||
|
if (close(fd) < 0) {
|
||||||
|
GWARN("Error closing fd %d: %s", fd, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_driver_free_buffer(
|
gbinder_driver_free_buffer(
|
||||||
GBinderDriver* self,
|
GBinderDriver* self,
|
||||||
@@ -933,6 +969,7 @@ int
|
|||||||
gbinder_driver_transact(
|
gbinder_driver_transact(
|
||||||
GBinderDriver* self,
|
GBinderDriver* self,
|
||||||
GBinderObjectRegistry* reg,
|
GBinderObjectRegistry* reg,
|
||||||
|
GBinderHandler* handler,
|
||||||
guint32 handle,
|
guint32 handle,
|
||||||
guint32 code,
|
guint32 code,
|
||||||
GBinderLocalRequest* req,
|
GBinderLocalRequest* req,
|
||||||
@@ -989,7 +1026,7 @@ gbinder_driver_transact(
|
|||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
txstatus = err;
|
txstatus = err;
|
||||||
} else {
|
} else {
|
||||||
txstatus = gbinder_driver_txstatus(self, reg, NULL, &rb, reply);
|
txstatus = gbinder_driver_txstatus(self, reg, handler, &rb, reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -998,14 +1035,14 @@ gbinder_driver_transact(
|
|||||||
GASSERT(write.consumed == write.size || txstatus > 0);
|
GASSERT(write.consumed == write.size || txstatus > 0);
|
||||||
|
|
||||||
/* Loop until we have handled all the incoming commands */
|
/* Loop until we have handled all the incoming commands */
|
||||||
gbinder_driver_handle_commands(self, reg, NULL, &rb);
|
gbinder_driver_handle_commands(self, reg, handler, &rb);
|
||||||
while (rb.buf.consumed) {
|
while (rb.buf.consumed) {
|
||||||
int err = gbinder_driver_write_read(self, NULL, &rb.buf);
|
int err = gbinder_driver_write_read(self, NULL, &rb.buf);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
txstatus = err;
|
txstatus = err;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
gbinder_driver_handle_commands(self, reg, NULL, &rb);
|
gbinder_driver_handle_commands(self, reg, handler, &rb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1014,6 +1051,28 @@ gbinder_driver_transact(
|
|||||||
return txstatus;
|
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, NULL, handle, protocol->ping_tx,
|
||||||
|
req, reply);
|
||||||
|
|
||||||
|
gbinder_local_request_unref(req);
|
||||||
|
gbinder_remote_reply_unref(reply);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
GBinderLocalRequest*
|
GBinderLocalRequest*
|
||||||
gbinder_driver_local_request_new(
|
gbinder_driver_local_request_new(
|
||||||
GBinderDriver* self,
|
GBinderDriver* self,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -40,95 +40,129 @@ struct pollfd;
|
|||||||
GBinderDriver*
|
GBinderDriver*
|
||||||
gbinder_driver_new(
|
gbinder_driver_new(
|
||||||
const char* dev,
|
const char* dev,
|
||||||
const GBinderRpcProtocol* protocol);
|
const GBinderRpcProtocol* protocol)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderDriver*
|
GBinderDriver*
|
||||||
gbinder_driver_ref(
|
gbinder_driver_ref(
|
||||||
GBinderDriver* driver);
|
GBinderDriver* driver)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_driver_unref(
|
gbinder_driver_unref(
|
||||||
GBinderDriver* driver);
|
GBinderDriver* driver)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
int
|
int
|
||||||
gbinder_driver_fd(
|
gbinder_driver_fd(
|
||||||
GBinderDriver* driver);
|
GBinderDriver* driver)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
int
|
int
|
||||||
gbinder_driver_poll(
|
gbinder_driver_poll(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
struct pollfd* pollfd);
|
struct pollfd* pollfd)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
gbinder_driver_dev(
|
gbinder_driver_dev(
|
||||||
GBinderDriver* driver);
|
GBinderDriver* driver)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
const GBinderIo*
|
const GBinderIo*
|
||||||
gbinder_driver_io(
|
gbinder_driver_io(
|
||||||
GBinderDriver* driver);
|
GBinderDriver* driver)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_driver_request_death_notification(
|
gbinder_driver_request_death_notification(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
GBinderRemoteObject* obj);
|
GBinderRemoteObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_driver_clear_death_notification(
|
gbinder_driver_clear_death_notification(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
GBinderRemoteObject* obj);
|
GBinderRemoteObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_driver_increfs(
|
gbinder_driver_increfs(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
guint32 handle);
|
guint32 handle)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_driver_decrefs(
|
gbinder_driver_decrefs(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
guint32 handle);
|
guint32 handle)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_driver_acquire(
|
gbinder_driver_acquire(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
guint32 handle);
|
guint32 handle)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_driver_release(
|
gbinder_driver_release(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
guint32 handle);
|
guint32 handle)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_driver_close_fds(
|
||||||
|
GBinderDriver* self,
|
||||||
|
void** objects,
|
||||||
|
const void* end)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_driver_free_buffer(
|
gbinder_driver_free_buffer(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
void* buffer);
|
void* buffer)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_driver_enter_looper(
|
gbinder_driver_enter_looper(
|
||||||
GBinderDriver* driver);
|
GBinderDriver* driver)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_driver_exit_looper(
|
gbinder_driver_exit_looper(
|
||||||
GBinderDriver* driver);
|
GBinderDriver* driver)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
int
|
int
|
||||||
gbinder_driver_read(
|
gbinder_driver_read(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
GBinderObjectRegistry* reg,
|
GBinderObjectRegistry* reg,
|
||||||
GBinderHandler* handler);
|
GBinderHandler* handler)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
int
|
int
|
||||||
gbinder_driver_transact(
|
gbinder_driver_transact(
|
||||||
GBinderDriver* driver,
|
GBinderDriver* driver,
|
||||||
GBinderObjectRegistry* reg,
|
GBinderObjectRegistry* reg,
|
||||||
|
GBinderHandler* handler,
|
||||||
guint32 handle,
|
guint32 handle,
|
||||||
guint32 code,
|
guint32 code,
|
||||||
GBinderLocalRequest* request,
|
GBinderLocalRequest* request,
|
||||||
GBinderRemoteReply* reply);
|
GBinderRemoteReply* reply)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
int
|
||||||
|
gbinder_driver_ping(
|
||||||
|
GBinderDriver* driver,
|
||||||
|
GBinderObjectRegistry* reg,
|
||||||
|
guint32 handle)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderLocalRequest*
|
GBinderLocalRequest*
|
||||||
gbinder_driver_local_request_new(
|
gbinder_driver_local_request_new(
|
||||||
GBinderDriver* self,
|
GBinderDriver* self,
|
||||||
const char* iface);
|
const char* iface)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_DRIVER_H */
|
#endif /* GBINDER_DRIVER_H */
|
||||||
|
|
||||||
|
|||||||
347
src/gbinder_eventloop.c
Normal file
347
src/gbinder_eventloop.c
Normal file
@@ -0,0 +1,347 @@
|
|||||||
|
/*
|
||||||
|
* 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_eventloop_p.h"
|
||||||
|
|
||||||
|
#include <gutil_macros.h>
|
||||||
|
|
||||||
|
#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
|
||||||
|
};
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
|
*/
|
||||||
104
src/gbinder_eventloop_p.h
Normal file
104
src/gbinder_eventloop_p.h
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* 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_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)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
GBinderEventLoopTimeout*
|
||||||
|
gbinder_idle_add(
|
||||||
|
GSourceFunc func,
|
||||||
|
gpointer data)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_timeout_remove(
|
||||||
|
GBinderEventLoopTimeout* timeout)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
GBinderEventLoopCallback*
|
||||||
|
gbinder_idle_callback_new(
|
||||||
|
GBinderEventLoopCallbackFunc func,
|
||||||
|
gpointer data,
|
||||||
|
GDestroyNotify destroy)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
GBinderEventLoopCallback*
|
||||||
|
gbinder_idle_callback_schedule_new(
|
||||||
|
GBinderEventLoopCallbackFunc func,
|
||||||
|
gpointer data,
|
||||||
|
GDestroyNotify destroy)
|
||||||
|
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;
|
||||||
|
|
||||||
|
#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-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -35,20 +35,36 @@
|
|||||||
#include "gbinder_log.h"
|
#include "gbinder_log.h"
|
||||||
|
|
||||||
#include <gbinder_client.h>
|
#include <gbinder_client.h>
|
||||||
|
#include <gbinder_local_object.h>
|
||||||
#include <gbinder_local_request.h>
|
#include <gbinder_local_request.h>
|
||||||
#include <gbinder_remote_reply.h>
|
#include <gbinder_remote_reply.h>
|
||||||
|
#include <gbinder_remote_request.h>
|
||||||
#include <gbinder_reader.h>
|
#include <gbinder_reader.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
typedef GBinderServiceManager GBinderHwServiceManager;
|
typedef struct gbinder_hwservicemanager_watch {
|
||||||
|
char* name;
|
||||||
|
GBinderLocalObject* callback;
|
||||||
|
} GBinderHwServiceManagerWatch;
|
||||||
|
|
||||||
typedef GBinderServiceManagerClass GBinderHwServiceManagerClass;
|
typedef GBinderServiceManagerClass GBinderHwServiceManagerClass;
|
||||||
|
typedef struct gbinder_hwservicemanager {
|
||||||
|
GBinderServiceManager manager;
|
||||||
|
GHashTable* watch_table;
|
||||||
|
} GBinderHwServiceManager;
|
||||||
|
|
||||||
G_DEFINE_TYPE(GBinderHwServiceManager,
|
G_DEFINE_TYPE(GBinderHwServiceManager,
|
||||||
gbinder_hwservicemanager,
|
gbinder_hwservicemanager,
|
||||||
GBINDER_TYPE_SERVICEMANAGER)
|
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)
|
||||||
|
|
||||||
enum gbinder_hwservicemanager_calls {
|
enum gbinder_hwservicemanager_calls {
|
||||||
GET_TRANSACTION = GBINDER_FIRST_CALL_TRANSACTION,
|
GET_TRANSACTION = GBINDER_FIRST_CALL_TRANSACTION,
|
||||||
ADD_TRANSACTION,
|
ADD_TRANSACTION,
|
||||||
@@ -60,9 +76,74 @@ enum gbinder_hwservicemanager_calls {
|
|||||||
REGISTER_PASSTHROUGH_CLIENT_TRANSACTION
|
REGISTER_PASSTHROUGH_CLIENT_TRANSACTION
|
||||||
};
|
};
|
||||||
|
|
||||||
/* As a special case, ServiceManager's handle is zero */
|
enum gbinder_hwservicemanager_notifications {
|
||||||
#define HWSERVICEMANAGER_HANDLE (0)
|
ON_REGISTRATION_TRANSACTION = GBINDER_FIRST_CALL_TRANSACTION
|
||||||
|
};
|
||||||
|
|
||||||
#define HWSERVICEMANAGER_IFACE "android.hidl.manager@1.0::IServiceManager"
|
#define HWSERVICEMANAGER_IFACE "android.hidl.manager@1.0::IServiceManager"
|
||||||
|
#define HWSERVICEMANAGER_NOTIFICATION_IFACE \
|
||||||
|
"android.hidl.manager@1.0::IServiceNotification"
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_hwservicemanager_handle_registration(
|
||||||
|
GBinderHwServiceManager* self,
|
||||||
|
GBinderReader* reader)
|
||||||
|
{
|
||||||
|
char* fqname = gbinder_reader_read_hidl_string(reader);
|
||||||
|
char* name = gbinder_reader_read_hidl_string(reader);
|
||||||
|
gboolean preexisting;
|
||||||
|
|
||||||
|
/* (string fqName, string name, bool preexisting) */
|
||||||
|
if (fqname && name && gbinder_reader_read_bool(reader, &preexisting) &&
|
||||||
|
gbinder_reader_at_end(reader)) {
|
||||||
|
char* full_name = g_strconcat(fqname, "/", name, NULL);
|
||||||
|
|
||||||
|
GDEBUG("%s %s", full_name, preexisting ? "true" : "false");
|
||||||
|
gbinder_servicemanager_service_registered(&self->manager, full_name);
|
||||||
|
g_free(full_name);
|
||||||
|
} else {
|
||||||
|
GWARN("Failed to parse IServiceNotification::onRegistration payload");
|
||||||
|
}
|
||||||
|
g_free(fqname);
|
||||||
|
g_free(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
GBinderLocalReply*
|
||||||
|
gbinder_hwservicemanager_notification(
|
||||||
|
GBinderLocalObject* obj,
|
||||||
|
GBinderRemoteRequest* req,
|
||||||
|
guint code,
|
||||||
|
guint flags,
|
||||||
|
int* status,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
GBinderHwServiceManager* self = GBINDER_HWSERVICEMANAGER(user_data);
|
||||||
|
const char* iface = gbinder_remote_request_interface(req);
|
||||||
|
|
||||||
|
if (!g_strcmp0(iface, HWSERVICEMANAGER_NOTIFICATION_IFACE)) {
|
||||||
|
GBinderReader reader;
|
||||||
|
|
||||||
|
gbinder_remote_request_init_reader(req, &reader);
|
||||||
|
switch (code) {
|
||||||
|
case ON_REGISTRATION_TRANSACTION:
|
||||||
|
GDEBUG(HWSERVICEMANAGER_NOTIFICATION_IFACE " %u onRegistration",
|
||||||
|
code);
|
||||||
|
gbinder_hwservicemanager_handle_registration(self, &reader);
|
||||||
|
*status = GBINDER_STATUS_OK;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
GDEBUG(HWSERVICEMANAGER_NOTIFICATION_IFACE " %u", code);
|
||||||
|
*status = GBINDER_STATUS_FAILED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GDEBUG("%s %u", iface, code);
|
||||||
|
*status = GBINDER_STATUS_FAILED;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
GBinderServiceManager*
|
GBinderServiceManager*
|
||||||
gbinder_hwservicemanager_new(
|
gbinder_hwservicemanager_new(
|
||||||
@@ -75,7 +156,7 @@ gbinder_hwservicemanager_new(
|
|||||||
static
|
static
|
||||||
char**
|
char**
|
||||||
gbinder_hwservicemanager_list(
|
gbinder_hwservicemanager_list(
|
||||||
GBinderHwServiceManager* self)
|
GBinderServiceManager* self)
|
||||||
{
|
{
|
||||||
GBinderLocalRequest* req = gbinder_client_new_request(self->client);
|
GBinderLocalRequest* req = gbinder_client_new_request(self->client);
|
||||||
GBinderRemoteReply* reply = gbinder_client_transact_sync_reply
|
GBinderRemoteReply* reply = gbinder_client_transact_sync_reply
|
||||||
@@ -111,6 +192,7 @@ gbinder_hwservicemanager_get_service(
|
|||||||
/* e.g. "android.hardware.radio@1.1::IRadio/slot1" */
|
/* e.g. "android.hardware.radio@1.1::IRadio/slot1" */
|
||||||
const char* sep = strchr(fqinstance, '/');
|
const char* sep = strchr(fqinstance, '/');
|
||||||
GBinderRemoteObject* obj = NULL;
|
GBinderRemoteObject* obj = NULL;
|
||||||
|
|
||||||
if (sep) {
|
if (sep) {
|
||||||
GBinderRemoteReply* reply;
|
GBinderRemoteReply* reply;
|
||||||
GBinderLocalRequest* req = gbinder_client_new_request(self->client);
|
GBinderLocalRequest* req = gbinder_client_new_request(self->client);
|
||||||
@@ -170,11 +252,123 @@ gbinder_hwservicemanager_add_service(
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_hwservicemanager_watch_free(
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
GBinderHwServiceManagerWatch* watch = data;
|
||||||
|
|
||||||
|
g_free(watch->name);
|
||||||
|
gbinder_local_object_drop(watch->callback);
|
||||||
|
g_free(watch);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
GBINDER_SERVICEMANAGER_NAME_CHECK
|
||||||
|
gbinder_hwservicemanager_check_name(
|
||||||
|
GBinderServiceManager* self,
|
||||||
|
const char* name)
|
||||||
|
{
|
||||||
|
if (name) {
|
||||||
|
const gsize len = strlen(name);
|
||||||
|
static const char allowed_chars[] = "./0123456789:@"
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
"abcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
|
if (len && strspn(name, allowed_chars) == len) {
|
||||||
|
return strchr(name, '/') ?
|
||||||
|
GBINDER_SERVICEMANAGER_NAME_NORMALIZE :
|
||||||
|
GBINDER_SERVICEMANAGER_NAME_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return GBINDER_SERVICEMANAGER_NAME_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
char*
|
||||||
|
gbinder_hwservicemanager_normalize_name(
|
||||||
|
GBinderServiceManager* self,
|
||||||
|
const char* name)
|
||||||
|
{
|
||||||
|
/* Slash must be there, see gbinder_hwservicemanager_check_name() above */
|
||||||
|
return g_strndup(name, strchr(name, '/') - name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
gbinder_hwservicemanager_watch(
|
||||||
|
GBinderServiceManager* manager,
|
||||||
|
const char* name)
|
||||||
|
{
|
||||||
|
GBinderHwServiceManager* self = GBINDER_HWSERVICEMANAGER(manager);
|
||||||
|
GBinderLocalRequest* req = gbinder_client_new_request(manager->client);
|
||||||
|
GBinderRemoteReply* reply;
|
||||||
|
GBinderHwServiceManagerWatch* watch =
|
||||||
|
g_new0(GBinderHwServiceManagerWatch, 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);
|
||||||
|
g_hash_table_replace(self->watch_table, watch->name, watch);
|
||||||
|
|
||||||
|
/* registerForNotifications(string fqName, string name,
|
||||||
|
* IServiceNotification callback) generates (bool success); */
|
||||||
|
gbinder_local_request_append_hidl_string(req, name);
|
||||||
|
gbinder_local_request_append_hidl_string(req, "");
|
||||||
|
gbinder_local_request_append_local_object(req, watch->callback);
|
||||||
|
reply = gbinder_client_transact_sync_reply(manager->client,
|
||||||
|
REGISTER_FOR_NOTIFICATIONS_TRANSACTION, req, &status);
|
||||||
|
|
||||||
|
if (status == GBINDER_STATUS_OK && reply) {
|
||||||
|
GBinderReader reader;
|
||||||
|
|
||||||
|
gbinder_remote_reply_init_reader(reply, &reader);
|
||||||
|
if (gbinder_reader_read_int32(&reader, &status) &&
|
||||||
|
status == GBINDER_STATUS_OK) {
|
||||||
|
gbinder_reader_read_bool(&reader, &success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gbinder_remote_reply_unref(reply);
|
||||||
|
gbinder_local_request_unref(req);
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
/* unwatch() won't be called if we return FALSE */
|
||||||
|
g_hash_table_remove(self->watch_table, watch->name);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_hwservicemanager_unwatch(
|
||||||
|
GBinderServiceManager* manager,
|
||||||
|
const char* name)
|
||||||
|
{
|
||||||
|
g_hash_table_remove(GBINDER_HWSERVICEMANAGER(manager)->watch_table, name);
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
gbinder_hwservicemanager_init(
|
gbinder_hwservicemanager_init(
|
||||||
GBinderHwServiceManager* self)
|
GBinderHwServiceManager* self)
|
||||||
{
|
{
|
||||||
|
self->watch_table = g_hash_table_new_full(g_str_hash, g_str_equal,
|
||||||
|
NULL, gbinder_hwservicemanager_watch_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_hwservicemanager_finalize(
|
||||||
|
GObject* object)
|
||||||
|
{
|
||||||
|
GBinderHwServiceManager* self = GBINDER_HWSERVICEMANAGER(object);
|
||||||
|
|
||||||
|
g_hash_table_destroy(self->watch_table);
|
||||||
|
G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -182,7 +376,6 @@ void
|
|||||||
gbinder_hwservicemanager_class_init(
|
gbinder_hwservicemanager_class_init(
|
||||||
GBinderHwServiceManagerClass* klass)
|
GBinderHwServiceManagerClass* klass)
|
||||||
{
|
{
|
||||||
klass->handle = HWSERVICEMANAGER_HANDLE;
|
|
||||||
klass->iface = HWSERVICEMANAGER_IFACE;
|
klass->iface = HWSERVICEMANAGER_IFACE;
|
||||||
klass->default_device = GBINDER_DEFAULT_HWBINDER;
|
klass->default_device = GBINDER_DEFAULT_HWBINDER;
|
||||||
klass->rpc_protocol = &gbinder_rpc_protocol_hwbinder;
|
klass->rpc_protocol = &gbinder_rpc_protocol_hwbinder;
|
||||||
@@ -190,6 +383,11 @@ gbinder_hwservicemanager_class_init(
|
|||||||
klass->list = gbinder_hwservicemanager_list;
|
klass->list = gbinder_hwservicemanager_list;
|
||||||
klass->get_service = gbinder_hwservicemanager_get_service;
|
klass->get_service = gbinder_hwservicemanager_get_service;
|
||||||
klass->add_service = gbinder_hwservicemanager_add_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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -128,9 +128,13 @@ GBINDER_IO_FN(encode_local_object)(
|
|||||||
struct flat_binder_object* dest = out;
|
struct flat_binder_object* dest = out;
|
||||||
|
|
||||||
memset(dest, 0, sizeof(*dest));
|
memset(dest, 0, sizeof(*dest));
|
||||||
dest->hdr.type = obj ? BINDER_TYPE_BINDER : BINDER_TYPE_WEAK_HANDLE;
|
if (obj) {
|
||||||
dest->flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
|
dest->hdr.type = BINDER_TYPE_BINDER;
|
||||||
dest->binder = (uintptr_t)obj;
|
dest->flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
|
||||||
|
dest->binder = (uintptr_t)obj;
|
||||||
|
} else {
|
||||||
|
dest->hdr.type = BINDER_TYPE_WEAK_BINDER;
|
||||||
|
}
|
||||||
return sizeof(*dest);
|
return sizeof(*dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +157,21 @@ GBINDER_IO_FN(encode_remote_object)(
|
|||||||
return sizeof(*dest);
|
return sizeof(*dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
guint
|
||||||
|
GBINDER_IO_FN(encode_fd_object)(
|
||||||
|
void* out,
|
||||||
|
int fd)
|
||||||
|
{
|
||||||
|
struct flat_binder_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;
|
||||||
|
return sizeof(*dest);
|
||||||
|
}
|
||||||
|
|
||||||
/* Encodes binder_buffer_object */
|
/* Encodes binder_buffer_object */
|
||||||
static
|
static
|
||||||
guint
|
guint
|
||||||
@@ -394,7 +413,7 @@ guint
|
|||||||
GBINDER_IO_FN(decode_buffer_object)(
|
GBINDER_IO_FN(decode_buffer_object)(
|
||||||
GBinderBuffer* buf,
|
GBinderBuffer* buf,
|
||||||
gsize offset,
|
gsize offset,
|
||||||
GBinderBuffer** out)
|
GBinderIoBufferObject* out)
|
||||||
{
|
{
|
||||||
const void* data = (guint8*)buf->data + offset;
|
const void* data = (guint8*)buf->data + offset;
|
||||||
const gsize size = (offset < buf->size) ? (buf->size - offset) : 0;
|
const gsize size = (offset < buf->size) ? (buf->size - offset) : 0;
|
||||||
@@ -402,12 +421,36 @@ GBINDER_IO_FN(decode_buffer_object)(
|
|||||||
|
|
||||||
if (size >= sizeof(*flat) && flat->hdr.type == BINDER_TYPE_PTR) {
|
if (size >= sizeof(*flat) && flat->hdr.type == BINDER_TYPE_PTR) {
|
||||||
if (out) {
|
if (out) {
|
||||||
*out = gbinder_buffer_new_with_parent(buf,
|
out->data = (void*)(uintptr_t)flat->buffer;
|
||||||
(void*)(uintptr_t)flat->buffer, flat->length);
|
out->size = (gsize)flat->length;
|
||||||
|
out->parent_offset = (gsize)flat->parent_offset;
|
||||||
|
out->has_parent = (flat->flags & BINDER_BUFFER_FLAG_HAS_PARENT) ?
|
||||||
|
TRUE : FALSE;
|
||||||
}
|
}
|
||||||
return sizeof(*flat);
|
return sizeof(*flat);
|
||||||
}
|
}
|
||||||
if (out) *out = NULL;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
guint
|
||||||
|
GBINDER_IO_FN(decode_fd_object)(
|
||||||
|
const void* data,
|
||||||
|
gsize size,
|
||||||
|
int* fd)
|
||||||
|
{
|
||||||
|
const struct flat_binder_object* obj = data;
|
||||||
|
|
||||||
|
if (size >= sizeof(*obj)) {
|
||||||
|
switch (obj->hdr.type) {
|
||||||
|
case BINDER_TYPE_FD:
|
||||||
|
if (fd) *fd = obj->handle;
|
||||||
|
return sizeof(*obj);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fd) *fd = -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,6 +509,7 @@ const GBinderIo GBINDER_IO_PREFIX = {
|
|||||||
.encode_pointer = GBINDER_IO_FN(encode_pointer),
|
.encode_pointer = GBINDER_IO_FN(encode_pointer),
|
||||||
.encode_local_object = GBINDER_IO_FN(encode_local_object),
|
.encode_local_object = GBINDER_IO_FN(encode_local_object),
|
||||||
.encode_remote_object = GBINDER_IO_FN(encode_remote_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_buffer_object = GBINDER_IO_FN(encode_buffer_object),
|
||||||
.encode_death_notification = GBINDER_IO_FN(encode_death_notification),
|
.encode_death_notification = GBINDER_IO_FN(encode_death_notification),
|
||||||
.encode_transaction = GBINDER_IO_FN(encode_transaction),
|
.encode_transaction = GBINDER_IO_FN(encode_transaction),
|
||||||
@@ -478,6 +522,7 @@ const GBinderIo GBINDER_IO_PREFIX = {
|
|||||||
.decode_binder_ptr_cookie = GBINDER_IO_FN(decode_binder_ptr_cookie),
|
.decode_binder_ptr_cookie = GBINDER_IO_FN(decode_binder_ptr_cookie),
|
||||||
.decode_binder_object = GBINDER_IO_FN(decode_binder_object),
|
.decode_binder_object = GBINDER_IO_FN(decode_binder_object),
|
||||||
.decode_buffer_object = GBINDER_IO_FN(decode_buffer_object),
|
.decode_buffer_object = GBINDER_IO_FN(decode_buffer_object),
|
||||||
|
.decode_fd_object = GBINDER_IO_FN(decode_fd_object),
|
||||||
|
|
||||||
/* ioctl wrappers */
|
/* ioctl wrappers */
|
||||||
.write_read = GBINDER_IO_FN(write_read)
|
.write_read = GBINDER_IO_FN(write_read)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -43,6 +43,13 @@ typedef struct gbinder_io_buf {
|
|||||||
gsize consumed;
|
gsize consumed;
|
||||||
} GBinderIoBuf;
|
} GBinderIoBuf;
|
||||||
|
|
||||||
|
typedef struct gbinder_io_buffer_object {
|
||||||
|
void* data;
|
||||||
|
gsize size;
|
||||||
|
gsize parent_offset;
|
||||||
|
gboolean has_parent;
|
||||||
|
} GBinderIoBufferObject;
|
||||||
|
|
||||||
typedef struct gbinder_io_tx_data {
|
typedef struct gbinder_io_tx_data {
|
||||||
int status;
|
int status;
|
||||||
guint32 code;
|
guint32 code;
|
||||||
@@ -131,6 +138,7 @@ struct gbinder_io {
|
|||||||
#define GBINDER_MAX_BINDER_OBJECT_SIZE (24)
|
#define GBINDER_MAX_BINDER_OBJECT_SIZE (24)
|
||||||
guint (*encode_local_object)(void* out, GBinderLocalObject* obj);
|
guint (*encode_local_object)(void* out, GBinderLocalObject* obj);
|
||||||
guint (*encode_remote_object)(void* out, GBinderRemoteObject* obj);
|
guint (*encode_remote_object)(void* out, GBinderRemoteObject* obj);
|
||||||
|
guint (*encode_fd_object)(void* out, int fd);
|
||||||
|
|
||||||
/* Encode binder_buffer_object */
|
/* Encode binder_buffer_object */
|
||||||
#define GBINDER_MAX_BUFFER_OBJECT_SIZE (40)
|
#define GBINDER_MAX_BUFFER_OBJECT_SIZE (40)
|
||||||
@@ -164,16 +172,17 @@ struct gbinder_io {
|
|||||||
void* (*decode_binder_ptr_cookie)(const void* data);
|
void* (*decode_binder_ptr_cookie)(const void* data);
|
||||||
guint (*decode_cookie)(const void* data, guint64* cookie);
|
guint (*decode_cookie)(const void* data, guint64* cookie);
|
||||||
guint (*decode_binder_object)(const void* data, gsize size,
|
guint (*decode_binder_object)(const void* data, gsize size,
|
||||||
GBinderObjectRegistry* reg, GBinderRemoteObject** obj);
|
GBinderObjectRegistry* reg, GBinderRemoteObject** obj);
|
||||||
guint (*decode_buffer_object)(GBinderBuffer* buf, gsize offset,
|
guint (*decode_buffer_object)(GBinderBuffer* buf, gsize offset,
|
||||||
GBinderBuffer** out);
|
GBinderIoBufferObject* out);
|
||||||
|
guint (*decode_fd_object)(const void* data, gsize size, int* fd);
|
||||||
|
|
||||||
/* ioctl wrappers */
|
/* ioctl wrappers */
|
||||||
int (*write_read)(int fd, GBinderIoBuf* write, GBinderIoBuf* read);
|
int (*write_read)(int fd, GBinderIoBuf* write, GBinderIoBuf* read);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const GBinderIo gbinder_io_32;
|
extern const GBinderIo gbinder_io_32 GBINDER_INTERNAL;
|
||||||
extern const GBinderIo gbinder_io_64;
|
extern const GBinderIo gbinder_io_64 GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_IO_H */
|
#endif /* GBINDER_IO_H */
|
||||||
|
|
||||||
|
|||||||
1080
src/gbinder_ipc.c
1080
src/gbinder_ipc.c
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -42,7 +42,6 @@ struct gbinder_ipc {
|
|||||||
GObject object;
|
GObject object;
|
||||||
GBinderIpcPriv* priv;
|
GBinderIpcPriv* priv;
|
||||||
GBinderDriver* driver;
|
GBinderDriver* driver;
|
||||||
GUtilIdlePool* pool;
|
|
||||||
const char* dev;
|
const char* dev;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,36 +69,48 @@ void
|
|||||||
|
|
||||||
GBinderIpc*
|
GBinderIpc*
|
||||||
gbinder_ipc_new(
|
gbinder_ipc_new(
|
||||||
const char* dev,
|
const char* dev,
|
||||||
const GBinderRpcProtocol* protocol);
|
const GBinderRpcProtocol* protocol)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderIpc*
|
GBinderIpc*
|
||||||
gbinder_ipc_ref(
|
gbinder_ipc_ref(
|
||||||
GBinderIpc* ipc);
|
GBinderIpc* ipc)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_ipc_unref(
|
gbinder_ipc_unref(
|
||||||
GBinderIpc* ipc);
|
GBinderIpc* ipc)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_ipc_looper_check(
|
gbinder_ipc_looper_check(
|
||||||
GBinderIpc* ipc);
|
GBinderIpc* ipc)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderObjectRegistry*
|
GBinderObjectRegistry*
|
||||||
gbinder_ipc_object_registry(
|
gbinder_ipc_object_registry(
|
||||||
GBinderIpc* ipc);
|
GBinderIpc* ipc)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderLocalObject*
|
void
|
||||||
gbinder_ipc_new_local_object(
|
gbinder_ipc_register_local_object(
|
||||||
GBinderIpc* ipc,
|
GBinderIpc* ipc,
|
||||||
const char* iface,
|
GBinderLocalObject* obj)
|
||||||
GBinderLocalTransactFunc txproc,
|
GBINDER_INTERNAL;
|
||||||
void* data);
|
|
||||||
|
|
||||||
GBinderRemoteObject*
|
GBinderRemoteObject*
|
||||||
gbinder_ipc_get_remote_object(
|
gbinder_ipc_get_remote_object(
|
||||||
GBinderIpc* ipc,
|
GBinderIpc* ipc,
|
||||||
guint32 handle);
|
guint32 handle,
|
||||||
|
gboolean maybe_dead)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_ipc_invalidate_remote_handle(
|
||||||
|
GBinderIpc* ipc,
|
||||||
|
guint32 handle)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderRemoteReply*
|
GBinderRemoteReply*
|
||||||
gbinder_ipc_transact_sync_reply(
|
gbinder_ipc_transact_sync_reply(
|
||||||
@@ -107,14 +118,16 @@ gbinder_ipc_transact_sync_reply(
|
|||||||
guint32 handle,
|
guint32 handle,
|
||||||
guint32 code,
|
guint32 code,
|
||||||
GBinderLocalRequest* req,
|
GBinderLocalRequest* req,
|
||||||
int* status);
|
int* status)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
int
|
int
|
||||||
gbinder_ipc_transact_sync_oneway(
|
gbinder_ipc_transact_sync_oneway(
|
||||||
GBinderIpc* ipc,
|
GBinderIpc* ipc,
|
||||||
guint32 handle,
|
guint32 handle,
|
||||||
guint32 code,
|
guint32 code,
|
||||||
GBinderLocalRequest* req);
|
GBinderLocalRequest* req)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gulong
|
gulong
|
||||||
gbinder_ipc_transact(
|
gbinder_ipc_transact(
|
||||||
@@ -125,7 +138,8 @@ gbinder_ipc_transact(
|
|||||||
GBinderLocalRequest* req,
|
GBinderLocalRequest* req,
|
||||||
GBinderIpcReplyFunc func,
|
GBinderIpcReplyFunc func,
|
||||||
GDestroyNotify destroy,
|
GDestroyNotify destroy,
|
||||||
void* user_data);
|
void* user_data)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gulong
|
gulong
|
||||||
gbinder_ipc_transact_custom(
|
gbinder_ipc_transact_custom(
|
||||||
@@ -133,24 +147,35 @@ gbinder_ipc_transact_custom(
|
|||||||
GBinderIpcTxFunc exec,
|
GBinderIpcTxFunc exec,
|
||||||
GBinderIpcTxFunc done,
|
GBinderIpcTxFunc done,
|
||||||
GDestroyNotify destroy,
|
GDestroyNotify destroy,
|
||||||
void* user_data);
|
void* user_data)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_ipc_cancel(
|
gbinder_ipc_cancel(
|
||||||
GBinderIpc* ipc,
|
GBinderIpc* ipc,
|
||||||
gulong id);
|
gulong id)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
/* Internal for GBinderLocalObject */
|
/* Internal for GBinderLocalObject */
|
||||||
void
|
void
|
||||||
gbinder_ipc_local_object_disposed(
|
gbinder_ipc_local_object_disposed(
|
||||||
GBinderIpc* self,
|
GBinderIpc* self,
|
||||||
GBinderLocalObject* obj);
|
GBinderLocalObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
/* Internal for GBinderRemoteObject */
|
/* Internal for GBinderRemoteObject */
|
||||||
void
|
void
|
||||||
gbinder_ipc_remote_object_disposed(
|
gbinder_ipc_remote_object_disposed(
|
||||||
GBinderIpc* self,
|
GBinderIpc* self,
|
||||||
GBinderRemoteObject* obj);
|
GBinderRemoteObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
/* Declared for unit tests */
|
||||||
|
__attribute__((destructor))
|
||||||
|
void
|
||||||
|
gbinder_ipc_exit(
|
||||||
|
void)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_IPC_H */
|
#endif /* GBINDER_IPC_H */
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -30,6 +30,8 @@
|
|||||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
||||||
|
|
||||||
#include "gbinder_driver.h"
|
#include "gbinder_driver.h"
|
||||||
#include "gbinder_ipc.h"
|
#include "gbinder_ipc.h"
|
||||||
#include "gbinder_local_object_p.h"
|
#include "gbinder_local_object_p.h"
|
||||||
@@ -38,11 +40,13 @@
|
|||||||
#include "gbinder_writer.h"
|
#include "gbinder_writer.h"
|
||||||
#include "gbinder_log.h"
|
#include "gbinder_log.h"
|
||||||
|
|
||||||
|
#include <gutil_strv.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
struct gbinder_local_object_priv {
|
struct gbinder_local_object_priv {
|
||||||
GMainContext* context;
|
GMainContext* context;
|
||||||
char* iface;
|
char** ifaces;
|
||||||
GBinderLocalTransactFunc txproc;
|
GBinderLocalTransactFunc txproc;
|
||||||
void* user_data;
|
void* user_data;
|
||||||
};
|
};
|
||||||
@@ -53,6 +57,13 @@ G_DEFINE_TYPE(GBinderLocalObject, gbinder_local_object, G_TYPE_OBJECT)
|
|||||||
G_TYPE_INSTANCE_GET_CLASS((obj), GBINDER_TYPE_LOCAL_OBJECT, \
|
G_TYPE_INSTANCE_GET_CLASS((obj), GBINDER_TYPE_LOCAL_OBJECT, \
|
||||||
GBinderLocalObjectClass)
|
GBinderLocalObjectClass)
|
||||||
|
|
||||||
|
typedef
|
||||||
|
GBinderLocalReply*
|
||||||
|
(*GBinderLocalObjectTxHandler)(
|
||||||
|
GBinderLocalObject* self,
|
||||||
|
GBinderRemoteRequest* req,
|
||||||
|
int* status);
|
||||||
|
|
||||||
enum gbinder_local_object_signal {
|
enum gbinder_local_object_signal {
|
||||||
SIGNAL_WEAK_REFS_CHANGED,
|
SIGNAL_WEAK_REFS_CHANGED,
|
||||||
SIGNAL_STRONG_REFS_CHANGED,
|
SIGNAL_STRONG_REFS_CHANGED,
|
||||||
@@ -78,6 +89,9 @@ gbinder_local_object_default_can_handle_transaction(
|
|||||||
guint code)
|
guint code)
|
||||||
{
|
{
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
case GBINDER_PING_TRANSACTION:
|
||||||
|
case GBINDER_INTERFACE_TRANSACTION:
|
||||||
|
return GBINDER_LOCAL_TRANSACTION_LOOPER;
|
||||||
case HIDL_PING_TRANSACTION:
|
case HIDL_PING_TRANSACTION:
|
||||||
case HIDL_GET_DESCRIPTOR_TRANSACTION:
|
case HIDL_GET_DESCRIPTOR_TRANSACTION:
|
||||||
case HIDL_DESCRIPTOR_CHAIN_TRANSACTION:
|
case HIDL_DESCRIPTOR_CHAIN_TRANSACTION:
|
||||||
@@ -110,6 +124,39 @@ gbinder_local_object_default_handle_transaction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
GBinderLocalReply*
|
||||||
|
gbinder_local_object_ping_transaction(
|
||||||
|
GBinderLocalObject* self,
|
||||||
|
GBinderRemoteRequest* req,
|
||||||
|
int* status)
|
||||||
|
{
|
||||||
|
const GBinderIo* io = gbinder_local_object_io(self);
|
||||||
|
GBinderLocalReply* reply = gbinder_local_reply_new(io);
|
||||||
|
|
||||||
|
GVERBOSE(" PING_TRANSACTION");
|
||||||
|
gbinder_local_reply_append_int32(reply, GBINDER_STATUS_OK);
|
||||||
|
*status = GBINDER_STATUS_OK;
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
GBinderLocalReply*
|
||||||
|
gbinder_local_object_interface_transaction(
|
||||||
|
GBinderLocalObject* self,
|
||||||
|
GBinderRemoteRequest* req,
|
||||||
|
int* status)
|
||||||
|
{
|
||||||
|
const GBinderIo* io = gbinder_local_object_io(self);
|
||||||
|
GBinderLocalObjectPriv* priv = self->priv;
|
||||||
|
GBinderLocalReply* reply = gbinder_local_reply_new(io);
|
||||||
|
|
||||||
|
GVERBOSE(" INTERFACE_TRANSACTION");
|
||||||
|
gbinder_local_reply_append_string16(reply, priv->ifaces[0]);
|
||||||
|
*status = GBINDER_STATUS_OK;
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
GBinderLocalReply*
|
GBinderLocalReply*
|
||||||
gbinder_local_object_hidl_ping_transaction(
|
gbinder_local_object_hidl_ping_transaction(
|
||||||
@@ -120,12 +167,10 @@ gbinder_local_object_hidl_ping_transaction(
|
|||||||
/*android.hidl.base@1.0::IBase interfaceDescriptor() */
|
/*android.hidl.base@1.0::IBase interfaceDescriptor() */
|
||||||
const GBinderIo* io = gbinder_local_object_io(self);
|
const GBinderIo* io = gbinder_local_object_io(self);
|
||||||
GBinderLocalReply* reply = gbinder_local_reply_new(io);
|
GBinderLocalReply* reply = gbinder_local_reply_new(io);
|
||||||
GBinderWriter writer;
|
|
||||||
|
|
||||||
GVERBOSE(" HIDL_PING_TRANSACTION \"%s\"",
|
GVERBOSE(" HIDL_PING_TRANSACTION \"%s\"",
|
||||||
gbinder_remote_request_interface(req));
|
gbinder_remote_request_interface(req));
|
||||||
gbinder_local_reply_init_writer(reply, &writer);
|
gbinder_local_reply_append_int32(reply, GBINDER_STATUS_OK);
|
||||||
gbinder_writer_append_int32(&writer, GBINDER_STATUS_OK);
|
|
||||||
*status = GBINDER_STATUS_OK;
|
*status = GBINDER_STATUS_OK;
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
@@ -139,6 +184,7 @@ gbinder_local_object_hidl_get_descriptor_transaction(
|
|||||||
{
|
{
|
||||||
/*android.hidl.base@1.0::IBase interfaceDescriptor() */
|
/*android.hidl.base@1.0::IBase interfaceDescriptor() */
|
||||||
const GBinderIo* io = gbinder_local_object_io(self);
|
const GBinderIo* io = gbinder_local_object_io(self);
|
||||||
|
GBinderLocalObjectPriv* priv = self->priv;
|
||||||
GBinderLocalReply* reply = gbinder_local_reply_new(io);
|
GBinderLocalReply* reply = gbinder_local_reply_new(io);
|
||||||
GBinderWriter writer;
|
GBinderWriter writer;
|
||||||
|
|
||||||
@@ -146,8 +192,7 @@ gbinder_local_object_hidl_get_descriptor_transaction(
|
|||||||
gbinder_remote_request_interface(req));
|
gbinder_remote_request_interface(req));
|
||||||
gbinder_local_reply_init_writer(reply, &writer);
|
gbinder_local_reply_init_writer(reply, &writer);
|
||||||
gbinder_writer_append_int32(&writer, GBINDER_STATUS_OK);
|
gbinder_writer_append_int32(&writer, GBINDER_STATUS_OK);
|
||||||
gbinder_writer_append_hidl_string(&writer, self->iface ? self->iface :
|
gbinder_writer_append_hidl_string(&writer, priv->ifaces[0]);
|
||||||
hidl_base_interface);
|
|
||||||
*status = GBINDER_STATUS_OK;
|
*status = GBINDER_STATUS_OK;
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
@@ -163,17 +208,14 @@ gbinder_local_object_hidl_descriptor_chain_transaction(
|
|||||||
const GBinderIo* io = gbinder_local_object_io(self);
|
const GBinderIo* io = gbinder_local_object_io(self);
|
||||||
GBinderLocalReply* reply = gbinder_local_reply_new(io);
|
GBinderLocalReply* reply = gbinder_local_reply_new(io);
|
||||||
GBinderWriter writer;
|
GBinderWriter writer;
|
||||||
const char* chain[2];
|
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
GVERBOSE(" HIDL_DESCRIPTOR_CHAIN_TRANSACTION \"%s\"",
|
GVERBOSE(" HIDL_DESCRIPTOR_CHAIN_TRANSACTION \"%s\"",
|
||||||
gbinder_remote_request_interface(req));
|
gbinder_remote_request_interface(req));
|
||||||
if (self->iface) chain[n++] = self->iface;
|
|
||||||
chain[n++] = hidl_base_interface;
|
|
||||||
|
|
||||||
gbinder_local_reply_init_writer(reply, &writer);
|
gbinder_local_reply_init_writer(reply, &writer);
|
||||||
gbinder_writer_append_int32(&writer, GBINDER_STATUS_OK);
|
gbinder_writer_append_int32(&writer, GBINDER_STATUS_OK);
|
||||||
gbinder_writer_append_hidl_string_vec(&writer, chain, n);
|
gbinder_writer_append_hidl_string_vec(&writer, (const char**)
|
||||||
|
self->ifaces, -1);
|
||||||
*status = GBINDER_STATUS_OK;
|
*status = GBINDER_STATUS_OK;
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
@@ -187,23 +229,31 @@ gbinder_local_object_default_handle_looper_transaction(
|
|||||||
guint flags,
|
guint flags,
|
||||||
int* status)
|
int* status)
|
||||||
{
|
{
|
||||||
|
GBinderLocalObjectTxHandler handler = NULL;
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
case GBINDER_PING_TRANSACTION:
|
||||||
|
handler = gbinder_local_object_ping_transaction;
|
||||||
|
break;
|
||||||
|
case GBINDER_INTERFACE_TRANSACTION:
|
||||||
|
handler = gbinder_local_object_interface_transaction;
|
||||||
|
break;
|
||||||
case HIDL_PING_TRANSACTION:
|
case HIDL_PING_TRANSACTION:
|
||||||
GASSERT(!(flags & GBINDER_TX_FLAG_ONEWAY));
|
handler = gbinder_local_object_hidl_ping_transaction;
|
||||||
return gbinder_local_object_hidl_ping_transaction
|
break;
|
||||||
(self, req, status);
|
|
||||||
case HIDL_GET_DESCRIPTOR_TRANSACTION:
|
case HIDL_GET_DESCRIPTOR_TRANSACTION:
|
||||||
GASSERT(!(flags & GBINDER_TX_FLAG_ONEWAY));
|
handler = gbinder_local_object_hidl_get_descriptor_transaction;
|
||||||
return gbinder_local_object_hidl_get_descriptor_transaction
|
break;
|
||||||
(self, req, status);
|
|
||||||
case HIDL_DESCRIPTOR_CHAIN_TRANSACTION:
|
case HIDL_DESCRIPTOR_CHAIN_TRANSACTION:
|
||||||
GASSERT(!(flags & GBINDER_TX_FLAG_ONEWAY));
|
handler = gbinder_local_object_hidl_descriptor_chain_transaction;
|
||||||
return gbinder_local_object_hidl_descriptor_chain_transaction
|
break;
|
||||||
(self, req, status);
|
|
||||||
default:
|
default:
|
||||||
if (status) *status = (-EBADMSG);
|
if (status) *status = (-EBADMSG);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GASSERT(!(flags & GBINDER_TX_FLAG_ONEWAY));
|
||||||
|
return handler(self, req, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -282,20 +332,40 @@ gbinder_local_object_handle_release_proc(
|
|||||||
GBinderLocalObject*
|
GBinderLocalObject*
|
||||||
gbinder_local_object_new(
|
gbinder_local_object_new(
|
||||||
GBinderIpc* ipc,
|
GBinderIpc* ipc,
|
||||||
const char* iface,
|
const char* const* ifaces,
|
||||||
GBinderLocalTransactFunc txproc,
|
GBinderLocalTransactFunc txproc,
|
||||||
void* user_data)
|
void* user_data) /* Since 1.0.30 */
|
||||||
{
|
{
|
||||||
/* Should only be called from gbinder_ipc_new_local_local_object() */
|
|
||||||
if (G_LIKELY(ipc)) {
|
if (G_LIKELY(ipc)) {
|
||||||
GBinderLocalObject* self = g_object_new
|
GBinderLocalObject* self = g_object_new
|
||||||
(GBINDER_TYPE_LOCAL_OBJECT, NULL);
|
(GBINDER_TYPE_LOCAL_OBJECT, NULL);
|
||||||
GBinderLocalObjectPriv* priv = self->priv;
|
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->ipc = gbinder_ipc_ref(ipc);
|
||||||
self->iface = priv->iface = g_strdup(iface);
|
self->ifaces = (const char**)priv->ifaces;
|
||||||
priv->txproc = txproc;
|
priv->txproc = txproc;
|
||||||
priv->user_data = user_data;
|
priv->user_data = user_data;
|
||||||
|
gbinder_ipc_register_local_object(ipc, self);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -491,7 +561,7 @@ gbinder_local_object_finalize(
|
|||||||
|
|
||||||
GASSERT(!self->strong_refs);
|
GASSERT(!self->strong_refs);
|
||||||
gbinder_ipc_unref(self->ipc);
|
gbinder_ipc_unref(self->ipc);
|
||||||
g_free(priv->iface);
|
g_strfreev(priv->ifaces);
|
||||||
G_OBJECT_CLASS(gbinder_local_object_parent_class)->finalize(local);
|
G_OBJECT_CLASS(gbinder_local_object_parent_class)->finalize(local);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -55,7 +55,7 @@ struct gbinder_local_object {
|
|||||||
GObject object;
|
GObject object;
|
||||||
GBinderLocalObjectPriv* priv;
|
GBinderLocalObjectPriv* priv;
|
||||||
GBinderIpc* ipc;
|
GBinderIpc* ipc;
|
||||||
const char* iface;
|
const char* const* ifaces;
|
||||||
gint weak_refs;
|
gint weak_refs;
|
||||||
gint strong_refs;
|
gint strong_refs;
|
||||||
};
|
};
|
||||||
@@ -79,7 +79,7 @@ typedef struct gbinder_local_object_class {
|
|||||||
/* Need to add some placeholders if this class becomes public */
|
/* Need to add some placeholders if this class becomes public */
|
||||||
} GBinderLocalObjectClass;
|
} 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_TYPE_LOCAL_OBJECT (gbinder_local_object_get_type())
|
||||||
#define GBINDER_LOCAL_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
|
#define GBINDER_LOCAL_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
|
||||||
GBINDER_TYPE_LOCAL_OBJECT, GBinderLocalObject))
|
GBINDER_TYPE_LOCAL_OBJECT, GBinderLocalObject))
|
||||||
@@ -87,36 +87,32 @@ GType gbinder_local_object_get_type(void);
|
|||||||
#define gbinder_local_object_dev(obj) (gbinder_driver_dev((obj)->ipc->driver))
|
#define gbinder_local_object_dev(obj) (gbinder_driver_dev((obj)->ipc->driver))
|
||||||
#define gbinder_local_object_io(obj) (gbinder_driver_io((obj)->ipc->driver))
|
#define gbinder_local_object_io(obj) (gbinder_driver_io((obj)->ipc->driver))
|
||||||
|
|
||||||
/* Should only be called from gbinder_ipc_new_local_object() */
|
|
||||||
GBinderLocalObject*
|
|
||||||
gbinder_local_object_new(
|
|
||||||
GBinderIpc* ipc,
|
|
||||||
const char* iface,
|
|
||||||
GBinderLocalTransactFunc handler,
|
|
||||||
void* user_data);
|
|
||||||
|
|
||||||
gulong
|
gulong
|
||||||
gbinder_local_object_add_weak_refs_changed_handler(
|
gbinder_local_object_add_weak_refs_changed_handler(
|
||||||
GBinderLocalObject* obj,
|
GBinderLocalObject* obj,
|
||||||
GBinderLocalObjectFunc func,
|
GBinderLocalObjectFunc func,
|
||||||
void* user_data);
|
void* user_data)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gulong
|
gulong
|
||||||
gbinder_local_object_add_strong_refs_changed_handler(
|
gbinder_local_object_add_strong_refs_changed_handler(
|
||||||
GBinderLocalObject* obj,
|
GBinderLocalObject* obj,
|
||||||
GBinderLocalObjectFunc func,
|
GBinderLocalObjectFunc func,
|
||||||
void* user_data);
|
void* user_data)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_local_object_remove_handler(
|
gbinder_local_object_remove_handler(
|
||||||
GBinderLocalObject* obj,
|
GBinderLocalObject* obj,
|
||||||
gulong id);
|
gulong id)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBINDER_LOCAL_TRANSACTION_SUPPORT
|
GBINDER_LOCAL_TRANSACTION_SUPPORT
|
||||||
gbinder_local_object_can_handle_transaction(
|
gbinder_local_object_can_handle_transaction(
|
||||||
GBinderLocalObject* self,
|
GBinderLocalObject* self,
|
||||||
const char* iface,
|
const char* iface,
|
||||||
guint code);
|
guint code)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderLocalReply*
|
GBinderLocalReply*
|
||||||
gbinder_local_object_handle_transaction(
|
gbinder_local_object_handle_transaction(
|
||||||
@@ -124,7 +120,8 @@ gbinder_local_object_handle_transaction(
|
|||||||
GBinderRemoteRequest* req,
|
GBinderRemoteRequest* req,
|
||||||
guint code,
|
guint code,
|
||||||
guint flags,
|
guint flags,
|
||||||
int* status);
|
int* status)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderLocalReply*
|
GBinderLocalReply*
|
||||||
gbinder_local_object_handle_looper_transaction(
|
gbinder_local_object_handle_looper_transaction(
|
||||||
@@ -132,23 +129,28 @@ gbinder_local_object_handle_looper_transaction(
|
|||||||
GBinderRemoteRequest* req,
|
GBinderRemoteRequest* req,
|
||||||
guint code,
|
guint code,
|
||||||
guint flags,
|
guint flags,
|
||||||
int* status);
|
int* status)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_local_object_handle_increfs(
|
gbinder_local_object_handle_increfs(
|
||||||
GBinderLocalObject* obj);
|
GBinderLocalObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_local_object_handle_decrefs(
|
gbinder_local_object_handle_decrefs(
|
||||||
GBinderLocalObject* obj);
|
GBinderLocalObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_local_object_handle_acquire(
|
gbinder_local_object_handle_acquire(
|
||||||
GBinderLocalObject* obj);
|
GBinderLocalObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_local_object_handle_release(
|
gbinder_local_object_handle_release(
|
||||||
GBinderLocalObject* obj);
|
GBinderLocalObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_LOCAL_OBJECT_PRIVATE_H */
|
#endif /* GBINDER_LOCAL_OBJECT_PRIVATE_H */
|
||||||
|
|
||||||
|
|||||||
@@ -95,14 +95,13 @@ gbinder_local_reply_new(
|
|||||||
|
|
||||||
GBinderLocalReply*
|
GBinderLocalReply*
|
||||||
gbinder_local_reply_new_from_data(
|
gbinder_local_reply_new_from_data(
|
||||||
GBinderBuffer* buffer,
|
GBinderBuffer* buffer)
|
||||||
void** objects)
|
|
||||||
{
|
{
|
||||||
const GBinderIo* io = gbinder_buffer_io(buffer);
|
const GBinderIo* io = gbinder_buffer_io(buffer);
|
||||||
GBinderLocalReply* self = gbinder_local_reply_new(io);
|
GBinderLocalReply* self = gbinder_local_reply_new(io);
|
||||||
|
|
||||||
if (self) {
|
if (self) {
|
||||||
gbinder_writer_data_set_contents(&self->data, buffer, objects);
|
gbinder_writer_data_set_contents(&self->data, buffer);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -39,16 +39,18 @@
|
|||||||
|
|
||||||
GBinderLocalReply*
|
GBinderLocalReply*
|
||||||
gbinder_local_reply_new(
|
gbinder_local_reply_new(
|
||||||
const GBinderIo* io);
|
const GBinderIo* io)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderOutputData*
|
GBinderOutputData*
|
||||||
gbinder_local_reply_data(
|
gbinder_local_reply_data(
|
||||||
GBinderLocalReply* reply);
|
GBinderLocalReply* reply)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderLocalReply*
|
GBinderLocalReply*
|
||||||
gbinder_local_reply_new_from_data(
|
gbinder_local_reply_new_from_data(
|
||||||
GBinderBuffer* buffer,
|
GBinderBuffer* buffer)
|
||||||
void** objects);
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_LOCAL_REPLY_PRIVATE_H */
|
#endif /* GBINDER_LOCAL_REPLY_PRIVATE_H */
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ struct gbinder_local_request {
|
|||||||
gint refcount;
|
gint refcount;
|
||||||
GBinderWriterData data;
|
GBinderWriterData data;
|
||||||
GBinderOutputData out;
|
GBinderOutputData out;
|
||||||
GBinderBufferMemory* memory;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GBINDER_INLINE_FUNC
|
GBINDER_INLINE_FUNC
|
||||||
@@ -106,14 +105,13 @@ gbinder_local_request_new(
|
|||||||
|
|
||||||
GBinderLocalRequest*
|
GBinderLocalRequest*
|
||||||
gbinder_local_request_new_from_data(
|
gbinder_local_request_new_from_data(
|
||||||
GBinderBuffer* buffer,
|
GBinderBuffer* buffer)
|
||||||
void** objects)
|
|
||||||
{
|
{
|
||||||
GBinderLocalRequest* self = gbinder_local_request_new
|
GBinderLocalRequest* self = gbinder_local_request_new
|
||||||
(gbinder_buffer_io(buffer), NULL);
|
(gbinder_buffer_io(buffer), NULL);
|
||||||
|
|
||||||
if (self) {
|
if (self) {
|
||||||
gbinder_writer_data_set_contents(&self->data, buffer, objects);
|
gbinder_writer_data_set_contents(&self->data, buffer);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -128,7 +126,6 @@ gbinder_local_request_free(
|
|||||||
g_byte_array_free(data->bytes, TRUE);
|
g_byte_array_free(data->bytes, TRUE);
|
||||||
gutil_int_array_free(data->offsets, TRUE);
|
gutil_int_array_free(data->offsets, TRUE);
|
||||||
gbinder_cleanup_free(data->cleanup);
|
gbinder_cleanup_free(data->cleanup);
|
||||||
gbinder_buffer_memory_unref(self->memory);
|
|
||||||
g_slice_free(GBinderLocalRequest, self);
|
g_slice_free(GBinderLocalRequest, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -40,16 +40,18 @@
|
|||||||
GBinderLocalRequest*
|
GBinderLocalRequest*
|
||||||
gbinder_local_request_new(
|
gbinder_local_request_new(
|
||||||
const GBinderIo* io,
|
const GBinderIo* io,
|
||||||
GBytes* init);
|
GBytes* init)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderOutputData*
|
GBinderOutputData*
|
||||||
gbinder_local_request_data(
|
gbinder_local_request_data(
|
||||||
GBinderLocalRequest* req);
|
GBinderLocalRequest* req)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
GBinderLocalRequest*
|
GBinderLocalRequest*
|
||||||
gbinder_local_request_new_from_data(
|
gbinder_local_request_new_from_data(
|
||||||
GBinderBuffer* buffer,
|
GBinderBuffer* buffer)
|
||||||
void** objects);
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_LOCAL_REQUEST_PRIVATE_H */
|
#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-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -33,11 +33,18 @@
|
|||||||
#ifndef GBINDER_LOG_H
|
#ifndef GBINDER_LOG_H
|
||||||
#define GBINDER_LOG_H
|
#define GBINDER_LOG_H
|
||||||
|
|
||||||
#include "gbinder_types.h"
|
#include "gbinder_types_p.h"
|
||||||
|
|
||||||
#define GLOG_MODULE_NAME GBINDER_LOG_MODULE
|
#define GLOG_MODULE_NAME GBINDER_LOG_MODULE
|
||||||
#include <gutil_log.h>
|
#include <gutil_log.h>
|
||||||
|
|
||||||
|
/* Declared for unit tests */
|
||||||
|
__attribute__((constructor))
|
||||||
|
void
|
||||||
|
gbinder_log_init(
|
||||||
|
void)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_LOG_H */
|
#endif /* GBINDER_LOG_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -38,6 +38,9 @@
|
|||||||
|
|
||||||
#include <gutil_macros.h>
|
#include <gutil_macros.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
typedef struct gbinder_reader_priv {
|
typedef struct gbinder_reader_priv {
|
||||||
const guint8* start;
|
const guint8* start;
|
||||||
const guint8* end;
|
const guint8* end;
|
||||||
@@ -50,6 +53,8 @@ G_STATIC_ASSERT(sizeof(GBinderReader) >= sizeof(GBinderReaderPriv));
|
|||||||
|
|
||||||
static inline GBinderReaderPriv* gbinder_reader_cast(GBinderReader* reader)
|
static inline GBinderReaderPriv* gbinder_reader_cast(GBinderReader* reader)
|
||||||
{ return (GBinderReaderPriv*)reader; }
|
{ return (GBinderReaderPriv*)reader; }
|
||||||
|
static inline const GBinderReaderPriv* gbinder_reader_cast_c
|
||||||
|
(const GBinderReader* reader) { return (GBinderReaderPriv*)reader; }
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_reader_init(
|
gbinder_reader_init(
|
||||||
@@ -81,9 +86,9 @@ gbinder_reader_init(
|
|||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_reader_at_end(
|
gbinder_reader_at_end(
|
||||||
GBinderReader* reader)
|
const GBinderReader* reader)
|
||||||
{
|
{
|
||||||
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
const GBinderReaderPriv* p = gbinder_reader_cast_c(reader);
|
||||||
|
|
||||||
return p->ptr >= p->end;
|
return p->ptr >= p->end;
|
||||||
}
|
}
|
||||||
@@ -229,16 +234,67 @@ gbinder_reader_read_double(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
inline
|
||||||
|
gboolean
|
||||||
|
gbinder_reader_can_read_object(
|
||||||
|
GBinderReaderPriv* p)
|
||||||
|
{
|
||||||
|
const GBinderReaderData* data = p->data;
|
||||||
|
|
||||||
|
return data && data->reg &&
|
||||||
|
p->objects && p->objects[0] &&
|
||||||
|
p->ptr == p->objects[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gbinder_reader_read_fd(
|
||||||
|
GBinderReader* reader) /* Since 1.0.18 */
|
||||||
|
{
|
||||||
|
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
||||||
|
|
||||||
|
if (gbinder_reader_can_read_object(p)) {
|
||||||
|
int fd;
|
||||||
|
const guint eaten = p->data->reg->io->decode_fd_object(p->ptr,
|
||||||
|
gbinder_reader_bytes_remaining(reader), &fd);
|
||||||
|
|
||||||
|
if (eaten) {
|
||||||
|
GASSERT(fd >= 0);
|
||||||
|
p->ptr += eaten;
|
||||||
|
p->objects++;
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gbinder_reader_read_dup_fd(
|
||||||
|
GBinderReader* reader) /* Since 1.0.18 */
|
||||||
|
{
|
||||||
|
const int fd = gbinder_reader_read_fd(reader);
|
||||||
|
|
||||||
|
if (fd >= 0) {
|
||||||
|
const int dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
|
||||||
|
|
||||||
|
if (dupfd >= 0) {
|
||||||
|
return dupfd;
|
||||||
|
} else {
|
||||||
|
GWARN("Error dupping fd %d: %s", fd, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_reader_read_nullable_object(
|
gbinder_reader_read_nullable_object(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
GBinderRemoteObject** out)
|
GBinderRemoteObject** out)
|
||||||
{
|
{
|
||||||
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
||||||
const GBinderReaderData* data = p->data;
|
|
||||||
|
|
||||||
if (data && data->reg && p->objects && p->objects[0] &&
|
if (gbinder_reader_can_read_object(p)) {
|
||||||
p->ptr == p->objects[0]) {
|
const GBinderReaderData* data = p->data;
|
||||||
const guint eaten = data->reg->io->decode_binder_object(p->ptr,
|
const guint eaten = data->reg->io->decode_binder_object(p->ptr,
|
||||||
gbinder_reader_bytes_remaining(reader), data->reg, out);
|
gbinder_reader_bytes_remaining(reader), data->reg, out);
|
||||||
|
|
||||||
@@ -264,15 +320,14 @@ gbinder_reader_read_object(
|
|||||||
|
|
||||||
static
|
static
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_reader_read_buffer_impl(
|
gbinder_reader_read_buffer_object(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
GBinderBuffer** out)
|
GBinderIoBufferObject* out)
|
||||||
{
|
{
|
||||||
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
||||||
const GBinderReaderData* data = p->data;
|
|
||||||
|
|
||||||
if (data && data->reg && p->objects && p->objects[0] &&
|
if (gbinder_reader_can_read_object(p)) {
|
||||||
p->ptr == p->objects[0]) {
|
const GBinderReaderData* data = p->data;
|
||||||
GBinderBuffer* buf = data->buffer;
|
GBinderBuffer* buf = data->buffer;
|
||||||
const GBinderIo* io = data->reg->io;
|
const GBinderIo* io = data->reg->io;
|
||||||
const gsize offset = p->ptr - (guint8*)buf->data;
|
const gsize offset = p->ptr - (guint8*)buf->data;
|
||||||
@@ -284,7 +339,6 @@ gbinder_reader_read_buffer_impl(
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (out) *out = NULL;
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,34 +346,36 @@ GBinderBuffer*
|
|||||||
gbinder_reader_read_buffer(
|
gbinder_reader_read_buffer(
|
||||||
GBinderReader* reader)
|
GBinderReader* reader)
|
||||||
{
|
{
|
||||||
GBinderBuffer* buf = NULL;
|
GBinderIoBufferObject obj;
|
||||||
|
|
||||||
gbinder_reader_read_buffer_impl(reader, &buf);
|
if (gbinder_reader_read_buffer_object(reader, &obj)) {
|
||||||
return buf;
|
const GBinderReaderData* data = gbinder_reader_cast(reader)->data;
|
||||||
|
GBinderBuffer* buf = data->buffer;
|
||||||
|
|
||||||
|
return gbinder_buffer_new_with_parent(buf, obj.data, obj.size);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_reader_skip_buffer(
|
gbinder_reader_skip_buffer(
|
||||||
GBinderReader* reader)
|
GBinderReader* reader)
|
||||||
{
|
{
|
||||||
return gbinder_reader_read_buffer_impl(reader, NULL);
|
return gbinder_reader_read_buffer_object(reader, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper for gbinder_reader_read_hidl_struct() macro */
|
/* Helper for gbinder_reader_read_hidl_struct() macro */
|
||||||
const void*
|
const void*
|
||||||
gbinder_reader_read_hidl_struct1(
|
gbinder_reader_read_hidl_struct1(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
gsize size) /* since 1.0.9 */
|
gsize size) /* Since 1.0.9 */
|
||||||
{
|
{
|
||||||
const void* result = NULL;
|
GBinderIoBufferObject obj;
|
||||||
GBinderBuffer* buf = gbinder_reader_read_buffer(reader);
|
|
||||||
|
|
||||||
/* Check the size */
|
if (gbinder_reader_read_buffer_object(reader, &obj) && obj.size == size) {
|
||||||
if (buf && buf->size == size) {
|
return obj.data;
|
||||||
result = buf->data;
|
|
||||||
}
|
}
|
||||||
gbinder_buffer_free(buf);
|
return NULL;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Doesn't copy the data */
|
/* Doesn't copy the data */
|
||||||
@@ -329,30 +385,28 @@ gbinder_reader_read_hidl_vec(
|
|||||||
gsize* count,
|
gsize* count,
|
||||||
gsize* elemsize)
|
gsize* elemsize)
|
||||||
{
|
{
|
||||||
GBinderBuffer* buf = gbinder_reader_read_buffer(reader);
|
GBinderIoBufferObject obj;
|
||||||
gsize out_count = 0, out_elemsize = 0;
|
|
||||||
const void* out = NULL;
|
const void* out = NULL;
|
||||||
|
gsize out_count = 0, out_elemsize = 0;
|
||||||
|
|
||||||
if (buf && buf->size == sizeof(HidlVec)) {
|
if (gbinder_reader_read_buffer_object(reader, &obj) &&
|
||||||
const HidlVec* vec = buf->data;
|
obj.data && obj.size == sizeof(GBinderHidlVec)) {
|
||||||
|
const GBinderHidlVec* vec = obj.data;
|
||||||
const void* next = vec->data.ptr;
|
const void* next = vec->data.ptr;
|
||||||
|
|
||||||
if (next) {
|
if (next) {
|
||||||
GBinderBuffer* vbuf = gbinder_reader_read_buffer(reader);
|
if (gbinder_reader_read_buffer_object(reader, &obj) &&
|
||||||
|
obj.data == next && ((!vec->count && !obj.size) ||
|
||||||
if (vbuf && vbuf->data == next && ((!vec->count && !vbuf->size) ||
|
(vec->count && obj.size && !(obj.size % vec->count)))) {
|
||||||
(vec->count && vbuf->size && !(vbuf->size % vec->count)))) {
|
out_elemsize = vec->count ? (obj.size / vec->count) : 0;
|
||||||
out_elemsize = vec->count ? (vbuf->size / vec->count) : 0;
|
|
||||||
out_count = vec->count;
|
out_count = vec->count;
|
||||||
out = vbuf->data;
|
out = obj.data;
|
||||||
}
|
}
|
||||||
gbinder_buffer_free(vbuf);
|
|
||||||
} else if (!vec->count) {
|
} else if (!vec->count) {
|
||||||
/* Any non-NULL pointer just to indicate success */
|
/* Any non-NULL pointer just to indicate success? */
|
||||||
out = vec;
|
out = vec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gbinder_buffer_free(buf);
|
|
||||||
if (elemsize) {
|
if (elemsize) {
|
||||||
*elemsize = out_elemsize;
|
*elemsize = out_elemsize;
|
||||||
}
|
}
|
||||||
@@ -367,7 +421,7 @@ const void*
|
|||||||
gbinder_reader_read_hidl_vec1(
|
gbinder_reader_read_hidl_vec1(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
gsize* count,
|
gsize* count,
|
||||||
guint expected_elem_size) /* since 1.0.9 */
|
guint expected_elem_size) /* Since 1.0.9 */
|
||||||
{
|
{
|
||||||
gsize actual;
|
gsize actual;
|
||||||
const void* data = gbinder_reader_read_hidl_vec(reader, count, &actual);
|
const void* data = gbinder_reader_read_hidl_vec(reader, count, &actual);
|
||||||
@@ -376,88 +430,94 @@ gbinder_reader_read_hidl_vec1(
|
|||||||
return (data && (actual == expected_elem_size || !actual)) ? data : NULL;
|
return (data && (actual == expected_elem_size || !actual)) ? data : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char*
|
||||||
|
gbinder_reader_read_hidl_string_c(
|
||||||
|
GBinderReader* reader) /* Since 1.0.23 */
|
||||||
|
{
|
||||||
|
GBinderIoBufferObject obj;
|
||||||
|
|
||||||
|
if (gbinder_reader_read_buffer_object(reader, &obj) &&
|
||||||
|
obj.data && obj.size == sizeof(GBinderHidlString)) {
|
||||||
|
const GBinderHidlString* str = obj.data;
|
||||||
|
|
||||||
|
if (gbinder_reader_read_buffer_object(reader, &obj) &&
|
||||||
|
obj.has_parent &&
|
||||||
|
obj.parent_offset == GBINDER_HIDL_STRING_BUFFER_OFFSET &&
|
||||||
|
obj.data == str->data.str &&
|
||||||
|
obj.size == str->len + 1 &&
|
||||||
|
str->data.str[str->len] == 0) {
|
||||||
|
return str->data.str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
gbinder_reader_read_hidl_string(
|
gbinder_reader_read_hidl_string(
|
||||||
GBinderReader* reader)
|
GBinderReader* reader)
|
||||||
{
|
{
|
||||||
GBinderBuffer* buf = gbinder_reader_read_buffer(reader);
|
/* This function should've been called gbinder_reader_dup_hidl_string */
|
||||||
char* str = NULL;
|
return g_strdup(gbinder_reader_read_hidl_string_c(reader));
|
||||||
|
|
||||||
if (buf && buf->size == sizeof(HidlString)) {
|
|
||||||
const HidlString* s = buf->data;
|
|
||||||
GBinderBuffer* sbuf = gbinder_reader_read_buffer(reader);
|
|
||||||
|
|
||||||
if (sbuf && sbuf->size == s->len + 1 &&
|
|
||||||
sbuf->data == s->data.str &&
|
|
||||||
s->data.str[s->len] == 0) {
|
|
||||||
str = g_strdup(s->data.str);
|
|
||||||
}
|
|
||||||
gbinder_buffer_free(sbuf);
|
|
||||||
}
|
|
||||||
gbinder_buffer_free(buf);
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char**
|
char**
|
||||||
gbinder_reader_read_hidl_string_vec(
|
gbinder_reader_read_hidl_string_vec(
|
||||||
GBinderReader* reader)
|
GBinderReader* reader)
|
||||||
{
|
{
|
||||||
GBinderBuffer* buf = gbinder_reader_read_buffer(reader);
|
GBinderIoBufferObject obj;
|
||||||
|
|
||||||
/* First buffer contains hidl_vector */
|
/* First buffer contains hidl_vector */
|
||||||
if (buf && buf->size == sizeof(HidlVec)) {
|
if (gbinder_reader_read_buffer_object(reader, &obj) &&
|
||||||
HidlVec* vec = buf->data;
|
obj.data && obj.size == sizeof(GBinderHidlVec)) {
|
||||||
|
GBinderHidlVec* vec = obj.data;
|
||||||
const guint n = vec->count;
|
const guint n = vec->count;
|
||||||
const void* next = vec->data.ptr;
|
const void* next = vec->data.ptr;
|
||||||
|
|
||||||
gbinder_buffer_free(buf);
|
|
||||||
if (!next && !n) {
|
if (!next && !n) {
|
||||||
char** out = g_new(char*, 1);
|
/* Should this be considered an error? */
|
||||||
|
return g_new0(char*, 1);
|
||||||
|
} else if (gbinder_reader_read_buffer_object(reader, &obj) &&
|
||||||
|
/* The second buffer (if any) contains n hidl_string's */
|
||||||
|
obj.parent_offset == GBINDER_HIDL_VEC_BUFFER_OFFSET &&
|
||||||
|
obj.has_parent &&
|
||||||
|
obj.data == next &&
|
||||||
|
obj.size == (sizeof(GBinderHidlString) * n)) {
|
||||||
|
const GBinderHidlString* strings = obj.data;
|
||||||
|
GPtrArray* list = g_ptr_array_sized_new(n + 1);
|
||||||
|
guint i;
|
||||||
|
|
||||||
out[0] = NULL;
|
/* Now we expect n buffers containing the actual data */
|
||||||
return out;
|
for (i = 0; i < n &&
|
||||||
} else {
|
gbinder_reader_read_buffer_object(reader, &obj); i++) {
|
||||||
/* The second buffer (if any) contains n hidl_string's */
|
const GBinderHidlString* s = strings + i;
|
||||||
buf = gbinder_reader_read_buffer(reader);
|
const gsize expected_offset = (i * sizeof(*s)) +
|
||||||
if (buf && buf->data == next && buf->size == sizeof(HidlString)*n) {
|
GBINDER_HIDL_STRING_BUFFER_OFFSET;
|
||||||
const HidlString* strings = buf->data;
|
if (obj.has_parent &&
|
||||||
GBinderBuffer* sbuf;
|
obj.parent_offset == expected_offset &&
|
||||||
GPtrArray* list = g_ptr_array_new();
|
obj.data == s->data.str &&
|
||||||
guint i;
|
obj.size == s->len + 1 &&
|
||||||
|
s->data.str[s->len] == 0) {
|
||||||
|
char* name = g_strdup(s->data.str);
|
||||||
|
|
||||||
/* Now we expect n buffers containing the actual data */
|
g_ptr_array_add(list, name);
|
||||||
for (i=0; i<n &&
|
GVERBOSE_("%u. %s", i + 1, name);
|
||||||
(sbuf = gbinder_reader_read_buffer(reader)); i++) {
|
} else {
|
||||||
const HidlString* s = strings + i;
|
GWARN("Unexpected hidl_string buffer %p/%u vs %p/%u",
|
||||||
if (sbuf->size == s->len + 1 &&
|
obj.data, (guint)obj.size, s->data.str, s->len);
|
||||||
sbuf->data == s->data.str &&
|
break;
|
||||||
s->data.str[s->len] == 0) {
|
|
||||||
char* name = g_strdup(s->data.str);
|
|
||||||
|
|
||||||
g_ptr_array_add(list, name);
|
|
||||||
GVERBOSE_("%u. %s", i + 1, name);
|
|
||||||
gbinder_buffer_free(sbuf);
|
|
||||||
} else {
|
|
||||||
GWARN("Unexpected hidl_string buffer %p/%u vs %p/%u",
|
|
||||||
sbuf->data, (guint)sbuf->size, s->data.str, s->len);
|
|
||||||
gbinder_buffer_free(sbuf);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == n) {
|
|
||||||
gbinder_buffer_free(buf);
|
|
||||||
g_ptr_array_add(list, NULL);
|
|
||||||
return (char**)g_ptr_array_free(list, FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_ptr_array_set_free_func(list, g_free);
|
|
||||||
g_ptr_array_free(list, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (i == n) {
|
||||||
|
g_ptr_array_add(list, NULL);
|
||||||
|
return (char**)g_ptr_array_free(list, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_ptr_array_set_free_func(list, g_free);
|
||||||
|
g_ptr_array_free(list, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GWARN("Invalid hidl_vec<string>");
|
GWARN("Invalid hidl_vec<string>");
|
||||||
gbinder_buffer_free(buf);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,6 +549,24 @@ gboolean
|
|||||||
gbinder_reader_read_nullable_string16(
|
gbinder_reader_read_nullable_string16(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
char** out)
|
char** out)
|
||||||
|
{
|
||||||
|
const gunichar2* str;
|
||||||
|
gsize len;
|
||||||
|
|
||||||
|
if (gbinder_reader_read_nullable_string16_utf16(reader, &str, &len)) {
|
||||||
|
if (out) {
|
||||||
|
*out = str ? g_utf16_to_utf8(str, len, NULL, NULL, NULL) : NULL;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gbinder_reader_read_nullable_string16_utf16(
|
||||||
|
GBinderReader* reader,
|
||||||
|
const gunichar2** out,
|
||||||
|
gsize* out_len) /* Since 1.0.17 */
|
||||||
{
|
{
|
||||||
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
||||||
|
|
||||||
@@ -502,15 +580,21 @@ gbinder_reader_read_nullable_string16(
|
|||||||
if (out) {
|
if (out) {
|
||||||
*out = NULL;
|
*out = NULL;
|
||||||
}
|
}
|
||||||
|
if (out_len) {
|
||||||
|
*out_len = 0;
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (len >= 0) {
|
} else if (len >= 0) {
|
||||||
const guint32 padded_len = G_ALIGN4((len+1)*2);
|
const guint32 padded_len = G_ALIGN4((len + 1)*2);
|
||||||
const gunichar2* utf16 = (const gunichar2*)(p->ptr + 4);
|
const gunichar2* utf16 = (gunichar2*)(p->ptr + 4);
|
||||||
|
|
||||||
if ((p->ptr + padded_len + 4) <= p->end) {
|
if ((p->ptr + padded_len + 4) <= p->end) {
|
||||||
p->ptr += padded_len + 4;
|
p->ptr += padded_len + 4;
|
||||||
if (out) {
|
if (out) {
|
||||||
*out = g_utf16_to_utf8(utf16, len, NULL, NULL, NULL);
|
*out = utf16;
|
||||||
|
}
|
||||||
|
if (out_len) {
|
||||||
|
*out_len = len;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -519,6 +603,21 @@ gbinder_reader_read_nullable_string16(
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gunichar2*
|
||||||
|
gbinder_reader_read_string16_utf16(
|
||||||
|
GBinderReader* reader,
|
||||||
|
gsize* len) /* Since 1.0.26 */
|
||||||
|
{
|
||||||
|
const gunichar2* str;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use gbinder_reader_read_nullable_string16_utf16 to distinguish
|
||||||
|
* NULL string from a parsing failure.
|
||||||
|
*/
|
||||||
|
return gbinder_reader_read_nullable_string16_utf16(reader, &str, len) ?
|
||||||
|
str : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
gbinder_reader_read_string16(
|
gbinder_reader_read_string16(
|
||||||
GBinderReader* reader)
|
GBinderReader* reader)
|
||||||
@@ -558,7 +657,7 @@ gbinder_reader_skip_string16(
|
|||||||
const void*
|
const void*
|
||||||
gbinder_reader_read_byte_array(
|
gbinder_reader_read_byte_array(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
gsize* len) /* since 1.0.12 */
|
gsize* len) /* Since 1.0.12 */
|
||||||
{
|
{
|
||||||
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
||||||
const void* data = NULL;
|
const void* data = NULL;
|
||||||
@@ -583,22 +682,31 @@ gbinder_reader_read_byte_array(
|
|||||||
|
|
||||||
gsize
|
gsize
|
||||||
gbinder_reader_bytes_read(
|
gbinder_reader_bytes_read(
|
||||||
GBinderReader* reader)
|
const GBinderReader* reader)
|
||||||
{
|
{
|
||||||
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
const GBinderReaderPriv* p = gbinder_reader_cast_c(reader);
|
||||||
|
|
||||||
return p->ptr - p->start;
|
return p->ptr - p->start;
|
||||||
}
|
}
|
||||||
|
|
||||||
gsize
|
gsize
|
||||||
gbinder_reader_bytes_remaining(
|
gbinder_reader_bytes_remaining(
|
||||||
GBinderReader* reader)
|
const GBinderReader* reader)
|
||||||
{
|
{
|
||||||
GBinderReaderPriv* p = gbinder_reader_cast(reader);
|
const GBinderReaderPriv* p = gbinder_reader_cast_c(reader);
|
||||||
|
|
||||||
return p->end - p->ptr;
|
return p->end - p->ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_reader_copy(
|
||||||
|
GBinderReader* dest,
|
||||||
|
const GBinderReader* src)
|
||||||
|
{
|
||||||
|
/* It's actually quite simple :) */
|
||||||
|
memcpy(dest, src, sizeof(*dest));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* mode: C
|
* mode: C
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -48,7 +48,8 @@ gbinder_reader_init(
|
|||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
GBinderReaderData* data,
|
GBinderReaderData* data,
|
||||||
gsize offset,
|
gsize offset,
|
||||||
gsize len);
|
gsize len)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_READER_PRIVATE_H */
|
#endif /* GBINDER_READER_PRIVATE_H */
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -30,9 +30,12 @@
|
|||||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
||||||
|
|
||||||
#include "gbinder_driver.h"
|
#include "gbinder_driver.h"
|
||||||
#include "gbinder_ipc.h"
|
#include "gbinder_ipc.h"
|
||||||
#include "gbinder_remote_object_p.h"
|
#include "gbinder_remote_object_p.h"
|
||||||
|
#include "gbinder_servicemanager_p.h"
|
||||||
#include "gbinder_log.h"
|
#include "gbinder_log.h"
|
||||||
|
|
||||||
struct gbinder_remote_object_priv {
|
struct gbinder_remote_object_priv {
|
||||||
@@ -65,9 +68,20 @@ void
|
|||||||
gbinder_remote_object_died_on_main_thread(
|
gbinder_remote_object_died_on_main_thread(
|
||||||
GBinderRemoteObject* self)
|
GBinderRemoteObject* self)
|
||||||
{
|
{
|
||||||
|
GBinderIpc* ipc = self->ipc;
|
||||||
|
GBinderDriver* driver = ipc->driver;
|
||||||
|
|
||||||
GASSERT(!self->dead);
|
GASSERT(!self->dead);
|
||||||
self->dead = TRUE;
|
if (!self->dead) {
|
||||||
g_signal_emit(self, gbinder_remote_object_signals[SIGNAL_DEATH], 0);
|
self->dead = TRUE;
|
||||||
|
/* ServiceManager always has the same handle, and can be reanimated. */
|
||||||
|
if (self->handle != GBINDER_SERVICEMANAGER_HANDLE) {
|
||||||
|
gbinder_ipc_invalidate_remote_handle(self->ipc, self->handle);
|
||||||
|
}
|
||||||
|
gbinder_driver_clear_death_notification(driver, self);
|
||||||
|
gbinder_driver_release(driver, self->handle);
|
||||||
|
g_signal_emit(self, gbinder_remote_object_signals[SIGNAL_DEATH], 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -79,6 +93,47 @@ gbinder_remote_object_died_handle(
|
|||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* Internal interface
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gbinder_remote_object_reanimate(
|
||||||
|
GBinderRemoteObject* self)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Don't try to reanimate those who hasn't died yet. Reanimation is
|
||||||
|
* kind of a special case and should only be used for servicemanager
|
||||||
|
* objects.
|
||||||
|
*/
|
||||||
|
if (self->dead) {
|
||||||
|
GBinderIpc* ipc = self->ipc;
|
||||||
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
|
|
||||||
|
/* Kick the horse */
|
||||||
|
GASSERT(self->handle == GBINDER_SERVICEMANAGER_HANDLE);
|
||||||
|
if (gbinder_driver_ping(ipc->driver, reg, self->handle) == 0) {
|
||||||
|
/* Wow, it's alive! */
|
||||||
|
self->dead = FALSE;
|
||||||
|
gbinder_driver_acquire(ipc->driver, self->handle);
|
||||||
|
gbinder_driver_request_death_notification(ipc->driver, self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !self->dead;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_remote_object_handle_death_notification(
|
||||||
|
GBinderRemoteObject* self)
|
||||||
|
{
|
||||||
|
/* This function is invoked from the looper thread, the caller has
|
||||||
|
* checked the object pointer */
|
||||||
|
GVERBOSE_("%p %u", self, self->handle);
|
||||||
|
g_main_context_invoke_full(self->priv->context, G_PRIORITY_DEFAULT,
|
||||||
|
gbinder_remote_object_died_handle, gbinder_remote_object_ref(self),
|
||||||
|
g_object_unref);
|
||||||
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* Interface
|
* Interface
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@@ -86,15 +141,19 @@ gbinder_remote_object_died_handle(
|
|||||||
GBinderRemoteObject*
|
GBinderRemoteObject*
|
||||||
gbinder_remote_object_new(
|
gbinder_remote_object_new(
|
||||||
GBinderIpc* ipc,
|
GBinderIpc* ipc,
|
||||||
guint32 handle)
|
guint32 handle,
|
||||||
|
gboolean dead)
|
||||||
{
|
{
|
||||||
if (G_LIKELY(ipc) && gbinder_driver_acquire(ipc->driver, handle)) {
|
if (G_LIKELY(ipc)) {
|
||||||
GBinderRemoteObject* self = g_object_new
|
GBinderRemoteObject* self = g_object_new
|
||||||
(GBINDER_TYPE_REMOTE_OBJECT, NULL);
|
(GBINDER_TYPE_REMOTE_OBJECT, NULL);
|
||||||
|
|
||||||
self->ipc = gbinder_ipc_ref(ipc);
|
self->ipc = gbinder_ipc_ref(ipc);
|
||||||
self->handle = handle;
|
self->handle = handle;
|
||||||
gbinder_driver_request_death_notification(ipc->driver, self);
|
if (!(self->dead = dead)) {
|
||||||
|
gbinder_driver_acquire(ipc->driver, handle);
|
||||||
|
gbinder_driver_request_death_notification(ipc->driver, self);
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -121,6 +180,13 @@ gbinder_remote_object_unref(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GBinderIpc*
|
||||||
|
gbinder_remote_object_ipc(
|
||||||
|
GBinderRemoteObject* self) /* Since 1.0.30 */
|
||||||
|
{
|
||||||
|
return G_LIKELY(self) ? self->ipc : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_remote_object_is_dead(
|
gbinder_remote_object_is_dead(
|
||||||
GBinderRemoteObject* self)
|
GBinderRemoteObject* self)
|
||||||
@@ -152,18 +218,6 @@ gbinder_remote_object_remove_handler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
gbinder_remote_object_handle_death_notification(
|
|
||||||
GBinderRemoteObject* self)
|
|
||||||
{
|
|
||||||
/* This function is invoked from the looper thread, the caller has
|
|
||||||
* checked the object pointer */
|
|
||||||
GVERBOSE_("%p %u", self, self->handle);
|
|
||||||
g_main_context_invoke_full(self->priv->context, G_PRIORITY_DEFAULT,
|
|
||||||
gbinder_remote_object_died_handle, gbinder_remote_object_ref(self),
|
|
||||||
g_object_unref);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* Internals
|
* Internals
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@@ -200,8 +254,10 @@ gbinder_remote_object_finalize(
|
|||||||
GBinderIpc* ipc = self->ipc;
|
GBinderIpc* ipc = self->ipc;
|
||||||
GBinderDriver* driver = ipc->driver;
|
GBinderDriver* driver = ipc->driver;
|
||||||
|
|
||||||
gbinder_driver_clear_death_notification(driver, self);
|
if (!self->dead) {
|
||||||
gbinder_driver_release(driver, self->handle);
|
gbinder_driver_clear_death_notification(driver, self);
|
||||||
|
gbinder_driver_release(driver, self->handle);
|
||||||
|
}
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
G_OBJECT_CLASS(gbinder_remote_object_parent_class)->finalize(remote);
|
G_OBJECT_CLASS(gbinder_remote_object_parent_class)->finalize(remote);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -54,11 +54,19 @@ struct gbinder_remote_object {
|
|||||||
GBinderRemoteObject*
|
GBinderRemoteObject*
|
||||||
gbinder_remote_object_new(
|
gbinder_remote_object_new(
|
||||||
GBinderIpc* ipc,
|
GBinderIpc* ipc,
|
||||||
guint32 handle);
|
guint32 handle,
|
||||||
|
gboolean maybe_dead)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gbinder_remote_object_reanimate(
|
||||||
|
GBinderRemoteObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_remote_object_handle_death_notification(
|
gbinder_remote_object_handle_death_notification(
|
||||||
GBinderRemoteObject* obj);
|
GBinderRemoteObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_REMOTE_OBJECT_PRIVATE_H */
|
#endif /* GBINDER_REMOTE_OBJECT_PRIVATE_H */
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
#include "gbinder_local_reply_p.h"
|
#include "gbinder_local_reply_p.h"
|
||||||
#include "gbinder_reader_p.h"
|
#include "gbinder_reader_p.h"
|
||||||
#include "gbinder_object_registry.h"
|
#include "gbinder_object_registry.h"
|
||||||
#include "gbinder_buffer.h"
|
#include "gbinder_buffer_p.h"
|
||||||
#include "gbinder_log.h"
|
#include "gbinder_log.h"
|
||||||
|
|
||||||
#include <gutil_macros.h>
|
#include <gutil_macros.h>
|
||||||
@@ -65,26 +65,22 @@ gbinder_remote_reply_free(
|
|||||||
|
|
||||||
gbinder_object_registry_unref(data->reg);
|
gbinder_object_registry_unref(data->reg);
|
||||||
gbinder_buffer_free(data->buffer);
|
gbinder_buffer_free(data->buffer);
|
||||||
g_free(data->objects);
|
|
||||||
g_slice_free(GBinderRemoteReply, self);
|
g_slice_free(GBinderRemoteReply, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_remote_reply_set_data(
|
gbinder_remote_reply_set_data(
|
||||||
GBinderRemoteReply* self,
|
GBinderRemoteReply* self,
|
||||||
GBinderBuffer* buffer,
|
GBinderBuffer* buffer)
|
||||||
void** objects)
|
|
||||||
{
|
{
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderReaderData* data = &self->data;
|
GBinderReaderData* data = &self->data;
|
||||||
|
|
||||||
g_free(data->objects);
|
|
||||||
gbinder_buffer_free(data->buffer);
|
gbinder_buffer_free(data->buffer);
|
||||||
data->buffer = buffer;
|
data->buffer = buffer;
|
||||||
data->objects = objects;
|
data->objects = gbinder_buffer_objects(buffer);
|
||||||
} else {
|
} else {
|
||||||
gbinder_buffer_free(buffer);
|
gbinder_buffer_free(buffer);
|
||||||
g_free(objects);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +121,7 @@ gbinder_remote_reply_copy_to_local(
|
|||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderReaderData* d = &self->data;
|
GBinderReaderData* d = &self->data;
|
||||||
|
|
||||||
return gbinder_local_reply_new_from_data(d->buffer, d->objects);
|
return gbinder_local_reply_new_from_data(d->buffer);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -39,17 +39,19 @@
|
|||||||
|
|
||||||
GBinderRemoteReply*
|
GBinderRemoteReply*
|
||||||
gbinder_remote_reply_new(
|
gbinder_remote_reply_new(
|
||||||
GBinderObjectRegistry* reg);
|
GBinderObjectRegistry* reg)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_remote_reply_set_data(
|
gbinder_remote_reply_set_data(
|
||||||
GBinderRemoteReply* reply,
|
GBinderRemoteReply* reply,
|
||||||
GBinderBuffer* buffer,
|
GBinderBuffer* buffer)
|
||||||
void** objects);
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_remote_reply_is_empty(
|
gbinder_remote_reply_is_empty(
|
||||||
GBinderRemoteReply* reply);
|
GBinderRemoteReply* reply)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_REMOTE_REPLY_PRIVATE_H */
|
#endif /* GBINDER_REMOTE_REPLY_PRIVATE_H */
|
||||||
|
|
||||||
|
|||||||
@@ -35,12 +35,15 @@
|
|||||||
#include "gbinder_rpc_protocol.h"
|
#include "gbinder_rpc_protocol.h"
|
||||||
#include "gbinder_local_request_p.h"
|
#include "gbinder_local_request_p.h"
|
||||||
#include "gbinder_object_registry.h"
|
#include "gbinder_object_registry.h"
|
||||||
#include "gbinder_buffer.h"
|
#include "gbinder_buffer_p.h"
|
||||||
#include "gbinder_log.h"
|
#include "gbinder_log.h"
|
||||||
|
|
||||||
#include <gutil_macros.h>
|
#include <gutil_macros.h>
|
||||||
|
|
||||||
struct gbinder_remote_request {
|
#include <errno.h>
|
||||||
|
|
||||||
|
typedef struct gbinder_remote_request_priv {
|
||||||
|
GBinderRemoteRequest pub;
|
||||||
gint refcount;
|
gint refcount;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
uid_t euid;
|
uid_t euid;
|
||||||
@@ -49,7 +52,11 @@ struct gbinder_remote_request {
|
|||||||
char* iface2;
|
char* iface2;
|
||||||
gsize header_size;
|
gsize header_size;
|
||||||
GBinderReaderData data;
|
GBinderReaderData data;
|
||||||
};
|
} GBinderRemoteRequestPriv;
|
||||||
|
|
||||||
|
GBINDER_INLINE_FUNC GBinderRemoteRequestPriv*
|
||||||
|
gbinder_remote_request_cast(GBinderRemoteRequest* pub)
|
||||||
|
{ return G_LIKELY(pub) ? G_CAST(pub,GBinderRemoteRequestPriv,pub) : NULL; }
|
||||||
|
|
||||||
GBinderRemoteRequest*
|
GBinderRemoteRequest*
|
||||||
gbinder_remote_request_new(
|
gbinder_remote_request_new(
|
||||||
@@ -58,7 +65,7 @@ gbinder_remote_request_new(
|
|||||||
pid_t pid,
|
pid_t pid,
|
||||||
uid_t euid)
|
uid_t euid)
|
||||||
{
|
{
|
||||||
GBinderRemoteRequest* self = g_slice_new0(GBinderRemoteRequest);
|
GBinderRemoteRequestPriv* self = g_slice_new0(GBinderRemoteRequestPriv);
|
||||||
GBinderReaderData* data = &self->data;
|
GBinderReaderData* data = &self->data;
|
||||||
|
|
||||||
g_atomic_int_set(&self->refcount, 1);
|
g_atomic_int_set(&self->refcount, 1);
|
||||||
@@ -66,17 +73,19 @@ gbinder_remote_request_new(
|
|||||||
self->euid = euid;
|
self->euid = euid;
|
||||||
self->protocol = protocol;
|
self->protocol = protocol;
|
||||||
data->reg = gbinder_object_registry_ref(reg);
|
data->reg = gbinder_object_registry_ref(reg);
|
||||||
return self;
|
return &self->pub;
|
||||||
}
|
}
|
||||||
|
|
||||||
GBinderLocalRequest*
|
GBinderLocalRequest*
|
||||||
gbinder_remote_request_copy_to_local(
|
gbinder_remote_request_copy_to_local(
|
||||||
GBinderRemoteRequest* self)
|
GBinderRemoteRequest* req)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderReaderData* d = &self->data;
|
GBinderReaderData* d = &self->data;
|
||||||
|
|
||||||
return gbinder_local_request_new_from_data(d->buffer, d->objects);
|
return gbinder_local_request_new_from_data(d->buffer);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -84,22 +93,27 @@ gbinder_remote_request_copy_to_local(
|
|||||||
static
|
static
|
||||||
void
|
void
|
||||||
gbinder_remote_request_free(
|
gbinder_remote_request_free(
|
||||||
GBinderRemoteRequest* self)
|
GBinderRemoteRequestPriv* self)
|
||||||
{
|
{
|
||||||
GBinderReaderData* data = &self->data;
|
GBinderReaderData* data = &self->data;
|
||||||
|
GBinderRemoteRequest* req = &self->pub;
|
||||||
|
|
||||||
|
GASSERT(!req->tx);
|
||||||
|
if (req->tx) {
|
||||||
|
GWARN("Request is dropped without completing the transaction");
|
||||||
|
gbinder_remote_request_complete(req, NULL, -ECANCELED);
|
||||||
|
}
|
||||||
gbinder_object_registry_unref(data->reg);
|
gbinder_object_registry_unref(data->reg);
|
||||||
gbinder_buffer_free(data->buffer);
|
gbinder_buffer_free(data->buffer);
|
||||||
g_free(data->objects);
|
|
||||||
g_free(self->iface2);
|
g_free(self->iface2);
|
||||||
g_slice_free(GBinderRemoteRequest, self);
|
g_slice_free(GBinderRemoteRequestPriv, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
inline
|
inline
|
||||||
void
|
void
|
||||||
gbinder_remote_request_init_reader2(
|
gbinder_remote_request_init_reader2(
|
||||||
GBinderRemoteRequest* self,
|
GBinderRemoteRequestPriv* self,
|
||||||
GBinderReader* p)
|
GBinderReader* p)
|
||||||
{
|
{
|
||||||
/* The caller has already checked the request for NULL */
|
/* The caller has already checked the request for NULL */
|
||||||
@@ -116,53 +130,64 @@ gbinder_remote_request_init_reader2(
|
|||||||
|
|
||||||
void
|
void
|
||||||
gbinder_remote_request_set_data(
|
gbinder_remote_request_set_data(
|
||||||
GBinderRemoteRequest* self,
|
GBinderRemoteRequest* req,
|
||||||
GBinderBuffer* buffer,
|
guint32 txcode,
|
||||||
void** objects)
|
GBinderBuffer* buffer)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderReaderData* data = &self->data;
|
GBinderReaderData* data = &self->data;
|
||||||
GBinderReader reader;
|
GBinderReader reader;
|
||||||
|
|
||||||
g_free(self->iface2);
|
g_free(self->iface2);
|
||||||
g_free(data->objects);
|
|
||||||
gbinder_buffer_free(data->buffer);
|
gbinder_buffer_free(data->buffer);
|
||||||
data->buffer = buffer;
|
data->buffer = buffer;
|
||||||
data->objects = objects;
|
data->objects = gbinder_buffer_objects(buffer);
|
||||||
|
|
||||||
/* Parse RPC header */
|
/* Parse RPC header */
|
||||||
self->header_size = 0;
|
|
||||||
gbinder_remote_request_init_reader2(self, &reader);
|
gbinder_remote_request_init_reader2(self, &reader);
|
||||||
self->iface = self->protocol->read_rpc_header(&reader, &self->iface2);
|
self->iface = self->protocol->read_rpc_header(&reader, txcode,
|
||||||
self->header_size = gbinder_reader_bytes_read(&reader);
|
&self->iface2);
|
||||||
|
if (self->iface) {
|
||||||
|
self->header_size = gbinder_reader_bytes_read(&reader);
|
||||||
|
} else {
|
||||||
|
/* No RPC header */
|
||||||
|
self->header_size = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
gbinder_buffer_free(buffer);
|
gbinder_buffer_free(buffer);
|
||||||
g_free(objects);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
gbinder_remote_request_interface(
|
gbinder_remote_request_interface(
|
||||||
GBinderRemoteRequest* self)
|
GBinderRemoteRequest* req)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
return G_LIKELY(self) ? self->iface : NULL;
|
return G_LIKELY(self) ? self->iface : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GBinderRemoteRequest*
|
GBinderRemoteRequest*
|
||||||
gbinder_remote_request_ref(
|
gbinder_remote_request_ref(
|
||||||
GBinderRemoteRequest* self)
|
GBinderRemoteRequest* req)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GASSERT(self->refcount > 0);
|
GASSERT(self->refcount > 0);
|
||||||
g_atomic_int_inc(&self->refcount);
|
g_atomic_int_inc(&self->refcount);
|
||||||
}
|
}
|
||||||
return self;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_remote_request_unref(
|
gbinder_remote_request_unref(
|
||||||
GBinderRemoteRequest* self)
|
GBinderRemoteRequest* req)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GASSERT(self->refcount > 0);
|
GASSERT(self->refcount > 0);
|
||||||
if (g_atomic_int_dec_and_test(&self->refcount)) {
|
if (g_atomic_int_dec_and_test(&self->refcount)) {
|
||||||
@@ -173,9 +198,11 @@ gbinder_remote_request_unref(
|
|||||||
|
|
||||||
void
|
void
|
||||||
gbinder_remote_request_init_reader(
|
gbinder_remote_request_init_reader(
|
||||||
GBinderRemoteRequest* self,
|
GBinderRemoteRequest* req,
|
||||||
GBinderReader* reader)
|
GBinderReader* reader)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
gbinder_remote_request_init_reader2(self, reader);
|
gbinder_remote_request_init_reader2(self, reader);
|
||||||
} else {
|
} else {
|
||||||
@@ -185,15 +212,19 @@ gbinder_remote_request_init_reader(
|
|||||||
|
|
||||||
pid_t
|
pid_t
|
||||||
gbinder_remote_request_sender_pid(
|
gbinder_remote_request_sender_pid(
|
||||||
GBinderRemoteRequest* self)
|
GBinderRemoteRequest* req)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
return G_LIKELY(self) ? self->pid : (uid_t)(-1);
|
return G_LIKELY(self) ? self->pid : (uid_t)(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uid_t
|
uid_t
|
||||||
gbinder_remote_request_sender_euid(
|
gbinder_remote_request_sender_euid(
|
||||||
GBinderRemoteRequest* self)
|
GBinderRemoteRequest* req)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
return G_LIKELY(self) ? self->euid : (uid_t)(-1);
|
return G_LIKELY(self) ? self->euid : (uid_t)(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,9 +238,11 @@ gbinder_remote_request_read_int32(
|
|||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_remote_request_read_uint32(
|
gbinder_remote_request_read_uint32(
|
||||||
GBinderRemoteRequest* self,
|
GBinderRemoteRequest* req,
|
||||||
guint32* value)
|
guint32* value)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderReader reader;
|
GBinderReader reader;
|
||||||
|
|
||||||
@@ -229,9 +262,11 @@ gbinder_remote_request_read_int64(
|
|||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gbinder_remote_request_read_uint64(
|
gbinder_remote_request_read_uint64(
|
||||||
GBinderRemoteRequest* self,
|
GBinderRemoteRequest* req,
|
||||||
guint64* value)
|
guint64* value)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderReader reader;
|
GBinderReader reader;
|
||||||
|
|
||||||
@@ -243,8 +278,10 @@ gbinder_remote_request_read_uint64(
|
|||||||
|
|
||||||
const char*
|
const char*
|
||||||
gbinder_remote_request_read_string8(
|
gbinder_remote_request_read_string8(
|
||||||
GBinderRemoteRequest* self)
|
GBinderRemoteRequest* req)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderReader reader;
|
GBinderReader reader;
|
||||||
|
|
||||||
@@ -256,8 +293,10 @@ gbinder_remote_request_read_string8(
|
|||||||
|
|
||||||
char*
|
char*
|
||||||
gbinder_remote_request_read_string16(
|
gbinder_remote_request_read_string16(
|
||||||
GBinderRemoteRequest* self)
|
GBinderRemoteRequest* req)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderReader reader;
|
GBinderReader reader;
|
||||||
|
|
||||||
@@ -269,8 +308,10 @@ gbinder_remote_request_read_string16(
|
|||||||
|
|
||||||
GBinderRemoteObject*
|
GBinderRemoteObject*
|
||||||
gbinder_remote_request_read_object(
|
gbinder_remote_request_read_object(
|
||||||
GBinderRemoteRequest* self)
|
GBinderRemoteRequest* req)
|
||||||
{
|
{
|
||||||
|
GBinderRemoteRequestPriv* self = gbinder_remote_request_cast(req);
|
||||||
|
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
GBinderReader reader;
|
GBinderReader reader;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -37,18 +37,24 @@
|
|||||||
|
|
||||||
#include "gbinder_types_p.h"
|
#include "gbinder_types_p.h"
|
||||||
|
|
||||||
|
struct gbinder_remote_request {
|
||||||
|
GBinderIpcLooperTx* tx;
|
||||||
|
};
|
||||||
|
|
||||||
GBinderRemoteRequest*
|
GBinderRemoteRequest*
|
||||||
gbinder_remote_request_new(
|
gbinder_remote_request_new(
|
||||||
GBinderObjectRegistry* reg,
|
GBinderObjectRegistry* reg,
|
||||||
const GBinderRpcProtocol* protocol,
|
const GBinderRpcProtocol* protocol,
|
||||||
pid_t pid,
|
pid_t pid,
|
||||||
uid_t euid);
|
uid_t euid)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_remote_request_set_data(
|
gbinder_remote_request_set_data(
|
||||||
GBinderRemoteRequest* request,
|
GBinderRemoteRequest* request,
|
||||||
GBinderBuffer* buffer,
|
guint txcode,
|
||||||
void** objects);
|
GBinderBuffer* buffer)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_REMOTE_REQUEST_PRIVATE_H */
|
#endif /* GBINDER_REMOTE_REQUEST_PRIVATE_H */
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -50,6 +50,14 @@
|
|||||||
#define STRICT_MODE_PENALTY_GATHER (0x40 << 16)
|
#define STRICT_MODE_PENALTY_GATHER (0x40 << 16)
|
||||||
#define BINDER_RPC_FLAGS (STRICT_MODE_PENALTY_GATHER)
|
#define BINDER_RPC_FLAGS (STRICT_MODE_PENALTY_GATHER)
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_rpc_protocol_binder_write_ping(
|
||||||
|
GBinderWriter* writer)
|
||||||
|
{
|
||||||
|
/* No payload */
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
gbinder_rpc_protocol_binder_write_rpc_header(
|
gbinder_rpc_protocol_binder_write_rpc_header(
|
||||||
@@ -69,9 +77,13 @@ static
|
|||||||
const char*
|
const char*
|
||||||
gbinder_rpc_protocol_binder_read_rpc_header(
|
gbinder_rpc_protocol_binder_read_rpc_header(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
|
guint32 txcode,
|
||||||
char** iface)
|
char** iface)
|
||||||
{
|
{
|
||||||
if (gbinder_reader_read_int32(reader, NULL)) {
|
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)) {
|
||||||
*iface = gbinder_reader_read_string16(reader);
|
*iface = gbinder_reader_read_string16(reader);
|
||||||
} else {
|
} else {
|
||||||
*iface = NULL;
|
*iface = NULL;
|
||||||
@@ -95,10 +107,20 @@ gbinder_rpc_protocol_hwbinder_write_rpc_header(
|
|||||||
gbinder_writer_append_string8(writer, iface);
|
gbinder_writer_append_string8(writer, iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_rpc_protocol_hwbinder_write_ping(
|
||||||
|
GBinderWriter* writer)
|
||||||
|
{
|
||||||
|
gbinder_rpc_protocol_hwbinder_write_rpc_header(writer,
|
||||||
|
"android.hidl.base@1.0::IBase");
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
const char*
|
const char*
|
||||||
gbinder_rpc_protocol_hwbinder_read_rpc_header(
|
gbinder_rpc_protocol_hwbinder_read_rpc_header(
|
||||||
GBinderReader* reader,
|
GBinderReader* reader,
|
||||||
|
guint32 txcode,
|
||||||
char** iface)
|
char** iface)
|
||||||
{
|
{
|
||||||
*iface = NULL;
|
*iface = NULL;
|
||||||
@@ -110,13 +132,17 @@ gbinder_rpc_protocol_hwbinder_read_rpc_header(
|
|||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
|
|
||||||
const GBinderRpcProtocol gbinder_rpc_protocol_binder = {
|
const GBinderRpcProtocol gbinder_rpc_protocol_binder = {
|
||||||
.read_rpc_header = gbinder_rpc_protocol_binder_read_rpc_header,
|
.ping_tx = GBINDER_PING_TRANSACTION,
|
||||||
.write_rpc_header = gbinder_rpc_protocol_binder_write_rpc_header
|
.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 = {
|
const GBinderRpcProtocol gbinder_rpc_protocol_hwbinder = {
|
||||||
.read_rpc_header = gbinder_rpc_protocol_hwbinder_read_rpc_header,
|
.ping_tx = HIDL_PING_TRANSACTION,
|
||||||
.write_rpc_header = gbinder_rpc_protocol_hwbinder_write_rpc_header
|
.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*
|
const GBinderRpcProtocol*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -42,17 +42,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct gbinder_rpc_protocol {
|
struct gbinder_rpc_protocol {
|
||||||
const char* (*read_rpc_header)(GBinderReader* reader, char** iface);
|
guint32 ping_tx;
|
||||||
|
void (*write_ping)(GBinderWriter* writer);
|
||||||
void (*write_rpc_header)(GBinderWriter* writer, const char* iface);
|
void (*write_rpc_header)(GBinderWriter* writer, const char* iface);
|
||||||
|
const char* (*read_rpc_header)(GBinderReader* reader, guint32 txcode,
|
||||||
|
char** iface);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const GBinderRpcProtocol gbinder_rpc_protocol_binder;
|
extern const GBinderRpcProtocol gbinder_rpc_protocol_binder GBINDER_INTERNAL;
|
||||||
extern const GBinderRpcProtocol gbinder_rpc_protocol_hwbinder;
|
extern const GBinderRpcProtocol gbinder_rpc_protocol_hwbinder GBINDER_INTERNAL;
|
||||||
|
|
||||||
/* Returns one of the above based on the device name */
|
/* Returns one of the above based on the device name */
|
||||||
const GBinderRpcProtocol*
|
const GBinderRpcProtocol*
|
||||||
gbinder_rpc_protocol_for_device(
|
gbinder_rpc_protocol_for_device(
|
||||||
const char* dev);
|
const char* dev)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_RPC_PROTOCOL_H */
|
#endif /* GBINDER_RPC_PROTOCOL_H */
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -30,20 +30,44 @@
|
|||||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
||||||
|
|
||||||
#include "gbinder_servicemanager_p.h"
|
#include "gbinder_servicemanager_p.h"
|
||||||
#include "gbinder_client_p.h"
|
#include "gbinder_client_p.h"
|
||||||
#include "gbinder_local_object_p.h"
|
#include "gbinder_local_object_p.h"
|
||||||
#include "gbinder_remote_object_p.h"
|
#include "gbinder_remote_object_p.h"
|
||||||
|
#include "gbinder_eventloop_p.h"
|
||||||
#include "gbinder_driver.h"
|
#include "gbinder_driver.h"
|
||||||
#include "gbinder_ipc.h"
|
#include "gbinder_ipc.h"
|
||||||
#include "gbinder_log.h"
|
#include "gbinder_log.h"
|
||||||
|
|
||||||
#include <gbinder_client.h>
|
#include <gbinder_client.h>
|
||||||
|
|
||||||
#include <gutil_idlepool.h>
|
#include <gutil_misc.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#define PRESENSE_WAIT_MS_MIN (100)
|
||||||
|
#define PRESENSE_WAIT_MS_MAX (1000)
|
||||||
|
#define PRESENSE_WAIT_MS_STEP (100)
|
||||||
|
|
||||||
|
typedef struct gbinder_servicemanager_watch {
|
||||||
|
char* name;
|
||||||
|
char* detail;
|
||||||
|
GQuark quark;
|
||||||
|
gboolean watched;
|
||||||
|
} GBinderServiceManagerWatch;
|
||||||
|
|
||||||
|
struct gbinder_servicemanager_priv {
|
||||||
|
GHashTable* watch_table;
|
||||||
|
gulong death_id;
|
||||||
|
gboolean present;
|
||||||
|
GBinderEventLoopTimeout* presence_check;
|
||||||
|
guint presence_check_delay_ms;
|
||||||
|
GBinderEventLoopCallback* autorelease_cb;
|
||||||
|
GSList* autorelease;
|
||||||
|
};
|
||||||
|
|
||||||
G_DEFINE_ABSTRACT_TYPE(GBinderServiceManager, gbinder_servicemanager,
|
G_DEFINE_ABSTRACT_TYPE(GBinderServiceManager, gbinder_servicemanager,
|
||||||
G_TYPE_OBJECT)
|
G_TYPE_OBJECT)
|
||||||
|
|
||||||
@@ -60,6 +84,18 @@ G_DEFINE_ABSTRACT_TYPE(GBinderServiceManager, gbinder_servicemanager,
|
|||||||
#define GBINDER_IS_SERVICEMANAGER_TYPE(klass) \
|
#define GBINDER_IS_SERVICEMANAGER_TYPE(klass) \
|
||||||
G_TYPE_CHECK_CLASS_TYPE(klass, GBINDER_TYPE_SERVICEMANAGER)
|
G_TYPE_CHECK_CLASS_TYPE(klass, GBINDER_TYPE_SERVICEMANAGER)
|
||||||
|
|
||||||
|
enum gbinder_servicemanager_signal {
|
||||||
|
SIGNAL_PRESENCE,
|
||||||
|
SIGNAL_REGISTRATION,
|
||||||
|
SIGNAL_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char SIGNAL_PRESENCE_NAME[] = "servicemanager-presence";
|
||||||
|
static const char SIGNAL_REGISTRATION_NAME[] = "servicemanager-registration";
|
||||||
|
#define DETAIL_LEN 32
|
||||||
|
|
||||||
|
static guint gbinder_servicemanager_signals[SIGNAL_COUNT] = { 0 };
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* Implementation
|
* Implementation
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@@ -81,53 +117,29 @@ gbinder_servicemanager_class_ref(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GBinderServiceManager*
|
static
|
||||||
gbinder_servicemanager_new_with_type(
|
GBinderServiceManagerWatch*
|
||||||
GType type,
|
gbinder_servicemanager_watch_new(
|
||||||
const char* dev)
|
const char* name)
|
||||||
{
|
{
|
||||||
GBinderServiceManager* self = NULL;
|
GBinderServiceManagerWatch* watch = g_new0(GBinderServiceManagerWatch, 1);
|
||||||
GBinderServiceManagerClass* klass = gbinder_servicemanager_class_ref(type);
|
|
||||||
|
|
||||||
if (klass) {
|
watch->name = g_strdup(name);
|
||||||
GBinderIpc* ipc;
|
watch->detail = g_compute_checksum_for_string(G_CHECKSUM_MD5, name, -1);
|
||||||
|
watch->quark = g_quark_from_string(watch->detail);
|
||||||
|
return watch;
|
||||||
|
}
|
||||||
|
|
||||||
if (!dev) dev = klass->default_device;
|
static
|
||||||
ipc = gbinder_ipc_new(dev, klass->rpc_protocol);
|
void
|
||||||
if (ipc) {
|
gbinder_servicemanager_watch_free(
|
||||||
GBinderRemoteObject* object = gbinder_ipc_get_remote_object
|
gpointer data)
|
||||||
(ipc, klass->handle);
|
{
|
||||||
|
GBinderServiceManagerWatch* watch = data;
|
||||||
|
|
||||||
if (object) {
|
g_free(watch->name);
|
||||||
/* Lock */
|
g_free(watch->detail);
|
||||||
g_mutex_lock(&klass->mutex);
|
g_free(watch);
|
||||||
if (klass->table) {
|
|
||||||
self = g_hash_table_lookup(klass->table, dev);
|
|
||||||
}
|
|
||||||
if (self) {
|
|
||||||
gbinder_servicemanager_ref(self);
|
|
||||||
} else {
|
|
||||||
char* key = g_strdup(dev); /* Owned by the hashtable */
|
|
||||||
|
|
||||||
GVERBOSE_("%s", dev);
|
|
||||||
self = g_object_new(type, NULL);
|
|
||||||
self->client = gbinder_client_new(object, klass->iface);
|
|
||||||
self->dev = gbinder_remote_object_dev(object);
|
|
||||||
if (!klass->table) {
|
|
||||||
klass->table = g_hash_table_new_full(g_str_hash,
|
|
||||||
g_str_equal, g_free, NULL);
|
|
||||||
}
|
|
||||||
g_hash_table_replace(klass->table, key, self);
|
|
||||||
}
|
|
||||||
g_mutex_unlock(&klass->mutex);
|
|
||||||
/* Unlock */
|
|
||||||
gbinder_remote_object_unref(object);
|
|
||||||
}
|
|
||||||
gbinder_ipc_unref(ipc);
|
|
||||||
}
|
|
||||||
g_type_class_unref(klass);
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct gbinder_servicemanager_list_tx_data {
|
typedef struct gbinder_servicemanager_list_tx_data {
|
||||||
@@ -157,6 +169,7 @@ gbinder_servicemanager_list_tx_done(
|
|||||||
if (!data->func(data->sm, data->result, data->user_data)) {
|
if (!data->func(data->sm, data->result, data->user_data)) {
|
||||||
g_strfreev(data->result);
|
g_strfreev(data->result);
|
||||||
}
|
}
|
||||||
|
data->result = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -166,6 +179,7 @@ gbinder_servicemanager_list_tx_free(
|
|||||||
{
|
{
|
||||||
GBinderServiceManagerListTxData* data = user_data;
|
GBinderServiceManagerListTxData* data = user_data;
|
||||||
|
|
||||||
|
g_strfreev(data->result);
|
||||||
gbinder_servicemanager_unref(data->sm);
|
gbinder_servicemanager_unref(data->sm);
|
||||||
g_slice_free(GBinderServiceManagerListTxData, data);
|
g_slice_free(GBinderServiceManagerListTxData, data);
|
||||||
}
|
}
|
||||||
@@ -256,6 +270,245 @@ gbinder_servicemanager_add_service_tx_free(
|
|||||||
g_slice_free(GBinderServiceManagerAddServiceTxData, data);
|
g_slice_free(GBinderServiceManagerAddServiceTxData, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_servicemanager_reanimated(
|
||||||
|
GBinderServiceManager* self)
|
||||||
|
{
|
||||||
|
GBinderServiceManagerPriv* priv = self->priv;
|
||||||
|
|
||||||
|
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 */
|
||||||
|
if (g_hash_table_size(priv->watch_table) > 0) {
|
||||||
|
gpointer value;
|
||||||
|
GHashTableIter it;
|
||||||
|
GBinderServiceManagerClass* klass =
|
||||||
|
GBINDER_SERVICEMANAGER_GET_CLASS(self);
|
||||||
|
|
||||||
|
g_hash_table_iter_init(&it, priv->watch_table);
|
||||||
|
while (g_hash_table_iter_next(&it, NULL, &value)) {
|
||||||
|
GBinderServiceManagerWatch* watch = value;
|
||||||
|
|
||||||
|
GASSERT(!watch->watched);
|
||||||
|
watch->watched = klass->watch(self, watch->name);
|
||||||
|
if (watch->watched) {
|
||||||
|
GDEBUG("Watching %s", watch->name);
|
||||||
|
} else {
|
||||||
|
GWARN("Failed to watch %s", watch->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_signal_emit(self, gbinder_servicemanager_signals[SIGNAL_PRESENCE], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
gbinder_servicemanager_presense_check_timer(
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GBinderServiceManager* self = GBINDER_SERVICEMANAGER(user_data);
|
||||||
|
GBinderRemoteObject* remote = self->client->remote;
|
||||||
|
GBinderServiceManagerPriv* priv = self->priv;
|
||||||
|
gboolean result;
|
||||||
|
|
||||||
|
GASSERT(remote->dead);
|
||||||
|
gbinder_servicemanager_ref(self);
|
||||||
|
if (gbinder_remote_object_reanimate(remote)) {
|
||||||
|
/* Done */
|
||||||
|
priv->presence_check = 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 =
|
||||||
|
gbinder_timeout_add(priv->presence_check_delay_ms,
|
||||||
|
gbinder_servicemanager_presense_check_timer, self);
|
||||||
|
result = G_SOURCE_REMOVE;
|
||||||
|
} else {
|
||||||
|
result = G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
gbinder_servicemanager_unref(self);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_servicemanager_presence_check_start(
|
||||||
|
GBinderServiceManager* self)
|
||||||
|
{
|
||||||
|
GBinderServiceManagerPriv* priv = self->priv;
|
||||||
|
|
||||||
|
GASSERT(!priv->presence_check);
|
||||||
|
priv->presence_check_delay_ms = PRESENSE_WAIT_MS_MIN;
|
||||||
|
priv->presence_check = gbinder_timeout_add(PRESENSE_WAIT_MS_MIN,
|
||||||
|
gbinder_servicemanager_presense_check_timer, self);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_servicemanager_died(
|
||||||
|
GBinderRemoteObject* remote,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
GBinderServiceManager* self = GBINDER_SERVICEMANAGER(user_data);
|
||||||
|
GBinderServiceManagerPriv* priv = self->priv;
|
||||||
|
|
||||||
|
GWARN("Service manager %s has died", self->dev);
|
||||||
|
gbinder_servicemanager_presence_check_start(self);
|
||||||
|
|
||||||
|
/* Will re-arm watches after servicemanager gets restarted */
|
||||||
|
if (g_hash_table_size(priv->watch_table) > 0) {
|
||||||
|
gpointer value;
|
||||||
|
GHashTableIter it;
|
||||||
|
GBinderServiceManagerClass* klass =
|
||||||
|
GBINDER_SERVICEMANAGER_GET_CLASS(self);
|
||||||
|
|
||||||
|
g_hash_table_iter_init(&it, priv->watch_table);
|
||||||
|
while (g_hash_table_iter_next(&it, NULL, &value)) {
|
||||||
|
GBinderServiceManagerWatch* watch = value;
|
||||||
|
|
||||||
|
if (watch->watched) {
|
||||||
|
GDEBUG("Unwatching %s", watch->name);
|
||||||
|
watch->watched = FALSE;
|
||||||
|
klass->unwatch(self, watch->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_signal_emit(self, gbinder_servicemanager_signals[SIGNAL_PRESENCE], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_servicemanager_sleep_ms(
|
||||||
|
gulong ms)
|
||||||
|
{
|
||||||
|
struct timespec wait;
|
||||||
|
|
||||||
|
wait.tv_sec = ms/1000; /* seconds */
|
||||||
|
wait.tv_nsec = (ms % 1000) * 1000000; /* nanoseconds */
|
||||||
|
while (nanosleep(&wait, &wait) == -1 && errno == EINTR &&
|
||||||
|
(wait.tv_sec > 0 || wait.tv_nsec > 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* Internal interface
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
GBinderServiceManager*
|
||||||
|
gbinder_servicemanager_new_with_type(
|
||||||
|
GType type,
|
||||||
|
const char* dev)
|
||||||
|
{
|
||||||
|
GBinderServiceManager* self = NULL;
|
||||||
|
GBinderServiceManagerClass* klass = gbinder_servicemanager_class_ref(type);
|
||||||
|
|
||||||
|
if (klass) {
|
||||||
|
GBinderIpc* ipc;
|
||||||
|
|
||||||
|
if (!dev) dev = klass->default_device;
|
||||||
|
ipc = gbinder_ipc_new(dev, klass->rpc_protocol);
|
||||||
|
if (ipc) {
|
||||||
|
/* Create a possible dead remote object */
|
||||||
|
GBinderRemoteObject* object = gbinder_ipc_get_remote_object
|
||||||
|
(ipc, GBINDER_SERVICEMANAGER_HANDLE, TRUE);
|
||||||
|
|
||||||
|
if (object) {
|
||||||
|
gboolean first_ref;
|
||||||
|
|
||||||
|
/* Lock */
|
||||||
|
g_mutex_lock(&klass->mutex);
|
||||||
|
if (klass->table) {
|
||||||
|
self = g_hash_table_lookup(klass->table, dev);
|
||||||
|
}
|
||||||
|
if (self) {
|
||||||
|
first_ref = FALSE;
|
||||||
|
gbinder_servicemanager_ref(self);
|
||||||
|
} else {
|
||||||
|
char* key = g_strdup(dev); /* Owned by the hashtable */
|
||||||
|
|
||||||
|
first_ref = TRUE;
|
||||||
|
self = g_object_new(type, NULL);
|
||||||
|
self->client = gbinder_client_new(object, klass->iface);
|
||||||
|
self->dev = gbinder_remote_object_dev(object);
|
||||||
|
if (!klass->table) {
|
||||||
|
klass->table = g_hash_table_new_full(g_str_hash,
|
||||||
|
g_str_equal, g_free, NULL);
|
||||||
|
}
|
||||||
|
g_hash_table_replace(klass->table, key, self);
|
||||||
|
}
|
||||||
|
g_mutex_unlock(&klass->mutex);
|
||||||
|
/* Unlock */
|
||||||
|
if (first_ref) {
|
||||||
|
GBinderServiceManagerPriv* priv = self->priv;
|
||||||
|
|
||||||
|
priv->death_id =
|
||||||
|
gbinder_remote_object_add_death_handler(object,
|
||||||
|
gbinder_servicemanager_died, self);
|
||||||
|
/* Query the actual state if necessary */
|
||||||
|
gbinder_remote_object_reanimate(object);
|
||||||
|
if (object->dead) {
|
||||||
|
gbinder_servicemanager_presence_check_start(self);
|
||||||
|
}
|
||||||
|
GDEBUG("%s has %sservice manager", dev,
|
||||||
|
object->dead ? "no " : "");
|
||||||
|
}
|
||||||
|
gbinder_remote_object_unref(object);
|
||||||
|
}
|
||||||
|
gbinder_ipc_unref(ipc);
|
||||||
|
}
|
||||||
|
g_type_class_unref(klass);
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicemanager_service_registered(
|
||||||
|
GBinderServiceManager* self,
|
||||||
|
const char* name)
|
||||||
|
{
|
||||||
|
GBinderServiceManagerClass* klass = GBINDER_SERVICEMANAGER_GET_CLASS(self);
|
||||||
|
GBinderServiceManagerPriv* priv = self->priv;
|
||||||
|
GBinderServiceManagerWatch* watch = NULL;
|
||||||
|
const char* normalized_name;
|
||||||
|
char* tmp_name = NULL;
|
||||||
|
|
||||||
|
switch (klass->check_name(self, name)) {
|
||||||
|
case GBINDER_SERVICEMANAGER_NAME_OK:
|
||||||
|
normalized_name = name;
|
||||||
|
break;
|
||||||
|
case GBINDER_SERVICEMANAGER_NAME_NORMALIZE:
|
||||||
|
normalized_name = tmp_name = klass->normalize_name(self, name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
normalized_name = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (normalized_name) {
|
||||||
|
watch = g_hash_table_lookup(priv->watch_table, normalized_name);
|
||||||
|
}
|
||||||
|
g_free(tmp_name);
|
||||||
|
g_signal_emit(self, gbinder_servicemanager_signals[SIGNAL_REGISTRATION],
|
||||||
|
watch ? watch->quark : 0, name);
|
||||||
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* Interface
|
* Interface
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@@ -277,10 +530,25 @@ gbinder_servicemanager_new_local_object(
|
|||||||
const char* iface,
|
const char* iface,
|
||||||
GBinderLocalTransactFunc txproc,
|
GBinderLocalTransactFunc txproc,
|
||||||
void* user_data)
|
void* user_data)
|
||||||
|
{
|
||||||
|
const char* ifaces[2];
|
||||||
|
|
||||||
|
ifaces[0] = iface;
|
||||||
|
ifaces[1] = NULL;
|
||||||
|
return gbinder_servicemanager_new_local_object2
|
||||||
|
(self, ifaces, txproc, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
GBinderLocalObject*
|
||||||
|
gbinder_servicemanager_new_local_object2(
|
||||||
|
GBinderServiceManager* self,
|
||||||
|
const char* const* ifaces,
|
||||||
|
GBinderLocalTransactFunc txproc,
|
||||||
|
void* user_data)
|
||||||
{
|
{
|
||||||
if (G_LIKELY(self)) {
|
if (G_LIKELY(self)) {
|
||||||
return gbinder_ipc_new_local_object(gbinder_client_ipc(self->client),
|
return gbinder_local_object_new(gbinder_client_ipc(self->client),
|
||||||
iface, txproc, user_data);
|
ifaces, txproc, user_data);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -304,6 +572,58 @@ gbinder_servicemanager_unref(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gbinder_servicemanager_is_present(
|
||||||
|
GBinderServiceManager* self) /* Since 1.0.25 */
|
||||||
|
{
|
||||||
|
return G_LIKELY(self) && !self->client->remote->dead;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gbinder_servicemanager_wait(
|
||||||
|
GBinderServiceManager* self,
|
||||||
|
long max_wait_ms) /* Since 1.0.25 */
|
||||||
|
{
|
||||||
|
if (G_LIKELY(self)) {
|
||||||
|
GBinderRemoteObject* remote = self->client->remote;
|
||||||
|
|
||||||
|
if (!remote->dead) {
|
||||||
|
return TRUE;
|
||||||
|
} else if (gbinder_remote_object_reanimate(remote)) {
|
||||||
|
gbinder_servicemanager_reanimated(self);
|
||||||
|
return TRUE;
|
||||||
|
} else if (max_wait_ms != 0) {
|
||||||
|
/* Zero timeout means a singe check and it's already done */
|
||||||
|
long delay_ms = PRESENSE_WAIT_MS_MIN;
|
||||||
|
|
||||||
|
while (max_wait_ms != 0) {
|
||||||
|
if (max_wait_ms > 0) {
|
||||||
|
if (max_wait_ms < delay_ms) {
|
||||||
|
delay_ms = max_wait_ms;
|
||||||
|
max_wait_ms = 0;
|
||||||
|
} else {
|
||||||
|
max_wait_ms -= delay_ms;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gbinder_servicemanager_sleep_ms(delay_ms);
|
||||||
|
if (gbinder_remote_object_reanimate(remote)) {
|
||||||
|
gbinder_servicemanager_reanimated(self);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
if (delay_ms < PRESENSE_WAIT_MS_MAX) {
|
||||||
|
delay_ms += PRESENSE_WAIT_MS_STEP;
|
||||||
|
if (delay_ms > PRESENSE_WAIT_MS_MAX) {
|
||||||
|
delay_ms = PRESENSE_WAIT_MS_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Timeout */
|
||||||
|
GWARN("Timeout waiting for service manager %s", self->dev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
gulong
|
gulong
|
||||||
gbinder_servicemanager_list(
|
gbinder_servicemanager_list(
|
||||||
GBinderServiceManager* self,
|
GBinderServiceManager* self,
|
||||||
@@ -372,10 +692,15 @@ gbinder_servicemanager_get_service_sync(
|
|||||||
if (G_LIKELY(self) && name) {
|
if (G_LIKELY(self) && name) {
|
||||||
obj = GBINDER_SERVICEMANAGER_GET_CLASS(self)->get_service
|
obj = GBINDER_SERVICEMANAGER_GET_CLASS(self)->get_service
|
||||||
(self, name, status);
|
(self, name, status);
|
||||||
if (!self->pool) {
|
if (obj) {
|
||||||
self->pool = gutil_idle_pool_new();
|
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) {
|
} else if (status) {
|
||||||
*status = (-EINVAL);
|
*status = (-EINVAL);
|
||||||
}
|
}
|
||||||
@@ -433,6 +758,118 @@ gbinder_servicemanager_cancel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gulong
|
||||||
|
gbinder_servicemanager_add_presence_handler(
|
||||||
|
GBinderServiceManager* self,
|
||||||
|
GBinderServiceManagerFunc func,
|
||||||
|
void* user_data) /* Since 1.0.25 */
|
||||||
|
{
|
||||||
|
return (G_LIKELY(self) && G_LIKELY(func)) ? g_signal_connect(self,
|
||||||
|
SIGNAL_PRESENCE_NAME, G_CALLBACK(func), user_data) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
gulong
|
||||||
|
gbinder_servicemanager_add_registration_handler(
|
||||||
|
GBinderServiceManager* self,
|
||||||
|
const char* name,
|
||||||
|
GBinderServiceManagerRegistrationFunc func,
|
||||||
|
void* data) /* Since 1.0.13 */
|
||||||
|
{
|
||||||
|
gulong id = 0;
|
||||||
|
|
||||||
|
if (G_LIKELY(self) && G_LIKELY(func)) {
|
||||||
|
char* tmp_name = NULL;
|
||||||
|
GBinderServiceManagerClass* klass =
|
||||||
|
GBINDER_SERVICEMANAGER_GET_CLASS(self);
|
||||||
|
|
||||||
|
switch (klass->check_name(self, name)) {
|
||||||
|
case GBINDER_SERVICEMANAGER_NAME_OK:
|
||||||
|
break;
|
||||||
|
case GBINDER_SERVICEMANAGER_NAME_NORMALIZE:
|
||||||
|
name = tmp_name = klass->normalize_name(self, name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
name = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (name) {
|
||||||
|
GBinderServiceManagerPriv* priv = self->priv;
|
||||||
|
GBinderServiceManagerWatch* watch = NULL;
|
||||||
|
|
||||||
|
watch = g_hash_table_lookup(priv->watch_table, name);
|
||||||
|
if (!watch) {
|
||||||
|
watch = gbinder_servicemanager_watch_new(name);
|
||||||
|
g_hash_table_insert(priv->watch_table, watch->name, watch);
|
||||||
|
}
|
||||||
|
if (!watch->watched && !self->client->remote->dead) {
|
||||||
|
watch->watched = klass->watch(self, watch->name);
|
||||||
|
if (watch->watched) {
|
||||||
|
GDEBUG("Watching %s", watch->name);
|
||||||
|
} else {
|
||||||
|
GWARN("Failed to watch %s", watch->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
id = g_signal_connect_closure_by_id(self,
|
||||||
|
gbinder_servicemanager_signals[SIGNAL_REGISTRATION],
|
||||||
|
watch->quark, g_cclosure_new(G_CALLBACK(func), data, NULL),
|
||||||
|
FALSE);
|
||||||
|
}
|
||||||
|
g_free(tmp_name);
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicemanager_remove_handler(
|
||||||
|
GBinderServiceManager* self,
|
||||||
|
gulong id) /* Since 1.0.13 */
|
||||||
|
{
|
||||||
|
gbinder_servicemanager_remove_handlers(self, &id, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicemanager_remove_handlers(
|
||||||
|
GBinderServiceManager* self,
|
||||||
|
gulong* ids,
|
||||||
|
guint count) /* Since 1.0.25 */
|
||||||
|
{
|
||||||
|
if (G_LIKELY(self) && G_LIKELY(ids) && G_LIKELY(count)) {
|
||||||
|
guint i, disconnected = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
if (ids[i]) {
|
||||||
|
g_signal_handler_disconnect(self, ids[i]);
|
||||||
|
disconnected++;
|
||||||
|
ids[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disconnected) {
|
||||||
|
GBinderServiceManagerClass* klass =
|
||||||
|
GBINDER_SERVICEMANAGER_GET_CLASS(self);
|
||||||
|
GBinderServiceManagerPriv* priv = self->priv;
|
||||||
|
GHashTableIter it;
|
||||||
|
gpointer value;
|
||||||
|
|
||||||
|
g_hash_table_iter_init(&it, priv->watch_table);
|
||||||
|
while (disconnected && g_hash_table_iter_next(&it, NULL, &value)) {
|
||||||
|
GBinderServiceManagerWatch* watch = value;
|
||||||
|
|
||||||
|
if (watch->watched && !g_signal_has_handler_pending(self,
|
||||||
|
gbinder_servicemanager_signals[SIGNAL_REGISTRATION],
|
||||||
|
watch->quark, TRUE)) {
|
||||||
|
/* This must be one of those we have just removed */
|
||||||
|
GDEBUG("Unwatching %s", watch->name);
|
||||||
|
watch->watched = FALSE;
|
||||||
|
klass->unwatch(self, watch->name);
|
||||||
|
disconnected--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* Internals
|
* Internals
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@@ -442,6 +879,12 @@ void
|
|||||||
gbinder_servicemanager_init(
|
gbinder_servicemanager_init(
|
||||||
GBinderServiceManager* self)
|
GBinderServiceManager* self)
|
||||||
{
|
{
|
||||||
|
GBinderServiceManagerPriv* priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
|
||||||
|
GBINDER_TYPE_SERVICEMANAGER, GBinderServiceManagerPriv);
|
||||||
|
|
||||||
|
self->priv = priv;
|
||||||
|
priv->watch_table = g_hash_table_new_full(g_str_hash, g_str_equal,
|
||||||
|
NULL, gbinder_servicemanager_watch_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -450,8 +893,7 @@ gbinder_servicemanager_dispose(
|
|||||||
GObject* object)
|
GObject* object)
|
||||||
{
|
{
|
||||||
GBinderServiceManager* self = GBINDER_SERVICEMANAGER(object);
|
GBinderServiceManager* self = GBINDER_SERVICEMANAGER(object);
|
||||||
GBinderServiceManagerClass* klass =
|
GBinderServiceManagerClass* klass = GBINDER_SERVICEMANAGER_GET_CLASS(self);
|
||||||
GBINDER_SERVICEMANAGER_GET_CLASS(self);
|
|
||||||
|
|
||||||
GVERBOSE_("%s", self->dev);
|
GVERBOSE_("%s", self->dev);
|
||||||
/* Lock */
|
/* Lock */
|
||||||
@@ -493,9 +935,13 @@ gbinder_servicemanager_finalize(
|
|||||||
GObject* object)
|
GObject* object)
|
||||||
{
|
{
|
||||||
GBinderServiceManager* self = GBINDER_SERVICEMANAGER(object);
|
GBinderServiceManager* self = GBINDER_SERVICEMANAGER(object);
|
||||||
|
GBinderServiceManagerPriv* priv = self->priv;
|
||||||
|
|
||||||
gutil_idle_pool_drain(self->pool);
|
gbinder_timeout_remove(priv->presence_check);
|
||||||
gutil_idle_pool_unref(self->pool);
|
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);
|
||||||
gbinder_client_unref(self->client);
|
gbinder_client_unref(self->client);
|
||||||
G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
|
G_OBJECT_CLASS(PARENT_CLASS)->finalize(object);
|
||||||
}
|
}
|
||||||
@@ -506,10 +952,20 @@ gbinder_servicemanager_class_init(
|
|||||||
GBinderServiceManagerClass* klass)
|
GBinderServiceManagerClass* klass)
|
||||||
{
|
{
|
||||||
GObjectClass* object_class = G_OBJECT_CLASS(klass);
|
GObjectClass* object_class = G_OBJECT_CLASS(klass);
|
||||||
|
GType type = G_OBJECT_CLASS_TYPE(klass);
|
||||||
|
|
||||||
g_mutex_init(&klass->mutex);
|
g_mutex_init(&klass->mutex);
|
||||||
|
g_type_class_add_private(klass, sizeof(GBinderServiceManagerPriv));
|
||||||
object_class->dispose = gbinder_servicemanager_dispose;
|
object_class->dispose = gbinder_servicemanager_dispose;
|
||||||
object_class->finalize = gbinder_servicemanager_finalize;
|
object_class->finalize = gbinder_servicemanager_finalize;
|
||||||
|
gbinder_servicemanager_signals[SIGNAL_PRESENCE] =
|
||||||
|
g_signal_new(SIGNAL_PRESENCE_NAME, type,
|
||||||
|
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL,
|
||||||
|
G_TYPE_NONE, 0);
|
||||||
|
gbinder_servicemanager_signals[SIGNAL_REGISTRATION] =
|
||||||
|
g_signal_new(SIGNAL_REGISTRATION_NAME, type,
|
||||||
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED, 0, NULL, NULL, NULL,
|
||||||
|
G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -39,19 +39,29 @@
|
|||||||
|
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
|
||||||
|
/* As a special case, ServiceManager's handle is zero */
|
||||||
|
#define GBINDER_SERVICEMANAGER_HANDLE (0)
|
||||||
|
|
||||||
|
typedef struct gbinder_servicemanager_priv GBinderServiceManagerPriv;
|
||||||
|
|
||||||
typedef struct gbinder_servicemanager {
|
typedef struct gbinder_servicemanager {
|
||||||
GObject parent;
|
GObject parent;
|
||||||
|
GBinderServiceManagerPriv* priv;
|
||||||
const char* dev;
|
const char* dev;
|
||||||
GBinderClient* client;
|
GBinderClient* client;
|
||||||
GUtilIdlePool* pool;
|
|
||||||
} GBinderServiceManager;
|
} GBinderServiceManager;
|
||||||
|
|
||||||
|
typedef enum gbinder_servicemanager_name_check {
|
||||||
|
GBINDER_SERVICEMANAGER_NAME_OK,
|
||||||
|
GBINDER_SERVICEMANAGER_NAME_NORMALIZE,
|
||||||
|
GBINDER_SERVICEMANAGER_NAME_INVALID,
|
||||||
|
} GBINDER_SERVICEMANAGER_NAME_CHECK;
|
||||||
|
|
||||||
typedef struct gbinder_servicemanager_class {
|
typedef struct gbinder_servicemanager_class {
|
||||||
GObjectClass parent;
|
GObjectClass parent;
|
||||||
GMutex mutex;
|
GMutex mutex;
|
||||||
GHashTable* table;
|
GHashTable* table;
|
||||||
|
|
||||||
guint32 handle;
|
|
||||||
const char* iface;
|
const char* iface;
|
||||||
const char* default_device;
|
const char* default_device;
|
||||||
const GBinderRpcProtocol* rpc_protocol;
|
const GBinderRpcProtocol* rpc_protocol;
|
||||||
@@ -63,15 +73,31 @@ typedef struct gbinder_servicemanager_class {
|
|||||||
int (*add_service)
|
int (*add_service)
|
||||||
(GBinderServiceManager* self, const char* name,
|
(GBinderServiceManager* self, const char* name,
|
||||||
GBinderLocalObject* obj);
|
GBinderLocalObject* obj);
|
||||||
|
|
||||||
|
/* Checking/normalizing watch names */
|
||||||
|
GBINDER_SERVICEMANAGER_NAME_CHECK (*check_name)
|
||||||
|
(GBinderServiceManager* self, const char* name);
|
||||||
|
char* (*normalize_name)(GBinderServiceManager* self, const char* name);
|
||||||
|
|
||||||
|
/* If watch() returns FALSE, unwatch() is not called */
|
||||||
|
gboolean (*watch)(GBinderServiceManager* self, const char* name);
|
||||||
|
void (*unwatch)(GBinderServiceManager* self, const char* name);
|
||||||
} GBinderServiceManagerClass;
|
} 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_TYPE_SERVICEMANAGER (gbinder_servicemanager_get_type())
|
||||||
|
|
||||||
GBinderServiceManager*
|
GBinderServiceManager*
|
||||||
gbinder_servicemanager_new_with_type(
|
gbinder_servicemanager_new_with_type(
|
||||||
GType type,
|
GType type,
|
||||||
const char* dev);
|
const char* dev)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicemanager_service_registered(
|
||||||
|
GBinderServiceManager* self,
|
||||||
|
const char* name)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_SERVICEMANAGER_PRIVATE_H */
|
#endif /* GBINDER_SERVICEMANAGER_PRIVATE_H */
|
||||||
|
|
||||||
|
|||||||
173
src/gbinder_servicename.c
Normal file
173
src/gbinder_servicename.c
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Jolla Ltd.
|
||||||
|
* Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
|
||||||
|
*
|
||||||
|
* You may use this file under the terms of BSD license as follows:
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gbinder_types_p.h"
|
||||||
|
#include "gbinder_servicename.h"
|
||||||
|
#include "gbinder_servicemanager.h"
|
||||||
|
#include "gbinder_local_object.h"
|
||||||
|
#include "gbinder_log.h"
|
||||||
|
|
||||||
|
#include <gutil_macros.h>
|
||||||
|
|
||||||
|
/* Since 1.0.26 */
|
||||||
|
|
||||||
|
typedef struct gbinder_servicename_priv {
|
||||||
|
GBinderServiceName pub;
|
||||||
|
gint refcount;
|
||||||
|
char* name;
|
||||||
|
GBinderLocalObject* object;
|
||||||
|
GBinderServiceManager* sm;
|
||||||
|
gulong presence_id;
|
||||||
|
gulong add_call_id;
|
||||||
|
} GBinderServiceNamePriv;
|
||||||
|
|
||||||
|
GBINDER_INLINE_FUNC GBinderServiceNamePriv*
|
||||||
|
gbinder_servicename_cast(GBinderServiceName* pub)
|
||||||
|
{ return G_CAST(pub, GBinderServiceNamePriv, pub); }
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* Implementation
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_servicename_add_service_done(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
int status,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
GBinderServiceNamePriv* priv = user_data;
|
||||||
|
|
||||||
|
GASSERT(priv->add_call_id);
|
||||||
|
priv->add_call_id = 0;
|
||||||
|
if (status) {
|
||||||
|
GWARN("Error %d adding name \"%s\"", status, priv->name);
|
||||||
|
} else {
|
||||||
|
GDEBUG("Service \"%s\" has been registered", priv->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_servicename_add_service(
|
||||||
|
GBinderServiceNamePriv* priv)
|
||||||
|
{
|
||||||
|
GDEBUG("Adding service \"%s\"", priv->name);
|
||||||
|
gbinder_servicemanager_cancel(priv->sm, priv->add_call_id);
|
||||||
|
priv->add_call_id = gbinder_servicemanager_add_service(priv->sm,
|
||||||
|
priv->name, priv->object, gbinder_servicename_add_service_done, priv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_servicename_presence_handler(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
GBinderServiceNamePriv* priv = user_data;
|
||||||
|
|
||||||
|
if (gbinder_servicemanager_is_present(sm)) {
|
||||||
|
gbinder_servicename_add_service(priv);
|
||||||
|
} else if (priv->add_call_id) {
|
||||||
|
gbinder_servicemanager_cancel(priv->sm, priv->add_call_id);
|
||||||
|
priv->add_call_id = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* Interface
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
GBinderServiceName*
|
||||||
|
gbinder_servicename_new(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
GBinderLocalObject* object,
|
||||||
|
const char* name)
|
||||||
|
{
|
||||||
|
if (G_LIKELY(sm) && G_LIKELY(object) && G_LIKELY(name)) {
|
||||||
|
GBinderServiceNamePriv* priv = g_slice_new0(GBinderServiceNamePriv);
|
||||||
|
GBinderServiceName* self = &priv->pub;
|
||||||
|
|
||||||
|
g_atomic_int_set(&priv->refcount, 1);
|
||||||
|
priv->object = gbinder_local_object_ref(object);
|
||||||
|
priv->sm = gbinder_servicemanager_ref(sm);
|
||||||
|
self->name = priv->name = g_strdup(name);
|
||||||
|
priv->presence_id = gbinder_servicemanager_add_presence_handler(sm,
|
||||||
|
gbinder_servicename_presence_handler, priv);
|
||||||
|
if (gbinder_servicemanager_is_present(sm)) {
|
||||||
|
gbinder_servicename_add_service(priv);
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GBinderServiceName*
|
||||||
|
gbinder_servicename_ref(
|
||||||
|
GBinderServiceName* self)
|
||||||
|
{
|
||||||
|
if (G_LIKELY(self)) {
|
||||||
|
GBinderServiceNamePriv* priv = gbinder_servicename_cast(self);
|
||||||
|
|
||||||
|
GASSERT(priv->refcount > 0);
|
||||||
|
g_atomic_int_inc(&priv->refcount);
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicename_unref(
|
||||||
|
GBinderServiceName* self)
|
||||||
|
{
|
||||||
|
if (G_LIKELY(self)) {
|
||||||
|
GBinderServiceNamePriv* priv = gbinder_servicename_cast(self);
|
||||||
|
|
||||||
|
GASSERT(priv->refcount > 0);
|
||||||
|
if (g_atomic_int_dec_and_test(&priv->refcount)) {
|
||||||
|
gbinder_servicemanager_cancel(priv->sm, priv->add_call_id);
|
||||||
|
gbinder_servicemanager_remove_handler(priv->sm, priv->presence_id);
|
||||||
|
gbinder_servicemanager_unref(priv->sm);
|
||||||
|
gbinder_local_object_unref(priv->object);
|
||||||
|
g_free(priv->name);
|
||||||
|
g_slice_free(GBinderServiceName, self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local Variables:
|
||||||
|
* mode: C
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* indent-tabs-mode: nil
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
269
src/gbinder_servicepoll.c
Normal file
269
src/gbinder_servicepoll.c
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
/*
|
||||||
|
* 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:
|
||||||
|
*
|
||||||
|
* 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_servicepoll.h"
|
||||||
|
#include "gbinder_servicemanager.h"
|
||||||
|
#include "gbinder_eventloop_p.h"
|
||||||
|
|
||||||
|
#include <gutil_strv.h>
|
||||||
|
|
||||||
|
#include <glib-object.h>
|
||||||
|
|
||||||
|
/* This is configurable mostly so that unit testing doesn't take too long */
|
||||||
|
guint gbinder_servicepoll_interval_ms = 2000;
|
||||||
|
|
||||||
|
typedef GObjectClass GBinderServicePollClass;
|
||||||
|
struct gbinder_servicepoll {
|
||||||
|
GObject object;
|
||||||
|
GBinderServiceManager* manager;
|
||||||
|
char** list;
|
||||||
|
gulong list_id;
|
||||||
|
GBinderEventLoopTimeout* timer;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE(GBinderServicePoll, gbinder_servicepoll, G_TYPE_OBJECT)
|
||||||
|
#define GBINDER_TYPE_SERVICEPOLL (gbinder_servicepoll_get_type())
|
||||||
|
#define GBINDER_SERVICEPOLL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
|
||||||
|
GBINDER_TYPE_SERVICEPOLL, GBinderServicePoll))
|
||||||
|
|
||||||
|
enum gbinder_servicepoll_signal {
|
||||||
|
SIGNAL_NAME_ADDED,
|
||||||
|
SIGNAL_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char SIGNAL_NAME_ADDED_NAME[] = "servicepoll-name-added";
|
||||||
|
|
||||||
|
static guint gbinder_servicepoll_signals[SIGNAL_COUNT] = { 0 };
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* Implementation
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
/* GBinderServiceManagerListFunc callback returns TRUE to keep the services
|
||||||
|
* list, otherwise the caller will deallocate it. */
|
||||||
|
gboolean
|
||||||
|
gbinder_servicepoll_list(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
char** services,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
GBinderServicePoll* self = GBINDER_SERVICEPOLL(user_data);
|
||||||
|
|
||||||
|
gbinder_servicepoll_ref(self);
|
||||||
|
self->list_id = 0;
|
||||||
|
if (services) {
|
||||||
|
const GStrV* ptr_new;
|
||||||
|
|
||||||
|
ptr_new = services = gutil_strv_sort(services, TRUE);
|
||||||
|
if (self->list) {
|
||||||
|
const GStrV* ptr_old = self->list;
|
||||||
|
|
||||||
|
while (*ptr_new && *ptr_old) {
|
||||||
|
const int i = gutil_strv_find(ptr_old, *ptr_new);
|
||||||
|
|
||||||
|
if (i < 0) {
|
||||||
|
/* New name */
|
||||||
|
g_signal_emit(self, gbinder_servicepoll_signals
|
||||||
|
[SIGNAL_NAME_ADDED], 0, *ptr_new);
|
||||||
|
} else {
|
||||||
|
int k;
|
||||||
|
|
||||||
|
/* If some names have disappeared, then i may be > 0 */
|
||||||
|
for (k = 0; k < i; k ++) ptr_old++;
|
||||||
|
ptr_old++;
|
||||||
|
}
|
||||||
|
ptr_new++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (*ptr_new) {
|
||||||
|
g_signal_emit(self, gbinder_servicepoll_signals
|
||||||
|
[SIGNAL_NAME_ADDED], 0, *ptr_new);
|
||||||
|
ptr_new++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_strfreev(self->list);
|
||||||
|
self->list = services;
|
||||||
|
gbinder_servicepoll_unref(self);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
gbinder_servicepoll_timer(
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GBinderServicePoll* self = GBINDER_SERVICEPOLL(user_data);
|
||||||
|
|
||||||
|
if (!self->list_id) {
|
||||||
|
self->list_id = gbinder_servicemanager_list(self->manager,
|
||||||
|
gbinder_servicepoll_list, self);
|
||||||
|
}
|
||||||
|
return G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
GBinderServicePoll*
|
||||||
|
gbinder_servicepoll_create(
|
||||||
|
GBinderServiceManager* manager)
|
||||||
|
{
|
||||||
|
GBinderServicePoll* self = g_object_new(GBINDER_TYPE_SERVICEPOLL, NULL);
|
||||||
|
|
||||||
|
self->manager = gbinder_servicemanager_ref(manager);
|
||||||
|
self->list_id = gbinder_servicemanager_list(manager,
|
||||||
|
gbinder_servicepoll_list, self);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* API
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
GBinderServicePoll*
|
||||||
|
gbinder_servicepoll_new(
|
||||||
|
GBinderServiceManager* manager,
|
||||||
|
GBinderServicePoll** weakptr)
|
||||||
|
{
|
||||||
|
if (weakptr) {
|
||||||
|
if (*weakptr) {
|
||||||
|
gbinder_servicepoll_ref(*weakptr);
|
||||||
|
} else {
|
||||||
|
*weakptr = gbinder_servicepoll_create(manager);
|
||||||
|
g_object_add_weak_pointer(G_OBJECT(*weakptr), (gpointer*)weakptr);
|
||||||
|
}
|
||||||
|
return *weakptr;
|
||||||
|
} else {
|
||||||
|
return gbinder_servicepoll_create(manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GBinderServicePoll*
|
||||||
|
gbinder_servicepoll_ref(
|
||||||
|
GBinderServicePoll* self)
|
||||||
|
{
|
||||||
|
if (G_LIKELY(self)) {
|
||||||
|
g_object_ref(GBINDER_SERVICEPOLL(self));
|
||||||
|
return self;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicepoll_unref(
|
||||||
|
GBinderServicePoll* self)
|
||||||
|
{
|
||||||
|
if (G_LIKELY(self)) {
|
||||||
|
g_object_unref(GBINDER_SERVICEPOLL(self));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GBinderServiceManager*
|
||||||
|
gbinder_servicepoll_manager(
|
||||||
|
GBinderServicePoll* self)
|
||||||
|
{
|
||||||
|
return G_LIKELY(self) ? self->manager : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gbinder_servicepoll_is_known_name(
|
||||||
|
GBinderServicePoll* self,
|
||||||
|
const char* name)
|
||||||
|
{
|
||||||
|
return G_LIKELY(self) && gutil_strv_contains(self->list, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
gulong
|
||||||
|
gbinder_servicepoll_add_handler(
|
||||||
|
GBinderServicePoll* self,
|
||||||
|
GBinderServicePollFunc fn,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
return (G_LIKELY(self) && G_LIKELY(fn)) ? g_signal_connect(self,
|
||||||
|
SIGNAL_NAME_ADDED_NAME, G_CALLBACK(fn), user_data) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicepoll_remove_handler(
|
||||||
|
GBinderServicePoll* self,
|
||||||
|
gulong id)
|
||||||
|
{
|
||||||
|
if (G_LIKELY(self) && G_LIKELY(id)) {
|
||||||
|
g_signal_handler_disconnect(self, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* Internals
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_servicepoll_init(
|
||||||
|
GBinderServicePoll* self)
|
||||||
|
{
|
||||||
|
self->timer = gbinder_timeout_add(gbinder_servicepoll_interval_ms,
|
||||||
|
gbinder_servicepoll_timer, self);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_servicepoll_finalize(
|
||||||
|
GObject* object)
|
||||||
|
{
|
||||||
|
GBinderServicePoll* self = GBINDER_SERVICEPOLL(object);
|
||||||
|
|
||||||
|
gbinder_timeout_remove(self->timer);
|
||||||
|
gbinder_servicemanager_cancel(self->manager, self->list_id);
|
||||||
|
gbinder_servicemanager_unref(self->manager);
|
||||||
|
g_strfreev(self->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_servicepoll_class_init(
|
||||||
|
GBinderServicePollClass* klass)
|
||||||
|
{
|
||||||
|
G_OBJECT_CLASS(klass)->finalize = gbinder_servicepoll_finalize;
|
||||||
|
gbinder_servicepoll_signals[SIGNAL_NAME_ADDED] =
|
||||||
|
g_signal_new(SIGNAL_NAME_ADDED_NAME, G_OBJECT_CLASS_TYPE(klass),
|
||||||
|
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE,
|
||||||
|
1, G_TYPE_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local Variables:
|
||||||
|
* mode: C
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* indent-tabs-mode: nil
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
95
src/gbinder_servicepoll.h
Normal file
95
src/gbinder_servicepoll.h
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* 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:
|
||||||
|
*
|
||||||
|
* 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_SERVICEPOLL_H
|
||||||
|
#define GBINDER_SERVICEPOLL_H
|
||||||
|
|
||||||
|
#include "gbinder_types_p.h"
|
||||||
|
|
||||||
|
extern guint gbinder_servicepoll_interval_ms GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
typedef
|
||||||
|
void
|
||||||
|
(*GBinderServicePollFunc)(
|
||||||
|
GBinderServicePoll* poll,
|
||||||
|
const char* name_added,
|
||||||
|
void* user_data);
|
||||||
|
|
||||||
|
GBinderServicePoll*
|
||||||
|
gbinder_servicepoll_new(
|
||||||
|
GBinderServiceManager* manager,
|
||||||
|
GBinderServicePoll** weakptr)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
GBinderServicePoll*
|
||||||
|
gbinder_servicepoll_ref(
|
||||||
|
GBinderServicePoll* poll)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicepoll_unref(
|
||||||
|
GBinderServicePoll* poll)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
GBinderServiceManager*
|
||||||
|
gbinder_servicepoll_manager(
|
||||||
|
GBinderServicePoll* poll)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gbinder_servicepoll_is_known_name(
|
||||||
|
GBinderServicePoll* poll,
|
||||||
|
const char* name)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
gulong
|
||||||
|
gbinder_servicepoll_add_handler(
|
||||||
|
GBinderServicePoll* poll,
|
||||||
|
GBinderServicePollFunc func,
|
||||||
|
void* user_data)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_servicepoll_remove_handler(
|
||||||
|
GBinderServicePoll* poll,
|
||||||
|
gulong id)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
|
#endif /* GBINDER_SERVICEPOLL_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-2020 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -38,29 +38,34 @@
|
|||||||
int
|
int
|
||||||
gbinder_system_open(
|
gbinder_system_open(
|
||||||
const char* path,
|
const char* path,
|
||||||
int flags);
|
int flags)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
int
|
int
|
||||||
gbinder_system_close(
|
gbinder_system_close(
|
||||||
int fd);
|
int fd)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
int
|
int
|
||||||
gbinder_system_ioctl(
|
gbinder_system_ioctl(
|
||||||
int fd,
|
int fd,
|
||||||
int request,
|
int request,
|
||||||
void* data);
|
void* data)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void*
|
void*
|
||||||
gbinder_system_mmap(
|
gbinder_system_mmap(
|
||||||
size_t length,
|
size_t length,
|
||||||
int prot,
|
int prot,
|
||||||
int flags,
|
int flags,
|
||||||
int fd);
|
int fd)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
int
|
int
|
||||||
gbinder_system_munmap(
|
gbinder_system_munmap(
|
||||||
void* addr,
|
void* addr,
|
||||||
size_t length);
|
size_t length)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_SYSTEM_H */
|
#endif /* GBINDER_SYSTEM_H */
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -35,39 +35,19 @@
|
|||||||
|
|
||||||
#include <gbinder_types.h>
|
#include <gbinder_types.h>
|
||||||
|
|
||||||
typedef struct gbinder_buffer_memory GBinderBufferMemory;
|
typedef struct gbinder_buffer_contents GBinderBufferContents;
|
||||||
typedef struct gbinder_cleanup GBinderCleanup;
|
typedef struct gbinder_cleanup GBinderCleanup;
|
||||||
typedef struct gbinder_driver GBinderDriver;
|
typedef struct gbinder_driver GBinderDriver;
|
||||||
typedef struct gbinder_handler GBinderHandler;
|
typedef struct gbinder_handler GBinderHandler;
|
||||||
typedef struct gbinder_io GBinderIo;
|
typedef struct gbinder_io GBinderIo;
|
||||||
typedef struct gbinder_ipc GBinderIpc;
|
|
||||||
typedef struct gbinder_object_registry GBinderObjectRegistry;
|
typedef struct gbinder_object_registry GBinderObjectRegistry;
|
||||||
typedef struct gbinder_output_data GBinderOutputData;
|
typedef struct gbinder_output_data GBinderOutputData;
|
||||||
typedef struct gbinder_rpc_protocol GBinderRpcProtocol;
|
typedef struct gbinder_rpc_protocol GBinderRpcProtocol;
|
||||||
|
typedef struct gbinder_servicepoll GBinderServicePoll;
|
||||||
typedef struct hidl_vec {
|
typedef struct gbinder_ipc_looper_tx GBinderIpcLooperTx;
|
||||||
union {
|
|
||||||
guint64 value;
|
|
||||||
const void* ptr;
|
|
||||||
} data;
|
|
||||||
guint32 count;
|
|
||||||
guint32 owns_buffer;
|
|
||||||
} HidlVec;
|
|
||||||
|
|
||||||
#define HIDL_VEC_BUFFER_OFFSET (0)
|
|
||||||
|
|
||||||
typedef struct hidl_string {
|
|
||||||
union {
|
|
||||||
guint64 value;
|
|
||||||
const char* str;
|
|
||||||
} data;
|
|
||||||
guint32 len;
|
|
||||||
guint32 owns_buffer;
|
|
||||||
} HidlString;
|
|
||||||
|
|
||||||
#define HIDL_STRING_BUFFER_OFFSET (0)
|
|
||||||
|
|
||||||
#define GBINDER_INLINE_FUNC static inline
|
#define GBINDER_INLINE_FUNC static inline
|
||||||
|
#define GBINDER_INTERNAL G_GNUC_INTERNAL
|
||||||
|
|
||||||
#define GBINDER_TRANSACTION(c2,c3,c4) GBINDER_FOURCC('_',c2,c3,c4)
|
#define GBINDER_TRANSACTION(c2,c3,c4) GBINDER_FOURCC('_',c2,c3,c4)
|
||||||
#define GBINDER_PING_TRANSACTION GBINDER_TRANSACTION('P','N','G')
|
#define GBINDER_PING_TRANSACTION GBINDER_TRANSACTION('P','N','G')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -39,7 +39,10 @@
|
|||||||
#include <gutil_macros.h>
|
#include <gutil_macros.h>
|
||||||
#include <gutil_strv.h>
|
#include <gutil_strv.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
typedef struct gbinder_writer_priv {
|
typedef struct gbinder_writer_priv {
|
||||||
GBinderWriterData* data;
|
GBinderWriterData* data;
|
||||||
@@ -54,47 +57,49 @@ GBINDER_INLINE_FUNC GBinderWriterData* gbinder_writer_data(GBinderWriter* pub)
|
|||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
gbinder_writer_data_memory_cleanup(
|
gbinder_writer_data_buffer_cleanup(
|
||||||
gpointer memory)
|
gpointer data)
|
||||||
{
|
{
|
||||||
gbinder_buffer_memory_unref(memory);
|
gbinder_buffer_contents_unref((GBinderBufferContents*)data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_set_contents(
|
gbinder_writer_data_set_contents(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
GBinderBuffer* buffer,
|
GBinderBuffer* buffer)
|
||||||
void** objects)
|
|
||||||
{
|
{
|
||||||
gsize bufsize;
|
gsize bufsize;
|
||||||
const guint8* bufdata = gbinder_buffer_data(buffer, &bufsize);
|
const guint8* bufdata = gbinder_buffer_data(buffer, &bufsize);
|
||||||
const GBinderIo* io = gbinder_buffer_io(buffer);
|
const GBinderIo* io = gbinder_buffer_io(buffer);
|
||||||
GBinderBufferMemory* mem = gbinder_buffer_memory(buffer);
|
GBinderBufferContents* contents = gbinder_buffer_contents(buffer);
|
||||||
|
|
||||||
GASSERT(data->io == io);
|
GASSERT(data->io == io);
|
||||||
g_byte_array_set_size(data->bytes, 0);
|
g_byte_array_set_size(data->bytes, 0);
|
||||||
gutil_int_array_set_count(data->offsets, 0);
|
gutil_int_array_set_count(data->offsets, 0);
|
||||||
data->buffers_size = 0;
|
data->buffers_size = 0;
|
||||||
|
gbinder_cleanup_reset(data->cleanup);
|
||||||
|
|
||||||
g_byte_array_append(data->bytes, bufdata, bufsize);
|
g_byte_array_append(data->bytes, bufdata, bufsize);
|
||||||
if (mem) {
|
if (contents) {
|
||||||
data->cleanup = gbinder_cleanup_add(data->cleanup,
|
void** objects = gbinder_buffer_objects(buffer);
|
||||||
gbinder_writer_data_memory_cleanup,
|
|
||||||
gbinder_buffer_memory_ref(mem));
|
|
||||||
}
|
|
||||||
if (objects && *objects) {
|
|
||||||
if (!data->offsets) {
|
|
||||||
data->offsets = gutil_int_array_new();
|
|
||||||
}
|
|
||||||
while (*objects) {
|
|
||||||
const guint8* obj = *objects++;
|
|
||||||
gsize offset = obj - bufdata;
|
|
||||||
gsize objsize = io->object_data_size(obj);
|
|
||||||
|
|
||||||
GASSERT(offset > 0 && offset < bufsize);
|
data->cleanup = gbinder_cleanup_add(data->cleanup,
|
||||||
gutil_int_array_append(data->offsets, (int)offset);
|
gbinder_writer_data_buffer_cleanup,
|
||||||
/* Size of each buffer has to be 8-byte aligned */
|
gbinder_buffer_contents_ref(contents));
|
||||||
data->buffers_size += G_ALIGN8(objsize);
|
if (objects && *objects) {
|
||||||
|
if (!data->offsets) {
|
||||||
|
data->offsets = gutil_int_array_new();
|
||||||
|
}
|
||||||
|
while (*objects) {
|
||||||
|
const guint8* obj = *objects++;
|
||||||
|
gsize offset = obj - bufdata;
|
||||||
|
gsize objsize = io->object_data_size(obj);
|
||||||
|
|
||||||
|
GASSERT(offset > 0 && offset < bufsize);
|
||||||
|
gutil_int_array_append(data->offsets, (int)offset);
|
||||||
|
/* Size of each buffer has to be 8-byte aligned */
|
||||||
|
data->buffers_size += G_ALIGN8(objsize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,6 +149,14 @@ gbinder_writer_init(
|
|||||||
gbinder_writer_cast(self)->data = data;
|
gbinder_writer_cast(self)->data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gsize
|
||||||
|
gbinder_writer_bytes_written(
|
||||||
|
GBinderWriter* self) /* since 1.0.21 */
|
||||||
|
{
|
||||||
|
GBinderWriterData* data = gbinder_writer_data(self);
|
||||||
|
return data->bytes->len;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_append_bool(
|
gbinder_writer_append_bool(
|
||||||
GBinderWriter* self,
|
GBinderWriter* self,
|
||||||
@@ -165,7 +178,7 @@ gbinder_writer_data_append_bool(
|
|||||||
|
|
||||||
/* Boolean values are padded to 4-byte boundary */
|
/* Boolean values are padded to 4-byte boundary */
|
||||||
padded[0] = (value != FALSE);
|
padded[0] = (value != FALSE);
|
||||||
padded[1] = padded[2] = padded[3] = 0xff;
|
padded[1] = padded[2] = padded[3] = 0;
|
||||||
g_byte_array_append(data->bytes, padded, sizeof(padded));
|
g_byte_array_append(data->bytes, padded, sizeof(padded));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +207,26 @@ gbinder_writer_data_append_int32(
|
|||||||
*ptr = value;
|
*ptr = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_writer_overwrite_int32(
|
||||||
|
GBinderWriter* self,
|
||||||
|
gsize offset,
|
||||||
|
gint32 value) /* since 1.0.21 */
|
||||||
|
{
|
||||||
|
GBinderWriterData* data = gbinder_writer_data(self);
|
||||||
|
|
||||||
|
if (G_LIKELY(data)) {
|
||||||
|
GByteArray* buf = data->bytes;
|
||||||
|
|
||||||
|
if (buf->len >= offset + sizeof(gint32)) {
|
||||||
|
*((gint32*)(buf->data + offset)) = value;
|
||||||
|
} else {
|
||||||
|
GWARN("Can't overwrite at %lu as buffer is only %u bytes long",
|
||||||
|
(gulong)offset, buf->len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_append_int64(
|
gbinder_writer_append_int64(
|
||||||
GBinderWriter* self,
|
GBinderWriter* self,
|
||||||
@@ -351,15 +384,36 @@ gbinder_writer_data_append_string16(
|
|||||||
gbinder_writer_data_append_string16_len(data, utf8, utf8? strlen(utf8) : 0);
|
gbinder_writer_data_append_string16_len(data, utf8, utf8? strlen(utf8) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_writer_data_append_string16_null(
|
||||||
|
GBinderWriterData* data)
|
||||||
|
{
|
||||||
|
/* NULL string */
|
||||||
|
gbinder_writer_data_append_int32(data, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_writer_data_append_string16_empty(
|
||||||
|
GBinderWriterData* data)
|
||||||
|
{
|
||||||
|
GByteArray* buf = data->bytes;
|
||||||
|
const gsize old_size = buf->len;
|
||||||
|
guint16* ptr16;
|
||||||
|
|
||||||
|
/* Empty string */
|
||||||
|
g_byte_array_set_size(buf, old_size + 8);
|
||||||
|
ptr16 = (guint16*)(buf->data + old_size);
|
||||||
|
ptr16[0] = ptr16[1] = ptr16[2] = 0; ptr16[3] = 0xffff;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_string16_len(
|
gbinder_writer_data_append_string16_len(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
const char* utf8,
|
const char* utf8,
|
||||||
gssize num_bytes)
|
gssize num_bytes)
|
||||||
{
|
{
|
||||||
GByteArray* buf = data->bytes;
|
|
||||||
const gsize old_size = buf->len;
|
|
||||||
|
|
||||||
if (utf8) {
|
if (utf8) {
|
||||||
const char* end = utf8;
|
const char* end = utf8;
|
||||||
|
|
||||||
@@ -370,6 +424,8 @@ gbinder_writer_data_append_string16_len(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (num_bytes > 0) {
|
if (num_bytes > 0) {
|
||||||
|
GByteArray* buf = data->bytes;
|
||||||
|
const gsize old_size = buf->len;
|
||||||
glong len = g_utf8_strlen(utf8, num_bytes);
|
glong len = g_utf8_strlen(utf8, num_bytes);
|
||||||
gsize padded_len = G_ALIGN4((len+1)*2);
|
gsize padded_len = G_ALIGN4((len+1)*2);
|
||||||
guint32* len_ptr;
|
guint32* len_ptr;
|
||||||
@@ -407,14 +463,69 @@ gbinder_writer_data_append_string16_len(
|
|||||||
g_byte_array_set_size(buf, old_size + padded_len + 4);
|
g_byte_array_set_size(buf, old_size + padded_len + 4);
|
||||||
} else if (utf8) {
|
} else if (utf8) {
|
||||||
/* Empty string */
|
/* Empty string */
|
||||||
guint16* ptr16;
|
gbinder_writer_data_append_string16_empty(data);
|
||||||
|
|
||||||
g_byte_array_set_size(buf, old_size + 8);
|
|
||||||
ptr16 = (guint16*)(buf->data + old_size);
|
|
||||||
ptr16[0] = ptr16[1] = ptr16[2] = 0; ptr16[3] = 0xffff;
|
|
||||||
} else {
|
} else {
|
||||||
/* NULL string */
|
/* NULL string */
|
||||||
gbinder_writer_data_append_int32(data, -1);
|
gbinder_writer_data_append_string16_null(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_writer_data_append_string16_utf16(
|
||||||
|
GBinderWriterData* data,
|
||||||
|
const gunichar2* utf16,
|
||||||
|
gssize length)
|
||||||
|
{
|
||||||
|
if (length < 0) {
|
||||||
|
length = 0;
|
||||||
|
if (utf16) {
|
||||||
|
const guint16* ptr;
|
||||||
|
|
||||||
|
/* Assume NULL terminated string */
|
||||||
|
for (ptr = utf16; *ptr; ptr++);
|
||||||
|
length = ptr - utf16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (length > 0) {
|
||||||
|
GByteArray* buf = data->bytes;
|
||||||
|
const gsize old_size = buf->len;
|
||||||
|
const gsize padded_size = G_ALIGN4((length + 1) * 2);
|
||||||
|
guint32* len_ptr;
|
||||||
|
gunichar2* utf16_ptr;
|
||||||
|
|
||||||
|
/* Preallocate space */
|
||||||
|
g_byte_array_set_size(buf, old_size + padded_size + 4);
|
||||||
|
len_ptr = (guint32*)(buf->data + old_size);
|
||||||
|
utf16_ptr = (gunichar2*)(len_ptr + 1);
|
||||||
|
|
||||||
|
/* Actual length */
|
||||||
|
*len_ptr = length;
|
||||||
|
|
||||||
|
/* Characters */
|
||||||
|
memcpy(utf16_ptr, utf16, 2 * length);
|
||||||
|
|
||||||
|
/* Zero padding */
|
||||||
|
memset(utf16_ptr + length, 0, padded_size - 2 * length);
|
||||||
|
} else if (utf16) {
|
||||||
|
/* Empty string */
|
||||||
|
gbinder_writer_data_append_string16_empty(data);
|
||||||
|
} else {
|
||||||
|
/* NULL string */
|
||||||
|
gbinder_writer_data_append_string16_null(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_writer_append_string16_utf16(
|
||||||
|
GBinderWriter* self,
|
||||||
|
const gunichar2* utf16,
|
||||||
|
gssize length) /* Since 1.0.17 */
|
||||||
|
{
|
||||||
|
GBinderWriterData* data = gbinder_writer_data(self);
|
||||||
|
|
||||||
|
if (G_LIKELY(data)) {
|
||||||
|
gbinder_writer_data_append_string16_utf16(data, utf16, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,6 +553,60 @@ gbinder_writer_data_prepare(
|
|||||||
return data->offsets->count;
|
return data->offsets->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_writer_data_close_fd(
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
const int fd = GPOINTER_TO_INT(data);
|
||||||
|
|
||||||
|
if (close(fd) < 0) {
|
||||||
|
GWARN("Error closing fd %d: %s", fd, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
gbinder_writer_data_append_fd(
|
||||||
|
GBinderWriterData* data,
|
||||||
|
int fd)
|
||||||
|
{
|
||||||
|
GByteArray* buf = data->bytes;
|
||||||
|
const guint offset = buf->len;
|
||||||
|
/* Duplicate the descriptor so that caller can do whatever with
|
||||||
|
* the one it passed in. */
|
||||||
|
const int dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
|
||||||
|
guint written;
|
||||||
|
|
||||||
|
/* Preallocate enough space */
|
||||||
|
g_byte_array_set_size(buf, offset + GBINDER_MAX_BINDER_OBJECT_SIZE);
|
||||||
|
/* Write the original fd if we failed to dup it */
|
||||||
|
if (dupfd < 0) {
|
||||||
|
GWARN("Error dupping fd %d: %s", fd, strerror(errno));
|
||||||
|
written = data->io->encode_fd_object(buf->data + offset, fd);
|
||||||
|
} else {
|
||||||
|
written = data->io->encode_fd_object(buf->data + offset, dupfd);
|
||||||
|
data->cleanup = gbinder_cleanup_add(data->cleanup,
|
||||||
|
gbinder_writer_data_close_fd, GINT_TO_POINTER(dupfd));
|
||||||
|
}
|
||||||
|
/* Fix the data size */
|
||||||
|
g_byte_array_set_size(buf, offset + written);
|
||||||
|
/* Record the offset */
|
||||||
|
gbinder_writer_data_record_offset(data, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_writer_append_fd(
|
||||||
|
GBinderWriter* self,
|
||||||
|
int fd) /* Since 1.0.18 */
|
||||||
|
{
|
||||||
|
GBinderWriterData* data = gbinder_writer_data(self);
|
||||||
|
|
||||||
|
if (G_LIKELY(data)) {
|
||||||
|
gbinder_writer_data_append_fd(data, fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
guint
|
guint
|
||||||
gbinder_writer_append_buffer_object_with_parent(
|
gbinder_writer_append_buffer_object_with_parent(
|
||||||
GBinderWriter* self,
|
GBinderWriter* self,
|
||||||
@@ -504,13 +669,13 @@ gbinder_writer_data_append_hidl_vec(
|
|||||||
guint elemsize)
|
guint elemsize)
|
||||||
{
|
{
|
||||||
GBinderParent vec_parent;
|
GBinderParent vec_parent;
|
||||||
HidlVec* vec = g_new0(HidlVec, 1);
|
GBinderHidlVec* vec = g_new0(GBinderHidlVec, 1);
|
||||||
const gsize total = count * elemsize;
|
const gsize total = count * elemsize;
|
||||||
void* buf = g_memdup(base, total);
|
void* buf = g_memdup(base, total);
|
||||||
|
|
||||||
/* Prepare parent descriptor for the string data */
|
/* Prepare parent descriptor for the string data */
|
||||||
vec_parent.index = gbinder_writer_data_prepare(data);
|
vec_parent.index = gbinder_writer_data_prepare(data);
|
||||||
vec_parent.offset = HIDL_VEC_BUFFER_OFFSET;
|
vec_parent.offset = GBINDER_HIDL_VEC_BUFFER_OFFSET;
|
||||||
|
|
||||||
/* Fill in the vector descriptor */
|
/* Fill in the vector descriptor */
|
||||||
if (buf) {
|
if (buf) {
|
||||||
@@ -521,13 +686,9 @@ gbinder_writer_data_append_hidl_vec(
|
|||||||
vec->owns_buffer = TRUE;
|
vec->owns_buffer = TRUE;
|
||||||
data->cleanup = gbinder_cleanup_add(data->cleanup, g_free, vec);
|
data->cleanup = gbinder_cleanup_add(data->cleanup, g_free, vec);
|
||||||
|
|
||||||
/* Write the buffer object pointing to the vector descriptor */
|
/* Every vector, even the one without data, requires two buffer objects */
|
||||||
gbinder_writer_data_write_buffer_object(data, vec, sizeof(*vec), NULL);
|
gbinder_writer_data_write_buffer_object(data, vec, sizeof(*vec), NULL);
|
||||||
|
gbinder_writer_data_write_buffer_object(data, buf, total, &vec_parent);
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -550,12 +711,12 @@ gbinder_writer_data_append_hidl_string(
|
|||||||
const char* str)
|
const char* str)
|
||||||
{
|
{
|
||||||
GBinderParent str_parent;
|
GBinderParent str_parent;
|
||||||
HidlString* hidl_string = g_new0(HidlString, 1);
|
GBinderHidlString* hidl_string = g_new0(GBinderHidlString, 1);
|
||||||
const gsize len = str ? strlen(str) : 0;
|
const gsize len = str ? strlen(str) : 0;
|
||||||
|
|
||||||
/* Prepare parent descriptor for the string data */
|
/* Prepare parent descriptor for the string data */
|
||||||
str_parent.index = gbinder_writer_data_prepare(data);
|
str_parent.index = gbinder_writer_data_prepare(data);
|
||||||
str_parent.offset = HIDL_STRING_BUFFER_OFFSET;
|
str_parent.offset = GBINDER_HIDL_STRING_BUFFER_OFFSET;
|
||||||
|
|
||||||
/* Fill in the string descriptor and store it */
|
/* Fill in the string descriptor and store it */
|
||||||
hidl_string->data.str = str;
|
hidl_string->data.str = str;
|
||||||
@@ -567,13 +728,14 @@ gbinder_writer_data_append_hidl_string(
|
|||||||
gbinder_writer_data_write_buffer_object(data, hidl_string,
|
gbinder_writer_data_write_buffer_object(data, hidl_string,
|
||||||
sizeof(*hidl_string), NULL);
|
sizeof(*hidl_string), NULL);
|
||||||
|
|
||||||
/* Not sure what's the right way to deal with NULL strings... */
|
|
||||||
if (str) {
|
if (str) {
|
||||||
/* Write the buffer pointing to the string data including the
|
/* Write the buffer pointing to the string data including the
|
||||||
* NULL terminator, referencing string descriptor as a parent. */
|
* NULL terminator, referencing string descriptor as a parent. */
|
||||||
gbinder_writer_data_write_buffer_object(data, str, len+1, &str_parent);
|
gbinder_writer_data_write_buffer_object(data, str, len+1, &str_parent);
|
||||||
GVERBOSE_("\"%s\" %u %u %u", str, (guint)len, (guint)str_parent.index,
|
GVERBOSE_("\"%s\" %u %u %u", str, (guint)len, (guint)str_parent.index,
|
||||||
(guint)data->buffers_size);
|
(guint)data->buffers_size);
|
||||||
|
} else {
|
||||||
|
gbinder_writer_data_write_buffer_object(data, NULL, 0, &str_parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,8 +759,8 @@ gbinder_writer_data_append_hidl_string_vec(
|
|||||||
gssize count)
|
gssize count)
|
||||||
{
|
{
|
||||||
GBinderParent vec_parent;
|
GBinderParent vec_parent;
|
||||||
HidlVec* vec = g_new0(HidlVec, 1);
|
GBinderHidlVec* vec = g_new0(GBinderHidlVec, 1);
|
||||||
HidlString* strings = NULL;
|
GBinderHidlString* strings = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
@@ -608,11 +770,11 @@ gbinder_writer_data_append_hidl_string_vec(
|
|||||||
|
|
||||||
/* Prepare parent descriptor for the vector data */
|
/* Prepare parent descriptor for the vector data */
|
||||||
vec_parent.index = gbinder_writer_data_prepare(data);
|
vec_parent.index = gbinder_writer_data_prepare(data);
|
||||||
vec_parent.offset = HIDL_VEC_BUFFER_OFFSET;
|
vec_parent.offset = GBINDER_HIDL_VEC_BUFFER_OFFSET;
|
||||||
|
|
||||||
/* Fill in the vector descriptor */
|
/* Fill in the vector descriptor */
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
strings = g_new0(HidlString, count);
|
strings = g_new0(GBinderHidlString, count);
|
||||||
vec->data.ptr = strings;
|
vec->data.ptr = strings;
|
||||||
data->cleanup = gbinder_cleanup_add(data->cleanup, g_free, strings);
|
data->cleanup = gbinder_cleanup_add(data->cleanup, g_free, strings);
|
||||||
}
|
}
|
||||||
@@ -623,7 +785,7 @@ gbinder_writer_data_append_hidl_string_vec(
|
|||||||
/* Fill in string descriptors */
|
/* Fill in string descriptors */
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
const char* str = strv[i];
|
const char* str = strv[i];
|
||||||
HidlString* hidl_str = strings + i;
|
GBinderHidlString* hidl_str = strings + i;
|
||||||
|
|
||||||
if ((hidl_str->data.str = str) != NULL) {
|
if ((hidl_str->data.str = str) != NULL) {
|
||||||
hidl_str->len = strlen(str);
|
hidl_str->len = strlen(str);
|
||||||
@@ -638,7 +800,7 @@ gbinder_writer_data_append_hidl_string_vec(
|
|||||||
|
|
||||||
/* Prepare parent descriptor for the string data */
|
/* Prepare parent descriptor for the string data */
|
||||||
str_parent.index = data->offsets->count;
|
str_parent.index = data->offsets->count;
|
||||||
str_parent.offset = HIDL_STRING_BUFFER_OFFSET;
|
str_parent.offset = GBINDER_HIDL_STRING_BUFFER_OFFSET;
|
||||||
|
|
||||||
/* Write the vector data (it's parent for the string data) */
|
/* Write the vector data (it's parent for the string data) */
|
||||||
gbinder_writer_data_write_buffer_object(data, strings,
|
gbinder_writer_data_write_buffer_object(data, strings,
|
||||||
@@ -646,7 +808,7 @@ gbinder_writer_data_append_hidl_string_vec(
|
|||||||
|
|
||||||
/* Write the string data */
|
/* Write the string data */
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
HidlString* hidl_str = strings + i;
|
GBinderHidlString* hidl_str = strings + i;
|
||||||
|
|
||||||
if (hidl_str->data.str) {
|
if (hidl_str->data.str) {
|
||||||
gbinder_writer_data_write_buffer_object(data,
|
gbinder_writer_data_write_buffer_object(data,
|
||||||
@@ -654,9 +816,16 @@ gbinder_writer_data_append_hidl_string_vec(
|
|||||||
GVERBOSE_("%d. \"%s\" %u %u %u", i + 1, hidl_str->data.str,
|
GVERBOSE_("%d. \"%s\" %u %u %u", i + 1, hidl_str->data.str,
|
||||||
(guint)hidl_str->len, (guint)str_parent.index,
|
(guint)hidl_str->len, (guint)str_parent.index,
|
||||||
(guint)data->buffers_size);
|
(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_write_buffer_object(data, NULL, 0,
|
||||||
|
&str_parent);
|
||||||
}
|
}
|
||||||
str_parent.offset += sizeof(HidlString);
|
str_parent.offset += sizeof(GBinderHidlString);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
gbinder_writer_data_write_buffer_object(data, NULL, 0, &vec_parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,6 +921,73 @@ gbinder_writer_data_append_remote_object(
|
|||||||
gbinder_writer_data_record_offset(data, offset);
|
gbinder_writer_data_record_offset(data, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void*
|
||||||
|
gbinder_writer_alloc(
|
||||||
|
GBinderWriter* self,
|
||||||
|
gsize size,
|
||||||
|
gpointer (*alloc)(gsize),
|
||||||
|
void (*dealloc)())
|
||||||
|
{
|
||||||
|
GBinderWriterData* data = gbinder_writer_data(self);
|
||||||
|
|
||||||
|
if (G_LIKELY(data)) {
|
||||||
|
void* ptr = alloc(size);
|
||||||
|
|
||||||
|
data->cleanup = gbinder_cleanup_add(data->cleanup, dealloc, ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void*
|
||||||
|
gbinder_writer_malloc(
|
||||||
|
GBinderWriter* self,
|
||||||
|
gsize size) /* since 1.0.19 */
|
||||||
|
{
|
||||||
|
return gbinder_writer_alloc(self, size, g_malloc, g_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
void*
|
||||||
|
gbinder_writer_malloc0(
|
||||||
|
GBinderWriter* self,
|
||||||
|
gsize size) /* since 1.0.19 */
|
||||||
|
{
|
||||||
|
return gbinder_writer_alloc(self, size, g_malloc0, g_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
void*
|
||||||
|
gbinder_writer_memdup(
|
||||||
|
GBinderWriter* self,
|
||||||
|
const void* buf,
|
||||||
|
gsize size) /* since 1.0.19 */
|
||||||
|
{
|
||||||
|
if (buf) {
|
||||||
|
void* ptr = gbinder_writer_malloc(self, size);
|
||||||
|
|
||||||
|
if (ptr) {
|
||||||
|
memcpy(ptr, buf, size);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gbinder_writer_add_cleanup(
|
||||||
|
GBinderWriter* self,
|
||||||
|
GDestroyNotify destroy,
|
||||||
|
gpointer ptr) /* since 1.0.19 */
|
||||||
|
{
|
||||||
|
if (G_LIKELY(destroy)) {
|
||||||
|
GBinderWriterData* data = gbinder_writer_data(self);
|
||||||
|
|
||||||
|
if (G_LIKELY(data)) {
|
||||||
|
data->cleanup = gbinder_cleanup_add(data->cleanup, destroy, ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* mode: C
|
* mode: C
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -48,95 +48,111 @@ typedef struct gbinder_writer_data {
|
|||||||
void
|
void
|
||||||
gbinder_writer_init(
|
gbinder_writer_init(
|
||||||
GBinderWriter* writer,
|
GBinderWriter* writer,
|
||||||
GBinderWriterData* data);
|
GBinderWriterData* data)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_set_contents(
|
gbinder_writer_data_set_contents(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
GBinderBuffer* buffer,
|
GBinderBuffer* buffer)
|
||||||
void** objects);
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_bool(
|
gbinder_writer_data_append_bool(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
gboolean value);
|
gboolean value)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_int32(
|
gbinder_writer_data_append_int32(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
guint32 value);
|
guint32 value)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_int64(
|
gbinder_writer_data_append_int64(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
guint64 value);
|
guint64 value)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_float(
|
gbinder_writer_data_append_float(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
gfloat value);
|
gfloat value)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_double(
|
gbinder_writer_data_append_double(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
gdouble value);
|
gdouble value)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_string8(
|
gbinder_writer_data_append_string8(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
const char* str);
|
const char* str)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_string8_len(
|
gbinder_writer_data_append_string8_len(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
const char* str,
|
const char* str,
|
||||||
gsize len);
|
gsize len)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_string16(
|
gbinder_writer_data_append_string16(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
const char* utf8);
|
const char* utf8)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_string16_len(
|
gbinder_writer_data_append_string16_len(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
const char* utf8,
|
const char* utf8,
|
||||||
gssize num_bytes);
|
gssize num_bytes)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
guint
|
guint
|
||||||
gbinder_writer_data_append_buffer_object(
|
gbinder_writer_data_append_buffer_object(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
const void* ptr,
|
const void* ptr,
|
||||||
gsize size,
|
gsize size,
|
||||||
const GBinderParent* parent);
|
const GBinderParent* parent)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_hidl_vec(
|
gbinder_writer_data_append_hidl_vec(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
const void* base,
|
const void* base,
|
||||||
guint count,
|
guint count,
|
||||||
guint elemsize);
|
guint elemsize)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_hidl_string(
|
gbinder_writer_data_append_hidl_string(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
const char* str);
|
const char* str)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_hidl_string_vec(
|
gbinder_writer_data_append_hidl_string_vec(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
const char* strv[],
|
const char* strv[],
|
||||||
gssize count);
|
gssize count)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_local_object(
|
gbinder_writer_data_append_local_object(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
GBinderLocalObject* obj);
|
GBinderLocalObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
void
|
void
|
||||||
gbinder_writer_data_append_remote_object(
|
gbinder_writer_data_append_remote_object(
|
||||||
GBinderWriterData* data,
|
GBinderWriterData* data,
|
||||||
GBinderRemoteObject* obj);
|
GBinderRemoteObject* obj)
|
||||||
|
GBINDER_INTERNAL;
|
||||||
|
|
||||||
#endif /* GBINDER_WRITER_PRIVATE_H */
|
#endif /* GBINDER_WRITER_PRIVATE_H */
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
all:
|
all:
|
||||||
%:
|
%:
|
||||||
@$(MAKE) -C binder-client $*
|
@$(MAKE) -C binder-client $*
|
||||||
|
@$(MAKE) -C binder-dump $*
|
||||||
@$(MAKE) -C binder-list $*
|
@$(MAKE) -C binder-list $*
|
||||||
|
@$(MAKE) -C binder-ping $*
|
||||||
@$(MAKE) -C binder-service $*
|
@$(MAKE) -C binder-service $*
|
||||||
@$(MAKE) -C rild-card-status $*
|
@$(MAKE) -C rild-card-status $*
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release
|
|||||||
# Tools and flags
|
# Tools and flags
|
||||||
#
|
#
|
||||||
|
|
||||||
CC = $(CROSS_COMPILE)gcc
|
CC ?= $(CROSS_COMPILE)gcc
|
||||||
LD = $(CC)
|
LD = $(CC)
|
||||||
WARNINGS = -Wall
|
WARNINGS = -Wall
|
||||||
INCLUDES = -I$(LIB_DIR)/include
|
INCLUDES = -I$(LIB_DIR)/include
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived from
|
||||||
* without specific prior written permission.
|
* this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -54,10 +54,15 @@ typedef struct app_options {
|
|||||||
|
|
||||||
typedef struct app {
|
typedef struct app {
|
||||||
const AppOptions* opt;
|
const AppOptions* opt;
|
||||||
|
char* fqname;
|
||||||
GMainLoop* loop;
|
GMainLoop* loop;
|
||||||
GBinderServiceManager* sm;
|
GBinderServiceManager* sm;
|
||||||
GBinderLocalObject* local;
|
GBinderLocalObject* local;
|
||||||
|
GBinderRemoteObject* remote;
|
||||||
|
gulong wait_id;
|
||||||
|
gulong death_id;
|
||||||
GBinderClient* client;
|
GBinderClient* client;
|
||||||
|
GThread* thread;
|
||||||
int ret;
|
int ret;
|
||||||
} App;
|
} App;
|
||||||
|
|
||||||
@@ -171,46 +176,80 @@ app_input_thread(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
app_connect_remote(
|
||||||
|
App* app)
|
||||||
|
{
|
||||||
|
app->remote = gbinder_servicemanager_get_service_sync(app->sm,
|
||||||
|
app->fqname, NULL); /* autoreleased pointer */
|
||||||
|
|
||||||
|
if (app->remote) {
|
||||||
|
const AppOptions* opt = app->opt;
|
||||||
|
|
||||||
|
GINFO("Connected to %s", app->fqname);
|
||||||
|
gbinder_remote_object_ref(app->remote);
|
||||||
|
app->client = gbinder_client_new(app->remote, opt->iface);
|
||||||
|
app->death_id = gbinder_remote_object_add_death_handler(app->remote,
|
||||||
|
app_remote_died, app);
|
||||||
|
app->thread = g_thread_new("input", app_input_thread, app);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
app_registration_handler(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
const char* name,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
App* app = user_data;
|
||||||
|
|
||||||
|
GDEBUG("\"%s\" appeared", name);
|
||||||
|
if (!strcmp(name, app->fqname) && app_connect_remote(app)) {
|
||||||
|
gbinder_servicemanager_remove_handler(app->sm, app->wait_id);
|
||||||
|
app->wait_id = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
app_run(
|
app_run(
|
||||||
App* app)
|
App* app)
|
||||||
{
|
{
|
||||||
const AppOptions* opt = app->opt;
|
const AppOptions* opt = app->opt;
|
||||||
char* fqname = opt->fqname ? g_strdup(opt->fqname) :
|
guint sigtrm = g_unix_signal_add(SIGTERM, app_signal, app);
|
||||||
|
guint sigint = g_unix_signal_add(SIGINT, app_signal, app);
|
||||||
|
|
||||||
|
app->fqname = opt->fqname ? g_strdup(opt->fqname) :
|
||||||
strchr(opt->name, '/') ? g_strdup(opt->name) :
|
strchr(opt->name, '/') ? g_strdup(opt->name) :
|
||||||
g_strconcat(opt->iface, "/", opt->name, NULL);
|
g_strconcat(opt->iface, "/", opt->name, NULL);
|
||||||
int status = 0;
|
|
||||||
GBinderRemoteObject* remote = gbinder_remote_object_ref
|
|
||||||
(gbinder_servicemanager_get_service_sync(app->sm, fqname, &status));
|
|
||||||
if (remote) {
|
|
||||||
guint sigtrm = g_unix_signal_add(SIGTERM, app_signal, app);
|
|
||||||
guint sigint = g_unix_signal_add(SIGINT, app_signal, app);
|
|
||||||
gulong death_id = gbinder_remote_object_add_death_handler
|
|
||||||
(remote, app_remote_died, app);
|
|
||||||
GThread* thread = g_thread_new("input", app_input_thread, app);
|
|
||||||
|
|
||||||
GINFO("Connected to %s\n", fqname);
|
if (!app_connect_remote(app)) {
|
||||||
|
GINFO("Waiting for %s", app->fqname);
|
||||||
app->client = gbinder_client_new(remote, opt->iface);
|
app->wait_id = gbinder_servicemanager_add_registration_handler(app->sm,
|
||||||
app->ret = RET_OK;
|
app->fqname, app_registration_handler, app);
|
||||||
app->loop = g_main_loop_new(NULL, TRUE);
|
|
||||||
g_main_loop_run(app->loop);
|
|
||||||
|
|
||||||
g_source_remove(sigtrm);
|
|
||||||
g_source_remove(sigint);
|
|
||||||
g_main_loop_unref(app->loop);
|
|
||||||
|
|
||||||
gbinder_remote_object_remove_handler(remote, death_id);
|
|
||||||
gbinder_remote_object_unref(remote);
|
|
||||||
|
|
||||||
/* Not the cleanest exit, just dropping the thread... */
|
|
||||||
g_thread_unref(thread);
|
|
||||||
app->loop = NULL;
|
|
||||||
} else {
|
|
||||||
GERR("No such service: %s (%d)", fqname, status);
|
|
||||||
}
|
}
|
||||||
g_free(fqname);
|
|
||||||
|
app->loop = g_main_loop_new(NULL, TRUE);
|
||||||
|
app->ret = RET_OK;
|
||||||
|
g_main_loop_run(app->loop);
|
||||||
|
|
||||||
|
g_source_remove(sigtrm);
|
||||||
|
g_source_remove(sigint);
|
||||||
|
g_main_loop_unref(app->loop);
|
||||||
|
|
||||||
|
if (app->thread) {
|
||||||
|
/* Not the cleanest of exits, just dropping the thread... */
|
||||||
|
g_thread_unref(app->thread);
|
||||||
|
}
|
||||||
|
gbinder_remote_object_remove_handler(app->remote, app->death_id);
|
||||||
|
gbinder_remote_object_unref(app->remote);
|
||||||
|
gbinder_local_object_drop(app->local);
|
||||||
|
gbinder_client_unref(app->client);
|
||||||
|
g_free(app->fqname);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -311,8 +350,6 @@ int main(int argc, char* argv[])
|
|||||||
app.local = gbinder_servicemanager_new_local_object(app.sm,
|
app.local = gbinder_servicemanager_new_local_object(app.sm,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
app_run(&app);
|
app_run(&app);
|
||||||
gbinder_local_object_unref(app.local);
|
|
||||||
gbinder_client_unref(app.client);
|
|
||||||
gbinder_servicemanager_unref(app.sm);
|
gbinder_servicemanager_unref(app.sm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
140
test/binder-dump/Makefile
Normal file
140
test/binder-dump/Makefile
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
# -*- Mode: makefile-gmake -*-
|
||||||
|
|
||||||
|
.PHONY: all debug release clean cleaner
|
||||||
|
.PHONY: libgbinder-release libgbinder-debug
|
||||||
|
|
||||||
|
#
|
||||||
|
# Required packages
|
||||||
|
#
|
||||||
|
|
||||||
|
PKGS = glib-2.0 gio-2.0 gio-unix-2.0 libglibutil
|
||||||
|
|
||||||
|
#
|
||||||
|
# Default target
|
||||||
|
#
|
||||||
|
|
||||||
|
all: debug release
|
||||||
|
|
||||||
|
#
|
||||||
|
# Executable
|
||||||
|
#
|
||||||
|
|
||||||
|
EXE = binder-dump
|
||||||
|
|
||||||
|
#
|
||||||
|
# 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)
|
||||||
237
test/binder-dump/binder-dump.c
Normal file
237
test/binder-dump/binder-dump.c
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
/*
|
||||||
|
* 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.h>
|
||||||
|
|
||||||
|
#include <gutil_log.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define RET_OK (0)
|
||||||
|
#define RET_NOTFOUND (1)
|
||||||
|
#define RET_INVARG (2)
|
||||||
|
#define RET_ERR (3)
|
||||||
|
|
||||||
|
#define DEV_DEFAULT GBINDER_DEFAULT_BINDER
|
||||||
|
|
||||||
|
#define GBINDER_TRANSACTION(c2,c3,c4) GBINDER_FOURCC('_',c2,c3,c4)
|
||||||
|
#define GBINDER_DUMP_TRANSACTION GBINDER_TRANSACTION('D','M','P')
|
||||||
|
|
||||||
|
typedef struct app_options {
|
||||||
|
char* dev;
|
||||||
|
const char* service;
|
||||||
|
} AppOptions;
|
||||||
|
|
||||||
|
typedef struct app {
|
||||||
|
const AppOptions* opt;
|
||||||
|
GMainLoop* loop;
|
||||||
|
GBinderServiceManager* sm;
|
||||||
|
int ret;
|
||||||
|
} App;
|
||||||
|
|
||||||
|
static const char pname[] = "binder-dump";
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
app_dump_service(
|
||||||
|
App* app,
|
||||||
|
const char* service)
|
||||||
|
{
|
||||||
|
int status = 0;
|
||||||
|
GBinderRemoteObject* obj = gbinder_servicemanager_get_service_sync(app->sm,
|
||||||
|
service, &status);
|
||||||
|
|
||||||
|
if (obj) {
|
||||||
|
GBinderClient* client = gbinder_client_new(obj, NULL);
|
||||||
|
GBinderLocalRequest* req = gbinder_client_new_request(client);
|
||||||
|
GBinderRemoteReply* reply;
|
||||||
|
GBinderWriter writer;
|
||||||
|
|
||||||
|
gbinder_remote_object_ref(obj);
|
||||||
|
gbinder_local_request_init_writer(req, &writer);
|
||||||
|
gbinder_writer_append_fd(&writer, STDOUT_FILENO);
|
||||||
|
gbinder_writer_append_int32(&writer, 0);
|
||||||
|
reply = gbinder_client_transact_sync_reply(client,
|
||||||
|
GBINDER_DUMP_TRANSACTION, req, &status);
|
||||||
|
if (status < 0) {
|
||||||
|
GERR("Error %d", status);
|
||||||
|
}
|
||||||
|
gbinder_remote_object_unref(obj);
|
||||||
|
gbinder_remote_reply_unref(reply);
|
||||||
|
gbinder_local_request_unref(req);
|
||||||
|
gbinder_client_unref(client);
|
||||||
|
return TRUE;
|
||||||
|
} else {
|
||||||
|
GERR("No such service: %s (%d)", service, status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
app_dump_services(
|
||||||
|
App* app,
|
||||||
|
char** strv)
|
||||||
|
{
|
||||||
|
if (strv) {
|
||||||
|
while (*strv) {
|
||||||
|
const char* name = *strv++;
|
||||||
|
|
||||||
|
printf("========= %s\n", name);
|
||||||
|
app_dump_service(app, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
app_run(
|
||||||
|
App* app)
|
||||||
|
{
|
||||||
|
const AppOptions* opt = app->opt;
|
||||||
|
|
||||||
|
if (opt->service) {
|
||||||
|
app->ret = app_dump_service(app, opt->service) ? RET_OK : RET_NOTFOUND;
|
||||||
|
} else {
|
||||||
|
char** services = gbinder_servicemanager_list_sync(app->sm);
|
||||||
|
|
||||||
|
if (services) {
|
||||||
|
app_dump_services(app, services);
|
||||||
|
g_strfreev(services);
|
||||||
|
app->ret = RET_OK;
|
||||||
|
} else {
|
||||||
|
app->ret = RET_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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_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 },
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
GError* error = NULL;
|
||||||
|
GOptionContext* options = g_option_context_new("[SERVICE]");
|
||||||
|
|
||||||
|
memset(opt, 0, sizeof(*opt));
|
||||||
|
|
||||||
|
gutil_log_timestamp = FALSE;
|
||||||
|
gutil_log_set_type(GLOG_TYPE_STDERR, pname);
|
||||||
|
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)) {
|
||||||
|
char* help;
|
||||||
|
|
||||||
|
opt->dev = g_strdup(DEV_DEFAULT);
|
||||||
|
switch (argc) {
|
||||||
|
case 2:
|
||||||
|
opt->service = argv[1];
|
||||||
|
/* no break */
|
||||||
|
case 1:
|
||||||
|
ok = TRUE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
help = g_option_context_get_help(options, TRUE, NULL);
|
||||||
|
fprintf(stderr, "%s", help);
|
||||||
|
g_free(help);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_free(opt.dev);
|
||||||
|
return app.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
|
# Tools and flags
|
||||||
#
|
#
|
||||||
|
|
||||||
CC = $(CROSS_COMPILE)gcc
|
CC ?= $(CROSS_COMPILE)gcc
|
||||||
LD = $(CC)
|
LD = $(CC)
|
||||||
WARNINGS = -Wall
|
WARNINGS = -Wall
|
||||||
INCLUDES = -I$(LIB_DIR)/include
|
INCLUDES = -I$(LIB_DIR)/include
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -194,7 +194,7 @@ app_init(
|
|||||||
{ "quiet", 'q', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
|
{ "quiet", 'q', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
|
||||||
app_log_quiet, "Be quiet", NULL },
|
app_log_quiet, "Be quiet", NULL },
|
||||||
{ "async", 'a', 0, G_OPTION_ARG_NONE, &opt->async,
|
{ "async", 'a', 0, G_OPTION_ARG_NONE, &opt->async,
|
||||||
"Parform operations asynchronously", NULL },
|
"Perform operations asynchronously", NULL },
|
||||||
{ "device", 'd', 0, G_OPTION_ARG_STRING, &opt->dev,
|
{ "device", 'd', 0, G_OPTION_ARG_STRING, &opt->dev,
|
||||||
"Binder device [" DEV_DEFAULT "]", "DEVICE" },
|
"Binder device [" DEV_DEFAULT "]", "DEVICE" },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
@@ -245,7 +245,7 @@ int main(int argc, char* argv[])
|
|||||||
app.opt = &opt;
|
app.opt = &opt;
|
||||||
if (app_init(&opt, argc, argv)) {
|
if (app_init(&opt, argc, argv)) {
|
||||||
app.sm = gbinder_servicemanager_new(opt.dev);
|
app.sm = gbinder_servicemanager_new(opt.dev);
|
||||||
if (app.sm) {
|
if (gbinder_servicemanager_wait(app.sm, -1)) {
|
||||||
if (opt.async) {
|
if (opt.async) {
|
||||||
app_async(&app);
|
app_async(&app);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
140
test/binder-ping/Makefile
Normal file
140
test/binder-ping/Makefile
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
# -*- Mode: makefile-gmake -*-
|
||||||
|
|
||||||
|
.PHONY: all debug release clean cleaner
|
||||||
|
.PHONY: libgbinder-release libgbinder-debug
|
||||||
|
|
||||||
|
#
|
||||||
|
# Required packages
|
||||||
|
#
|
||||||
|
|
||||||
|
PKGS = glib-2.0 gio-2.0 gio-unix-2.0 libglibutil
|
||||||
|
|
||||||
|
#
|
||||||
|
# Default target
|
||||||
|
#
|
||||||
|
|
||||||
|
all: debug release
|
||||||
|
|
||||||
|
#
|
||||||
|
# Executable
|
||||||
|
#
|
||||||
|
|
||||||
|
EXE = binder-ping
|
||||||
|
|
||||||
|
#
|
||||||
|
# Sources
|
||||||
|
#
|
||||||
|
|
||||||
|
SRC = $(EXE).c
|
||||||
|
|
||||||
|
#
|
||||||
|
# Directories
|
||||||
|
#
|
||||||
|
|
||||||
|
SRC_DIR = .
|
||||||
|
BUILD_DIR = build
|
||||||
|
LIB_DIR = ../..
|
||||||
|
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
|
||||||
|
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tools and flags
|
||||||
|
#
|
||||||
|
|
||||||
|
CC ?= $(CROSS_COMPILE)gcc
|
||||||
|
LD = $(CC)
|
||||||
|
WARNINGS = -Wall
|
||||||
|
INCLUDES = -I$(LIB_DIR)/include
|
||||||
|
BASE_FLAGS = -fPIC
|
||||||
|
CFLAGS = $(BASE_FLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \
|
||||||
|
$(shell pkg-config --cflags $(PKGS))
|
||||||
|
LDFLAGS = $(BASE_FLAGS) $(shell pkg-config --libs $(PKGS))
|
||||||
|
QUIET_MAKE = make --no-print-directory
|
||||||
|
DEBUG_FLAGS = -g
|
||||||
|
RELEASE_FLAGS =
|
||||||
|
|
||||||
|
ifndef KEEP_SYMBOLS
|
||||||
|
KEEP_SYMBOLS = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ($(KEEP_SYMBOLS),0)
|
||||||
|
RELEASE_FLAGS += -g
|
||||||
|
SUBMAKE_OPTS += KEEP_SYMBOLS=1
|
||||||
|
endif
|
||||||
|
|
||||||
|
DEBUG_LDFLAGS = $(LDFLAGS) $(DEBUG_FLAGS)
|
||||||
|
RELEASE_LDFLAGS = $(LDFLAGS) $(RELEASE_FLAGS)
|
||||||
|
DEBUG_CFLAGS = $(CFLAGS) $(DEBUG_FLAGS) -DDEBUG
|
||||||
|
RELEASE_CFLAGS = $(CFLAGS) $(RELEASE_FLAGS) -O2
|
||||||
|
|
||||||
|
#
|
||||||
|
# Files
|
||||||
|
#
|
||||||
|
|
||||||
|
DEBUG_OBJS = $(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o)
|
||||||
|
RELEASE_OBJS = $(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o)
|
||||||
|
DEBUG_SO_FILE := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_debug_so)
|
||||||
|
RELEASE_SO_FILE := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_release_so)
|
||||||
|
DEBUG_LINK_FILE := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_debug_link)
|
||||||
|
RELEASE_LINK_FILE := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_release_link)
|
||||||
|
DEBUG_SO = $(LIB_DIR)/$(DEBUG_SO_FILE)
|
||||||
|
RELEASE_SO = $(LIB_DIR)/$(RELEASE_SO_FILE)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Dependencies
|
||||||
|
#
|
||||||
|
|
||||||
|
DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d)
|
||||||
|
ifneq ($(MAKECMDGOALS),clean)
|
||||||
|
ifneq ($(strip $(DEPS)),)
|
||||||
|
-include $(DEPS)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
|
||||||
|
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Rules
|
||||||
|
#
|
||||||
|
|
||||||
|
DEBUG_EXE = $(DEBUG_BUILD_DIR)/$(EXE)
|
||||||
|
RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
|
||||||
|
|
||||||
|
debug: libgbinder-debug $(DEBUG_EXE)
|
||||||
|
|
||||||
|
release: libgbinder-release $(RELEASE_EXE)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~
|
||||||
|
rm -fr $(BUILD_DIR)
|
||||||
|
|
||||||
|
cleaner: clean
|
||||||
|
@make -C $(LIB_DIR) clean
|
||||||
|
|
||||||
|
$(DEBUG_BUILD_DIR):
|
||||||
|
mkdir -p $@
|
||||||
|
|
||||||
|
$(RELEASE_BUILD_DIR):
|
||||||
|
mkdir -p $@
|
||||||
|
|
||||||
|
$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
|
||||||
|
$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
|
||||||
|
|
||||||
|
$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
|
||||||
|
$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
|
||||||
|
|
||||||
|
$(DEBUG_EXE): $(DEBUG_SO) $(DEBUG_BUILD_DIR) $(DEBUG_OBJS)
|
||||||
|
$(LD) $(DEBUG_OBJS) $(DEBUG_LDFLAGS) $< -o $@
|
||||||
|
|
||||||
|
$(RELEASE_EXE): $(RELEASE_SO) $(RELEASE_BUILD_DIR) $(RELEASE_OBJS)
|
||||||
|
$(LD) $(RELEASE_OBJS) $(RELEASE_LDFLAGS) $< -o $@
|
||||||
|
ifeq ($(KEEP_SYMBOLS),0)
|
||||||
|
strip $@
|
||||||
|
endif
|
||||||
|
|
||||||
|
libgbinder-debug:
|
||||||
|
@make $(SUBMAKE_OPTS) -C $(LIB_DIR) $(DEBUG_SO_FILE) $(DEBUG_LINK_FILE)
|
||||||
|
|
||||||
|
libgbinder-release:
|
||||||
|
@make $(SUBMAKE_OPTS) -C $(LIB_DIR) $(RELEASE_SO_FILE) $(RELEASE_LINK_FILE)
|
||||||
187
test/binder-ping/binder-ping.c
Normal file
187
test/binder-ping/binder-ping.c
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Jolla Ltd.
|
||||||
|
* Copyright (C) 2020 Slava Monich <slava.monich@jolla.com>
|
||||||
|
*
|
||||||
|
* You may use this file under the terms of BSD license as follows:
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gbinder.h>
|
||||||
|
|
||||||
|
#include <gutil_log.h>
|
||||||
|
|
||||||
|
#define RET_OK (0)
|
||||||
|
#define RET_NOTFOUND (1)
|
||||||
|
#define RET_INVARG (2)
|
||||||
|
#define RET_ERR (3)
|
||||||
|
|
||||||
|
#define DEFAULT_BINDER GBINDER_DEFAULT_HWBINDER
|
||||||
|
#define AIDL_PING_TRANSACTION GBINDER_FOURCC('_','P','N','G')
|
||||||
|
#define HIDL_PING_TRANSACTION GBINDER_FOURCC(0x0f,'P','N','G')
|
||||||
|
|
||||||
|
typedef struct app_options {
|
||||||
|
const char* fqname;
|
||||||
|
char* dev;
|
||||||
|
guint32 ping_code;
|
||||||
|
const char* iface;
|
||||||
|
} AppOptions;
|
||||||
|
|
||||||
|
static
|
||||||
|
int
|
||||||
|
app_run(
|
||||||
|
const AppOptions* opt)
|
||||||
|
{
|
||||||
|
int ret = RET_NOTFOUND;
|
||||||
|
GBinderServiceManager* sm = gbinder_servicemanager_new(opt->dev);
|
||||||
|
|
||||||
|
if (sm) {
|
||||||
|
int status = 0;
|
||||||
|
GBinderRemoteObject* remote = gbinder_servicemanager_get_service_sync
|
||||||
|
(sm, opt->fqname, &status);
|
||||||
|
|
||||||
|
if (remote) {
|
||||||
|
int status;
|
||||||
|
GBinderClient* client = gbinder_client_new(remote, opt->iface);
|
||||||
|
GBinderRemoteReply* reply = gbinder_client_transact_sync_reply
|
||||||
|
(client, opt->ping_code, NULL, &status);
|
||||||
|
|
||||||
|
if (reply) {
|
||||||
|
GINFO("OK");
|
||||||
|
ret = RET_OK;
|
||||||
|
} else {
|
||||||
|
GERR("Ping failed (%d)", status);
|
||||||
|
ret = RET_ERR;
|
||||||
|
}
|
||||||
|
gbinder_remote_reply_unref(reply);
|
||||||
|
gbinder_client_unref(client);
|
||||||
|
} else {
|
||||||
|
GERR("%s not found", opt->fqname);
|
||||||
|
}
|
||||||
|
gbinder_servicemanager_unref(sm);
|
||||||
|
} else {
|
||||||
|
GERR("No servicemanager at %s", opt->dev);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
app_log_verbose(
|
||||||
|
const gchar* name,
|
||||||
|
const gchar* value,
|
||||||
|
gpointer data,
|
||||||
|
GError** error)
|
||||||
|
{
|
||||||
|
gutil_log_default.level = GLOG_LEVEL_VERBOSE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
app_log_quiet(
|
||||||
|
const gchar* name,
|
||||||
|
const gchar* value,
|
||||||
|
gpointer data,
|
||||||
|
GError** error)
|
||||||
|
{
|
||||||
|
gutil_log_default.level = GLOG_LEVEL_NONE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
app_init(
|
||||||
|
AppOptions* opt,
|
||||||
|
int argc,
|
||||||
|
char* argv[])
|
||||||
|
{
|
||||||
|
gboolean ok = FALSE;
|
||||||
|
GOptionEntry entries[] = {
|
||||||
|
{ "verbose", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
|
||||||
|
app_log_verbose, "Enable verbose output", NULL },
|
||||||
|
{ "quiet", 'q', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
|
||||||
|
app_log_quiet, "Be quiet", NULL },
|
||||||
|
{ "device", 'd', 0, G_OPTION_ARG_STRING, &opt->dev,
|
||||||
|
"Binder device [" DEFAULT_BINDER "]", "DEVICE" },
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
GError* error = NULL;
|
||||||
|
GOptionContext* options = g_option_context_new("[FQNAME]");
|
||||||
|
|
||||||
|
gutil_log_timestamp = FALSE;
|
||||||
|
gutil_log_default.level = GLOG_LEVEL_DEFAULT;
|
||||||
|
|
||||||
|
g_option_context_add_main_entries(options, entries, NULL);
|
||||||
|
if (g_option_context_parse(options, &argc, &argv, &error)) {
|
||||||
|
if (!opt->dev || !opt->dev[0]) {
|
||||||
|
opt->dev = g_strdup(DEFAULT_BINDER);
|
||||||
|
}
|
||||||
|
if (argc == 2) {
|
||||||
|
opt->fqname = argv[1];
|
||||||
|
if (g_strcmp0(opt->dev, GBINDER_DEFAULT_BINDER)) {
|
||||||
|
opt->ping_code = HIDL_PING_TRANSACTION;
|
||||||
|
opt->iface = "android.hidl.base@1.0::IBase";
|
||||||
|
} else {
|
||||||
|
opt->ping_code = AIDL_PING_TRANSACTION;
|
||||||
|
opt->iface = "android.os.IBinder";
|
||||||
|
}
|
||||||
|
ok = TRUE;
|
||||||
|
} else {
|
||||||
|
char* help = g_option_context_get_help(options, TRUE, NULL);
|
||||||
|
|
||||||
|
fprintf(stderr, "%s", help);
|
||||||
|
g_free(help);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GERR("%s", error->message);
|
||||||
|
g_error_free(error);
|
||||||
|
}
|
||||||
|
g_option_context_free(options);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
AppOptions opt;
|
||||||
|
int ret = RET_INVARG;
|
||||||
|
|
||||||
|
memset(&opt, 0, sizeof(opt));
|
||||||
|
if (app_init(&opt, argc, argv)) {
|
||||||
|
ret = app_run(&opt);
|
||||||
|
}
|
||||||
|
g_free(opt.dev);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local Variables:
|
||||||
|
* mode: C
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* indent-tabs-mode: nil
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -41,7 +41,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release
|
|||||||
# Tools and flags
|
# Tools and flags
|
||||||
#
|
#
|
||||||
|
|
||||||
CC = $(CROSS_COMPILE)gcc
|
CC ?= $(CROSS_COMPILE)gcc
|
||||||
LD = $(CC)
|
LD = $(CC)
|
||||||
WARNINGS = -Wall
|
WARNINGS = -Wall
|
||||||
INCLUDES = -I$(LIB_DIR)/include
|
INCLUDES = -I$(LIB_DIR)/include
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* 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 name of Jolla Ltd nor the names of its contributors may
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* be used to endorse or promote products derived from this software
|
* contributors may be used to endorse or promote products derived
|
||||||
* without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -36,6 +36,9 @@
|
|||||||
|
|
||||||
#include <glib-unix.h>
|
#include <glib-unix.h>
|
||||||
|
|
||||||
|
#define BINDER_TRANSACTION(c2,c3,c4) GBINDER_FOURCC('_',c2,c3,c4)
|
||||||
|
#define BINDER_DUMP_TRANSACTION BINDER_TRANSACTION('D','M','P')
|
||||||
|
|
||||||
#define RET_OK (0)
|
#define RET_OK (0)
|
||||||
#define RET_NOTFOUND (1)
|
#define RET_NOTFOUND (1)
|
||||||
#define RET_INVARG (2)
|
#define RET_INVARG (2)
|
||||||
@@ -49,6 +52,7 @@ typedef struct app_options {
|
|||||||
char* dev;
|
char* dev;
|
||||||
char* iface;
|
char* iface;
|
||||||
const char* name;
|
const char* name;
|
||||||
|
gboolean async;
|
||||||
} AppOptions;
|
} AppOptions;
|
||||||
|
|
||||||
typedef struct app {
|
typedef struct app {
|
||||||
@@ -59,6 +63,11 @@ typedef struct app {
|
|||||||
int ret;
|
int ret;
|
||||||
} App;
|
} App;
|
||||||
|
|
||||||
|
typedef struct response {
|
||||||
|
GBinderRemoteRequest* req;
|
||||||
|
GBinderLocalReply* reply;
|
||||||
|
} Response;
|
||||||
|
|
||||||
static const char pname[] = "binder-service";
|
static const char pname[] = "binder-service";
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -73,6 +82,29 @@ app_signal(
|
|||||||
return G_SOURCE_CONTINUE;
|
return G_SOURCE_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
app_async_resp(
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
Response* resp = user_data;
|
||||||
|
|
||||||
|
gbinder_remote_request_complete(resp->req, resp->reply, 0);
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
app_async_free(
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
Response* resp = user_data;
|
||||||
|
|
||||||
|
gbinder_local_reply_unref(resp->reply);
|
||||||
|
gbinder_remote_request_unref(resp->req);
|
||||||
|
g_free(resp);
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
GBinderLocalReply*
|
GBinderLocalReply*
|
||||||
app_reply(
|
app_reply(
|
||||||
@@ -83,15 +115,52 @@ app_reply(
|
|||||||
int* status,
|
int* status,
|
||||||
void* user_data)
|
void* user_data)
|
||||||
{
|
{
|
||||||
char* str = gbinder_remote_request_read_string16(req);
|
App* app = user_data;
|
||||||
GBinderLocalReply* reply = gbinder_local_object_new_reply(obj);
|
GBinderReader reader;
|
||||||
|
|
||||||
GVERBOSE("\"%s\" %u", gbinder_remote_request_interface(req), code);
|
gbinder_remote_request_init_reader(req, &reader);
|
||||||
GDEBUG("\"%s\"", str);
|
if (code == GBINDER_FIRST_CALL_TRANSACTION) {
|
||||||
gbinder_local_reply_append_string16(reply, str);
|
const AppOptions* opt = app->opt;
|
||||||
g_free(str);
|
const char* iface = gbinder_remote_request_interface(req);
|
||||||
*status = 0;
|
|
||||||
return reply;
|
if (!g_strcmp0(iface, opt->iface)) {
|
||||||
|
char* str = gbinder_reader_read_string16(&reader);
|
||||||
|
GBinderLocalReply* reply = gbinder_local_object_new_reply(obj);
|
||||||
|
|
||||||
|
GVERBOSE("\"%s\" %u", iface, code);
|
||||||
|
GDEBUG("\"%s\"", str);
|
||||||
|
*status = 0;
|
||||||
|
gbinder_local_reply_append_string16(reply, str);
|
||||||
|
g_free(str);
|
||||||
|
if (opt->async) {
|
||||||
|
Response* resp = g_new0(Response, 1);
|
||||||
|
|
||||||
|
resp->reply = reply;
|
||||||
|
resp->req = gbinder_remote_request_ref(req);
|
||||||
|
g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, app_async_resp,
|
||||||
|
resp, app_async_free);
|
||||||
|
gbinder_remote_request_block(resp->req);
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GDEBUG("Unexpected interface \"%s\"", iface);
|
||||||
|
}
|
||||||
|
} else if (code == BINDER_DUMP_TRANSACTION) {
|
||||||
|
int fd = gbinder_reader_read_fd(&reader);
|
||||||
|
const char* dump = "Sorry, I've got nothing to dump...\n";
|
||||||
|
const gssize dump_len = strlen(dump);
|
||||||
|
|
||||||
|
GDEBUG("Dump request from %d", gbinder_remote_request_sender_pid(req));
|
||||||
|
if (write(fd, dump, dump_len) != dump_len) {
|
||||||
|
GERR("Failed to write dump: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
*status = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
*status = -1;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -112,6 +181,23 @@ app_add_service_done(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
app_sm_presence_handler(
|
||||||
|
GBinderServiceManager* sm,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
App* app = user_data;
|
||||||
|
|
||||||
|
if (gbinder_servicemanager_is_present(app->sm)) {
|
||||||
|
GINFO("Service manager has reappeared");
|
||||||
|
gbinder_servicemanager_add_service(app->sm, app->opt->name, app->obj,
|
||||||
|
app_add_service_done, app);
|
||||||
|
} else {
|
||||||
|
GINFO("Service manager has died");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
app_run(
|
app_run(
|
||||||
@@ -120,6 +206,8 @@ app_run(
|
|||||||
const char* name = app->opt->name;
|
const char* name = app->opt->name;
|
||||||
guint sigtrm = g_unix_signal_add(SIGTERM, app_signal, app);
|
guint sigtrm = g_unix_signal_add(SIGTERM, app_signal, app);
|
||||||
guint sigint = g_unix_signal_add(SIGINT, app_signal, app);
|
guint sigint = g_unix_signal_add(SIGINT, app_signal, app);
|
||||||
|
gulong presence_id = gbinder_servicemanager_add_presence_handler
|
||||||
|
(app->sm, app_sm_presence_handler, app);
|
||||||
|
|
||||||
app->loop = g_main_loop_new(NULL, TRUE);
|
app->loop = g_main_loop_new(NULL, TRUE);
|
||||||
|
|
||||||
@@ -130,6 +218,7 @@ app_run(
|
|||||||
|
|
||||||
if (sigtrm) g_source_remove(sigtrm);
|
if (sigtrm) g_source_remove(sigtrm);
|
||||||
if (sigint) g_source_remove(sigint);
|
if (sigint) g_source_remove(sigint);
|
||||||
|
gbinder_servicemanager_remove_handler(app->sm, presence_id);
|
||||||
g_main_loop_unref(app->loop);
|
g_main_loop_unref(app->loop);
|
||||||
app->loop = NULL;
|
app->loop = NULL;
|
||||||
}
|
}
|
||||||
@@ -175,6 +264,8 @@ app_init(
|
|||||||
"Binder device [" DEFAULT_DEVICE "]", "DEVICE" },
|
"Binder device [" DEFAULT_DEVICE "]", "DEVICE" },
|
||||||
{ "interface", 'i', 0, G_OPTION_ARG_STRING, &opt->iface,
|
{ "interface", 'i', 0, G_OPTION_ARG_STRING, &opt->iface,
|
||||||
"Local interface [" DEFAULT_IFACE "]", "IFACE" },
|
"Local interface [" DEFAULT_IFACE "]", "IFACE" },
|
||||||
|
{ "async", 'a', 0, G_OPTION_ARG_NONE, &opt->async,
|
||||||
|
"Handle calls asynchronously", NULL },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -226,7 +317,7 @@ int main(int argc, char* argv[])
|
|||||||
app.opt = &opt;
|
app.opt = &opt;
|
||||||
if (app_init(&opt, argc, argv)) {
|
if (app_init(&opt, argc, argv)) {
|
||||||
app.sm = gbinder_servicemanager_new(opt.dev);
|
app.sm = gbinder_servicemanager_new(opt.dev);
|
||||||
if (app.sm) {
|
if (gbinder_servicemanager_wait(app.sm, -1)) {
|
||||||
app.obj = gbinder_servicemanager_new_local_object
|
app.obj = gbinder_servicemanager_new_local_object
|
||||||
(app.sm, opt.iface, app_reply, &app);
|
(app.sm, opt.iface, app_reply, &app);
|
||||||
app_run(&app);
|
app_run(&app);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release
|
|||||||
# Tools and flags
|
# Tools and flags
|
||||||
#
|
#
|
||||||
|
|
||||||
CC = $(CROSS_COMPILE)gcc
|
CC ?= $(CROSS_COMPILE)gcc
|
||||||
LD = $(CC)
|
LD = $(CC)
|
||||||
WARNINGS = -Wall
|
WARNINGS = -Wall
|
||||||
INCLUDES = -I$(LIB_DIR)/include
|
INCLUDES = -I$(LIB_DIR)/include
|
||||||
|
|||||||
@@ -3,17 +3,23 @@
|
|||||||
all:
|
all:
|
||||||
%:
|
%:
|
||||||
@$(MAKE) -C unit_buffer $*
|
@$(MAKE) -C unit_buffer $*
|
||||||
|
@$(MAKE) -C unit_cleanup $*
|
||||||
@$(MAKE) -C unit_client $*
|
@$(MAKE) -C unit_client $*
|
||||||
@$(MAKE) -C unit_driver $*
|
@$(MAKE) -C unit_driver $*
|
||||||
|
@$(MAKE) -C unit_eventloop $*
|
||||||
@$(MAKE) -C unit_ipc $*
|
@$(MAKE) -C unit_ipc $*
|
||||||
@$(MAKE) -C unit_local_object $*
|
@$(MAKE) -C unit_local_object $*
|
||||||
@$(MAKE) -C unit_local_reply $*
|
@$(MAKE) -C unit_local_reply $*
|
||||||
@$(MAKE) -C unit_local_request $*
|
@$(MAKE) -C unit_local_request $*
|
||||||
|
@$(MAKE) -C unit_log $*
|
||||||
@$(MAKE) -C unit_protocol $*
|
@$(MAKE) -C unit_protocol $*
|
||||||
@$(MAKE) -C unit_reader $*
|
@$(MAKE) -C unit_reader $*
|
||||||
@$(MAKE) -C unit_remote_object $*
|
@$(MAKE) -C unit_remote_object $*
|
||||||
@$(MAKE) -C unit_remote_reply $*
|
@$(MAKE) -C unit_remote_reply $*
|
||||||
@$(MAKE) -C unit_remote_request $*
|
@$(MAKE) -C unit_remote_request $*
|
||||||
|
@$(MAKE) -C unit_servicemanager $*
|
||||||
|
@$(MAKE) -C unit_servicename $*
|
||||||
|
@$(MAKE) -C unit_servicepoll $*
|
||||||
@$(MAKE) -C unit_writer $*
|
@$(MAKE) -C unit_writer $*
|
||||||
|
|
||||||
clean: unitclean
|
clean: unitclean
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ COVERAGE_BUILD_DIR = $(BUILD_DIR)/coverage
|
|||||||
# Tools and flags
|
# Tools and flags
|
||||||
#
|
#
|
||||||
|
|
||||||
CC = $(CROSS_COMPILE)gcc
|
CC ?= $(CROSS_COMPILE)gcc
|
||||||
LD = $(CC)
|
LD = $(CC)
|
||||||
WARNINGS += -Wall
|
WARNINGS += -Wall
|
||||||
INCLUDES += -I$(COMMON_DIR) -I$(LIB_DIR)/src -I$(LIB_DIR)/include
|
INCLUDES += -I$(COMMON_DIR) -I$(LIB_DIR)/src -I$(LIB_DIR)/include
|
||||||
@@ -138,10 +138,10 @@ test_banner:
|
|||||||
@echo "===========" $(EXE) "=========== "
|
@echo "===========" $(EXE) "=========== "
|
||||||
|
|
||||||
test: test_banner debug
|
test: test_banner debug
|
||||||
@LD_LIBRARY_PATH="$(LIB_DIR)/$(DEBUG_LIB_PATH)" $(DEBUG_EXE)
|
@$(DEBUG_EXE)
|
||||||
|
|
||||||
valgrind: test_banner debug
|
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):
|
$(DEBUG_BUILD_DIR):
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -45,6 +45,7 @@ GLOG_MODULE_DEFINE2("test_binder", gutil_log_default);
|
|||||||
|
|
||||||
static GHashTable* test_fd_map = NULL;
|
static GHashTable* test_fd_map = NULL;
|
||||||
static GHashTable* test_node_map = NULL;
|
static GHashTable* test_node_map = NULL;
|
||||||
|
static GPrivate test_looper;
|
||||||
|
|
||||||
#define public_fd fd[0]
|
#define public_fd fd[0]
|
||||||
#define private_fd fd[1]
|
#define private_fd fd[1]
|
||||||
@@ -58,6 +59,22 @@ static GHashTable* test_node_map = NULL;
|
|||||||
#define TF_ACCEPT_FDS 0x10
|
#define TF_ACCEPT_FDS 0x10
|
||||||
|
|
||||||
typedef struct test_binder_io TestBinderIo;
|
typedef struct test_binder_io TestBinderIo;
|
||||||
|
typedef struct test_binder TestBinder;
|
||||||
|
|
||||||
|
typedef
|
||||||
|
void
|
||||||
|
(*TestBinderPushDataFunc)(
|
||||||
|
int fd,
|
||||||
|
const void* data);
|
||||||
|
|
||||||
|
typedef struct test_binder_submit_thread {
|
||||||
|
GThread* thread;
|
||||||
|
GCond cond;
|
||||||
|
GMutex mutex;
|
||||||
|
gboolean run;
|
||||||
|
GSList* queue;
|
||||||
|
TestBinder* binder;
|
||||||
|
} TestBinderSubmitThread;
|
||||||
|
|
||||||
typedef struct test_binder_node {
|
typedef struct test_binder_node {
|
||||||
char* path;
|
char* path;
|
||||||
@@ -68,6 +85,8 @@ typedef struct test_binder_node {
|
|||||||
|
|
||||||
typedef struct test_binder {
|
typedef struct test_binder {
|
||||||
TestBinderNode* node;
|
TestBinderNode* node;
|
||||||
|
TestBinderSubmitThread* submit_thread;
|
||||||
|
gboolean looper_enabled;
|
||||||
int fd[2];
|
int fd[2];
|
||||||
} TestBinder;
|
} TestBinder;
|
||||||
|
|
||||||
@@ -104,6 +123,11 @@ typedef struct binder_pre_cookie_64 {
|
|||||||
guint64 cookie;
|
guint64 cookie;
|
||||||
} BinderPtrCookie64;
|
} BinderPtrCookie64;
|
||||||
|
|
||||||
|
typedef struct binder_handle_cookie_64 {
|
||||||
|
guint32 handle;
|
||||||
|
guint64 cookie;
|
||||||
|
} __attribute__((packed)) BinderHandleCookie64;
|
||||||
|
|
||||||
#define BC_TRANSACTION_64 _IOW('c', 0, BinderTransactionData64)
|
#define BC_TRANSACTION_64 _IOW('c', 0, BinderTransactionData64)
|
||||||
#define BC_REPLY_64 _IOW('c', 1, BinderTransactionData64)
|
#define BC_REPLY_64 _IOW('c', 1, BinderTransactionData64)
|
||||||
#define BC_FREE_BUFFER_64 _IOW('c', 3, guint64)
|
#define BC_FREE_BUFFER_64 _IOW('c', 3, guint64)
|
||||||
@@ -113,6 +137,8 @@ typedef struct binder_pre_cookie_64 {
|
|||||||
#define BC_DECREFS _IOW('c', 7, guint32)
|
#define BC_DECREFS _IOW('c', 7, guint32)
|
||||||
#define BC_ENTER_LOOPER _IO('c', 12)
|
#define BC_ENTER_LOOPER _IO('c', 12)
|
||||||
#define BC_EXIT_LOOPER _IO('c', 13)
|
#define BC_EXIT_LOOPER _IO('c', 13)
|
||||||
|
#define BC_REQUEST_DEATH_NOTIFICATION_64 _IOW('c', 14, BinderHandleCookie64)
|
||||||
|
#define BC_CLEAR_DEATH_NOTIFICATION_64 _IOW('c', 15, BinderHandleCookie64)
|
||||||
|
|
||||||
#define BR_TRANSACTION_64 _IOR('r', 2, BinderTransactionData64)
|
#define BR_TRANSACTION_64 _IOR('r', 2, BinderTransactionData64)
|
||||||
#define BR_REPLY_64 _IOR('r', 3, BinderTransactionData64)
|
#define BR_REPLY_64 _IOR('r', 3, BinderTransactionData64)
|
||||||
@@ -126,6 +152,110 @@ typedef struct binder_pre_cookie_64 {
|
|||||||
#define BR_DEAD_BINDER_64 _IOR('r', 15, guint64)
|
#define BR_DEAD_BINDER_64 _IOR('r', 15, guint64)
|
||||||
#define BR_FAILED_REPLY _IO('r', 17)
|
#define BR_FAILED_REPLY _IO('r', 17)
|
||||||
|
|
||||||
|
static
|
||||||
|
gpointer
|
||||||
|
test_binder_submit_thread_proc(
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
TestBinderSubmitThread* submit = data;
|
||||||
|
TestBinder* binder = submit->binder;
|
||||||
|
GMutex* mutex = &submit->mutex;
|
||||||
|
GCond* cond = &submit->cond;
|
||||||
|
|
||||||
|
GDEBUG("Submit thread started");
|
||||||
|
g_mutex_lock(mutex);
|
||||||
|
while (submit->run) {
|
||||||
|
GBytes* next = NULL;
|
||||||
|
|
||||||
|
while (submit->run && !next) {
|
||||||
|
if (submit->queue) {
|
||||||
|
next = submit->queue->data;
|
||||||
|
submit->queue = g_slist_remove(submit->queue, next);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
g_cond_wait(cond, mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next) {
|
||||||
|
int bytes_available = 0;
|
||||||
|
int err = ioctl(binder->public_fd, FIONREAD, &bytes_available);
|
||||||
|
|
||||||
|
/* Wait until the queue is empty */
|
||||||
|
g_assert(err >= 0);
|
||||||
|
while (bytes_available > 0 && submit->run) {
|
||||||
|
/* Wait a bit between polls */
|
||||||
|
g_cond_wait_until(cond, mutex, g_get_monotonic_time () +
|
||||||
|
100 * G_TIME_SPAN_MILLISECOND);
|
||||||
|
err = ioctl(binder->public_fd, FIONREAD, &bytes_available);
|
||||||
|
g_assert(err >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (submit->run) {
|
||||||
|
gsize len;
|
||||||
|
gconstpointer data = g_bytes_get_data(next, &len);
|
||||||
|
|
||||||
|
GDEBUG("Submitting command 0x%08x", *(guint32*)data);
|
||||||
|
g_assert(write(binder->private_fd, data, len) == len);
|
||||||
|
}
|
||||||
|
g_bytes_unref(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_mutex_unlock(mutex);
|
||||||
|
GDEBUG("Submit thread exiting");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
TestBinderSubmitThread*
|
||||||
|
test_binder_submit_thread_new(
|
||||||
|
TestBinder* binder)
|
||||||
|
{
|
||||||
|
TestBinderSubmitThread* submit = g_new0(TestBinderSubmitThread, 1);
|
||||||
|
|
||||||
|
submit->run = TRUE;
|
||||||
|
submit->binder = binder;
|
||||||
|
g_cond_init(&submit->cond);
|
||||||
|
g_mutex_init(&submit->mutex);
|
||||||
|
submit->thread = g_thread_new(binder->node->path,
|
||||||
|
test_binder_submit_thread_proc, submit);
|
||||||
|
return submit;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_binder_submit_thread_free(
|
||||||
|
TestBinderSubmitThread* submit)
|
||||||
|
{
|
||||||
|
if (submit) {
|
||||||
|
g_mutex_lock(&submit->mutex);
|
||||||
|
submit->run = FALSE;
|
||||||
|
g_cond_signal(&submit->cond);
|
||||||
|
g_mutex_unlock(&submit->mutex);
|
||||||
|
g_thread_join(submit->thread);
|
||||||
|
|
||||||
|
g_slist_free_full(submit->queue, (GDestroyNotify) g_bytes_unref);
|
||||||
|
g_cond_clear(&submit->cond);
|
||||||
|
g_mutex_clear(&submit->mutex);
|
||||||
|
g_free(submit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_binder_submit_later(
|
||||||
|
TestBinderSubmitThread* submit,
|
||||||
|
const void* data)
|
||||||
|
{
|
||||||
|
const guint32* cmd = data;
|
||||||
|
|
||||||
|
g_mutex_lock(&submit->mutex);
|
||||||
|
submit->queue = g_slist_append(submit->queue,
|
||||||
|
g_bytes_new(cmd, sizeof(*cmd) + _IOC_SIZE(*cmd)));
|
||||||
|
g_cond_signal(&submit->cond);
|
||||||
|
g_mutex_unlock(&submit->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
test_io_free_buffer(
|
test_io_free_buffer(
|
||||||
@@ -151,11 +281,11 @@ test_io_handle_write_read_64(
|
|||||||
TestBinder* binder,
|
TestBinder* binder,
|
||||||
void* data)
|
void* data)
|
||||||
{
|
{
|
||||||
int err, bytes_available = 0;
|
|
||||||
BinderWriteRead64* wr = data;
|
BinderWriteRead64* wr = data;
|
||||||
gssize bytes_left = wr->write_size - wr->write_consumed;
|
gssize bytes_left = wr->write_size - wr->write_consumed;
|
||||||
const guint8* write_ptr = (void*)(gsize)
|
const guint8* write_ptr = (void*)(gsize)
|
||||||
(wr->write_buffer + wr->write_consumed);
|
(wr->write_buffer + wr->write_consumed);
|
||||||
|
gboolean is_looper;
|
||||||
|
|
||||||
while (bytes_left >= sizeof(guint32)) {
|
while (bytes_left >= sizeof(guint32)) {
|
||||||
const guint cmd = *(guint32*)write_ptr;
|
const guint cmd = *(guint32*)write_ptr;
|
||||||
@@ -176,12 +306,18 @@ test_io_handle_write_read_64(
|
|||||||
test_io_free_buffer(binder,
|
test_io_free_buffer(binder,
|
||||||
GSIZE_TO_POINTER(*(guint64*)write_ptr));
|
GSIZE_TO_POINTER(*(guint64*)write_ptr));
|
||||||
break;
|
break;
|
||||||
|
case BC_ENTER_LOOPER:
|
||||||
|
g_private_set(&test_looper, GINT_TO_POINTER(TRUE));
|
||||||
|
break;
|
||||||
|
case BC_EXIT_LOOPER:
|
||||||
|
g_private_set(&test_looper, NULL);
|
||||||
|
break;
|
||||||
|
case BC_REQUEST_DEATH_NOTIFICATION_64:
|
||||||
|
case BC_CLEAR_DEATH_NOTIFICATION_64:
|
||||||
case BC_INCREFS:
|
case BC_INCREFS:
|
||||||
case BC_ACQUIRE:
|
case BC_ACQUIRE:
|
||||||
case BC_RELEASE:
|
case BC_RELEASE:
|
||||||
case BC_DECREFS:
|
case BC_DECREFS:
|
||||||
case BC_ENTER_LOOPER:
|
|
||||||
case BC_EXIT_LOOPER:
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
#pragma message("TODO: implement more BINDER_WRITE_READ commands")
|
#pragma message("TODO: implement more BINDER_WRITE_READ commands")
|
||||||
@@ -198,24 +334,45 @@ test_io_handle_write_read_64(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now read the data from the socket */
|
is_looper = g_private_get(&test_looper) ? TRUE : FALSE;
|
||||||
err = ioctl(binder->public_fd, FIONREAD, &bytes_available);
|
if (binder->looper_enabled || !is_looper) {
|
||||||
if (err >= 0) {
|
/* Now read the data from the socket */
|
||||||
int bytes_read = 0;
|
int bytes_available = 0;
|
||||||
if (bytes_available > 0) {
|
int err = ioctl(binder->public_fd, FIONREAD, &bytes_available);
|
||||||
bytes_read = read(binder->public_fd,
|
|
||||||
(void*)(gsize)(wr->read_buffer + wr->read_consumed),
|
|
||||||
wr->read_size - wr->read_consumed);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytes_read >= 0) {
|
if (err >= 0) {
|
||||||
wr->read_consumed += bytes_read;
|
int bytes_read = 0;
|
||||||
return 0;
|
|
||||||
} else {
|
if (bytes_available >= 4) {
|
||||||
err = bytes_read;
|
bytes_read = read(binder->public_fd,
|
||||||
|
(void*)(gsize)(wr->read_buffer + wr->read_consumed),
|
||||||
|
wr->read_size - wr->read_consumed);
|
||||||
|
} else {
|
||||||
|
struct timespec wait;
|
||||||
|
|
||||||
|
wait.tv_sec = 0;
|
||||||
|
wait.tv_nsec = 10 * 1000000; /* 10 ms */
|
||||||
|
nanosleep(&wait, &wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytes_read >= 0) {
|
||||||
|
wr->read_consumed += bytes_read;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
err = bytes_read;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return err;
|
||||||
|
} else {
|
||||||
|
if (wr->read_size > 0) {
|
||||||
|
struct timespec wait;
|
||||||
|
|
||||||
|
wait.tv_sec = 0;
|
||||||
|
wait.tv_nsec = 100 * 1000000; /* 100 ms */
|
||||||
|
nanosleep(&wait, &wait);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const TestBinderIo test_io_64 = {
|
static const TestBinderIo test_io_64 = {
|
||||||
@@ -274,6 +431,17 @@ test_io_destroy_none(
|
|||||||
GDEBUG("Not freeing %p", data);
|
GDEBUG("Not freeing %p", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_binder_set_looper_enabled(
|
||||||
|
int fd,
|
||||||
|
gboolean enabled)
|
||||||
|
{
|
||||||
|
TestBinder* binder = test_binder_from_fd(fd);
|
||||||
|
|
||||||
|
g_assert(binder);
|
||||||
|
binder->looper_enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
test_binder_set_destroy(
|
test_binder_set_destroy(
|
||||||
int fd,
|
int fd,
|
||||||
@@ -291,43 +459,35 @@ test_binder_set_destroy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
gboolean
|
void
|
||||||
test_binder_push_data(
|
test_binder_push_data(
|
||||||
int fd,
|
int fd,
|
||||||
const void* data)
|
const void* data)
|
||||||
|
{
|
||||||
|
const guint32* cmd = data;
|
||||||
|
const int len = sizeof(*cmd) + _IOC_SIZE(*cmd);
|
||||||
|
TestBinder* binder = test_binder_from_fd(fd);
|
||||||
|
|
||||||
|
g_assert(binder);
|
||||||
|
g_assert(write(binder->private_fd, data, len) == len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_binder_push_data_later(
|
||||||
|
int fd,
|
||||||
|
const void* data)
|
||||||
{
|
{
|
||||||
TestBinder* binder = test_binder_from_fd(fd);
|
TestBinder* binder = test_binder_from_fd(fd);
|
||||||
|
|
||||||
if (binder) {
|
g_assert(binder);
|
||||||
const guint32* cmd = data;
|
if (!binder->submit_thread) {
|
||||||
const int len = sizeof(*cmd) + _IOC_SIZE(*cmd);
|
binder->submit_thread = test_binder_submit_thread_new(binder);
|
||||||
|
|
||||||
return write(binder->private_fd, data, len) == len;
|
|
||||||
}
|
}
|
||||||
return FALSE;
|
test_binder_submit_later(binder->submit_thread, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
void
|
void
|
||||||
test_binder_fill_transaction_data(
|
|
||||||
BinderTransactionData64* tr,
|
|
||||||
guint64 handle,
|
|
||||||
guint32 code,
|
|
||||||
const GByteArray* bytes)
|
|
||||||
{
|
|
||||||
g_assert(bytes);
|
|
||||||
|
|
||||||
memset(tr, 0, sizeof(*tr));
|
|
||||||
tr->handle = handle;
|
|
||||||
tr->code = code;
|
|
||||||
tr->data_size = bytes->len;
|
|
||||||
tr->sender_pid = getpid();
|
|
||||||
tr->sender_euid = geteuid();
|
|
||||||
/* This memory should eventually get deallocated with BC_FREE_BUFFER_64 */
|
|
||||||
tr->data_buffer = (gsize)g_memdup(bytes->data, bytes->len);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
test_binder_push_ptr_cookie(
|
test_binder_push_ptr_cookie(
|
||||||
int fd,
|
int fd,
|
||||||
guint32 cmd,
|
guint32 cmd,
|
||||||
@@ -339,60 +499,69 @@ test_binder_push_ptr_cookie(
|
|||||||
memcpy(buf, &cmd, sizeof(cmd));
|
memcpy(buf, &cmd, sizeof(cmd));
|
||||||
memset(data, 0, sizeof(*data));
|
memset(data, 0, sizeof(*data));
|
||||||
data->ptr = (gsize)ptr;
|
data->ptr = (gsize)ptr;
|
||||||
return test_binder_push_data(fd, buf);
|
test_binder_push_data(fd, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_noop(
|
test_binder_br_noop(
|
||||||
int fd)
|
int fd)
|
||||||
{
|
{
|
||||||
guint32 cmd = BR_NOOP;
|
guint32 cmd = BR_NOOP;
|
||||||
|
|
||||||
return test_binder_push_data(fd, &cmd);
|
test_binder_push_data(fd, &cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_increfs(
|
test_binder_br_increfs(
|
||||||
int fd,
|
int fd,
|
||||||
void* ptr)
|
void* ptr)
|
||||||
{
|
{
|
||||||
return test_binder_push_ptr_cookie(fd, BR_INCREFS_64, ptr);
|
test_binder_push_ptr_cookie(fd, BR_INCREFS_64, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_acquire(
|
test_binder_br_acquire(
|
||||||
int fd,
|
int fd,
|
||||||
void* ptr)
|
void* ptr)
|
||||||
{
|
{
|
||||||
return test_binder_push_ptr_cookie(fd, BR_ACQUIRE_64, ptr);
|
test_binder_push_ptr_cookie(fd, BR_ACQUIRE_64, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_release(
|
test_binder_br_release(
|
||||||
int fd,
|
int fd,
|
||||||
void* ptr)
|
void* ptr)
|
||||||
{
|
{
|
||||||
return test_binder_push_ptr_cookie(fd, BR_RELEASE_64, ptr);
|
test_binder_push_ptr_cookie(fd, BR_RELEASE_64, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_decrefs(
|
test_binder_br_decrefs(
|
||||||
int fd,
|
int fd,
|
||||||
void* ptr)
|
void* ptr)
|
||||||
{
|
{
|
||||||
return test_binder_push_ptr_cookie(fd, BR_DECREFS_64, ptr);
|
test_binder_push_ptr_cookie(fd, BR_DECREFS_64, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_transaction_complete(
|
test_binder_br_transaction_complete(
|
||||||
int fd)
|
int fd)
|
||||||
{
|
{
|
||||||
guint32 cmd = BR_TRANSACTION_COMPLETE;
|
guint32 cmd = BR_TRANSACTION_COMPLETE;
|
||||||
|
|
||||||
return test_binder_push_data(fd, &cmd);
|
test_binder_push_data(fd, &cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
|
test_binder_br_transaction_complete_later(
|
||||||
|
int fd)
|
||||||
|
{
|
||||||
|
guint32 cmd = BR_TRANSACTION_COMPLETE;
|
||||||
|
|
||||||
|
test_binder_push_data_later(fd, &cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
test_binder_br_dead_binder(
|
test_binder_br_dead_binder(
|
||||||
int fd,
|
int fd,
|
||||||
guint handle)
|
guint handle)
|
||||||
@@ -403,28 +572,47 @@ test_binder_br_dead_binder(
|
|||||||
buf[0] = BR_DEAD_BINDER_64;
|
buf[0] = BR_DEAD_BINDER_64;
|
||||||
memcpy(buf + 1, &handle64, sizeof(handle64));
|
memcpy(buf + 1, &handle64, sizeof(handle64));
|
||||||
|
|
||||||
return test_binder_push_data(fd, buf);
|
test_binder_push_data(fd, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_dead_reply(
|
test_binder_br_dead_reply(
|
||||||
int fd)
|
int fd)
|
||||||
{
|
{
|
||||||
guint32 cmd = BR_DEAD_REPLY;
|
guint32 cmd = BR_DEAD_REPLY;
|
||||||
|
|
||||||
return test_binder_push_data(fd, &cmd);
|
test_binder_push_data(fd, &cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_failed_reply(
|
test_binder_br_failed_reply(
|
||||||
int fd)
|
int fd)
|
||||||
{
|
{
|
||||||
guint32 cmd = BR_FAILED_REPLY;
|
guint32 cmd = BR_FAILED_REPLY;
|
||||||
|
|
||||||
return test_binder_push_data(fd, &cmd);
|
test_binder_push_data(fd, &cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
static
|
||||||
|
void
|
||||||
|
test_binder_fill_transaction_data(
|
||||||
|
BinderTransactionData64* tr,
|
||||||
|
guint64 handle,
|
||||||
|
guint32 code,
|
||||||
|
const GByteArray* bytes)
|
||||||
|
{
|
||||||
|
memset(tr, 0, sizeof(*tr));
|
||||||
|
tr->handle = handle;
|
||||||
|
tr->code = code;
|
||||||
|
tr->data_size = bytes ? bytes->len : 0;
|
||||||
|
tr->sender_pid = getpid();
|
||||||
|
tr->sender_euid = geteuid();
|
||||||
|
/* This memory should eventually get deallocated with BC_FREE_BUFFER_64 */
|
||||||
|
tr->data_buffer = (gsize)g_memdup(bytes ? (void*)bytes->data : (void*)"",
|
||||||
|
tr->data_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
test_binder_br_transaction(
|
test_binder_br_transaction(
|
||||||
int fd,
|
int fd,
|
||||||
void* target,
|
void* target,
|
||||||
@@ -438,15 +626,17 @@ test_binder_br_transaction(
|
|||||||
test_binder_fill_transaction_data((void*)(buf + sizeof(cmd)),
|
test_binder_fill_transaction_data((void*)(buf + sizeof(cmd)),
|
||||||
(gsize)target, code, bytes);
|
(gsize)target, code, bytes);
|
||||||
|
|
||||||
return test_binder_push_data(fd, buf);
|
test_binder_push_data(fd, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
static
|
||||||
test_binder_br_reply(
|
void
|
||||||
|
test_binder_br_reply1(
|
||||||
int fd,
|
int fd,
|
||||||
guint32 handle,
|
guint32 handle,
|
||||||
guint32 code,
|
guint32 code,
|
||||||
const GByteArray* bytes)
|
const GByteArray* bytes,
|
||||||
|
TestBinderPushDataFunc push)
|
||||||
{
|
{
|
||||||
guint32 cmd = BR_REPLY_64;
|
guint32 cmd = BR_REPLY_64;
|
||||||
guint8 buf[sizeof(guint32) + sizeof(BinderTransactionData64)];
|
guint8 buf[sizeof(guint32) + sizeof(BinderTransactionData64)];
|
||||||
@@ -455,13 +645,34 @@ test_binder_br_reply(
|
|||||||
test_binder_fill_transaction_data((void*)(buf + sizeof(cmd)),
|
test_binder_fill_transaction_data((void*)(buf + sizeof(cmd)),
|
||||||
handle, code, bytes);
|
handle, code, bytes);
|
||||||
|
|
||||||
return test_binder_push_data(fd, buf);
|
push(fd, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_reply_status(
|
test_binder_br_reply(
|
||||||
int fd,
|
int fd,
|
||||||
gint32 status)
|
guint32 handle,
|
||||||
|
guint32 code,
|
||||||
|
const GByteArray* bytes)
|
||||||
|
{
|
||||||
|
test_binder_br_reply1(fd, handle, code, bytes, test_binder_push_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_binder_br_reply_later(
|
||||||
|
int fd,
|
||||||
|
guint32 handle,
|
||||||
|
guint32 code,
|
||||||
|
const GByteArray* bytes)
|
||||||
|
{
|
||||||
|
test_binder_br_reply1(fd, handle, code, bytes, test_binder_push_data_later);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_binder_br_reply_status1(
|
||||||
|
int fd,
|
||||||
|
gint32 status,
|
||||||
|
TestBinderPushDataFunc push)
|
||||||
{
|
{
|
||||||
guint8 buf[sizeof(guint32) + sizeof(BinderTransactionData64)];
|
guint8 buf[sizeof(guint32) + sizeof(BinderTransactionData64)];
|
||||||
guint32* cmd = (void*)buf;
|
guint32* cmd = (void*)buf;
|
||||||
@@ -473,7 +684,24 @@ test_binder_br_reply_status(
|
|||||||
tr->data_size = sizeof(status);
|
tr->data_size = sizeof(status);
|
||||||
/* This memory should eventually get deallocated with BC_FREE_BUFFER_64 */
|
/* This memory should eventually get deallocated with BC_FREE_BUFFER_64 */
|
||||||
tr->data_buffer = (gsize)g_memdup(&status, sizeof(status));
|
tr->data_buffer = (gsize)g_memdup(&status, sizeof(status));
|
||||||
return test_binder_push_data(fd, buf);
|
|
||||||
|
push(fd, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_binder_br_reply_status(
|
||||||
|
int fd,
|
||||||
|
gint32 status)
|
||||||
|
{
|
||||||
|
test_binder_br_reply_status1(fd, status, test_binder_push_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
test_binder_br_reply_status_later(
|
||||||
|
int fd,
|
||||||
|
gint32 status)
|
||||||
|
{
|
||||||
|
test_binder_br_reply_status1(fd, status, test_binder_push_data_later);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -532,6 +760,7 @@ gbinder_system_close(
|
|||||||
g_hash_table_unref(test_fd_map);
|
g_hash_table_unref(test_fd_map);
|
||||||
test_fd_map = NULL;
|
test_fd_map = NULL;
|
||||||
}
|
}
|
||||||
|
test_binder_submit_thread_free(binder->submit_thread);
|
||||||
test_binder_node_unref(binder->node);
|
test_binder_node_unref(binder->node);
|
||||||
close(binder->public_fd);
|
close(binder->public_fd);
|
||||||
close(binder->private_fd);
|
close(binder->private_fd);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -35,66 +35,87 @@
|
|||||||
|
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_noop(
|
test_binder_br_noop(
|
||||||
int fd);
|
int fd);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_increfs(
|
test_binder_br_increfs(
|
||||||
int fd,
|
int fd,
|
||||||
void* ptr);
|
void* ptr);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_acquire(
|
test_binder_br_acquire(
|
||||||
int fd,
|
int fd,
|
||||||
void* ptr);
|
void* ptr);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_release(
|
test_binder_br_release(
|
||||||
int fd,
|
int fd,
|
||||||
void* ptr);
|
void* ptr);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_decrefs(
|
test_binder_br_decrefs(
|
||||||
int fd,
|
int fd,
|
||||||
void* ptr);
|
void* ptr);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_transaction_complete(
|
test_binder_br_transaction_complete(
|
||||||
int fd);
|
int fd);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
|
test_binder_br_transaction_complete_later(
|
||||||
|
int fd);
|
||||||
|
|
||||||
|
void
|
||||||
test_binder_br_dead_binder(
|
test_binder_br_dead_binder(
|
||||||
int fd,
|
int fd,
|
||||||
guint handle);
|
guint handle);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_dead_reply(
|
test_binder_br_dead_reply(
|
||||||
int fd);
|
int fd);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_failed_reply(
|
test_binder_br_failed_reply(
|
||||||
int fd);
|
int fd);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_transaction(
|
test_binder_br_transaction(
|
||||||
int fd,
|
int fd,
|
||||||
void* target,
|
void* target,
|
||||||
guint32 code,
|
guint32 code,
|
||||||
const GByteArray* bytes);
|
const GByteArray* bytes);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_reply(
|
test_binder_br_reply(
|
||||||
int fd,
|
int fd,
|
||||||
guint32 handle,
|
guint32 handle,
|
||||||
guint32 code,
|
guint32 code,
|
||||||
const GByteArray* bytes);
|
const GByteArray* bytes);
|
||||||
|
|
||||||
gboolean
|
void
|
||||||
test_binder_br_reply_status(
|
test_binder_br_reply_status(
|
||||||
int fd,
|
int fd,
|
||||||
gint32 status);
|
gint32 status);
|
||||||
|
|
||||||
|
void
|
||||||
|
test_binder_br_reply_later(
|
||||||
|
int fd,
|
||||||
|
guint32 handle,
|
||||||
|
guint32 code,
|
||||||
|
const GByteArray* bytes);
|
||||||
|
|
||||||
|
void
|
||||||
|
test_binder_br_reply_status_later(
|
||||||
|
int fd,
|
||||||
|
gint32 status);
|
||||||
|
|
||||||
|
void
|
||||||
|
test_binder_set_looper_enabled(
|
||||||
|
int fd,
|
||||||
|
gboolean enabled);
|
||||||
|
|
||||||
void
|
void
|
||||||
test_binder_set_destroy(
|
test_binder_set_destroy(
|
||||||
int fd,
|
int fd,
|
||||||
|
|||||||
@@ -5,17 +5,23 @@
|
|||||||
|
|
||||||
TESTS="\
|
TESTS="\
|
||||||
unit_buffer \
|
unit_buffer \
|
||||||
|
unit_cleanup \
|
||||||
unit_client \
|
unit_client \
|
||||||
unit_driver \
|
unit_driver \
|
||||||
|
unit_eventloop \
|
||||||
unit_ipc \
|
unit_ipc \
|
||||||
unit_local_object \
|
unit_local_object \
|
||||||
unit_local_reply \
|
unit_local_reply \
|
||||||
unit_local_request \
|
unit_local_request \
|
||||||
|
unit_log \
|
||||||
unit_protocol \
|
unit_protocol \
|
||||||
unit_reader \
|
unit_reader \
|
||||||
unit_remote_object \
|
unit_remote_object \
|
||||||
unit_remote_reply \
|
unit_remote_reply \
|
||||||
unit_remote_request \
|
unit_remote_request \
|
||||||
|
unit_servicemanager \
|
||||||
|
unit_servicename \
|
||||||
|
unit_servicepoll \
|
||||||
unit_writer"
|
unit_writer"
|
||||||
|
|
||||||
function err() {
|
function err() {
|
||||||
|
|||||||
@@ -47,19 +47,21 @@ test_null(
|
|||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
|
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
GBinderBuffer* buf = gbinder_buffer_new(NULL, NULL, 0);
|
GBinderBuffer* buf = gbinder_buffer_new(NULL, NULL, 0, NULL);
|
||||||
GBinderBuffer* buf2;
|
GBinderBuffer* buf2;
|
||||||
gsize size = 1;
|
gsize size = 1;
|
||||||
|
|
||||||
gbinder_buffer_free(buf);
|
gbinder_buffer_free(buf);
|
||||||
|
|
||||||
/* No need to reference the driver if there's no data */
|
/* No need to reference the driver if there's no data */
|
||||||
buf = gbinder_buffer_new(driver, NULL, 0);
|
buf = gbinder_buffer_new(driver, NULL, 0, NULL);
|
||||||
g_assert(!gbinder_buffer_driver(buf));
|
g_assert(!gbinder_buffer_driver(buf));
|
||||||
gbinder_buffer_free(buf);
|
gbinder_buffer_free(buf);
|
||||||
|
|
||||||
buf = gbinder_buffer_new_with_parent(NULL, NULL, 0);
|
buf = gbinder_buffer_new_with_parent(NULL, NULL, 0);
|
||||||
buf2 = gbinder_buffer_new_with_parent(buf, NULL, 0);
|
buf2 = gbinder_buffer_new_with_parent(buf, NULL, 0);
|
||||||
|
g_assert(!gbinder_buffer_objects(buf));
|
||||||
|
g_assert(!gbinder_buffer_objects(buf2));
|
||||||
g_assert(!gbinder_buffer_driver(buf));
|
g_assert(!gbinder_buffer_driver(buf));
|
||||||
g_assert(!gbinder_buffer_driver(buf2));
|
g_assert(!gbinder_buffer_driver(buf2));
|
||||||
gbinder_buffer_free(buf);
|
gbinder_buffer_free(buf);
|
||||||
@@ -67,6 +69,7 @@ test_null(
|
|||||||
|
|
||||||
gbinder_buffer_free(NULL);
|
gbinder_buffer_free(NULL);
|
||||||
g_assert(!gbinder_buffer_driver(NULL));
|
g_assert(!gbinder_buffer_driver(NULL));
|
||||||
|
g_assert(!gbinder_buffer_objects(NULL));
|
||||||
g_assert(!gbinder_buffer_io(NULL));
|
g_assert(!gbinder_buffer_io(NULL));
|
||||||
g_assert(!gbinder_buffer_data(NULL, NULL));
|
g_assert(!gbinder_buffer_data(NULL, NULL));
|
||||||
g_assert(!gbinder_buffer_data(NULL, &size));
|
g_assert(!gbinder_buffer_data(NULL, &size));
|
||||||
@@ -87,14 +90,14 @@ test_parent(
|
|||||||
void* ptr = g_memdup(data, sizeof(data));
|
void* ptr = g_memdup(data, sizeof(data));
|
||||||
gsize size = 0;
|
gsize size = 0;
|
||||||
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
|
GBinderDriver* driver = gbinder_driver_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
GBinderBuffer* parent = gbinder_buffer_new(driver, ptr, sizeof(data));
|
GBinderBuffer* parent = gbinder_buffer_new(driver, ptr, sizeof(data), NULL);
|
||||||
GBinderBuffer* buf = gbinder_buffer_new_with_parent
|
GBinderBuffer* buf = gbinder_buffer_new_with_parent
|
||||||
(parent, ptr, sizeof(data));
|
(parent, ptr, sizeof(data));
|
||||||
|
|
||||||
g_assert(gbinder_buffer_driver(buf) == driver);
|
g_assert(gbinder_buffer_driver(buf) == driver);
|
||||||
g_assert(gbinder_buffer_io(buf));
|
g_assert(gbinder_buffer_io(buf));
|
||||||
g_assert(gbinder_buffer_io(buf) == gbinder_driver_io(driver));
|
g_assert(gbinder_buffer_io(buf) == gbinder_driver_io(driver));
|
||||||
g_assert(gbinder_buffer_memory(buf));
|
g_assert(gbinder_buffer_contents(buf));
|
||||||
g_assert(gbinder_buffer_data(buf, NULL) == ptr);
|
g_assert(gbinder_buffer_data(buf, NULL) == ptr);
|
||||||
g_assert(gbinder_buffer_data(buf, &size) == ptr);
|
g_assert(gbinder_buffer_data(buf, &size) == ptr);
|
||||||
g_assert(size == sizeof(data));
|
g_assert(size == sizeof(data));
|
||||||
|
|||||||
5
unit/unit_cleanup/Makefile
Normal file
5
unit/unit_cleanup/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# -*- Mode: makefile-gmake -*-
|
||||||
|
|
||||||
|
EXE = unit_cleanup
|
||||||
|
|
||||||
|
include ../common/Makefile
|
||||||
126
unit/unit_cleanup/unit_cleanup.c
Normal file
126
unit/unit_cleanup/unit_cleanup.c
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* 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 "test_binder.h"
|
||||||
|
|
||||||
|
#include "gbinder_cleanup.h"
|
||||||
|
|
||||||
|
static TestOpt test_opt;
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_cleanup_inc(
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
(*((int*)data))++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* null
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_null(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
g_assert(!gbinder_cleanup_add(NULL, NULL, NULL));
|
||||||
|
gbinder_cleanup_free(NULL);
|
||||||
|
gbinder_cleanup_reset(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* basic
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_basic(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
int n1 = 0, n2 =0;
|
||||||
|
GBinderCleanup* cleanup = gbinder_cleanup_add(NULL, test_cleanup_inc, &n1);
|
||||||
|
|
||||||
|
g_assert(cleanup);
|
||||||
|
g_assert(gbinder_cleanup_add(cleanup, test_cleanup_inc, &n2) == cleanup);
|
||||||
|
gbinder_cleanup_free(cleanup);
|
||||||
|
g_assert(n1 == 1);
|
||||||
|
g_assert(n2 == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* reset
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_reset(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
int n1 = 0, n2 =0;
|
||||||
|
GBinderCleanup* cleanup = gbinder_cleanup_add(NULL, test_cleanup_inc, &n1);
|
||||||
|
|
||||||
|
g_assert(cleanup);
|
||||||
|
g_assert(gbinder_cleanup_add(cleanup, test_cleanup_inc, &n2) == cleanup);
|
||||||
|
gbinder_cleanup_reset(cleanup);
|
||||||
|
g_assert(n1 == 1);
|
||||||
|
g_assert(n2 == 1);
|
||||||
|
|
||||||
|
gbinder_cleanup_free(cleanup);
|
||||||
|
g_assert(n1 == 1);
|
||||||
|
g_assert(n2 == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* Common
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
#define TEST_PREFIX "/cleanup/"
|
||||||
|
#define TEST_(t) TEST_PREFIX t
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
g_test_add_func(TEST_("null"), test_null);
|
||||||
|
g_test_add_func(TEST_("basic"), test_basic);
|
||||||
|
g_test_add_func(TEST_("reset"), test_reset);
|
||||||
|
test_init(&test_opt, argc, argv);
|
||||||
|
return g_test_run();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local Variables:
|
||||||
|
* mode: C
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* indent-tabs-mode: nil
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -74,16 +74,18 @@ void
|
|||||||
test_null(
|
test_null(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
GBinderClient* null = NULL;
|
|
||||||
|
|
||||||
g_assert(!gbinder_client_new(NULL, NULL));
|
g_assert(!gbinder_client_new(NULL, NULL));
|
||||||
g_assert(!gbinder_client_ref(null));
|
g_assert(!gbinder_client_new2(NULL, NULL, 0));
|
||||||
gbinder_client_unref(null);
|
g_assert(!gbinder_client_ref(NULL));
|
||||||
|
g_assert(!gbinder_client_interface(NULL));
|
||||||
|
g_assert(!gbinder_client_interface2(NULL, 0));
|
||||||
|
gbinder_client_unref(NULL);
|
||||||
g_assert(!gbinder_client_new_request(NULL));
|
g_assert(!gbinder_client_new_request(NULL));
|
||||||
g_assert(!gbinder_client_transact_sync_reply(null, 0, NULL, NULL));
|
g_assert(!gbinder_client_new_request2(NULL, 0));
|
||||||
g_assert(gbinder_client_transact_sync_oneway(null, 0, NULL) == (-EINVAL));
|
g_assert(!gbinder_client_transact_sync_reply(NULL, 0, NULL, NULL));
|
||||||
g_assert(!gbinder_client_transact(null, 0, 0, NULL, NULL, NULL, NULL));
|
g_assert(gbinder_client_transact_sync_oneway(NULL, 0, NULL) == (-EINVAL));
|
||||||
gbinder_client_cancel(null, 0);
|
g_assert(!gbinder_client_transact(NULL, 0, 0, NULL, NULL, NULL, NULL));
|
||||||
|
gbinder_client_cancel(NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
@@ -98,11 +100,12 @@ test_basic(
|
|||||||
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
GBinderRemoteObject* obj = gbinder_object_registry_get_remote(reg, 0);
|
GBinderRemoteObject* obj = gbinder_object_registry_get_remote(reg, 0);
|
||||||
GBinderClient* client = gbinder_client_new(obj, "foo");
|
const char* iface = "foo";
|
||||||
|
GBinderClient* client = gbinder_client_new(obj, iface);
|
||||||
|
|
||||||
g_assert(!gbinder_client_new(obj, NULL));
|
|
||||||
g_assert(client);
|
g_assert(client);
|
||||||
g_assert(gbinder_client_ref(client) == client);
|
g_assert(gbinder_client_ref(client) == client);
|
||||||
|
g_assert_cmpstr(gbinder_client_interface(client), == ,iface);
|
||||||
gbinder_client_unref(client);
|
gbinder_client_unref(client);
|
||||||
gbinder_client_cancel(client, 0); /* does nothing */
|
gbinder_client_cancel(client, 0); /* does nothing */
|
||||||
|
|
||||||
@@ -111,6 +114,102 @@ test_basic(
|
|||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* interfaces
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_interfaces(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
|
GBinderRemoteObject* obj = gbinder_object_registry_get_remote(reg, 0);
|
||||||
|
static const GBinderClientIfaceInfo ifaces[] = {
|
||||||
|
{"33", 33 }, { "11", 11 }, { "22", 22 }
|
||||||
|
};
|
||||||
|
GBinderClient* client = gbinder_client_new2(obj, ifaces,
|
||||||
|
G_N_ELEMENTS(ifaces));
|
||||||
|
|
||||||
|
g_assert(client);
|
||||||
|
g_assert_cmpstr(gbinder_client_interface(client), == ,"11");
|
||||||
|
g_assert_cmpstr(gbinder_client_interface2(client, 11), == ,"11");
|
||||||
|
g_assert_cmpstr(gbinder_client_interface2(client, 22), == ,"22");
|
||||||
|
g_assert_cmpstr(gbinder_client_interface2(client, 33), == ,"33");
|
||||||
|
g_assert(!gbinder_client_interface2(client, 34));
|
||||||
|
g_assert(!gbinder_client_new_request2(client, 34));
|
||||||
|
gbinder_client_unref(client);
|
||||||
|
|
||||||
|
/* Client with no interface info */
|
||||||
|
client = gbinder_client_new2(obj, NULL, 0);
|
||||||
|
g_assert(client);
|
||||||
|
g_assert(!gbinder_client_interface(client));
|
||||||
|
g_assert(!gbinder_client_interface2(client, 1));
|
||||||
|
gbinder_client_unref(client);
|
||||||
|
|
||||||
|
gbinder_remote_object_unref(obj);
|
||||||
|
gbinder_ipc_unref(ipc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* no_header
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_no_header(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GBinderClient* client = test_client_new(0, NULL);
|
||||||
|
int fd = gbinder_driver_fd(gbinder_client_ipc(client)->driver);
|
||||||
|
|
||||||
|
test_binder_br_transaction_complete(fd);
|
||||||
|
g_assert(gbinder_client_transact_sync_oneway(client, 0, NULL) ==
|
||||||
|
GBINDER_STATUS_OK);
|
||||||
|
|
||||||
|
gbinder_client_unref(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* dead
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_dead_done(
|
||||||
|
GBinderRemoteObject* obj,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
GVERBOSE_("");
|
||||||
|
test_quit_later((GMainLoop*)user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_dead(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
const guint handle = 1;
|
||||||
|
GBinderClient* client = test_client_new(handle, "foo");
|
||||||
|
GBinderRemoteObject* obj = client->remote;
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
const int fd = gbinder_driver_fd(gbinder_client_ipc(client)->driver);
|
||||||
|
gbinder_remote_object_add_death_handler(obj, test_dead_done, loop);
|
||||||
|
|
||||||
|
test_binder_br_dead_binder(fd, handle);
|
||||||
|
test_binder_set_looper_enabled(fd, TRUE);
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
g_assert(gbinder_remote_object_is_dead(obj));
|
||||||
|
|
||||||
|
g_assert(!gbinder_client_transact_sync_reply(client, 0, NULL, NULL));
|
||||||
|
g_assert(gbinder_client_transact_sync_oneway(client, 0, NULL) == -ESTALE);
|
||||||
|
g_assert(!gbinder_client_transact(client, 0, 0, NULL, NULL, NULL, NULL));
|
||||||
|
|
||||||
|
gbinder_client_unref(client);
|
||||||
|
g_main_loop_unref(loop);
|
||||||
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* sync_oneway
|
* sync_oneway
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@@ -164,10 +263,10 @@ test_sync_reply_tx(
|
|||||||
data = gbinder_local_reply_data(reply);
|
data = gbinder_local_reply_data(reply);
|
||||||
g_assert(data);
|
g_assert(data);
|
||||||
|
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_transaction_complete(fd));
|
test_binder_br_transaction_complete(fd);
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_reply(fd, handle, code, data->bytes));
|
test_binder_br_reply(fd, handle, code, data->bytes);
|
||||||
|
|
||||||
tx_reply = gbinder_client_transact_sync_reply(client, 0, req, &status);
|
tx_reply = gbinder_client_transact_sync_reply(client, 0, req, &status);
|
||||||
g_assert(tx_reply);
|
g_assert(tx_reply);
|
||||||
@@ -265,10 +364,10 @@ test_reply_tx(
|
|||||||
data = gbinder_local_reply_data(reply);
|
data = gbinder_local_reply_data(reply);
|
||||||
g_assert(data);
|
g_assert(data);
|
||||||
|
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_transaction_complete(fd));
|
test_binder_br_transaction_complete(fd);
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_reply(fd, handle, code, data->bytes));
|
test_binder_br_reply(fd, handle, code, data->bytes);
|
||||||
|
|
||||||
id = gbinder_client_transact(client, 0, 0, req, done, destroy, loop);
|
id = gbinder_client_transact(client, 0, 0, req, done, destroy, loop);
|
||||||
g_assert(id);
|
g_assert(id);
|
||||||
@@ -286,8 +385,9 @@ test_reply(
|
|||||||
GDestroyNotify destroy)
|
GDestroyNotify destroy)
|
||||||
{
|
{
|
||||||
GBinderClient* client = test_client_new(0, TEST_INTERFACE);
|
GBinderClient* client = test_client_new(0, TEST_INTERFACE);
|
||||||
GBinderLocalRequest* req = gbinder_client_new_request(client);
|
GBinderLocalRequest* req = gbinder_client_new_request2(client, 0);
|
||||||
|
|
||||||
|
g_assert(req);
|
||||||
test_reply_tx(client, req, done, destroy);
|
test_reply_tx(client, req, done, destroy);
|
||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
|
|
||||||
@@ -326,17 +426,21 @@ test_reply_ok3(
|
|||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
|
|
||||||
#define TEST_PREFIX "/client/"
|
#define TEST_PREFIX "/client/"
|
||||||
|
#define TEST_(t) TEST_PREFIX t
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
g_test_add_func(TEST_PREFIX "null", test_null);
|
g_test_add_func(TEST_("null"), test_null);
|
||||||
g_test_add_func(TEST_PREFIX "basic", test_basic);
|
g_test_add_func(TEST_("basic"), test_basic);
|
||||||
g_test_add_func(TEST_PREFIX "sync_oneway", test_sync_oneway);
|
g_test_add_func(TEST_("interfaces"), test_interfaces);
|
||||||
g_test_add_func(TEST_PREFIX "sync_reply", test_sync_reply);
|
g_test_add_func(TEST_("dead"), test_dead);
|
||||||
g_test_add_func(TEST_PREFIX "reply/ok1", test_reply_ok1);
|
g_test_add_func(TEST_("no_header"), test_no_header);
|
||||||
g_test_add_func(TEST_PREFIX "reply/ok2", test_reply_ok2);
|
g_test_add_func(TEST_("sync_oneway"), test_sync_oneway);
|
||||||
g_test_add_func(TEST_PREFIX "reply/ok3", test_reply_ok3);
|
g_test_add_func(TEST_("sync_reply"), test_sync_reply);
|
||||||
|
g_test_add_func(TEST_("reply/ok1"), test_reply_ok1);
|
||||||
|
g_test_add_func(TEST_("reply/ok2"), test_reply_ok2);
|
||||||
|
g_test_add_func(TEST_("reply/ok3"), test_reply_ok3);
|
||||||
test_init(&test_opt, argc, argv);
|
test_init(&test_opt, argc, argv);
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -91,7 +91,7 @@ test_noop(
|
|||||||
|
|
||||||
g_assert(driver);
|
g_assert(driver);
|
||||||
g_assert(fd >= 0);
|
g_assert(fd >= 0);
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(gbinder_driver_poll(driver, NULL) == POLLIN);
|
g_assert(gbinder_driver_poll(driver, NULL) == POLLIN);
|
||||||
g_assert(gbinder_driver_read(driver, NULL, NULL) == 0);
|
g_assert(gbinder_driver_read(driver, NULL, NULL) == 0);
|
||||||
|
|
||||||
|
|||||||
5
unit/unit_eventloop/Makefile
Normal file
5
unit/unit_eventloop/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# -*- Mode: makefile-gmake -*-
|
||||||
|
|
||||||
|
EXE = unit_eventloop
|
||||||
|
|
||||||
|
include ../common/Makefile
|
||||||
262
unit/unit_eventloop/unit_eventloop.c
Normal file
262
unit/unit_eventloop/unit_eventloop.c
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
/*
|
||||||
|
* 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 "test_common.h"
|
||||||
|
#include "gbinder_eventloop_p.h"
|
||||||
|
|
||||||
|
static TestOpt test_opt;
|
||||||
|
|
||||||
|
static int test_eventloop_timeout_add_called;
|
||||||
|
static int test_eventloop_callback_new_called;
|
||||||
|
static int test_eventloop_cleanup_called;
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
test_unreached_proc(
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
return G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* Test event loop integration
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
GBinderEventLoopTimeout*
|
||||||
|
test_eventloop_timeout_add(
|
||||||
|
guint interval,
|
||||||
|
GSourceFunc func,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
test_eventloop_timeout_add_called++;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_eventloop_timeout_remove(
|
||||||
|
GBinderEventLoopTimeout* timeout)
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
GBinderEventLoopCallback*
|
||||||
|
test_eventloop_callback_new(
|
||||||
|
GBinderEventLoopCallbackFunc func,
|
||||||
|
gpointer data,
|
||||||
|
GDestroyNotify destroy)
|
||||||
|
{
|
||||||
|
test_eventloop_callback_new_called++;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_eventloop_callback_ref(
|
||||||
|
GBinderEventLoopCallback* cb)
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_eventloop_callback_unref(
|
||||||
|
GBinderEventLoopCallback* cb)
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_eventloop_callback_schedule(
|
||||||
|
GBinderEventLoopCallback* cb)
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_eventloop_callback_cancel(
|
||||||
|
GBinderEventLoopCallback* cb)
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_eventloop_cleanup(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
test_eventloop_cleanup_called++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const GBinderEventLoopIntegration test_eventloop = {
|
||||||
|
test_eventloop_timeout_add,
|
||||||
|
test_eventloop_timeout_remove,
|
||||||
|
test_eventloop_callback_new,
|
||||||
|
test_eventloop_callback_ref,
|
||||||
|
test_eventloop_callback_unref,
|
||||||
|
test_eventloop_callback_schedule,
|
||||||
|
test_eventloop_callback_cancel,
|
||||||
|
test_eventloop_cleanup
|
||||||
|
};
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* replace
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_replace(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
test_eventloop_timeout_add_called = 0;
|
||||||
|
test_eventloop_callback_new_called = 0;
|
||||||
|
test_eventloop_cleanup_called = 0;
|
||||||
|
|
||||||
|
gbinder_eventloop_set(NULL);
|
||||||
|
gbinder_eventloop_set(&test_eventloop);
|
||||||
|
|
||||||
|
g_assert(!gbinder_timeout_add(0, test_unreached_proc, NULL));
|
||||||
|
g_assert_cmpint(test_eventloop_timeout_add_called, == ,1);
|
||||||
|
g_assert(!gbinder_idle_add(test_unreached_proc, NULL));
|
||||||
|
g_assert_cmpint(test_eventloop_timeout_add_called, == ,2);
|
||||||
|
gbinder_timeout_remove(NULL);
|
||||||
|
g_assert(!gbinder_idle_callback_new(NULL, NULL, NULL));
|
||||||
|
g_assert_cmpint(test_eventloop_callback_new_called, == ,1);
|
||||||
|
g_assert(!gbinder_idle_callback_ref(NULL));
|
||||||
|
gbinder_idle_callback_unref(NULL);
|
||||||
|
gbinder_idle_callback_schedule(NULL);
|
||||||
|
gbinder_idle_callback_cancel(NULL);
|
||||||
|
|
||||||
|
gbinder_eventloop_set(NULL);
|
||||||
|
g_assert_cmpint(test_eventloop_cleanup_called, == ,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* idle
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
test_quit_func(
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
g_main_loop_quit((GMainLoop*)data);
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_idle(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
|
gbinder_eventloop_set(NULL);
|
||||||
|
g_assert(gbinder_idle_add(test_quit_func, loop));
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
g_main_loop_unref(loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* timeout
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_timeout(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
|
gbinder_eventloop_set(NULL);
|
||||||
|
g_assert(gbinder_timeout_add(10, test_quit_func, loop));
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
g_main_loop_unref(loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* callback
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_quit_cb(
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
g_main_loop_quit((GMainLoop*)data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_callback(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
GBinderEventLoopCallback* cb;
|
||||||
|
|
||||||
|
gbinder_eventloop_set(NULL);
|
||||||
|
cb = gbinder_idle_callback_new(test_quit_cb, loop, NULL);
|
||||||
|
gbinder_idle_callback_schedule(cb);
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
gbinder_idle_callback_unref(cb);
|
||||||
|
g_main_loop_unref(loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* Common
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
#define TEST_(t) "/eventloop/" t
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
g_test_add_func(TEST_("replace"), test_replace);
|
||||||
|
g_test_add_func(TEST_("idle"), test_idle);
|
||||||
|
g_test_add_func(TEST_("timeout"), test_timeout);
|
||||||
|
g_test_add_func(TEST_("callback"), test_callback);
|
||||||
|
test_init(&test_opt, argc, argv);
|
||||||
|
return g_test_run();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Local Variables:
|
||||||
|
* mode: C
|
||||||
|
* c-basic-offset: 4
|
||||||
|
* indent-tabs-mode: nil
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
#include "gbinder_ipc.h"
|
#include "gbinder_ipc.h"
|
||||||
#include "gbinder_driver.h"
|
#include "gbinder_driver.h"
|
||||||
#include "gbinder_local_object.h"
|
#include "gbinder_local_object_p.h"
|
||||||
#include "gbinder_local_reply_p.h"
|
#include "gbinder_local_reply_p.h"
|
||||||
#include "gbinder_local_request_p.h"
|
#include "gbinder_local_request_p.h"
|
||||||
#include "gbinder_object_registry.h"
|
#include "gbinder_object_registry.h"
|
||||||
@@ -52,6 +52,24 @@
|
|||||||
|
|
||||||
static TestOpt test_opt;
|
static TestOpt test_opt;
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
test_unref_ipc(
|
||||||
|
gpointer ipc)
|
||||||
|
{
|
||||||
|
gbinder_ipc_unref(ipc);
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_quit_when_destroyed(
|
||||||
|
gpointer loop,
|
||||||
|
GObject* obj)
|
||||||
|
{
|
||||||
|
test_quit_later((GMainLoop*)loop);
|
||||||
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* null
|
* null
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@@ -109,6 +127,48 @@ test_basic(
|
|||||||
|
|
||||||
/* Invalid path */
|
/* Invalid path */
|
||||||
g_assert(!gbinder_ipc_new("invalid path", NULL));
|
g_assert(!gbinder_ipc_new("invalid path", NULL));
|
||||||
|
|
||||||
|
gbinder_ipc_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* async_oneway
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_async_oneway_done(
|
||||||
|
GBinderIpc* ipc,
|
||||||
|
GBinderRemoteReply* reply,
|
||||||
|
int status,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
g_assert(!status);
|
||||||
|
g_assert(!reply);
|
||||||
|
test_quit_later((GMainLoop*)user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_async_oneway(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
|
const GBinderIo* io = gbinder_driver_io(ipc->driver);
|
||||||
|
const int fd = gbinder_driver_fd(ipc->driver);
|
||||||
|
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
gulong id;
|
||||||
|
|
||||||
|
test_binder_br_transaction_complete(fd);
|
||||||
|
id = gbinder_ipc_transact(ipc, 0, 1, GBINDER_TX_FLAG_ONEWAY,
|
||||||
|
req, test_async_oneway_done, NULL, loop);
|
||||||
|
g_assert(id);
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
gbinder_local_request_unref(req);
|
||||||
|
gbinder_ipc_unref(ipc);
|
||||||
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
@@ -125,11 +185,12 @@ test_sync_oneway(
|
|||||||
const int fd = gbinder_driver_fd(ipc->driver);
|
const int fd = gbinder_driver_fd(ipc->driver);
|
||||||
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
||||||
|
|
||||||
g_assert(test_binder_br_transaction_complete(fd));
|
test_binder_br_transaction_complete(fd);
|
||||||
g_assert(gbinder_ipc_transact_sync_oneway(ipc, 0, 1, req) ==
|
g_assert(gbinder_ipc_transact_sync_oneway(ipc, 0, 1, req) ==
|
||||||
GBINDER_STATUS_OK);
|
GBINDER_STATUS_OK);
|
||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
@@ -157,10 +218,10 @@ test_sync_reply_ok_status(
|
|||||||
data = gbinder_local_reply_data(reply);
|
data = gbinder_local_reply_data(reply);
|
||||||
g_assert(data);
|
g_assert(data);
|
||||||
|
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_transaction_complete(fd));
|
test_binder_br_transaction_complete(fd);
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_reply(fd, handle, code, data->bytes));
|
test_binder_br_reply(fd, handle, code, data->bytes);
|
||||||
|
|
||||||
tx_reply = gbinder_ipc_transact_sync_reply(ipc, handle, code, req, status);
|
tx_reply = gbinder_ipc_transact_sync_reply(ipc, handle, code, req, status);
|
||||||
g_assert(tx_reply);
|
g_assert(tx_reply);
|
||||||
@@ -173,6 +234,7 @@ test_sync_reply_ok_status(
|
|||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
gbinder_local_reply_unref(reply);
|
gbinder_local_reply_unref(reply);
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -205,16 +267,17 @@ test_sync_reply_error(
|
|||||||
const gint expected_status = GBINDER_STATUS_FAILED;
|
const gint expected_status = GBINDER_STATUS_FAILED;
|
||||||
int status = INT_MAX;
|
int status = INT_MAX;
|
||||||
|
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_transaction_complete(fd));
|
test_binder_br_transaction_complete(fd);
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_reply_status(fd, expected_status));
|
test_binder_br_reply_status(fd, expected_status);
|
||||||
|
|
||||||
g_assert(!gbinder_ipc_transact_sync_reply(ipc, handle, code, req, &status));
|
g_assert(!gbinder_ipc_transact_sync_reply(ipc, handle, code, req, &status));
|
||||||
g_assert(status == expected_status);
|
g_assert(status == expected_status);
|
||||||
|
|
||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
@@ -268,10 +331,10 @@ test_transact_ok(
|
|||||||
data = gbinder_local_reply_data(reply);
|
data = gbinder_local_reply_data(reply);
|
||||||
g_assert(data);
|
g_assert(data);
|
||||||
|
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_transaction_complete(fd));
|
test_binder_br_transaction_complete(fd);
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_reply(fd, handle, code, data->bytes));
|
test_binder_br_reply(fd, handle, code, data->bytes);
|
||||||
|
|
||||||
id = gbinder_ipc_transact(ipc, handle, code, 0, req,
|
id = gbinder_ipc_transact(ipc, handle, code, 0, req,
|
||||||
test_transact_ok_done, test_transact_ok_destroy, loop);
|
test_transact_ok_done, test_transact_ok_destroy, loop);
|
||||||
@@ -284,6 +347,7 @@ test_transact_ok(
|
|||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
gbinder_local_reply_unref(reply);
|
gbinder_local_reply_unref(reply);
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
g_main_loop_unref(loop);
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,8 +381,8 @@ test_transact_dead(
|
|||||||
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
gulong id;
|
gulong id;
|
||||||
|
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_dead_reply(fd));
|
test_binder_br_dead_reply(fd);
|
||||||
|
|
||||||
id = gbinder_ipc_transact(ipc, 1, 2, 0, req, test_transact_dead_done,
|
id = gbinder_ipc_transact(ipc, 1, 2, 0, req, test_transact_dead_done,
|
||||||
NULL, loop);
|
NULL, loop);
|
||||||
@@ -330,6 +394,7 @@ test_transact_dead(
|
|||||||
gbinder_ipc_cancel(ipc, id);
|
gbinder_ipc_cancel(ipc, id);
|
||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
g_main_loop_unref(loop);
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,8 +428,8 @@ test_transact_failed(
|
|||||||
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
gulong id;
|
gulong id;
|
||||||
|
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_failed_reply(fd));
|
test_binder_br_failed_reply(fd);
|
||||||
|
|
||||||
id = gbinder_ipc_transact(ipc, 1, 2, 0, req, test_transact_failed_done,
|
id = gbinder_ipc_transact(ipc, 1, 2, 0, req, test_transact_failed_done,
|
||||||
NULL, loop);
|
NULL, loop);
|
||||||
@@ -376,6 +441,7 @@ test_transact_failed(
|
|||||||
gbinder_ipc_cancel(ipc, id);
|
gbinder_ipc_cancel(ipc, id);
|
||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
g_main_loop_unref(loop);
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,8 +477,8 @@ test_transact_status(
|
|||||||
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
gulong id;
|
gulong id;
|
||||||
|
|
||||||
g_assert(test_binder_br_noop(fd));
|
test_binder_br_noop(fd);
|
||||||
g_assert(test_binder_br_reply_status(fd, EXPECTED_STATUS));
|
test_binder_br_reply_status(fd, EXPECTED_STATUS);
|
||||||
|
|
||||||
id = gbinder_ipc_transact(ipc, 1, 2, 0, req, test_transact_status_done,
|
id = gbinder_ipc_transact(ipc, 1, 2, 0, req, test_transact_status_done,
|
||||||
NULL, loop);
|
NULL, loop);
|
||||||
@@ -424,6 +490,7 @@ test_transact_status(
|
|||||||
gbinder_ipc_cancel(ipc, id);
|
gbinder_ipc_cancel(ipc, id);
|
||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
g_main_loop_unref(loop);
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,6 +520,7 @@ test_transact_custom(
|
|||||||
g_assert(id);
|
g_assert(id);
|
||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
gbinder_ipc_exit();
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
g_main_loop_unref(loop);
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
@@ -483,10 +551,44 @@ test_transact_custom2(
|
|||||||
g_assert(id);
|
g_assert(id);
|
||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
gbinder_ipc_exit();
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
g_main_loop_unref(loop);
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* transact_custom3
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_transact_custom3_exec(
|
||||||
|
const GBinderIpcTx* tx)
|
||||||
|
{
|
||||||
|
GVERBOSE_("");
|
||||||
|
gbinder_ipc_unref(tx->ipc);
|
||||||
|
test_quit_later((GMainLoop*)tx->user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_transact_custom3(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
/* Reusing test_transact_cancel_done and test_transact_cancel_destroy */
|
||||||
|
gulong id = gbinder_ipc_transact_custom(ipc, test_transact_custom3_exec,
|
||||||
|
NULL, NULL, loop);
|
||||||
|
|
||||||
|
g_assert(id);
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
/* Reference to GBinderIpc is released by test_transact_custom3_exec */
|
||||||
|
gbinder_ipc_exit();
|
||||||
|
g_main_loop_unref(loop);
|
||||||
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* transact_cancel
|
* transact_cancel
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@@ -532,6 +634,7 @@ test_transact_cancel(
|
|||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
g_main_loop_unref(loop);
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,6 +679,95 @@ test_transact_cancel2(
|
|||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
|
g_main_loop_unref(loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* transact_2way
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
GBinderLocalReply*
|
||||||
|
test_transact_2way_incoming_proc(
|
||||||
|
GBinderLocalObject* obj,
|
||||||
|
GBinderRemoteRequest* req,
|
||||||
|
guint code,
|
||||||
|
guint flags,
|
||||||
|
int* status,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
int* incoming_call = user_data;
|
||||||
|
|
||||||
|
GVERBOSE_("\"%s\" %u", gbinder_remote_request_interface(req), code);
|
||||||
|
g_assert_cmpuint(flags, == ,0);
|
||||||
|
g_assert_cmpint(gbinder_remote_request_sender_pid(req), == ,getpid());
|
||||||
|
g_assert_cmpint(gbinder_remote_request_sender_euid(req), == ,geteuid());
|
||||||
|
g_assert_cmpstr(gbinder_remote_request_interface(req), == ,"test");
|
||||||
|
g_assert_cmpstr(gbinder_remote_request_read_string8(req), == ,"message");
|
||||||
|
g_assert_cmpuint(code, == ,2);
|
||||||
|
g_assert_cmpint(*incoming_call, == ,0);
|
||||||
|
(*incoming_call)++;
|
||||||
|
|
||||||
|
*status = GBINDER_STATUS_OK;
|
||||||
|
return gbinder_local_object_new_reply(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_transact_2way(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
|
const GBinderIo* io = gbinder_driver_io(ipc->driver);
|
||||||
|
const int fd = gbinder_driver_fd(ipc->driver);
|
||||||
|
const char* dev = gbinder_driver_dev(ipc->driver);
|
||||||
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
|
const char* const ifaces[] = { "test", NULL };
|
||||||
|
const guint32 handle = 0;
|
||||||
|
const guint32 code = 1;
|
||||||
|
int incoming_call = 0;
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
GBinderLocalObject* obj = gbinder_local_object_new
|
||||||
|
(ipc, ifaces, test_transact_2way_incoming_proc, &incoming_call);
|
||||||
|
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
||||||
|
GBinderLocalRequest* incoming_req = gbinder_local_request_new(io, NULL);
|
||||||
|
GBinderLocalReply* reply = gbinder_local_reply_new(io);
|
||||||
|
GBinderWriter writer;
|
||||||
|
|
||||||
|
/* Prepare reply */
|
||||||
|
g_assert(gbinder_local_reply_append_string16(reply, TEST_REQ_PARAM_STR));
|
||||||
|
|
||||||
|
/* Prepare incoming request */
|
||||||
|
gbinder_local_request_init_writer(req, &writer);
|
||||||
|
prot->write_rpc_header(&writer, "test");
|
||||||
|
gbinder_writer_append_string8(&writer, "message");
|
||||||
|
|
||||||
|
test_binder_br_transaction(fd, obj, 2,
|
||||||
|
gbinder_local_request_data(req)->bytes);
|
||||||
|
test_binder_br_noop(fd);
|
||||||
|
test_binder_br_transaction_complete(fd);
|
||||||
|
test_binder_br_noop(fd);
|
||||||
|
test_binder_br_reply(fd, handle, code,
|
||||||
|
gbinder_local_reply_data(reply)->bytes);
|
||||||
|
|
||||||
|
/* NB. Reusing test_transact_ok_done and test_transact_ok_destroy */
|
||||||
|
g_assert(gbinder_ipc_transact(ipc, handle, code, 0, req,
|
||||||
|
test_transact_ok_done, test_transact_ok_destroy, loop));
|
||||||
|
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
/* Now we need to wait until GBinderIpc is destroyed */
|
||||||
|
GDEBUG("waiting for GBinderIpc to get destroyed");
|
||||||
|
g_object_weak_ref(G_OBJECT(ipc), test_quit_when_destroyed, loop);
|
||||||
|
gbinder_local_object_unref(obj);
|
||||||
|
gbinder_local_request_unref(req);
|
||||||
|
gbinder_local_request_unref(incoming_req);
|
||||||
|
gbinder_local_reply_unref(reply);
|
||||||
|
g_idle_add(test_unref_ipc, ipc);
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
gbinder_ipc_exit();
|
||||||
g_main_loop_unref(loop);
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -606,24 +798,6 @@ test_transact_incoming_proc(
|
|||||||
return gbinder_local_object_new_reply(obj);
|
return gbinder_local_object_new_reply(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
gboolean
|
|
||||||
test_transact_unref_ipc(
|
|
||||||
gpointer ipc)
|
|
||||||
{
|
|
||||||
gbinder_ipc_unref(ipc);
|
|
||||||
return G_SOURCE_REMOVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
void
|
|
||||||
test_transact_done(
|
|
||||||
gpointer loop,
|
|
||||||
GObject* ipc)
|
|
||||||
{
|
|
||||||
test_quit_later((GMainLoop*)loop);
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
test_transact_incoming(
|
test_transact_incoming(
|
||||||
@@ -634,34 +808,43 @@ test_transact_incoming(
|
|||||||
const int fd = gbinder_driver_fd(ipc->driver);
|
const int fd = gbinder_driver_fd(ipc->driver);
|
||||||
const char* dev = gbinder_driver_dev(ipc->driver);
|
const char* dev = gbinder_driver_dev(ipc->driver);
|
||||||
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
|
const char* const ifaces[] = { "test", NULL };
|
||||||
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
GBinderLocalObject* obj = gbinder_ipc_new_local_object
|
GBinderLocalObject* obj = gbinder_local_object_new
|
||||||
(ipc, "test", test_transact_incoming_proc, loop);
|
(ipc, ifaces, test_transact_incoming_proc, loop);
|
||||||
|
GBinderLocalRequest* ping = gbinder_local_request_new(io, NULL);
|
||||||
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
||||||
GBinderOutputData* data;
|
|
||||||
GBinderWriter writer;
|
GBinderWriter writer;
|
||||||
|
|
||||||
|
gbinder_local_request_init_writer(ping, &writer);
|
||||||
|
prot->write_ping(&writer);
|
||||||
|
|
||||||
gbinder_local_request_init_writer(req, &writer);
|
gbinder_local_request_init_writer(req, &writer);
|
||||||
prot->write_rpc_header(&writer, "test");
|
prot->write_rpc_header(&writer, "test");
|
||||||
gbinder_writer_append_string8(&writer, "message");
|
gbinder_writer_append_string8(&writer, "message");
|
||||||
data = gbinder_local_request_data(req);
|
|
||||||
|
|
||||||
test_binder_br_transaction(fd, obj, 1, data->bytes);
|
test_binder_br_transaction(fd, obj, prot->ping_tx,
|
||||||
|
gbinder_local_request_data(ping)->bytes);
|
||||||
|
test_binder_br_transaction(fd, obj, 1,
|
||||||
|
gbinder_local_request_data(req)->bytes);
|
||||||
|
test_binder_set_looper_enabled(fd, TRUE);
|
||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
/* Now we need to wait until GBinderIpc is destroyed */
|
/* Now we need to wait until GBinderIpc is destroyed */
|
||||||
GDEBUG("waiting for GBinderIpc to get destroyed");
|
GDEBUG("waiting for GBinderIpc to get destroyed");
|
||||||
g_object_weak_ref(G_OBJECT(ipc), test_transact_done, loop);
|
g_object_weak_ref(G_OBJECT(ipc), test_quit_when_destroyed, loop);
|
||||||
gbinder_local_object_unref(obj);
|
gbinder_local_object_unref(obj);
|
||||||
|
gbinder_local_request_unref(ping);
|
||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
g_idle_add(test_transact_unref_ipc, ipc);
|
g_idle_add(test_unref_ipc, ipc);
|
||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
gbinder_ipc_exit();
|
||||||
g_main_loop_unref(loop);
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* transact_incoming_status
|
* transact_status_reply
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -695,9 +878,10 @@ test_transact_status_reply(
|
|||||||
const int fd = gbinder_driver_fd(ipc->driver);
|
const int fd = gbinder_driver_fd(ipc->driver);
|
||||||
const char* dev = gbinder_driver_dev(ipc->driver);
|
const char* dev = gbinder_driver_dev(ipc->driver);
|
||||||
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
|
const char* const ifaces[] = { "test", NULL };
|
||||||
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
GBinderLocalObject* obj = gbinder_ipc_new_local_object
|
GBinderLocalObject* obj = gbinder_local_object_new
|
||||||
(ipc, "test", test_transact_status_reply_proc, loop);
|
(ipc, ifaces, test_transact_status_reply_proc, loop);
|
||||||
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
||||||
GBinderOutputData* data;
|
GBinderOutputData* data;
|
||||||
GBinderWriter writer;
|
GBinderWriter writer;
|
||||||
@@ -708,16 +892,277 @@ test_transact_status_reply(
|
|||||||
data = gbinder_local_request_data(req);
|
data = gbinder_local_request_data(req);
|
||||||
|
|
||||||
test_binder_br_transaction(fd, obj, 1, data->bytes);
|
test_binder_br_transaction(fd, obj, 1, data->bytes);
|
||||||
|
test_binder_set_looper_enabled(fd, TRUE);
|
||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
/* Now we need to wait until GBinderIpc is destroyed */
|
/* Now we need to wait until GBinderIpc is destroyed */
|
||||||
GDEBUG("waiting for GBinderIpc to get destroyed");
|
GDEBUG("waiting for GBinderIpc to get destroyed");
|
||||||
g_object_weak_ref(G_OBJECT(ipc), test_transact_done, loop);
|
g_object_weak_ref(G_OBJECT(ipc), test_quit_when_destroyed, loop);
|
||||||
gbinder_local_object_unref(obj);
|
gbinder_local_object_unref(obj);
|
||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
g_idle_add(test_transact_unref_ipc, ipc);
|
g_idle_add(test_unref_ipc, ipc);
|
||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
gbinder_ipc_exit();
|
||||||
|
g_main_loop_unref(loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* transact_async
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
typedef struct test_transact_async_req {
|
||||||
|
GBinderLocalObject* obj;
|
||||||
|
GBinderRemoteRequest* req;
|
||||||
|
GMainLoop* loop;
|
||||||
|
} TestTransactAsyncReq;
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_transact_async_done(
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
TestTransactAsyncReq* test = data;
|
||||||
|
|
||||||
|
gbinder_local_object_unref(test->obj);
|
||||||
|
gbinder_remote_request_unref(test->req);
|
||||||
|
test_quit_later(test->loop);
|
||||||
|
g_free(test);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
gboolean
|
||||||
|
test_transact_async_reply(
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
TestTransactAsyncReq* test = data;
|
||||||
|
GBinderLocalReply* reply = gbinder_local_object_new_reply(test->obj);
|
||||||
|
|
||||||
|
gbinder_remote_request_complete(test->req, reply, 0);
|
||||||
|
gbinder_local_reply_unref(reply);
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
GBinderLocalReply*
|
||||||
|
test_transact_async_proc(
|
||||||
|
GBinderLocalObject* obj,
|
||||||
|
GBinderRemoteRequest* req,
|
||||||
|
guint code,
|
||||||
|
guint flags,
|
||||||
|
int* status,
|
||||||
|
void* loop)
|
||||||
|
{
|
||||||
|
TestTransactAsyncReq* test = g_new(TestTransactAsyncReq, 1);
|
||||||
|
|
||||||
|
GVERBOSE_("\"%s\" %u", gbinder_remote_request_interface(req), code);
|
||||||
|
g_assert(!flags);
|
||||||
|
g_assert(gbinder_remote_request_sender_pid(req) == getpid());
|
||||||
|
g_assert(gbinder_remote_request_sender_euid(req) == geteuid());
|
||||||
|
g_assert(!g_strcmp0(gbinder_remote_request_interface(req), "test"));
|
||||||
|
g_assert(!g_strcmp0(gbinder_remote_request_read_string8(req), "message"));
|
||||||
|
g_assert(code == 1);
|
||||||
|
|
||||||
|
test->obj = gbinder_local_object_ref(obj);
|
||||||
|
test->req = gbinder_remote_request_ref(req);
|
||||||
|
test->loop = (GMainLoop*)loop;
|
||||||
|
|
||||||
|
gbinder_remote_request_block(req);
|
||||||
|
gbinder_remote_request_block(req); /* wrong state; has no effect */
|
||||||
|
|
||||||
|
g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, test_transact_async_reply, test,
|
||||||
|
test_transact_async_done);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_transact_async(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
|
const GBinderIo* io = gbinder_driver_io(ipc->driver);
|
||||||
|
const int fd = gbinder_driver_fd(ipc->driver);
|
||||||
|
const char* dev = gbinder_driver_dev(ipc->driver);
|
||||||
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
|
const char* const ifaces[] = { "test", NULL };
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
GBinderLocalObject* obj = gbinder_local_object_new
|
||||||
|
(ipc, ifaces, test_transact_async_proc, loop);
|
||||||
|
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
||||||
|
GBinderOutputData* data;
|
||||||
|
GBinderWriter writer;
|
||||||
|
|
||||||
|
gbinder_local_request_init_writer(req, &writer);
|
||||||
|
prot->write_rpc_header(&writer, "test");
|
||||||
|
gbinder_writer_append_string8(&writer, "message");
|
||||||
|
data = gbinder_local_request_data(req);
|
||||||
|
|
||||||
|
test_binder_br_transaction(fd, obj, 1, data->bytes);
|
||||||
|
test_binder_set_looper_enabled(fd, TRUE);
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
/* Now we need to wait until GBinderIpc is destroyed */
|
||||||
|
GDEBUG("waiting for GBinderIpc to get destroyed");
|
||||||
|
g_object_weak_ref(G_OBJECT(ipc), test_quit_when_destroyed, loop);
|
||||||
|
gbinder_local_object_unref(obj);
|
||||||
|
gbinder_local_request_unref(req);
|
||||||
|
g_idle_add(test_unref_ipc, ipc);
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
gbinder_ipc_exit();
|
||||||
|
g_main_loop_unref(loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* transact_async_sync
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
GBinderLocalReply*
|
||||||
|
test_transact_async_sync_proc(
|
||||||
|
GBinderLocalObject* obj,
|
||||||
|
GBinderRemoteRequest* req,
|
||||||
|
guint code,
|
||||||
|
guint flags,
|
||||||
|
int* status,
|
||||||
|
void* loop)
|
||||||
|
{
|
||||||
|
GBinderLocalReply* reply = gbinder_local_object_new_reply(obj);
|
||||||
|
|
||||||
|
GVERBOSE_("\"%s\" %u", gbinder_remote_request_interface(req), code);
|
||||||
|
g_assert(!flags);
|
||||||
|
g_assert(gbinder_remote_request_sender_pid(req) == getpid());
|
||||||
|
g_assert(gbinder_remote_request_sender_euid(req) == geteuid());
|
||||||
|
g_assert(!g_strcmp0(gbinder_remote_request_interface(req), "test"));
|
||||||
|
g_assert(!g_strcmp0(gbinder_remote_request_read_string8(req), "message"));
|
||||||
|
g_assert(code == 1);
|
||||||
|
|
||||||
|
/* Block and immediately complete the call */
|
||||||
|
gbinder_remote_request_block(req);
|
||||||
|
gbinder_remote_request_complete(req, reply, 0);
|
||||||
|
gbinder_remote_request_complete(req, reply, 0); /* This one is ignored */
|
||||||
|
gbinder_local_reply_unref(reply);
|
||||||
|
|
||||||
|
test_quit_later((GMainLoop*)loop);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_transact_async_sync(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
|
const GBinderIo* io = gbinder_driver_io(ipc->driver);
|
||||||
|
const int fd = gbinder_driver_fd(ipc->driver);
|
||||||
|
const char* dev = gbinder_driver_dev(ipc->driver);
|
||||||
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
|
const char* const ifaces[] = { "test", NULL };
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
GBinderLocalObject* obj = gbinder_local_object_new
|
||||||
|
(ipc, ifaces, test_transact_async_sync_proc, loop);
|
||||||
|
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
||||||
|
GBinderOutputData* data;
|
||||||
|
GBinderWriter writer;
|
||||||
|
|
||||||
|
gbinder_local_request_init_writer(req, &writer);
|
||||||
|
prot->write_rpc_header(&writer, "test");
|
||||||
|
gbinder_writer_append_string8(&writer, "message");
|
||||||
|
data = gbinder_local_request_data(req);
|
||||||
|
|
||||||
|
test_binder_br_transaction(fd, obj, 1, data->bytes);
|
||||||
|
test_binder_set_looper_enabled(fd, TRUE);
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
/* Now we need to wait until GBinderIpc is destroyed */
|
||||||
|
GDEBUG("waiting for GBinderIpc to get destroyed");
|
||||||
|
g_object_weak_ref(G_OBJECT(ipc), test_quit_when_destroyed, loop);
|
||||||
|
gbinder_local_object_unref(obj);
|
||||||
|
gbinder_local_request_unref(req);
|
||||||
|
g_idle_add(test_unref_ipc, ipc);
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
gbinder_ipc_exit();
|
||||||
|
g_main_loop_unref(loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* drop_remote_refs
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_drop_remote_refs_cb(
|
||||||
|
GBinderLocalObject* obj,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
GVERBOSE_("%d", obj->strong_refs);
|
||||||
|
g_assert(obj->strong_refs == 1);
|
||||||
|
test_quit_later((GMainLoop*)user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_drop_remote_refs(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
|
GBinderLocalObject* obj = gbinder_local_object_new
|
||||||
|
(ipc, NULL, NULL, NULL);
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
int fd = gbinder_driver_fd(ipc->driver);
|
||||||
|
gulong id = gbinder_local_object_add_strong_refs_changed_handler(obj,
|
||||||
|
test_drop_remote_refs_cb, loop);
|
||||||
|
|
||||||
|
test_binder_br_acquire(fd, obj);
|
||||||
|
test_binder_set_looper_enabled(fd, TRUE);
|
||||||
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
|
g_assert(obj->strong_refs == 1);
|
||||||
|
gbinder_local_object_remove_handler(obj, id);
|
||||||
|
gbinder_local_object_unref(obj);
|
||||||
|
|
||||||
|
/* gbinder_ipc_exit will drop the remote reference */
|
||||||
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
|
g_main_loop_unref(loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* cancel_on_exit
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_cancel_on_exit_not_reached(
|
||||||
|
GBinderIpc* ipc,
|
||||||
|
GBinderRemoteReply* reply,
|
||||||
|
int status,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
g_assert_not_reached();
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_cancel_on_exit(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
|
const GBinderIo* io = gbinder_driver_io(ipc->driver);
|
||||||
|
GBinderLocalRequest* req = gbinder_local_request_new(io, NULL);
|
||||||
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
int fd = gbinder_driver_fd(ipc->driver);
|
||||||
|
|
||||||
|
/* This transaction will be cancelled by gbinder_ipc_exit */
|
||||||
|
test_binder_br_transaction_complete(fd);
|
||||||
|
gbinder_ipc_transact(ipc, 0, 1, GBINDER_TX_FLAG_ONEWAY,
|
||||||
|
req, test_cancel_on_exit_not_reached, NULL, NULL);
|
||||||
|
|
||||||
|
gbinder_local_request_unref(req);
|
||||||
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_ipc_exit();
|
||||||
g_main_loop_unref(loop);
|
g_main_loop_unref(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -726,26 +1171,33 @@ test_transact_status_reply(
|
|||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
|
|
||||||
#define TEST_PREFIX "/ipc/"
|
#define TEST_PREFIX "/ipc/"
|
||||||
|
#define TEST_(t) TEST_PREFIX t
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
g_test_add_func(TEST_PREFIX "null", test_null);
|
g_test_add_func(TEST_("null"), test_null);
|
||||||
g_test_add_func(TEST_PREFIX "basic", test_basic);
|
g_test_add_func(TEST_("basic"), test_basic);
|
||||||
g_test_add_func(TEST_PREFIX "sync_oneway", test_sync_oneway);
|
g_test_add_func(TEST_("async_oneway"), test_async_oneway);
|
||||||
g_test_add_func(TEST_PREFIX "sync_reply_ok", test_sync_reply_ok);
|
g_test_add_func(TEST_("sync_oneway"), test_sync_oneway);
|
||||||
g_test_add_func(TEST_PREFIX "sync_reply_error", test_sync_reply_error);
|
g_test_add_func(TEST_("sync_reply_ok"), test_sync_reply_ok);
|
||||||
g_test_add_func(TEST_PREFIX "transact_ok", test_transact_ok);
|
g_test_add_func(TEST_("sync_reply_error"), test_sync_reply_error);
|
||||||
g_test_add_func(TEST_PREFIX "transact_dead", test_transact_dead);
|
g_test_add_func(TEST_("transact_ok"), test_transact_ok);
|
||||||
g_test_add_func(TEST_PREFIX "transact_failed", test_transact_failed);
|
g_test_add_func(TEST_("transact_dead"), test_transact_dead);
|
||||||
g_test_add_func(TEST_PREFIX "transact_status", test_transact_status);
|
g_test_add_func(TEST_("transact_failed"), test_transact_failed);
|
||||||
g_test_add_func(TEST_PREFIX "transact_custom", test_transact_custom);
|
g_test_add_func(TEST_("transact_status"), test_transact_status);
|
||||||
g_test_add_func(TEST_PREFIX "transact_custom2", test_transact_custom2);
|
g_test_add_func(TEST_("transact_custom"), test_transact_custom);
|
||||||
g_test_add_func(TEST_PREFIX "transact_cancel", test_transact_cancel);
|
g_test_add_func(TEST_("transact_custom2"), test_transact_custom2);
|
||||||
g_test_add_func(TEST_PREFIX "transact_cancel2", test_transact_cancel2);
|
g_test_add_func(TEST_("transact_custom3"), test_transact_custom3);
|
||||||
g_test_add_func(TEST_PREFIX "transact_incoming", test_transact_incoming);
|
g_test_add_func(TEST_("transact_cancel"), test_transact_cancel);
|
||||||
g_test_add_func(TEST_PREFIX "transact_status_reply",
|
g_test_add_func(TEST_("transact_cancel2"), test_transact_cancel2);
|
||||||
test_transact_status_reply);
|
g_test_add_func(TEST_("transact_2way"), test_transact_2way);
|
||||||
|
g_test_add_func(TEST_("transact_incoming"), test_transact_incoming);
|
||||||
|
g_test_add_func(TEST_("transact_status_reply"), test_transact_status_reply);
|
||||||
|
g_test_add_func(TEST_("transact_async"), test_transact_async);
|
||||||
|
g_test_add_func(TEST_("transact_async_sync"), test_transact_async_sync);
|
||||||
|
g_test_add_func(TEST_("drop_remote_refs"), test_drop_remote_refs);
|
||||||
|
g_test_add_func(TEST_("cancel_on_exit"), test_cancel_on_exit);
|
||||||
test_init(&test_opt, argc, argv);
|
test_init(&test_opt, argc, argv);
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2019 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* You may use this file under the terms of BSD license as follows:
|
||||||
*
|
*
|
||||||
@@ -73,7 +73,8 @@ test_reader_data_init_for_reply(
|
|||||||
GUtilIntArray* offsets = gbinder_output_data_offsets(out);
|
GUtilIntArray* offsets = gbinder_output_data_offsets(out);
|
||||||
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
GBinderBuffer* buf = gbinder_buffer_new(ipc->driver,
|
GBinderBuffer* buf = gbinder_buffer_new(ipc->driver,
|
||||||
g_memdup(out->bytes->data, out->bytes->len), out->bytes->len);
|
g_memdup(out->bytes->data, out->bytes->len),
|
||||||
|
out->bytes->len, NULL);
|
||||||
|
|
||||||
memset(data, 0, sizeof(*data));
|
memset(data, 0, sizeof(*data));
|
||||||
data->buffer = buf;
|
data->buffer = buf;
|
||||||
@@ -149,6 +150,8 @@ void
|
|||||||
test_basic(
|
test_basic(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
|
const char* const ifaces_foo[] = { "foo", NULL };
|
||||||
|
const char* const ifaces_bar[] = { "bar", NULL };
|
||||||
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
GBinderLocalObject* foo;
|
GBinderLocalObject* foo;
|
||||||
@@ -158,8 +161,8 @@ test_basic(
|
|||||||
g_assert(!gbinder_object_registry_get_local(reg, ipc));
|
g_assert(!gbinder_object_registry_get_local(reg, ipc));
|
||||||
|
|
||||||
/* Create a new local objects */
|
/* Create a new local objects */
|
||||||
foo = gbinder_ipc_new_local_object(ipc, "foo", NULL, NULL);
|
foo = gbinder_local_object_new(ipc, ifaces_foo, NULL, NULL);
|
||||||
bar = gbinder_ipc_new_local_object(ipc, "bar", NULL, NULL);
|
bar = gbinder_local_object_new(ipc, ifaces_bar, NULL, NULL);
|
||||||
|
|
||||||
/* But ipc is still not a local object! */
|
/* But ipc is still not a local object! */
|
||||||
g_assert(!gbinder_object_registry_get_local(reg, ipc));
|
g_assert(!gbinder_object_registry_get_local(reg, ipc));
|
||||||
@@ -186,6 +189,150 @@ test_basic(
|
|||||||
gbinder_local_object_unref(bar);
|
gbinder_local_object_unref(bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* ping
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_ping(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
int status = INT_MAX;
|
||||||
|
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
||||||
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
||||||
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
|
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
||||||
|
GBinderLocalObject* obj = gbinder_local_object_new(ipc, NULL, NULL, NULL);
|
||||||
|
GBinderLocalReply* reply;
|
||||||
|
GBinderOutputData* out_data;
|
||||||
|
static const guint8 result[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
|
g_assert(gbinder_local_object_can_handle_transaction(obj, NULL,
|
||||||
|
GBINDER_PING_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
|
||||||
|
|
||||||
|
/* If can_handle_transaction() returns TRANSACTION_LOOPER then it must be
|
||||||
|
* handled by handle_looper_transaction() */
|
||||||
|
g_assert(!gbinder_local_object_handle_transaction(obj, req,
|
||||||
|
GBINDER_PING_TRANSACTION, 0, &status));
|
||||||
|
g_assert(status == (-EBADMSG));
|
||||||
|
reply = gbinder_local_object_handle_looper_transaction(obj, req,
|
||||||
|
GBINDER_PING_TRANSACTION, 0, &status);
|
||||||
|
g_assert(reply);
|
||||||
|
g_assert(status == GBINDER_STATUS_OK);
|
||||||
|
|
||||||
|
out_data = gbinder_local_reply_data(reply);
|
||||||
|
g_assert(out_data);
|
||||||
|
g_assert(out_data->bytes);
|
||||||
|
g_assert(out_data->bytes->len == sizeof(result));
|
||||||
|
g_assert(!memcmp(out_data->bytes->data, result, sizeof(result)));
|
||||||
|
|
||||||
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_local_object_unref(obj);
|
||||||
|
gbinder_local_reply_unref(reply);
|
||||||
|
gbinder_remote_request_unref(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* interface
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_interface(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
int status = INT_MAX;
|
||||||
|
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
||||||
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
|
const char* const ifaces[] = { "x", NULL };
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
||||||
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
|
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
||||||
|
GBinderLocalObject* obj = gbinder_local_object_new(ipc, ifaces, NULL, NULL);
|
||||||
|
GBinderLocalReply* reply;
|
||||||
|
GBinderOutputData* out_data;
|
||||||
|
static const guint8 result[] = {
|
||||||
|
TEST_INT32_BYTES(1),
|
||||||
|
TEST_INT16_BYTES('x'), 0x00, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
g_assert(gbinder_local_object_can_handle_transaction(obj, NULL,
|
||||||
|
GBINDER_INTERFACE_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
|
||||||
|
|
||||||
|
/* If can_handle_transaction() returns TRANSACTION_LOOPER then it must be
|
||||||
|
* handled by handle_looper_transaction() */
|
||||||
|
g_assert(!gbinder_local_object_handle_transaction(obj, req,
|
||||||
|
GBINDER_INTERFACE_TRANSACTION, 0, &status));
|
||||||
|
g_assert(status == (-EBADMSG));
|
||||||
|
reply = gbinder_local_object_handle_looper_transaction(obj, req,
|
||||||
|
GBINDER_INTERFACE_TRANSACTION, 0, &status);
|
||||||
|
g_assert(reply);
|
||||||
|
g_assert(status == GBINDER_STATUS_OK);
|
||||||
|
|
||||||
|
out_data = gbinder_local_reply_data(reply);
|
||||||
|
g_assert(out_data);
|
||||||
|
g_assert(out_data->bytes);
|
||||||
|
g_assert(out_data->bytes->len == sizeof(result));
|
||||||
|
g_assert(!memcmp(out_data->bytes->data, result, sizeof(result)));
|
||||||
|
|
||||||
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_local_object_unref(obj);
|
||||||
|
gbinder_local_reply_unref(reply);
|
||||||
|
gbinder_remote_request_unref(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==========================================================================*
|
||||||
|
* hidl_ping
|
||||||
|
*==========================================================================*/
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
test_hidl_ping(
|
||||||
|
void)
|
||||||
|
{
|
||||||
|
static const guint8 req_data [] = { TEST_BASE_INTERFACE_HEADER_BYTES };
|
||||||
|
int status = INT_MAX;
|
||||||
|
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
||||||
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
|
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
||||||
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
|
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
||||||
|
GBinderLocalObject* obj = gbinder_local_object_new(ipc, NULL, NULL, NULL);
|
||||||
|
GBinderLocalReply* reply;
|
||||||
|
GBinderOutputData* out_data;
|
||||||
|
static const guint8 result[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
|
gbinder_remote_request_set_data(req, HIDL_PING_TRANSACTION,
|
||||||
|
gbinder_buffer_new(ipc->driver, g_memdup(req_data, sizeof(req_data)),
|
||||||
|
sizeof(req_data), NULL));
|
||||||
|
g_assert(!g_strcmp0(gbinder_remote_request_interface(req), base_interface));
|
||||||
|
g_assert(gbinder_local_object_can_handle_transaction(obj, base_interface,
|
||||||
|
HIDL_PING_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
|
||||||
|
|
||||||
|
/* If can_handle_transaction() returns TRANSACTION_LOOPER then it must be
|
||||||
|
* handled by handle_looper_transaction() */
|
||||||
|
g_assert(!gbinder_local_object_handle_transaction(obj, req,
|
||||||
|
HIDL_PING_TRANSACTION, 0, &status));
|
||||||
|
g_assert(status == (-EBADMSG));
|
||||||
|
reply = gbinder_local_object_handle_looper_transaction(obj, req,
|
||||||
|
HIDL_PING_TRANSACTION, 0, &status);
|
||||||
|
g_assert(reply);
|
||||||
|
g_assert(status == GBINDER_STATUS_OK);
|
||||||
|
|
||||||
|
out_data = gbinder_local_reply_data(reply);
|
||||||
|
g_assert(out_data);
|
||||||
|
g_assert(out_data->bytes);
|
||||||
|
g_assert(out_data->bytes->len == sizeof(result));
|
||||||
|
g_assert(!memcmp(out_data->bytes->data, result, sizeof(result)));
|
||||||
|
|
||||||
|
gbinder_ipc_unref(ipc);
|
||||||
|
gbinder_local_object_unref(obj);
|
||||||
|
gbinder_local_reply_unref(reply);
|
||||||
|
gbinder_remote_request_unref(req);
|
||||||
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* get_descriptor
|
* get_descriptor
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@@ -195,21 +342,19 @@ void
|
|||||||
test_get_descriptor(
|
test_get_descriptor(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
static const guint8 req_data [] = {
|
static const guint8 req_data [] = { TEST_BASE_INTERFACE_HEADER_BYTES };
|
||||||
TEST_BASE_INTERFACE_HEADER_BYTES
|
|
||||||
};
|
|
||||||
int status = INT_MAX;
|
int status = INT_MAX;
|
||||||
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
||||||
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
||||||
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
||||||
GBinderLocalObject* obj =
|
GBinderLocalObject* obj = gbinder_local_object_new(ipc, NULL, NULL, NULL);
|
||||||
gbinder_ipc_new_local_object(ipc, NULL, NULL, NULL);
|
|
||||||
GBinderLocalReply* reply;
|
GBinderLocalReply* reply;
|
||||||
|
|
||||||
gbinder_remote_request_set_data(req, gbinder_buffer_new(ipc->driver,
|
gbinder_remote_request_set_data(req, HIDL_PING_TRANSACTION,
|
||||||
g_memdup(req_data, sizeof(req_data)), sizeof(req_data)), NULL);
|
gbinder_buffer_new(ipc->driver, g_memdup(req_data, sizeof(req_data)),
|
||||||
|
sizeof(req_data), NULL));
|
||||||
g_assert(!g_strcmp0(gbinder_remote_request_interface(req), base_interface));
|
g_assert(!g_strcmp0(gbinder_remote_request_interface(req), base_interface));
|
||||||
g_assert(gbinder_local_object_can_handle_transaction(obj, base_interface,
|
g_assert(gbinder_local_object_can_handle_transaction(obj, base_interface,
|
||||||
HIDL_GET_DESCRIPTOR_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
|
HIDL_GET_DESCRIPTOR_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
|
||||||
@@ -255,16 +400,18 @@ test_descriptor_chain(
|
|||||||
};
|
};
|
||||||
int status = INT_MAX;
|
int status = INT_MAX;
|
||||||
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
||||||
|
const char* const ifaces[] = { "android.hidl.base@1.0::IBase", NULL };
|
||||||
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
||||||
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
||||||
GBinderLocalObject* obj =
|
GBinderLocalObject* obj = gbinder_local_object_new(ipc, ifaces, NULL, NULL);
|
||||||
gbinder_ipc_new_local_object(ipc, NULL, NULL, NULL);
|
|
||||||
GBinderLocalReply* reply;
|
GBinderLocalReply* reply;
|
||||||
|
GBinderOutputData* reply_data;
|
||||||
|
|
||||||
gbinder_remote_request_set_data(req, gbinder_buffer_new(ipc->driver,
|
gbinder_remote_request_set_data(req, HIDL_DESCRIPTOR_CHAIN_TRANSACTION,
|
||||||
g_memdup(req_data, sizeof(req_data)), sizeof(req_data)), NULL);
|
gbinder_buffer_new(ipc->driver, g_memdup(req_data, sizeof(req_data)),
|
||||||
|
sizeof(req_data), NULL));
|
||||||
g_assert(!g_strcmp0(gbinder_remote_request_interface(req), base_interface));
|
g_assert(!g_strcmp0(gbinder_remote_request_interface(req), base_interface));
|
||||||
g_assert(gbinder_local_object_can_handle_transaction(obj, base_interface,
|
g_assert(gbinder_local_object_can_handle_transaction(obj, base_interface,
|
||||||
HIDL_DESCRIPTOR_CHAIN_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
|
HIDL_DESCRIPTOR_CHAIN_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
|
||||||
@@ -279,6 +426,11 @@ test_descriptor_chain(
|
|||||||
g_assert(reply);
|
g_assert(reply);
|
||||||
g_assert(status == GBINDER_STATUS_OK);
|
g_assert(status == GBINDER_STATUS_OK);
|
||||||
|
|
||||||
|
/* Should get 3 buffers - vector, string and its contents */
|
||||||
|
reply_data = gbinder_local_reply_data(reply);
|
||||||
|
g_assert(gbinder_output_data_offsets(reply_data)->count == 3);
|
||||||
|
g_assert(gbinder_output_data_buffers_size(reply_data) == 64);
|
||||||
|
|
||||||
gbinder_ipc_unref(ipc);
|
gbinder_ipc_unref(ipc);
|
||||||
gbinder_local_object_unref(obj);
|
gbinder_local_object_unref(obj);
|
||||||
gbinder_local_reply_unref(reply);
|
gbinder_local_reply_unref(reply);
|
||||||
@@ -320,13 +472,14 @@ test_custom_iface(
|
|||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
static const guint8 req_data [] = { CUSTOM_INTERFACE_HEADER_BYTES };
|
static const guint8 req_data [] = { CUSTOM_INTERFACE_HEADER_BYTES };
|
||||||
|
const char* const ifaces[] = { custom_iface, NULL };
|
||||||
int count = 0, status = INT_MAX;
|
int count = 0, status = INT_MAX;
|
||||||
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
||||||
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
||||||
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
||||||
GBinderLocalObject* obj = gbinder_ipc_new_local_object(ipc, custom_iface,
|
GBinderLocalObject* obj = gbinder_local_object_new(ipc, ifaces,
|
||||||
test_custom_iface_handler, &count);
|
test_custom_iface_handler, &count);
|
||||||
GBinderLocalReply* reply;
|
GBinderLocalReply* reply;
|
||||||
GBinderReaderData reader_data;
|
GBinderReaderData reader_data;
|
||||||
@@ -334,8 +487,9 @@ test_custom_iface(
|
|||||||
char** strv;
|
char** strv;
|
||||||
char* str;
|
char* str;
|
||||||
|
|
||||||
gbinder_remote_request_set_data(req, gbinder_buffer_new(ipc->driver,
|
gbinder_remote_request_set_data(req, HIDL_PING_TRANSACTION,
|
||||||
g_memdup(req_data, sizeof(req_data)), sizeof(req_data)), NULL);
|
gbinder_buffer_new(ipc->driver, g_memdup(req_data, sizeof(req_data)),
|
||||||
|
sizeof(req_data), NULL));
|
||||||
g_assert(gbinder_local_object_can_handle_transaction(obj, base_interface,
|
g_assert(gbinder_local_object_can_handle_transaction(obj, base_interface,
|
||||||
HIDL_DESCRIPTOR_CHAIN_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
|
HIDL_DESCRIPTOR_CHAIN_TRANSACTION) == GBINDER_LOCAL_TRANSACTION_LOOPER);
|
||||||
g_assert(gbinder_local_object_can_handle_transaction(obj, custom_iface,
|
g_assert(gbinder_local_object_can_handle_transaction(obj, custom_iface,
|
||||||
@@ -425,17 +579,19 @@ test_reply_status(
|
|||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
static const guint8 req_data [] = { CUSTOM_INTERFACE_HEADER_BYTES };
|
static const guint8 req_data [] = { CUSTOM_INTERFACE_HEADER_BYTES };
|
||||||
|
const char* const ifaces[] = { custom_iface, NULL };
|
||||||
int count = 0, status = 0;
|
int count = 0, status = 0;
|
||||||
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
const char* dev = GBINDER_DEFAULT_HWBINDER;
|
||||||
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
const GBinderRpcProtocol* prot = gbinder_rpc_protocol_for_device(dev);
|
||||||
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(dev, NULL);
|
||||||
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
GBinderObjectRegistry* reg = gbinder_ipc_object_registry(ipc);
|
||||||
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
GBinderRemoteRequest* req = gbinder_remote_request_new(reg, prot, 0, 0);
|
||||||
GBinderLocalObject* obj = gbinder_ipc_new_local_object(ipc, custom_iface,
|
GBinderLocalObject* obj = gbinder_local_object_new(ipc, ifaces,
|
||||||
test_reply_status_handler, &count);
|
test_reply_status_handler, &count);
|
||||||
|
|
||||||
gbinder_remote_request_set_data(req, gbinder_buffer_new(ipc->driver,
|
gbinder_remote_request_set_data(req, HIDL_PING_TRANSACTION,
|
||||||
g_memdup(req_data, sizeof(req_data)), sizeof(req_data)), NULL);
|
gbinder_buffer_new(ipc->driver, g_memdup(req_data, sizeof(req_data)),
|
||||||
|
sizeof(req_data), NULL));
|
||||||
|
|
||||||
/* Execute the custom transaction */
|
/* Execute the custom transaction */
|
||||||
g_assert(!gbinder_local_object_handle_transaction(obj, req,
|
g_assert(!gbinder_local_object_handle_transaction(obj, req,
|
||||||
@@ -469,7 +625,7 @@ test_increfs(
|
|||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
GBinderLocalObject* obj = gbinder_ipc_new_local_object
|
GBinderLocalObject* obj = gbinder_local_object_new
|
||||||
(ipc, NULL, NULL, NULL);
|
(ipc, NULL, NULL, NULL);
|
||||||
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
int fd = gbinder_driver_fd(ipc->driver);
|
int fd = gbinder_driver_fd(ipc->driver);
|
||||||
@@ -479,7 +635,7 @@ test_increfs(
|
|||||||
/* ipc is not an object, will be ignored */
|
/* ipc is not an object, will be ignored */
|
||||||
test_binder_br_increfs(fd, ipc);
|
test_binder_br_increfs(fd, ipc);
|
||||||
test_binder_br_increfs(fd, obj);
|
test_binder_br_increfs(fd, obj);
|
||||||
|
test_binder_set_looper_enabled(fd, TRUE);
|
||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
g_assert(obj->weak_refs == 1);
|
g_assert(obj->weak_refs == 1);
|
||||||
@@ -511,7 +667,7 @@ test_decrefs(
|
|||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
GBinderLocalObject* obj = gbinder_ipc_new_local_object
|
GBinderLocalObject* obj = gbinder_local_object_new
|
||||||
(ipc, NULL, NULL, NULL);
|
(ipc, NULL, NULL, NULL);
|
||||||
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
int fd = gbinder_driver_fd(ipc->driver);
|
int fd = gbinder_driver_fd(ipc->driver);
|
||||||
@@ -522,7 +678,7 @@ test_decrefs(
|
|||||||
test_binder_br_decrefs(fd, ipc);
|
test_binder_br_decrefs(fd, ipc);
|
||||||
test_binder_br_increfs(fd, obj);
|
test_binder_br_increfs(fd, obj);
|
||||||
test_binder_br_decrefs(fd, obj);
|
test_binder_br_decrefs(fd, obj);
|
||||||
|
test_binder_set_looper_enabled(fd, TRUE);
|
||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
g_assert(obj->weak_refs == 0);
|
g_assert(obj->weak_refs == 0);
|
||||||
@@ -553,7 +709,7 @@ test_acquire(
|
|||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
GBinderLocalObject* obj = gbinder_ipc_new_local_object
|
GBinderLocalObject* obj = gbinder_local_object_new
|
||||||
(ipc, NULL, NULL, NULL);
|
(ipc, NULL, NULL, NULL);
|
||||||
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
int fd = gbinder_driver_fd(ipc->driver);
|
int fd = gbinder_driver_fd(ipc->driver);
|
||||||
@@ -563,7 +719,7 @@ test_acquire(
|
|||||||
/* ipc is not an object, will be ignored */
|
/* ipc is not an object, will be ignored */
|
||||||
test_binder_br_acquire(fd, ipc);
|
test_binder_br_acquire(fd, ipc);
|
||||||
test_binder_br_acquire(fd, obj);
|
test_binder_br_acquire(fd, obj);
|
||||||
|
test_binder_set_looper_enabled(fd, TRUE);
|
||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
g_assert(obj->strong_refs == 1);
|
g_assert(obj->strong_refs == 1);
|
||||||
@@ -595,8 +751,7 @@ test_release(
|
|||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(GBINDER_DEFAULT_BINDER, NULL);
|
||||||
GBinderLocalObject* obj = gbinder_ipc_new_local_object
|
GBinderLocalObject* obj = gbinder_local_object_new(ipc, NULL, NULL, NULL);
|
||||||
(ipc, NULL, NULL, NULL);
|
|
||||||
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
GMainLoop* loop = g_main_loop_new(NULL, FALSE);
|
||||||
int fd = gbinder_driver_fd(ipc->driver);
|
int fd = gbinder_driver_fd(ipc->driver);
|
||||||
gulong id = gbinder_local_object_add_strong_refs_changed_handler(obj,
|
gulong id = gbinder_local_object_add_strong_refs_changed_handler(obj,
|
||||||
@@ -606,7 +761,7 @@ test_release(
|
|||||||
test_binder_br_release(fd, ipc);
|
test_binder_br_release(fd, ipc);
|
||||||
test_binder_br_acquire(fd, obj);
|
test_binder_br_acquire(fd, obj);
|
||||||
test_binder_br_release(fd, obj);
|
test_binder_br_release(fd, obj);
|
||||||
|
test_binder_set_looper_enabled(fd, TRUE);
|
||||||
test_run(&test_opt, loop);
|
test_run(&test_opt, loop);
|
||||||
|
|
||||||
g_assert(obj->strong_refs == 0);
|
g_assert(obj->strong_refs == 0);
|
||||||
@@ -627,6 +782,9 @@ int main(int argc, char* argv[])
|
|||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
g_test_add_func(TEST_PREFIX "null", test_null);
|
g_test_add_func(TEST_PREFIX "null", test_null);
|
||||||
g_test_add_func(TEST_PREFIX "basic", test_basic);
|
g_test_add_func(TEST_PREFIX "basic", test_basic);
|
||||||
|
g_test_add_func(TEST_PREFIX "ping", test_ping);
|
||||||
|
g_test_add_func(TEST_PREFIX "interface", test_interface);
|
||||||
|
g_test_add_func(TEST_PREFIX "hidl_ping", test_hidl_ping);
|
||||||
g_test_add_func(TEST_PREFIX "get_descriptor", test_get_descriptor);
|
g_test_add_func(TEST_PREFIX "get_descriptor", test_get_descriptor);
|
||||||
g_test_add_func(TEST_PREFIX "descriptor_chain", test_descriptor_chain);
|
g_test_add_func(TEST_PREFIX "descriptor_chain", test_descriptor_chain);
|
||||||
g_test_add_func(TEST_PREFIX "custom_iface", test_custom_iface);
|
g_test_add_func(TEST_PREFIX "custom_iface", test_custom_iface);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -67,7 +67,7 @@ test_buffer_from_bytes(
|
|||||||
{
|
{
|
||||||
/* Prevent double free */
|
/* Prevent double free */
|
||||||
test_binder_set_destroy(gbinder_driver_fd(driver), bytes->data, NULL);
|
test_binder_set_destroy(gbinder_driver_fd(driver), bytes->data, NULL);
|
||||||
return gbinder_buffer_new(driver, bytes->data, bytes->len);
|
return gbinder_buffer_new(driver, bytes->data, bytes->len, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
@@ -88,7 +88,7 @@ test_null(
|
|||||||
gbinder_local_reply_init_writer(NULL, NULL);
|
gbinder_local_reply_init_writer(NULL, NULL);
|
||||||
gbinder_local_reply_init_writer(NULL, &writer);
|
gbinder_local_reply_init_writer(NULL, &writer);
|
||||||
g_assert(!gbinder_local_reply_data(NULL));
|
g_assert(!gbinder_local_reply_data(NULL));
|
||||||
g_assert(!gbinder_local_reply_new_from_data(NULL, NULL));
|
g_assert(!gbinder_local_reply_new_from_data(NULL));
|
||||||
|
|
||||||
gbinder_local_reply_cleanup(NULL, NULL, &count);
|
gbinder_local_reply_cleanup(NULL, NULL, &count);
|
||||||
gbinder_local_reply_cleanup(NULL, test_int_inc, &count);
|
gbinder_local_reply_cleanup(NULL, test_int_inc, &count);
|
||||||
@@ -137,8 +137,8 @@ void
|
|||||||
test_bool(
|
test_bool(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
static const guint8 output_true[] = { 0x01, 0xff, 0xff, 0xff };
|
static const guint8 output_true[] = { 0x01, 0x00, 0x00, 0x00 };
|
||||||
static const guint8 output_false[] = { 0x00, 0xff, 0xff, 0xff };
|
static const guint8 output_false[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||||
GBinderLocalReply* reply = gbinder_local_reply_new(&gbinder_io_32);
|
GBinderLocalReply* reply = gbinder_local_reply_new(&gbinder_io_32);
|
||||||
GBinderOutputData* data;
|
GBinderOutputData* data;
|
||||||
|
|
||||||
@@ -313,7 +313,7 @@ void
|
|||||||
test_string16(
|
test_string16(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
static const const char input[] = "x";
|
static const char input[] = "x";
|
||||||
static const guint8 output[] = {
|
static const guint8 output[] = {
|
||||||
TEST_INT32_BYTES(1),
|
TEST_INT32_BYTES(1),
|
||||||
TEST_INT16_BYTES('x'), 0x00, 0x00
|
TEST_INT16_BYTES('x'), 0x00, 0x00
|
||||||
@@ -357,10 +357,10 @@ test_hidl_string(
|
|||||||
gbinder_local_reply_append_hidl_string(reply, NULL);
|
gbinder_local_reply_append_hidl_string(reply, NULL);
|
||||||
data = gbinder_local_reply_data(reply);
|
data = gbinder_local_reply_data(reply);
|
||||||
offsets = gbinder_output_data_offsets(data);
|
offsets = gbinder_output_data_offsets(data);
|
||||||
g_assert(offsets->count == 1);
|
g_assert(offsets->count == 2);
|
||||||
g_assert(offsets->data[0] == 0);
|
g_assert(offsets->data[0] == 0);
|
||||||
g_assert(gbinder_output_data_buffers_size(data) == sizeof(HidlString));
|
g_assert(gbinder_output_data_buffers_size(data)==sizeof(GBinderHidlString));
|
||||||
g_assert(data->bytes->len == BUFFER_OBJECT_SIZE_32);
|
g_assert(data->bytes->len == 2*BUFFER_OBJECT_SIZE_32);
|
||||||
gbinder_local_reply_unref(reply);
|
gbinder_local_reply_unref(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,10 +380,10 @@ test_hidl_string_vec(
|
|||||||
gbinder_local_reply_append_hidl_string_vec(reply, NULL, 0);
|
gbinder_local_reply_append_hidl_string_vec(reply, NULL, 0);
|
||||||
data = gbinder_local_reply_data(reply);
|
data = gbinder_local_reply_data(reply);
|
||||||
offsets = gbinder_output_data_offsets(data);
|
offsets = gbinder_output_data_offsets(data);
|
||||||
g_assert(offsets->count == 1);
|
g_assert(offsets->count == 2);
|
||||||
g_assert(offsets->data[0] == 0);
|
g_assert(offsets->data[0] == 0);
|
||||||
g_assert(gbinder_output_data_buffers_size(data) == sizeof(HidlVec));
|
g_assert(gbinder_output_data_buffers_size(data) == sizeof(GBinderHidlVec));
|
||||||
g_assert(data->bytes->len == BUFFER_OBJECT_SIZE_32);
|
g_assert(data->bytes->len == 2*BUFFER_OBJECT_SIZE_32);
|
||||||
gbinder_local_reply_unref(reply);
|
gbinder_local_reply_unref(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,8 +400,8 @@ test_local_object(
|
|||||||
GBinderOutputData* data;
|
GBinderOutputData* data;
|
||||||
GUtilIntArray* offsets;
|
GUtilIntArray* offsets;
|
||||||
GBinderIpc* ipc = gbinder_ipc_new(NULL, NULL);
|
GBinderIpc* ipc = gbinder_ipc_new(NULL, NULL);
|
||||||
GBinderLocalObject* obj =
|
const char* const ifaces[] = { "android.hidl.base@1.0::IBase", NULL };
|
||||||
gbinder_ipc_new_local_object(ipc, "foo", NULL, NULL);
|
GBinderLocalObject* obj = gbinder_local_object_new(ipc, ifaces, NULL, NULL);
|
||||||
|
|
||||||
/* Append a real object (64-bit I/O is used by test_binder.c) */
|
/* Append a real object (64-bit I/O is used by test_binder.c) */
|
||||||
reply = gbinder_local_object_new_reply(obj);
|
reply = gbinder_local_object_new_reply(obj);
|
||||||
@@ -479,7 +479,7 @@ test_remote_reply(
|
|||||||
|
|
||||||
/* Copy flat structures (no binder objects) */
|
/* Copy flat structures (no binder objects) */
|
||||||
buffer = test_buffer_from_bytes(driver, bytes);
|
buffer = test_buffer_from_bytes(driver, bytes);
|
||||||
req2 = gbinder_local_reply_new_from_data(buffer, NULL);
|
req2 = gbinder_local_reply_new_from_data(buffer);
|
||||||
gbinder_buffer_free(buffer);
|
gbinder_buffer_free(buffer);
|
||||||
|
|
||||||
data2 = gbinder_local_reply_data(req2);
|
data2 = gbinder_local_reply_data(req2);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 Jolla Ltd.
|
* Copyright (C) 2018-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2018-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of BSD license as follows:
|
* 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
|
* 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
|
* 3. Neither the names of the copyright holders nor the names of its
|
||||||
* contributors may be used to endorse or promote products derived from
|
* contributors may be used to endorse or promote products derived
|
||||||
* this software without specific prior written permission.
|
* from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
@@ -65,7 +65,19 @@ test_buffer_from_bytes(
|
|||||||
{
|
{
|
||||||
/* Prevent double free */
|
/* Prevent double free */
|
||||||
test_binder_set_destroy(gbinder_driver_fd(driver), bytes->data, NULL);
|
test_binder_set_destroy(gbinder_driver_fd(driver), bytes->data, NULL);
|
||||||
return gbinder_buffer_new(driver, bytes->data, bytes->len);
|
return gbinder_buffer_new(driver, bytes->data, bytes->len, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
GBinderBuffer*
|
||||||
|
test_buffer_from_bytes_and_objects(
|
||||||
|
GBinderDriver* driver,
|
||||||
|
const GByteArray* bytes,
|
||||||
|
void** objects)
|
||||||
|
{
|
||||||
|
/* Prevent double free */
|
||||||
|
test_binder_set_destroy(gbinder_driver_fd(driver), bytes->data, NULL);
|
||||||
|
return gbinder_buffer_new(driver, bytes->data, bytes->len, objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
@@ -82,7 +94,7 @@ test_null(
|
|||||||
|
|
||||||
g_assert(!gbinder_local_request_new(NULL, NULL));
|
g_assert(!gbinder_local_request_new(NULL, NULL));
|
||||||
g_assert(!gbinder_local_request_ref(NULL));
|
g_assert(!gbinder_local_request_ref(NULL));
|
||||||
g_assert(!gbinder_local_request_new_from_data(NULL, NULL));
|
g_assert(!gbinder_local_request_new_from_data(NULL));
|
||||||
gbinder_local_request_unref(NULL);
|
gbinder_local_request_unref(NULL);
|
||||||
gbinder_local_request_init_writer(NULL, NULL);
|
gbinder_local_request_init_writer(NULL, NULL);
|
||||||
gbinder_local_request_init_writer(NULL, &writer);
|
gbinder_local_request_init_writer(NULL, &writer);
|
||||||
@@ -167,8 +179,8 @@ void
|
|||||||
test_bool(
|
test_bool(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
static const guint8 output_true[] = { 0x01, 0xff, 0xff, 0xff };
|
static const guint8 output_true[] = { 0x01, 0x00, 0x00, 0x00 };
|
||||||
static const guint8 output_false[] = { 0x00, 0xff, 0xff, 0xff };
|
static const guint8 output_false[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||||
GBinderLocalRequest* req = gbinder_local_request_new(&gbinder_io_32, NULL);
|
GBinderLocalRequest* req = gbinder_local_request_new(&gbinder_io_32, NULL);
|
||||||
GBinderOutputData* data;
|
GBinderOutputData* data;
|
||||||
|
|
||||||
@@ -329,7 +341,7 @@ void
|
|||||||
test_string16(
|
test_string16(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
static const const char input[] = "x";
|
static const char input[] = "x";
|
||||||
static const guint8 output[] = {
|
static const guint8 output[] = {
|
||||||
TEST_INT32_BYTES(1),
|
TEST_INT32_BYTES(1),
|
||||||
TEST_INT16_BYTES('x'), 0x00, 0x00
|
TEST_INT16_BYTES('x'), 0x00, 0x00
|
||||||
@@ -373,10 +385,10 @@ test_hidl_string(
|
|||||||
gbinder_local_request_append_hidl_string(req, NULL);
|
gbinder_local_request_append_hidl_string(req, NULL);
|
||||||
data = gbinder_local_request_data(req);
|
data = gbinder_local_request_data(req);
|
||||||
offsets = gbinder_output_data_offsets(data);
|
offsets = gbinder_output_data_offsets(data);
|
||||||
g_assert(offsets->count == 1);
|
g_assert(offsets->count == 2);
|
||||||
g_assert(offsets->data[0] == 0);
|
g_assert(offsets->data[0] == 0);
|
||||||
g_assert(gbinder_output_data_buffers_size(data) == sizeof(HidlString));
|
g_assert(gbinder_output_data_buffers_size(data)==sizeof(GBinderHidlString));
|
||||||
g_assert(data->bytes->len == BUFFER_OBJECT_SIZE_32);
|
g_assert(data->bytes->len == 2*BUFFER_OBJECT_SIZE_32);
|
||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,10 +408,10 @@ test_hidl_string_vec(
|
|||||||
gbinder_local_request_append_hidl_string_vec(req, NULL, 0);
|
gbinder_local_request_append_hidl_string_vec(req, NULL, 0);
|
||||||
data = gbinder_local_request_data(req);
|
data = gbinder_local_request_data(req);
|
||||||
offsets = gbinder_output_data_offsets(data);
|
offsets = gbinder_output_data_offsets(data);
|
||||||
g_assert(offsets->count == 1);
|
g_assert(offsets->count == 2);
|
||||||
g_assert(offsets->data[0] == 0);
|
g_assert(offsets->data[0] == 0);
|
||||||
g_assert(gbinder_output_data_buffers_size(data) == sizeof(HidlVec));
|
g_assert(gbinder_output_data_buffers_size(data) == sizeof(GBinderHidlVec));
|
||||||
g_assert(data->bytes->len == BUFFER_OBJECT_SIZE_32);
|
g_assert(data->bytes->len == 2*BUFFER_OBJECT_SIZE_32);
|
||||||
gbinder_local_request_unref(req);
|
gbinder_local_request_unref(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,14 +483,14 @@ test_remote_request(
|
|||||||
const GByteArray* bytes;
|
const GByteArray* bytes;
|
||||||
const GByteArray* bytes2;
|
const GByteArray* bytes2;
|
||||||
GBinderBuffer* buffer;
|
GBinderBuffer* buffer;
|
||||||
void* no_obj = NULL;
|
void** no_obj = g_new0(void*, 1);
|
||||||
|
|
||||||
gbinder_local_request_append_string8(req, input);
|
gbinder_local_request_append_string8(req, input);
|
||||||
bytes = gbinder_local_request_data(req)->bytes;
|
bytes = gbinder_local_request_data(req)->bytes;
|
||||||
|
|
||||||
/* Copy flat structures (no binder objects) */
|
/* Copy flat structures (no binder objects) */
|
||||||
buffer = test_buffer_from_bytes(driver, bytes);
|
buffer = test_buffer_from_bytes(driver, bytes);
|
||||||
req2 = gbinder_local_request_new_from_data(buffer, NULL);
|
req2 = gbinder_local_request_new_from_data(buffer);
|
||||||
gbinder_buffer_free(buffer);
|
gbinder_buffer_free(buffer);
|
||||||
|
|
||||||
data2 = gbinder_local_request_data(req2);
|
data2 = gbinder_local_request_data(req2);
|
||||||
@@ -490,8 +502,8 @@ test_remote_request(
|
|||||||
gbinder_local_request_unref(req2);
|
gbinder_local_request_unref(req2);
|
||||||
|
|
||||||
/* Same thing but with non-NULL (albeit empty) array of objects */
|
/* Same thing but with non-NULL (albeit empty) array of objects */
|
||||||
buffer = test_buffer_from_bytes(driver, bytes);
|
buffer = test_buffer_from_bytes_and_objects(driver, bytes, no_obj);
|
||||||
req2 = gbinder_local_request_new_from_data(buffer, &no_obj);
|
req2 = gbinder_local_request_new_from_data(buffer);
|
||||||
gbinder_buffer_free(buffer);
|
gbinder_buffer_free(buffer);
|
||||||
|
|
||||||
data2 = gbinder_local_request_data(req2);
|
data2 = gbinder_local_request_data(req2);
|
||||||
@@ -525,8 +537,9 @@ test_remote_request_obj_validate_data(
|
|||||||
g_assert(offsets->data[1] == 4 + BUFFER_OBJECT_SIZE_64);
|
g_assert(offsets->data[1] == 4 + BUFFER_OBJECT_SIZE_64);
|
||||||
g_assert(offsets->data[2] == 4 + 2*BUFFER_OBJECT_SIZE_64);
|
g_assert(offsets->data[2] == 4 + 2*BUFFER_OBJECT_SIZE_64);
|
||||||
g_assert(bytes->len == 4 + 2*BUFFER_OBJECT_SIZE_64 + BINDER_OBJECT_SIZE_64);
|
g_assert(bytes->len == 4 + 2*BUFFER_OBJECT_SIZE_64 + BINDER_OBJECT_SIZE_64);
|
||||||
/* HidlString + the contents (2 bytes) aligned at 8-byte boundary */
|
/* GBinderHidlString + the contents (2 bytes) aligned at 8-byte boundary */
|
||||||
g_assert(gbinder_output_data_buffers_size(data) == (sizeof(HidlString)+8));
|
g_assert(gbinder_output_data_buffers_size(data) ==
|
||||||
|
(sizeof(GBinderHidlString) + 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@@ -558,15 +571,15 @@ test_remote_request_obj(
|
|||||||
objects[i] = bytes->data + offsets->data[i];
|
objects[i] = bytes->data + offsets->data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = test_buffer_from_bytes(driver, data->bytes);
|
buffer = test_buffer_from_bytes_and_objects(driver, data->bytes, objects);
|
||||||
req2 = gbinder_local_request_new_from_data(buffer, objects);
|
req2 = gbinder_local_request_new_from_data(buffer);
|
||||||
gbinder_buffer_free(buffer);
|
gbinder_buffer_free(buffer);
|
||||||
g_free(objects);
|
|
||||||
|
|
||||||
test_remote_request_obj_validate_data(gbinder_local_request_data(req2));
|
test_remote_request_obj_validate_data(gbinder_local_request_data(req2));
|
||||||
|
|
||||||
gbinder_local_request_unref(req);
|
/* req2 has to be freed first because req owns data */
|
||||||
gbinder_local_request_unref(req2);
|
gbinder_local_request_unref(req2);
|
||||||
|
gbinder_local_request_unref(req);
|
||||||
gbinder_driver_unref(driver);
|
gbinder_driver_unref(driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
unit/unit_log/Makefile
Normal file
5
unit/unit_log/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# -*- Mode: makefile-gmake -*-
|
||||||
|
|
||||||
|
EXE = unit_log
|
||||||
|
|
||||||
|
include ../common/Makefile
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user