Browse Source

Merge pull request #523 from PurpleI2P/openssl

android build
pull/580/head
orignal 9 years ago committed by GitHub
parent
commit
fb213a1efd
  1. 2
      Daemon.cpp
  2. 13
      Daemon.h
  3. 18
      i2pd.cpp
  4. 1
      qt/.gitignore
  5. 179
      qt/i2pd_qt/DaemonQT.cpp
  6. 82
      qt/i2pd_qt/DaemonQT.h
  7. 4
      qt/i2pd_qt/android/AndroidManifest.xml
  8. 25
      qt/i2pd_qt/i2pd_qt.pro
  9. 51
      qt/i2pd_qt/mainwindow.cpp
  10. 18
      qt/i2pd_qt/mainwindow.h
  11. 60
      qt/i2pd_qt/mainwindow.ui

2
Daemon.cpp

@ -265,5 +265,5 @@ namespace i2p @@ -265,5 +265,5 @@ namespace i2p
return true;
}
}
}
}

13
Daemon.h

@ -33,8 +33,8 @@ namespace i2p @@ -33,8 +33,8 @@ namespace i2p
#if defined(QT_GUI_LIB) // check if QT
#define Daemon i2p::util::DaemonQT::Instance()
class DaemonQTImpl;
class DaemonQT: public i2p::util::Daemon_Singleton
// dummy, invoked from RunQT
class DaemonQT: public i2p::util::Daemon_Singleton
{
public:
@ -43,14 +43,7 @@ namespace i2p @@ -43,14 +43,7 @@ namespace i2p
static DaemonQT instance;
return instance;
}
bool init(int argc, char* argv[]);
void run ();
private:
std::shared_ptr<DaemonQTImpl> m_Impl;
};
};
#elif defined(_WIN32)
#define Daemon i2p::util::DaemonWin32::Instance()

18
i2pd.cpp

@ -1,9 +1,24 @@ @@ -1,9 +1,24 @@
#include <stdlib.h>
#include "Daemon.h"
#if defined(QT_GUI_LIB)
namespace i2p
{
namespace qt
{
int RunQT (int argc, char* argv[]);
}
}
int main( int argc, char* argv[] )
{
if (Daemon.init(argc, argv))
return i2p::qt::RunQT (argc, argv);
}
#else
int main( int argc, char* argv[] )
{
if (Daemon.init(argc, argv))
{
if (Daemon.start())
Daemon.run ();
@ -11,6 +26,7 @@ int main( int argc, char* argv[] ) @@ -11,6 +26,7 @@ int main( int argc, char* argv[] )
}
return EXIT_SUCCESS;
}
#endif
#ifdef _WIN32
#include <windows.h>

1
qt/.gitignore vendored

@ -1,2 +1,3 @@ @@ -1,2 +1,3 @@
/build-i2pd_qt-Android_armeabi_v7a_GCC_4_9_Qt_5_6_0-Debug/
/build-i2pd_qt-Desktop_Qt_5_6_0_GCC_64bit-Debug/
/build-i2pd_qt-Android_x86_GCC_4_9_Qt_5_6_0-Debug/

179
qt/i2pd_qt/DaemonQT.cpp

