int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); DBus::default_dispatcher = &dispatcher; dispatcher.attach(NULL); DBus::Connection conn = DBus::Connection::SessionBus(); DBusBrowser browser(conn); Gtk::Main::run(browser); return 0; }
int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); DBus::default_dispatcher = &dispatcher; dispatcher.attach(NULL); // activate one of both for either system or session bus // TODO: choose in the GUI DBus::Connection conn = DBus::Connection::SessionBus(); //DBus::Connection conn = DBus::Connection::SystemBus(); DBusBrowser browser(conn); Gtk::Main::run(browser); return 0; }
int main (int argc, char *argv[]) { //Force line-only buffering so we can see the output during hangs setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stderr, NULL, _IOLBF, 0); GOOGLE_PROTOBUF_VERIFY_VERSION; hu_log_library_versions(); hu_install_crash_handler(); DBus::_init_threading(); gst_init(&argc, &argv); try { MazdaCommandServerCallbacks commandCallbacks; CommandServer commandServer(commandCallbacks); printf("headunit version: %s \n", commandCallbacks.GetVersion().c_str()); if (!commandServer.Start()) { loge("Command server failed to start"); return 1; } if (argc >= 2 && strcmp(argv[1], "test") == 0) { //test mode from the installer, if we got here it's ok printf("###TESTMODE_OK###\n"); return 0; } config::readConfig(); printf("Looping\n"); while (true) { //Make a new one instead of using the default so we can clean it up each run run_on_thread_main_context = g_main_context_new(); //Recreate this each time, it makes the error handling logic simpler DBus::Glib::BusDispatcher dispatcher; dispatcher.attach(run_on_thread_main_context); printf("DBus::Glib::BusDispatcher attached\n"); DBus::default_dispatcher = &dispatcher; printf("Making debug connections\n"); DBus::Connection hmiBus(HMI_BUS_ADDRESS, false); hmiBus.register_bus(); DBus::Connection serviceBus(SERVICE_BUS_ADDRESS, false); serviceBus.register_bus(); hud_start(); MazdaEventCallbacks callbacks(serviceBus, hmiBus); HUServer headunit(callbacks); g_hu = &headunit.GetAnyThreadInterface(); commandCallbacks.eventCallbacks = &callbacks; //Wait forever for a connection int ret = headunit.hu_aap_start(config::transport_type, true); if (ret < 0) { loge("Something bad happened"); continue; } gst_app.loop = g_main_loop_new(run_on_thread_main_context, FALSE); callbacks.connected = true; std::condition_variable quitcv; std::mutex quitmutex; std::mutex hudmutex; std::thread nm_thread([&quitcv, &quitmutex](){ nightmode_thread_func(quitcv, quitmutex); } ); std::thread gp_thread([&quitcv, &quitmutex](){ gps_thread_func(quitcv, quitmutex); } ); std::thread hud_thread([&quitcv, &quitmutex, &hudmutex](){ hud_thread_func(quitcv, quitmutex, hudmutex); } ); /* Start gstreamer pipeline and main loop */ printf("Starting Android Auto...\n"); g_main_loop_run (gst_app.loop); commandCallbacks.eventCallbacks = nullptr; callbacks.connected = false; callbacks.videoFocus = false; callbacks.audioFocus = AudioManagerClient::FocusType::NONE; callbacks.inCall = false; printf("quitting...\n"); //wake up night mode and gps polling threads quitcv.notify_all(); printf("waiting for nm_thread\n"); nm_thread.join(); printf("waiting for gps_thread\n"); gp_thread.join(); printf("waiting for hud_thread\n"); hud_thread.join(); printf("shutting down\n"); g_main_loop_unref(gst_app.loop); gst_app.loop = nullptr; /* Stop AA processing */ ret = headunit.hu_aap_shutdown(); if (ret < 0) { printf("hu_aap_shutdown() ret: %d\n", ret); return ret; } g_main_context_unref(run_on_thread_main_context); run_on_thread_main_context = nullptr; g_hu = nullptr; DBus::default_dispatcher = nullptr; } } catch(DBus::Error& error) { loge("DBUS Error: %s: %s", error.name(), error.message()); return 1; } return 0; }
int main() { usleep(700000); std::map<uint32_t, PGN> allPGNs; std::map<int, std::string> allPorts; LoadConfig *configuration = new LoadConfig(); allPGNs = configuration->getAllPGNs(); allPorts = configuration->getAllPorts(); delete configuration; auto loop = g_main_loop_new(NULL, false); DBus::Glib::BusDispatcher dispatcher; DBus::default_dispatcher = &dispatcher; dispatcher.attach(NULL); DBus::Connection bus = DBus::Connection::SessionBus(); Can can0(bus, "can0"); Can can1(bus, "can1"); can1.getConfiguration()->StopInterface(); can0.getConfiguration()->StopInterface(); usleep(700000); can0.getConfiguration()->StartInterface(250000); /*if (can0.getConfiguration()->LinkState() == false) { exit(-1); }*/ for (std::map<uint32_t, PGN>::iterator it=allPGNs.begin(); it!=allPGNs.end(); ++it) { uint32_t masked_id1=it->first&0x00FFFF00; std::cout <<std::hex <<masked_id1 << std::endl; } FMSHandler * GenericFms = new FMSHandler(); auto can_frame_received = [&allPGNs,&GenericFms](uint32_t id, uint8_t data[8], uint8_t dlc) { uint32_t masked_id=id&0x00FFFF00; //std::cout<<std::hex<<masked_id<<std::endl; if (allPGNs.count(masked_id)) { GenericFms->setDATA(data); GenericFms->setDLC(dlc); GenericFms->setID(masked_id); PGN * detectedPGN = &allPGNs[masked_id]; CANFrameHandler::SPNHandler(detectedPGN,GenericFms); } }; SocketCAN socket("can0"); if (!socket.receive(can_frame_received)) { return 1; } thread ConsoleUIThread(printConsoleWorker); std::thread WebSocketServerThread(WebSocketServerWorker, bus); g_main_loop_run(loop); return 0; }