Android培训班(38)
<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } -->
在init.rc文件里,可以看到加载下面的服务:
service dbus /system/bin/dbus-daemon --system --nofork
socket dbus stream 660 bluetooth bluetooth
user bluetooth
group bluetooth net_bt_admin
dbus服务的代码在目录:
Android-2.0/external/dbus/bus
dbus服务是android使用的一种特殊的进程间通讯系统。它具有面向对象接口的协议,以及应用程序之间互相发现和监视的守护进程。dbus设计用来作为用户与系统服务之间的分隔以及系统服务之间的通讯。因此,dbus通讯安全,但效率有点差。
它的主要入口函数代码如下:
int
main (int argc, char **argv)
{
DBusError error;
DBusString config_file;
DBusString addr_fd;
DBusString pid_fd;
const char *prev_arg;
int print_addr_fd;
int print_pid_fd;
int i;
dbus_bool_t print_address;
dbus_bool_t print_pid;
int force_fork;
初始化配置文件/文件句柄/进程ID。
if (!_dbus_string_init (&config_file))
return 1;
if (!_dbus_string_init (&addr_fd))
return 1;
if (!_dbus_string_init (&pid_fd))
return 1;
print_address = FALSE;
print_pid = FALSE;
force_fork = FORK_FOLLOW_CONFIG_FILE;
下面分析进程输入的参数。
prev_arg = NULL;
i = 1;
while (i < argc)
{
const char *arg = argv[i];
if (strcmp (arg, "--help") == 0 ||
strcmp (arg, "-h") == 0 ||
strcmp (arg, "-?") == 0)
usage ();
else if (strcmp (arg, "--version") == 0)
version ();
else if (strcmp (arg, "--introspect") == 0)
introspect ();
else if (strcmp (arg, "--nofork") == 0)
force_fork = FORK_NEVER;
else if (strcmp (arg, "--fork") == 0)
force_fork = FORK_ALWAYS;
else if (strcmp (arg, "--system") == 0)
{
check_two_config_files (&config_file, "system");
if (!_dbus_string_append (&config_file, DBUS_SYSTEM_CONFIG_FILE))
exit (1);
}
else if (strcmp (arg, "--session") == 0)
{
check_two_config_files (&config_file, "session");
if (!_dbus_string_append (&config_file, DBUS_SESSION_CONFIG_FILE))
exit (1);
}
else if (strstr (arg, "--config-file=") == arg)
{
const char *file;
check_two_config_files (&config_file, "config-file");
file = strchr (arg, =);
++file;
if (!_dbus_string_append (&config_file, file))
exit (1);
}
else if (prev_arg &&
strcmp (prev_arg, "--config-file") == 0)
{
check_two_config_files (&config_file, "config-file");
if (!_dbus_string_append (&config_file, arg))
exit (1);
}
else if (strcmp (arg, "--config-file") == 0)
; /* wait for next arg */
else if (strstr (arg, "--print-address=") == arg)
{
const char *desc;
check_two_addr_descriptors (&addr_fd, "print-address");
desc = strchr (arg, =);
++desc;
if (!_dbus_string_append (&addr_fd, desc))
exit (1);
print_address = TRUE;
}
else if (prev_arg &&
strcmp (prev_arg, "--print-address") == 0)
{
check_two_addr_descriptors (&addr_fd, "print-address");
if (!_dbus_string_append (&addr_fd, arg))
exit (1);
print_address = TRUE;
}
else if (strcmp (arg, "--print-address") == 0)
print_address = TRUE; /* and well get the next arg if appropriate */
else if (strstr (arg, "--print-pid=") == arg)
{
const char *desc;
check_two_pid_descriptors (&pid_fd, "print-pid");
desc = strchr (arg, =);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>