@ -1,64 +1,165 @@ @@ -1,64 +1,165 @@
#include <memory>
#include "DaemonQT.h"
#include "../../Daemon.h"
#include "mainwindow.h"
#include <QMessageBox>
#include <QApplication>
#include <stdlib.h>
#include "../../Daemon.h"
#include <QMutexLocker>
#include <QThread>
namespace i2p
{
namespace util
namespace qt
{
class DaemonQTImpl: public std::enable_shared_from_this<DaemonQTImpl>
Worker::Worker (DaemonQTImpl& daemon):
m_Daemon (daemon)
{
}
void Worker::startDaemon()
{
public:
qDebug("Performing daemon start...");
m_Daemon.start();
qDebug("Daemon started.");
emit resultReady();
}
void Worker::restartDaemon()
{
qDebug("Performing daemon restart...");
m_Daemon.restart();
qDebug("Daemon restarted.");
emit resultReady();
}
void Worker::stopDaemon() {
qDebug("Performing daemon stop...");
m_Daemon.stop();
qDebug("Daemon stopped.");
emit resultReady();
}
DaemonQTImpl (int argc, char* argv[]):
m_App (argc, argv)
{
}
Controller::Controller(DaemonQTImpl& daemon):
m_Daemon (daemon)
{
Worker *worker = new Worker (m_Daemon);
worker->moveToThread(&workerThread);
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
connect(this, &Controller::startDaemon, worker, &Worker::startDaemon);
connect(this, &Controller::stopDaemon, worker, &Worker::stopDaemon);
connect(this, &Controller::restartDaemon, worker, &Worker::restartDaemon);
connect(worker, &Worker::resultReady, this, &Controller::handleResults);
workerThread.start();
}
Controller::~Controller()
{
qDebug("Closing and waiting for daemon worker thread...");
workerThread.quit();
workerThread.wait();
qDebug("Waiting for daemon worker thread finished.");
if(m_Daemon.isRunning())
{
qDebug("Stopping the daemon...");
m_Daemon.stop();
qDebug("Stopped the daemon.");
}
}
DaemonQTImpl::DaemonQTImpl ():
mutex(nullptr), m_IsRunning(nullptr), m_RunningChangedCallback(nullptr)
{
}
DaemonQTImpl::~DaemonQTImpl ()
{
delete mutex;
}
void Run ()
{
MainWindow w;
w.show ();
m_App.exec();
}
bool DaemonQTImpl::init(int argc, char* argv[])
{
mutex=new QMutex(QMutex::Recursive);
setRunningCallback(0);
m_IsRunning=false;
return Daemon.init(argc,argv);
private:
}
void DaemonQTImpl::deinit()
{
delete mutex; mutex = nullptr;
}
void StartDaemon ()
{
Daemon.start ();
}
void DaemonQTImpl::start()
{
QMutexLocker locker(mutex);
setRunning(true);
Daemon.start();
}
void StopDaemon ()
{
Daemon.stop ();
}
void DaemonQTImpl::stop()
{
QMutexLocker locker(mutex);
Daemon.stop();
setRunning(false);
}
bool IsRunning () const
{
return Daemon.running;
}
void DaemonQTImpl::restart()
{
QMutexLocker locker(mutex);
stop();
start();
}
private:
void DaemonQTImpl::setRunningCallback(runningChangedCallback cb)
{
m_RunningChangedCallback = cb;
}
QApplication m_App;
};
bool DaemonQTImpl::isRunning()
{
return m_IsRunning;
}
bool DaemonQT::init(int argc, char* argv[])
void DaemonQTImpl::setRunning(bool newValue)
{
m_Impl = std::make_shared<DaemonQTImpl> (argc, argv);
return Daemon_Singleton::init(argc, argv);
bool oldValue = m_IsRunning;
if(oldValue!=newValue)
{
m_IsRunning = newValue;
if(m_RunningChangedCallback)
m_RunningChangedCallback();
}
}
void DaemonQT::run ()
int RunQT (int argc, char* argv[])
{
if (m_Impl)
//int result = runGUI(argc, argv);
//QMessageBox::information(0,"Debug","runGUI completed");
QApplication app(argc, argv);
DaemonQTImpl daemon;
qDebug("Initialising the daemon...");
bool daemonInitSuccess = daemon.init(argc, argv);
if(!daemonInitSuccess)
{
QMessageBox::critical(0, "Error", "Daemon init failed");
return 1;
}
qDebug("Initialised, creating the main window...");
MainWindow w;
qDebug("Before main window.show()...");
w.show ();
int result;
{
m_Impl->Run ();
m_Impl = nullptr;
/* i2p::qt::Controller daemonQtController(daemon);
qDebug("Starting the daemon...");
emit daemonQtController.startDaemon();
qDebug("Starting gui event loop...");*/
daemon.start ();
result = app.exec();
daemon.stop ();
}
daemon.deinit();
//QMessageBox::information(&w, "Debug", "demon stopped");
//exit(result); //return from main() causes intermittent sigsegv bugs in some Androids. exit() is a workaround for this
qDebug("Exiting the application");
return result;
}
}
}

82
qt/i2pd_qt/DaemonQT.h

