blob: 009f7611f34633f0f70f3814cf179ea9decdd8a2 [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 Yu348f5ea2014-03-01 14:47:25 -080014#include "controller.h"
Yingdi Yu46948282013-11-06 18:43:31 -080015#include "logging.h"
Yingdi Yufa4ce792014-02-06 18:09:22 -080016#include <ndn-cpp-dev/face.hpp>
17#include <boost/thread/thread.hpp>
Yingdi Yu3b318c12013-10-15 17:54:00 -070018
Yingdi Yu46948282013-11-06 18:43:31 -080019INIT_LOGGER("MAIN");
20
Yingdi Yu3b318c12013-10-15 17:54:00 -070021using namespace ndn;
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070022
Yingdi Yu7989eb22013-10-31 17:38:22 -070023class NewApp : public QApplication
24{
25public:
26 NewApp(int & argc, char ** argv)
27 : QApplication(argc, argv)
Yingdi Yu46948282013-11-06 18:43:31 -080028 { }
Yingdi Yu7989eb22013-10-31 17:38:22 -070029
30 bool notify(QObject * receiver, QEvent * event)
31 {
Yingdi Yu8e135832013-11-09 20:12:31 -080032 try {
Yingdi Yu7989eb22013-10-31 17:38:22 -070033 return QApplication::notify(receiver, event);
Yingdi Yu8e135832013-11-09 20:12:31 -080034 }
Yingdi Yu8e135832013-11-09 20:12:31 -080035 catch(std::exception& e){
Yingdi Yu76dd8002013-12-24 11:16:32 +080036 std::cerr << "Exception thrown:" << e.what() << std::endl;
Yingdi Yu8e135832013-11-09 20:12:31 -080037 return false;
38 }
Yingdi Yu7989eb22013-10-31 17:38:22 -070039
40 }
41};
42
Yingdi Yufa4ce792014-02-06 18:09:22 -080043void 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 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 Yufa4ce792014-02-06 18:09:22 -080055
56 shared_ptr<Face> face = make_shared<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
61 boost::thread (runIO, face->ioService());
Yingdi Yu847aa862013-10-09 16:35:53 -070062
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070063 return app.exec();
64}