rild 进程流程分析
main()
RIL_Init
#define REFERENCE_RIL_PATH "/system/lib/libreference-ril.so"
dlHandle = dlopen(rilLibPath, RTLD_NOW);
rilInit = (const RIL_RadioFunctions *(*)(const struct RIL_Env *, int, char **))dlsym(dlHandle, "RIL_Init");
...
funcs = rilInit(&s_rilEnv, argc, rilArgv); //rild 启动时候的参数,如串口设备等是用过 rilInit传递给
//libreference-ril.so库,然后由库函数中打开串口
RIL_register(funcs);
Reference-ril.c (hardware\ril\reference-ril)中的
如果我们把Reference-ril.c 做为库调用那么执行的是
RIL_Init()
否则为
Reference-ril.c 的main函数
Reference-ril.c (hardware\ril\reference-ril)
#ifdef RIL_SHLIB
pthread_t s_tid_mainloop;
const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv)
....
#else
int main (int argc, char **argv)
....
#endif
从上面的程序片段可以看出如果定义了 RIL_SHLIB 那么将会被便宜成库这就是为什么
利用android的官方便宜脚本,我们很容易把源代码编译成库或者应用程序
RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen)
RIL_onRequestComplete()函数的声明和定义分别在文件 Ril.h 和 Ril.cpp 中
Ril.h (hardware\ril\include\telephony)
Ril.cpp (hardware\ril\libril):
Rild.c (hardware\ril\rild):
static struct RIL_Env s_rilEnv = {
RIL_onRequestComplete,
RIL_onUnsolicitedResponse,
RIL_requestTimedCallback
};
Rild.c (hardware\ril\rild):
funcs = rilInit(&s_rilEnv, argc, rilArgv);
Rild.c (hardware\ril\rild)
rilInit = (const RIL_RadioFunctions *(*)(const struct RIL_Env *, int, char **))dlsym(dlHandle, "RIL_Init");
const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv)
rilfd 启动的是时候调用了 Reference-ril.so 中的 RIL_Init函数进行了初始化
所以 onRequest (int request, void *data, size_t datalen, RIL_Token t) //Reference-ril.c (hardware\ril\reference-ril)
中执行的 RIL_onRequestComplete 函数实际上是调用 Ril.cpp (hardware\ril\libril)中的 RIL_onRequestComplete
RIL_register (const RIL_RadioFunctions *callbacks)
ril_event_set (&s_listen_event, s_fdListen, false,
listenCallback, NULL);
Ril_event.cpp (hardware\ril\libril)
void ril_event_init()
init_list(&pending_list);
RIL_register (const RIL_RadioFunctions *callbacks)
RIL_startEventLoop();
ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
static const RIL_RadioFunctions s_callbacks = {
RIL_VERSION,
onRequest,
currentState,
onSupports,
onCancel,
getVersion
};
static void listenCallback (int fd, short flags, void *param)
ril_event_set (&s_commands_event, s_fdCommand, 1, processCommandsCallback, p_rs);
rilEventAddWakeup (&s_commands_event);
onNewCommandConnect();
static void *eventLoop(void *param)
ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,processWakeupCallback, NULL);
void RIL_register (const RIL_RadioFunctions *callbacks)
ril_event_set (&s_listen_event, s_fdListen, false, listenCallback, NULL);
rilEventAddWakeup (&s_listen_event);
...
ril_event_set (&s_debug_event, s_fdDebug, true,debugCallback, NULL);
rilEventAddWakeup (&s_debug_event);
static UserCallbackInfo *
internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
const struct timeval *relativeTime)
ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
ril_timer_add(&(p_info->event), &myRelativeTime);
triggerEvLoop();
Ril.cpp (hardware\ril\libril)
RIL_requestTimedCallback
internalRequestTimedCallback (callback, param, relativeTime);
void RIL_onUnsolicitedResponse(int unsolResponse, void *data,size_t datalen)
internalRequestTimedCallback(wakeTimeoutCallback, NULL,&TIMEVAL_WAKE_TIMEOUT);
rild.c
main()
RIL_startEventLoop();
ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
在 eventLoop中有:
ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,processWakeupCallback, NULL);
rilEventAddWakeup (&s_wakeupfd_event);
ril_event_add(ev);
watch_table[i] = ev;
triggerEvLoop();
ril_event_loop();
processTimeouts(); //检测超时
processReadReadies(&rfds, n);
addToList(rev, &pending_list);
firePending();
struct ril_event * ev = pending_list.next;
while (ev != &pending_list) {
struct ril_event * next = ev->next;
removeFromList(ev);
ev->func(ev->fd, 0, ev->param);
ev = next;
}
//此处的 ev->func 为 ril_event_set 注册的函数 processWakeupCallback
rilInit = (const RIL_RadioFunctions *(*)(const struct RIL_Env *, int, char **))dlsym(dlHandle, "RIL_Init");
...
funcs = rilInit(&s_rilEnv, argc, rilArgv);
//此处执行的 rilInit 函数实际上为 Reference-ril.c (hardware\ril\reference-ril) 文件中的
const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv)
ret = pthread_create(&s_tid_mainloop, &attr, mainLoop, NULL);
mainLoop()
ret = at_open(fd, onUnsolicited);
RIL_requestTimedCallback(initializeCallback, NULL, &TIMEVAL_0);
initializeCallback()
at_handshake();
at_send_command("AT+CMEE=1", NULL);
at_send_command("AT+CCWA=1", NULL);
...
/* assume radio is off on error */
if (isRadioOn() > 0) {
setRadioState (RADIO_STATE_SIM_NOT_READY);
}
因为Radion一般嗾使On 所以默认都会执行 setRadioState (RADIO_STATE_SIM_NOT_READY)
所以通常会执行:onRadioPowerOn();
pollSIMState(NULL);
getSIMStatus()
根据返回结果:如果没有sim卡/需要pin/需要PUK 那么将执行:
setRadioState(RADIO_STATE_SIM_LOCKED_OR_ABSENT);
如果sim卡状态是就绪的,那么执行:
setRadioState(RADIO_STATE_SIM_READY);
return &s_callbacks;
//因为RIL_Init 返回值为 s_callbacks 所以 funcs 为变量s_callbacks的指针
RIL_register(funcs);
ril_event_set (&s_listen_event, s_fdListen, false,listenCallback, NULL);
rilEventAddWakeup (&s_listen_event);
static void listenCallback (int fd, short flags, void *param)
ril_event_set (&s_commands_event, s_fdCommand, 1,processCommandsCallback, p_rs);
Reference-ril.c (hardware\ril\reference-ril)
此函数类似 libgsmd-tools 的main
int main (int argc, char **argv)
{
...
RIL_register(&s_callbacks);
mainLoop(NULL);
...
}
阅读(2179) | 评论(0) | 转发(0) |