从上文知道IContexthub service最终通过socket和chre通信,暂且不关注chre通过 fastrpc和dsp的通信。
LOCAL_MODULE := chre
LOCAL_VENDOR_MODULE := true
LOCAL_CPP_EXTENSION := .cc
FASTRPC_INC := $(TARGET_OUT_INTERMEDIATES)/include/fastrpc/inc
LOCAL_ADDITIONAL_DEPENDENCIES ::= $(FASTRPC_INC)
LOCAL_SRC_FILES := \
../../platform/shared/host_protocol_common.cc \
../common/host_protocol_host.cc \
../common/socket_server.cc \
daemon/chre_daemon.cc \
daemon/generated/chre_slpi_stub.c
LOCAL_C_INCLUDES := \
$(FASTRPC_INC) \
system/chre/platform/slpi/include \
LOCAL_HEADER_LIBRARIES := chre_flatbuffers
LOCAL_SHARED_LIBRARIES := \
libbase \
libutils \
libcutils \
liblog \
LOCAL_SHARED_LIBRARIES += libadsprpc
system 2050 1 19300 4888 do_sys_poll 0 S chre
system 18927 1 2126252 5104 binder_ioctl_write_read 0 S [email protected]
CHRE server收到断开信息
chre/host/common/socket_server.cc -> handleClientData -> LOGI("Client %" PRIu16 " disconnected", clientId)
CHRE : Client 3 disconnected
[email protected]自动启动(init.rc不是one-shot), 再次注册service
ALOGI("Registration complete for %s/%s.",Interface::descriptor, name.c_str());
[email protected]: Registration complete for [email protected]::IContexthub/default.
SocketClient::reconnect() -> LOGD("Successfully (re)connected")
CHRE : Successfully (re)connected
03-27 15:18:27.290 18996 18996 I CHRE : Accepted new client connection (count 1), assigned client ID 1
CHRE : Caught signal 15
CHRE : Exiting poll loop: Interrupted system call
CHRE : Socket disconnected on remote end
ContextHubHal: Lost connection to CHRE daemon
CHRE : Shutdown complete
/vendor/bin/chre: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:1006: remote_handle_open: Successfully opened handle 0x37260a70 for chre_slpi on domain 2
/vendor/bin/chre: vendor/qcom/proprietary/commonsys-intf/adsprpc/src/fastrpc_apps_user.c:1006: remote_handle_open: Successfully opened handle 0x372609f0 for chre_slpi on domain 2
CHRE : CHRE on SLPI started
CHRE : Ready to accept connections
CHRE : Successfully (re)connected
ContextHubHal: Reconnected to CHRE daemon
CHRE : Accepted new client connection (count 1), assigned client ID 1
分为3部分:
对events的处理分两步a. 放入队列 b.处理每个nanoApp上的event
nanoappStart/HandleEvent/End : entry points from the system into the nanoapp 也就是实现这3个函数,其中主要是HandleEvent
实现entryPoints: start/end/handleEvent
DLL_EXPORT const struct chreNslNanoappInfo _chreNslDsoNanoappInfo = {
.magic = CHRE_NSL_NANOAPP_INFO_MAGIC,
.structMinorVersion = CHRE_NSL_NANOAPP_INFO_STRUCT_MINOR_VERSION,
.targetApiVersion = CHRE_API_VERSION,
// These values are supplied by the build environment
.vendor = NANOAPP_VENDOR_STRING,
.name = NANOAPP_NAME_STRING,
.isSystemNanoapp = 0,
.appId = NANOAPP_ID,
.appVersion = NANOAPP_VERSION,
.entryPoints = {
.start = nanoappStart,
.handleEvent = nanoappHandleEvent,
.end = nanoappEnd,
},
};
是个共享库 so文件
target_so = '${BUILDPATH}/'+LIBNAME+'.so'
BUILD_DLLS += chre_app_sensor_cfg
当通过socket: chre收到loadNanoapp时,创建nanoApp, 调用start函数
当收到client发来的message时