@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
#ifndef DAEMONQT_H
#define DAEMONQT_H
#include <QObject>
#include <QThread>
#include <QMutex>
namespace i2p
{
namespace qt
{
class DaemonQTImpl
{
public:
DaemonQTImpl ();
~DaemonQTImpl ();
typedef void (*runningChangedCallback)();
/**
* @brief init
* @param argc
* @param argv
* @return success
*/
bool init(int argc, char* argv[]);
void deinit();
void start();
void stop();
void restart();
void setRunningCallback(runningChangedCallback cb);
bool isRunning();
private:
void setRunning(bool running);
private:
QMutex* mutex;
bool m_IsRunning;
runningChangedCallback m_RunningChangedCallback;
};
class Worker : public QObject
{
Q_OBJECT
public:
Worker (DaemonQTImpl& daemon);
private:
DaemonQTImpl& m_Daemon;
public slots:
void startDaemon();
void restartDaemon();
void stopDaemon();
signals:
void resultReady();
};
class Controller : public QObject
{
Q_OBJECT
QThread workerThread;
public:
Controller(DaemonQTImpl& daemon);
~Controller();
private:
DaemonQTImpl& m_Daemon;
public slots:
void handleResults(){}
signals:
void startDaemon();
void stopDaemon();
void restartDaemon();
};
}
}
#endif // DAEMONQT_H

4
qt/i2pd_qt/android/AndroidManifest.xml

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
<?xml version="1.0"?>
<manifest package="org.purplei2p.i2pd" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="2.8.0" android:versionCode="1" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="i2pd">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@ -46,7 +46,7 @@ @@ -46,7 +46,7 @@
<!-- auto screen scale factor -->
</activity>
</application>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19"/>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.

25
qt/i2pd_qt/i2pd_qt.pro

