blob: 6ad597b4886efb0515ef7d3dc8c4ef2f2ac690b2 [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 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 Yu46948282013-11-06 18:43:31 -080019INIT_LOGGER("MAIN");
20
Yingdi Yu3b318c12013-10-15 17:54:00 -070021using namespace ndn;
Yingdi Yu17032f82014-03-25 15:48:23 -070022using ndn::shared_ptr;
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070023
Yingdi Yu7989eb22013-10-31 17:38:22 -070024class NewApp : public QApplication
25{
26public:
27 NewApp(int & argc, char ** argv)
28 : QApplication(argc, argv)
Yingdi Yu46948282013-11-06 18:43:31 -080029 { }
Yingdi Yu7989eb22013-10-31 17:38:22 -070030
Yingdi Yufa0b6a02014-04-30 14:26:42 -070031 bool notify(QObject * receiver, QEvent * event)
Yingdi Yu7989eb22013-10-31 17:38:22 -070032 {
Yingdi Yu8e135832013-11-09 20:12:31 -080033 try {
Yingdi Yu7989eb22013-10-31 17:38:22 -070034 return QApplication::notify(receiver, event);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070035 }
Yingdi Yu8e135832013-11-09 20:12:31 -080036 catch(std::exception& e){
Yingdi Yu76dd8002013-12-24 11:16:32 +080037 std::cerr << "Exception thrown:" << e.what() << std::endl;
Yingdi Yu8e135832013-11-09 20:12:31 -080038 return false;
39 }
Yingdi Yufa0b6a02014-04-30 14:26:42 -070040
Yingdi Yu7989eb22013-10-31 17:38:22 -070041 }
42};
43
Yingdi Yufa4ce792014-02-06 18:09:22 -080044void runIO(shared_ptr<boost::asio::io_service> ioService)
45{
46 try{
47 ioService->run();
48 }catch(std::runtime_error& e){
49 std::cerr << e.what() << std::endl;
50 }
51}
52
Alexander Afanasyevb4b92292013-07-09 13:54:59 -070053int main(int argc, char *argv[])
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070054{
Yingdi Yu7989eb22013-10-31 17:38:22 -070055 NewApp app(argc, argv);
Yingdi Yufa0b6a02014-04-30 14:26:42 -070056
Yingdi Yufa4ce792014-02-06 18:09:22 -080057 shared_ptr<Face> face = make_shared<Face>();
Yingdi Yu348f5ea2014-03-01 14:47:25 -080058 chronos::Controller controller(face);
Alexander Afanasyevb4b92292013-07-09 13:54:59 -070059
Yingdi Yu348f5ea2014-03-01 14:47:25 -080060 app.setQuitOnLastWindowClosed(false);
Yingdi Yufa4ce792014-02-06 18:09:22 -080061
62 boost::thread (runIO, face->ioService());
Yingdi Yufa0b6a02014-04-30 14:26:42 -070063
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070064 return app.exec();
65}