Lines Matching refs:context

59 static int dbus_init(struct mbox_context *context,  in dbus_init()  argument
64 rc = sd_bus_default_system(&context->bus); in dbus_init()
71 rc = control_legacy_init(context); in dbus_init()
78 rc = control_dbus_init(context); in dbus_init()
85 rc = transport_dbus_init(context, ops); in dbus_init()
92 rc = sd_bus_request_name(context->bus, MBOX_DBUS_NAME, in dbus_init()
100 rc = sd_bus_get_fd(context->bus); in dbus_init()
106 context->fds[DBUS_FD].fd = rc; in dbus_init()
111 static void dbus_free(struct mbox_context *context) in dbus_free() argument
113 transport_dbus_free(context); in dbus_free()
114 control_dbus_free(context); in dbus_free()
115 control_legacy_free(context); in dbus_free()
116 sd_bus_unref(context->bus); in dbus_free()
119 static int poll_loop(struct mbox_context *context) in poll_loop() argument
125 context->fds[i].events = POLLIN; in poll_loop()
129 rc = poll(context->fds, POLL_FDS, -1); in poll_loop()
137 if (context->fds[SIG_FD].revents & POLLIN) { /* Signal */ in poll_loop()
140 rc = read(context->fds[SIG_FD].fd, (void *) &info, in poll_loop()
152 context->terminate = true; in poll_loop()
155 rc = protocol_reset(context); in poll_loop()
166 if (context->fds[DBUS_FD].revents & POLLIN) { /* DBUS */ in poll_loop()
167 while ((rc = sd_bus_process(context->bus, NULL)) > 0) { in poll_loop()
175 if (context->terminate) { in poll_loop()
180 rc = protocol_reset(context); in poll_loop()
188 static int init_signals(struct mbox_context *context, sigset_t *set) in init_signals() argument
210 context->fds[SIG_FD].fd = rc; in init_signals()
220 struct mbox_context *context) in parse_cmdline() argument
241 context->current = NULL; /* No current window */ in parse_cmdline()
249 context->backend.flash_size = strtol(optarg, &endptr, 10); in parse_cmdline()
258 context->backend.flash_size <<= 20; in parse_cmdline()
261 context->backend.flash_size <<= 10; in parse_cmdline()
270 context->source = optarg; in parse_cmdline()
273 context->windows.num = strtol(argv[optind], &endptr, in parse_cmdline()
281 context->windows.default_size = strtol(argv[optind], in parse_cmdline()
283 context->windows.default_size <<= 20; /* Given in MB */ in parse_cmdline()
289 if (!is_power_of_2(context->windows.default_size)) { in parse_cmdline()
308 context->blktracefd = open(argv[optind], in parse_cmdline()
313 if (context->blktracefd == -1) { in parse_cmdline()
325 if (!context->backend.flash_size) { in parse_cmdline()
330 MSG_INFO("Flash size: 0x%.8x\n", context->backend.flash_size); in parse_cmdline()
340 static int mboxd_backend_init(struct mbox_context *context) in mboxd_backend_init() argument
346 if (!context->source) { in mboxd_backend_init()
350 rc = backend_probe_vpnor(&context->backend, &paths); in mboxd_backend_init()
352 rc = backend_probe_mtd(&context->backend, NULL); in mboxd_backend_init()
357 delim = strchr(context->source, ':'); in mboxd_backend_init()
360 if (!strncmp(context->source, "vpnor", strlen("vpnor"))) { in mboxd_backend_init()
367 rc = backend_probe_vpnor(&context->backend, &paths); in mboxd_backend_init()
369 } else if (!strncmp(context->source, "mtd", strlen("mtd"))) { in mboxd_backend_init()
370 rc = backend_probe_mtd(&context->backend, path); in mboxd_backend_init()
371 } else if (!strncmp(context->source, "file", strlen("file"))) { in mboxd_backend_init()
372 rc = backend_probe_file(&context->backend, path); in mboxd_backend_init()
378 MSG_ERR("Invalid backend argument: %s\n", context->source); in mboxd_backend_init()
386 struct mbox_context *context; in main() local
391 context = calloc(1, sizeof(*context)); in main()
392 if (!context) { in main()
397 if (!parse_cmdline(argc, argv, context)) { in main()
399 free(context); in main()
404 context->fds[i].fd = -1; in main()
409 rc = init_signals(context, &set); in main()
414 rc = mboxd_backend_init(context); in main()
419 rc = protocol_init(context); in main()
424 rc = lpc_dev_init(context); in main()
430 rc = windows_init(context); in main()
435 rc = dbus_init(context, &dbus_ops); in main()
441 __protocol_reset(context); in main()
444 context->bmc_events |= BMC_EVENT_DAEMON_READY; in main()
445 context->bmc_events |= BMC_EVENT_PROTOCOL_RESET; in main()
448 rc = protocol_events_put(context, dbus_ops); in main()
454 rc = poll_loop(context); in main()
459 context->bmc_events &= ~BMC_EVENT_DAEMON_READY; in main()
460 context->bmc_events |= BMC_EVENT_PROTOCOL_RESET; in main()
463 protocol_events_put(context, dbus_ops); in main()
466 dbus_free(context); in main()
468 windows_free(context); in main()
470 lpc_dev_free(context); in main()
472 protocol_free(context); in main()
474 backend_free(&context->backend); in main()
476 if (context->blktracefd) in main()
477 close(context->blktracefd); in main()
479 free(context); in main()