Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 1 | /* -*- 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 Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame^] | 12 | // #include <QSystemTrayIcon> |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 13 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame^] | 14 | #include "controller.h" |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 15 | #include "logging.h" |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 16 | #include <ndn-cpp-dev/face.hpp> |
17 | #include <boost/thread/thread.hpp> | ||||
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 18 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 19 | INIT_LOGGER("MAIN"); |
20 | |||||
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 21 | using namespace ndn; |
Zhenkai Zhu | 6d589aa | 2012-05-29 17:34:35 -0700 | [diff] [blame] | 22 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 23 | class NewApp : public QApplication |
24 | { | ||||
25 | public: | ||||
26 | NewApp(int & argc, char ** argv) | ||||
27 | : QApplication(argc, argv) | ||||
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 28 | { } |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 29 | |
30 | bool notify(QObject * receiver, QEvent * event) | ||||
31 | { | ||||
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 32 | try { |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 33 | return QApplication::notify(receiver, event); |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 34 | } |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 35 | catch(std::exception& e){ |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 36 | std::cerr << "Exception thrown:" << e.what() << std::endl; |
Yingdi Yu | 8e13583 | 2013-11-09 20:12:31 -0800 | [diff] [blame] | 37 | return false; |
38 | } | ||||
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 39 | |
40 | } | ||||
41 | }; | ||||
42 | |||||
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 43 | void runIO(shared_ptr<boost::asio::io_service> ioService) |
44 | { | ||||
45 | try{ | ||||
46 | ioService->run(); | ||||
47 | }catch(std::runtime_error& e){ | ||||
48 | std::cerr << e.what() << std::endl; | ||||
49 | } | ||||
50 | } | ||||
51 | |||||
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 52 | int main(int argc, char *argv[]) |
Zhenkai Zhu | 6d589aa | 2012-05-29 17:34:35 -0700 | [diff] [blame] | 53 | { |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 54 | NewApp app(argc, argv); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 55 | |
56 | shared_ptr<Face> face = make_shared<Face>(); | ||||
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame^] | 57 | chronos::Controller controller(face); |
Alexander Afanasyev | b4b9229 | 2013-07-09 13:54:59 -0700 | [diff] [blame] | 58 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame^] | 59 | app.setQuitOnLastWindowClosed(false); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 60 | |
61 | boost::thread (runIO, face->ioService()); | ||||
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 62 | |
Zhenkai Zhu | 6d589aa | 2012-05-29 17:34:35 -0700 | [diff] [blame] | 63 | return app.exec(); |
64 | } |