blob: afa36657786550f2a39e26af023190a99f253ae6 [file] [log] [blame]
Yingdi Yu847aa862013-10-09 16:35:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
11#include <QApplication>
Yingdi Yu348f5ea2014-03-01 14:47:25 -080012// #include <QSystemTrayIcon>
Yingdi Yu847aa862013-10-09 16:35:53 -070013
Yingdi Yu0b0a7362014-08-05 16:31:30 -070014#include "controller.hpp"
Yingdi Yu46948282013-11-06 18:43:31 -080015#include "logging.h"
Yingdi Yufa0b6a02014-04-30 14:26:42 -070016#include <ndn-cxx/face.hpp>
Yingdi Yufa4ce792014-02-06 18:09:22 -080017#include <boost/thread/thread.hpp>
Yingdi Yu3b318c12013-10-15 17:54:00 -070018
Yingdi Yu7989eb22013-10-31 17:38:22 -070019class NewApp : public QApplication
20{
21public:
Yingdi Yu0b0a7362014-08-05 16:31:30 -070022 NewApp(int& argc, char** argv)
Yingdi Yu7989eb22013-10-31 17:38:22 -070023 : QApplication(argc, argv)
Yingdi Yu0b0a7362014-08-05 16:31:30 -070024 {
25 }
Yingdi Yu7989eb22013-10-31 17:38:22 -070026
Yingdi Yu0b0a7362014-08-05 16:31:30 -070027 bool
28 notify(QObject* receiver, QEvent* event)
Yingdi Yu7989eb22013-10-31 17:38:22 -070029 {
Yingdi Yu8e135832013-11-09 20:12:31 -080030 try {
Yingdi Yu7989eb22013-10-31 17:38:22 -070031 return QApplication::notify(receiver, event);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070032 }
Yingdi Yu0b0a7362014-08-05 16:31:30 -070033 catch (std::exception& e) {
Yingdi Yu76dd8002013-12-24 11:16:32 +080034 std::cerr << "Exception thrown:" << e.what() << std::endl;
Yingdi Yu8e135832013-11-09 20:12:31 -080035 return false;
36 }
Yingdi Yufa0b6a02014-04-30 14:26:42 -070037
Yingdi Yu7989eb22013-10-31 17:38:22 -070038 }
39};
40
Yingdi Yu0b0a7362014-08-05 16:31:30 -070041void
42runIO(boost::asio::io_service& ioService)
Yingdi Yufa4ce792014-02-06 18:09:22 -080043{
Yingdi Yu0b0a7362014-08-05 16:31:30 -070044 try {
45 ioService.run();
46 }
47 catch (std::runtime_error& e) {
Yingdi Yufa4ce792014-02-06 18:09:22 -080048 std::cerr << e.what() << std::endl;
49 }
50}
51
Alexander Afanasyevb4b92292013-07-09 13:54:59 -070052int main(int argc, char *argv[])
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070053{
Yingdi Yu7989eb22013-10-31 17:38:22 -070054 NewApp app(argc, argv);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070055
Yingdi Yu0b0a7362014-08-05 16:31:30 -070056 ndn::shared_ptr<ndn::Face> face = ndn::make_shared<ndn::Face>();
Yingdi Yu348f5ea2014-03-01 14:47:25 -080057 chronos::Controller controller(face);
Alexander Afanasyevb4b92292013-07-09 13:54:59 -070058
Yingdi Yu348f5ea2014-03-01 14:47:25 -080059 app.setQuitOnLastWindowClosed(false);
Yingdi Yufa4ce792014-02-06 18:09:22 -080060
Yingdi Yu0b0a7362014-08-05 16:31:30 -070061 boost::thread(runIO, boost::ref(face->getIoService()));
Yingdi Yufa0b6a02014-04-30 14:26:42 -070062
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070063 return app.exec();
64}