@ -14,7 +14,7 @@ QMAKE_CXXFLAGS *= -std=c++11 @@ -14,7 +14,7 @@ QMAKE_CXXFLAGS *= -std=c++11
# git clone https://github.com/PurpleI2P/Boost-for-Android-Prebuilt.git
# git clone https://github.com/PurpleI2P/OpenSSL-for-Android-Prebuilt
# git clone https://github.com/PuerpleI2P/android-ifaddrs.git
# git clone https://github.com/PurpleI2P/android-ifaddrs.git
# change to your own
BOOST_PATH = /mnt/media/android/Boost-for-Android-Prebuilt
OPENSSL_PATH = /mnt/media/android/OpenSSL-for-Android-Prebuilt
@ -68,7 +68,7 @@ SOURCES += DaemonQT.cpp\ @@ -68,7 +68,7 @@ SOURCES += DaemonQT.cpp\
../../i2pd.cpp \
$$IFADDRS_PATH/ifaddrs.c
HEADERS += mainwindow.h \
HEADERS += DaemonQT.h mainwindow.h \
../../HTTPServer.h ../../I2PControl.h ../../UPnP.h ../../Daemon.h ../../Config.h \
../../AddressBook.h \
../../api.h \
@ -119,7 +119,7 @@ HEADERS += mainwindow.h \ @@ -119,7 +119,7 @@ HEADERS += mainwindow.h \
../../TunnelPool.h \
../../util.h \
../../version.h \
$$IFADDRS_PATH/ifaddrs.h
$$IFADDRS_PATH/ifaddrs.h
FORMS += mainwindow.ui
@ -135,11 +135,14 @@ DEFINES += ANDROID=1 @@ -135,11 +135,14 @@ DEFINES += ANDROID=1
INCLUDEPATH += $$BOOST_PATH/boost_1_53_0/include \
$$OPENSSL_PATH/openssl-1.0.2/include \
$$IFADDRS_PATH
DISTFILES += \
android/AndroidManifest.xml
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
equals(ANDROID_TARGET_ARCH, armeabi-v7a){
# http://stackoverflow.com/a/30235934/529442
LIBS += -L$$BOOST_PATH/boost_1_53_0/armeabi-v7a/lib \
#/home/anon5/git/OpenSSL-for-Android-Prebuilt/openssl-1.0.2/armeabi-v7a/lib/libcrypto.a \
#/home/anon5/git/OpenSSL-for-Android-Prebuilt/openssl-1.0.2/armeabi-v7a/lib/libssl.a \
-lboost_system-gcc-mt-1_53 \
-lboost_date_time-gcc-mt-1_53 \
-lboost_filesystem-gcc-mt-1_53 \
@ -157,8 +160,6 @@ ANDROID_EXTRA_LIBS += $$OPENSSL_PATH/openssl-1.0.2/armeabi-v7a/lib/libcrypto_1_0 @@ -157,8 +160,6 @@ ANDROID_EXTRA_LIBS += $$OPENSSL_PATH/openssl-1.0.2/armeabi-v7a/lib/libcrypto_1_0
equals(ANDROID_TARGET_ARCH, x86){
# http://stackoverflow.com/a/30235934/529442
LIBS += -L$$BOOST_PATH/boost_1_53_0/x86/lib \
#/home/anon5/git/OpenSSL-for-Android-Prebuilt/openssl-1.0.2/armeabi-v7a/lib/libcrypto.a \
#/home/anon5/git/OpenSSL-for-Android-Prebuilt/openssl-1.0.2/armeabi-v7a/lib/libssl.a \
-lboost_system-gcc-mt-1_53 \
-lboost_date_time-gcc-mt-1_53 \
-lboost_filesystem-gcc-mt-1_53 \
@ -180,13 +181,3 @@ message("Using Linux settings") @@ -180,13 +181,3 @@ message("Using Linux settings")
LIBS += -lcrypto -lssl -lboost_system -lboost_date_time -lboost_filesystem -lboost_program_options -lpthread
}
unix:!macx:
DISTFILES += \
android/AndroidManifest.xml
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android

51
qt/i2pd_qt/mainwindow.cpp

@ -1,14 +1,55 @@ @@ -1,14 +1,55 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
//#include "ui_mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
QMainWindow(parent)/*,
ui(new Ui::MainWindow)*/
{
ui->setupUi(this);
//ui->setupUi(this);
if (objectName().isEmpty())
setObjectName(QStringLiteral("MainWindow"));
resize(800, 480);
centralWidget = new QWidget(this);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
verticalLayoutWidget = new QWidget(centralWidget);
verticalLayoutWidget->setObjectName(QStringLiteral("verticalLayoutWidget"));
//verticalLayoutWidget->setGeometry(QRect(10, 20, 771, 441));
verticalLayout1 = new QVBoxLayout(verticalLayoutWidget);
verticalLayout1->setSpacing(6);
verticalLayout1->setContentsMargins(11, 11, 11, 11);
verticalLayout1->setObjectName(QStringLiteral("verticalLayout1"));
verticalLayout1->setContentsMargins(0, 0, 0, 0);
quitButton = new QPushButton(verticalLayoutWidget);
quitButton->setObjectName(QStringLiteral("quitButton"));
QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(quitButton->sizePolicy().hasHeightForWidth());
quitButton->setSizePolicy(sizePolicy);
verticalLayout1->addWidget(quitButton);
setCentralWidget(centralWidget);
setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0));
quitButton->setText(QApplication::translate("MainWindow", "Quit", 0));
QObject::connect(quitButton, SIGNAL(released()), this, SLOT(handleQuitButton()));
//QMetaObject::connectSlotsByName(this);
}
void MainWindow::handleQuitButton() {
qDebug("Quit pressed. Hiding the main window");
close();
QApplication::instance()->quit();
}
MainWindow::~MainWindow()
{
delete ui;
qDebug("Destroying main window");
//QMessageBox::information(0, "Debug", "mw destructor 1");
//delete ui;
//QMessageBox::information(0, "Debug", "mw destructor 2");
}

18
qt/i2pd_qt/mainwindow.h

@ -2,6 +2,16 @@ @@ -2,6 +2,16 @@
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
namespace Ui {
class MainWindow;
@ -15,8 +25,14 @@ public: @@ -15,8 +25,14 @@ public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void handleQuitButton();
private:
Ui::MainWindow *ui;
QWidget *centralWidget;
QWidget *verticalLayoutWidget;
QVBoxLayout *verticalLayout1;
QPushButton *quitButton;
};
#endif // MAINWINDOW_H

60
qt/i2pd_qt/mainwindow.ui

@ -1,7 +1,8 @@ @@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
@ -9,13 +10,58 @@ @@ -9,13 +10,58 @@
<height>480</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget" />
<widget class="QWidget" name="centralWidget">
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>771</width>
<height>441</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout1">
<item>
<widget class="QPushButton" name="quitButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Quit</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
<connections>
<connection>
<sender>quitButton</sender>
<signal>released()</signal>
<receiver>MainWindow</receiver>
<slot>handleQuitButton()</slot>
<hints>
<hint type="sourcelabel">
<x>384</x>
<y>244</y>
</hint>
<hint type="destinationlabel">
<x>373</x>
<y>419</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>handleQuitButton()</slot>
</slots>
</ui>

Loading…
Cancel
Save