IV. LibRIL Start Registration
Unicom RILJ and RILC
The init function parameter s_rilEnv of the previous Reference RIL passes LibRIL callbacks into Reference RIL so that Reference RIL can pass data to LibRIL.
The return value of the init function returns its callback function funcs, so that LibRIL can pass data to the Reference RIL.
This step is to put funcs into LibRIL.
Some initialization operations of port parameters are also carried out.
4.1 RIL_register
Start with RIL_register(funcs) and see what it does.
As mentioned earlier, funcs are the callback function of Reference RIL.
RIL_register is implemented in ril.cpp:
RIL_register (const RIL_RadioFunctions *callbacks) {
...
//Save callback functions locally
memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
//Initialize Socket parameters, a SIM card corresponds to a parameter, the structure details see 4.3
for (i = 0; i < SIM_COUNT; i++) {
s_ril_param_socket[i] = {
(RIL_SOCKET_ID)(RIL_SOCKET_1+i), /* socket_id */
-1, /* Socket Monitor handle*/
-1, /* Socket Flow handle */
PHONE_PROCESS, /* processName */
&s_commands_event[i], /* Socket Stream Processing Event*/
&s_listen_event[i], /* Socket Monitoring Event*/
processCommandsCallback, /* Socket Stream Processing Function*/
NULL /* p_rs */
};
}
//Start Socket listening with default parameters
//Notice here that RIL_SOCKET_1 is the first element of an enumeration variable.
for (i = 0; i < SIM_COUNT; i++) {
startListen((RIL_SOCKET_ID)(RIL_SOCKET_1+i), &s_ril_param_socket[i]);
}
}
static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
//Get the RILJ corresponding to socket_name and connect the Socket to RILD
fdListen = android_get_control_socket(socket_name);
//Attempt to connect this Socket and successfully return 0
ret = listen(fdListen, 4);
//If the connection fails, it exits
if (ret < 0) {
exit(-1);
}
//Put the Socket FD that can connect successfully into the Socket parameter
socket_listen_p->fdListen = fdListen;
//Constructing Event with Socket FD
//Note that the persist parameter here is false, and the Event can only be fired once, even if it can only pass data once.
//As you can see in 4.3.2, Event is added again after reading the data once.
ril_event_set (socket_listen_p->listen_event, fdListen, false,
listenCallback, socket_listen_p);
//Add Event to EventLoop
rilEventAddWakeup (socket_listen_p->listen_event);
}
From the above code, the RIL_register function does two main things:
1. Save the callback function of Reference RIL.
2. Establish a Socket connection between RILJ and RILC (via fdListen) and place it in EventLoop.
Then, by combining the EventLoop mechanism that has been launched, the connection between RILJ and RILC has been opened.