blob: 030ba437548ee31c2d599b1a9b6e0aeb386170ef [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>
12#include <QSystemTrayIcon>
13
Yingdi Yu847aa862013-10-09 16:35:53 -070014#include "contactpanel.h"
Yingdi Yu3b318c12013-10-15 17:54:00 -070015#include "contact-storage.h"
Yingdi Yu4685b1b2013-10-18 17:05:02 -070016#include "dns-storage.h"
Yingdi Yu9236c432013-10-18 11:29:25 -070017#include "contact-manager.h"
Yingdi Yu46948282013-11-06 18:43:31 -080018#include "logging.h"
Yingdi Yufa4ce792014-02-06 18:09:22 -080019#include <ndn-cpp-dev/face.hpp>
20#include <boost/thread/thread.hpp>
Yingdi Yu3b318c12013-10-15 17:54:00 -070021
Yingdi Yu46948282013-11-06 18:43:31 -080022INIT_LOGGER("MAIN");
23
Yingdi Yu3b318c12013-10-15 17:54:00 -070024using namespace ndn;
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070025
Yingdi Yu7989eb22013-10-31 17:38:22 -070026class NewApp : public QApplication
27{
28public:
29 NewApp(int & argc, char ** argv)
30 : QApplication(argc, argv)
Yingdi Yu46948282013-11-06 18:43:31 -080031 { }
Yingdi Yu7989eb22013-10-31 17:38:22 -070032
33 bool notify(QObject * receiver, QEvent * event)
34 {
Yingdi Yu8e135832013-11-09 20:12:31 -080035 try {
Yingdi Yu7989eb22013-10-31 17:38:22 -070036 return QApplication::notify(receiver, event);
Yingdi Yu8e135832013-11-09 20:12:31 -080037 }
Yingdi Yu8e135832013-11-09 20:12:31 -080038 catch(std::exception& e){
Yingdi Yu76dd8002013-12-24 11:16:32 +080039 std::cerr << "Exception thrown:" << e.what() << std::endl;
Yingdi Yu8e135832013-11-09 20:12:31 -080040 return false;
41 }
Yingdi Yu7989eb22013-10-31 17:38:22 -070042
43 }
44};
45
Yingdi Yufa4ce792014-02-06 18:09:22 -080046void runIO(shared_ptr<boost::asio::io_service> ioService)
47{
48 try{
49 ioService->run();
50 }catch(std::runtime_error& e){
51 std::cerr << e.what() << std::endl;
52 }
53}
54
Alexander Afanasyevb4b92292013-07-09 13:54:59 -070055int main(int argc, char *argv[])
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070056{
Yingdi Yu7989eb22013-10-31 17:38:22 -070057 NewApp app(argc, argv);
Yingdi Yufa4ce792014-02-06 18:09:22 -080058
59 shared_ptr<Face> face = make_shared<Face>();
60 ContactPanel contactPanel(face);
Alexander Afanasyevb4b92292013-07-09 13:54:59 -070061
Yingdi Yu847aa862013-10-09 16:35:53 -070062 contactPanel.show ();
63 contactPanel.activateWindow ();
64 contactPanel.raise ();
Yingdi Yufa4ce792014-02-06 18:09:22 -080065
66 boost::thread (runIO, face->ioService());
Yingdi Yu847aa862013-10-09 16:35:53 -070067
Zhenkai Zhu6d589aa2012-05-29 17:34:35 -070068 return app.exec();
69}