Skip to content

Commit 7729233

Browse files
committed
Merge branch 'master' of github.com:trikset/trikRuntime
Conflicts: trikControl/config.xml
2 parents dbb4244 + 27610a0 commit 7729233

File tree

105 files changed

+4137
-1430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+4137
-1430
lines changed

.travis.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
language: cpp
2+
compiler: gcc
3+
4+
env:
5+
- CONFIG=debug VERA=true
6+
- CONFIG=release VERA=false
7+
8+
install:
9+
- if [ "$CXX" = "g++" ]; then sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y; fi
10+
- if [ "$CXX" = "g++" ]; then sudo apt-get update -qq; fi
11+
- if [ "$CXX" = "g++" ]; then sudo apt-get install g++-4.8; fi
12+
- if [ "$CXX" = "g++" ]; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50; fi
13+
- if [ "$CXX" = "g++" ]; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50; fi
14+
- sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty universe"
15+
- sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu trusty main"
16+
- sudo add-apt-repository ppa:smspillaz/verapp-latest -y
17+
- sudo apt-get update
18+
- sudo apt-get install libboost-system-dev libboost-wave-dev tcl
19+
- sudo apt-get install vera++
20+
- sudo apt-get install qdbus qmlscene qt5-default qt5-qmake qtbase5-dev-tools qtchooser qtdeclarative5-dev xbitmaps xterm libqt5svg5-dev qttools5-dev qtscript5-dev -y
21+
- sudo apt-get install xvfb
22+
- Xvfb :0 &
23+
- export DISPLAY=:0
24+
25+
script:
26+
- gcc --version
27+
- qmake --version
28+
- if [ "$VERA" = "true" ]; then tclsh vera++/generatePaths.tcl; fi
29+
- if [ "$VERA" = "true" ]; then vera++ --error -p allRules --root vera++ <vera++/params; fi
30+
- qmake trikRuntime.pro CONFIG+=$CONFIG
31+
- make -j2
32+
- cd ./bin
33+
- ls -A

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
trikRuntime
1+
trikRuntime [![Build Status](https://travis-ci.org/trikset/trikRuntime.svg?branch=master)](https://travis-ci.org/trikset/trikRuntime)
22
===========
33

44
Runtime for TRIK controller.
@@ -10,8 +10,9 @@ Consists of following subprojects:
1010
- trikRun: command-line utility to execute Qt Script files.
1111
- trikServer: command-line server for network communications, uses trikCommunicator library.
1212
- trikGui: user interface that can show various settings (like IP address), file system, run scripts, act as a server with trikCommunicator and so on.
13+
- trikKernel: library with common code for all other projects.
1314

1415
Special thanks to:
1516
- Nikita Batov (https://github.com/Batov) for I2C direct access example.
1617
- Roman Kurbatov (https://github.com/romankurbatov) for his desktop environment code used in trikGui.
17-
- Anna Semakova for various artwork in "media" folder.
18+
- Anna Semakova for various artwork in "media" folder.

docs/trikRuntime.vpp

15 KB
Binary file not shown.

global.pri

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
# Build settings common to all projects in TrikRuntime.
1616
# Provides:
1717
# CONFIGURATION_SUFFIX variable that shall be consistently used in TARGET and LIBS variables in all projects.
18-
#
19-
# Depends on:
20-
# FILES_TO_COPY variable for a list of additional files and directories which needed to be copied after build to
21-
# target directory.
18+
# copyToDestdir function to copy arbitrary files and directories to DESTDIR
19+
# uses function to automatically add a library to INCLUDEPATH and LIBS.
2220

2321
CROSS_COMPILE = $$(CROSS_COMPILE)
2422

@@ -42,6 +40,11 @@ CONFIG(debug, debug | release) {
4240

4341
DESTDIR = $$PWD/bin/$$CONFIGURATION
4442

43+
PROJECT_BASENAME = $$basename(_PRO_FILE_)
44+
PROJECT_NAME = $$section(PROJECT_BASENAME, ".", 0, 0)
45+
46+
TARGET = $$PROJECT_NAME$$CONFIGURATION_SUFFIX
47+
4548
equals(TEMPLATE, app) {
4649
!macx {
4750
QMAKE_LFLAGS += -Wl,-O1,-rpath,.
@@ -54,15 +57,51 @@ MOC_DIR = .build/$$CONFIGURATION/.moc
5457
RCC_DIR = .build/$$CONFIGURATION/.rcc
5558
UI_DIR = .build/$$CONFIGURATION/.ui
5659

60+
INCLUDEPATH += $$_PRO_FILE_PWD_ \
61+
$$_PRO_FILE_PWD_/include/$$PROJECT_NAME \
62+
5763
unix {
5864
target.path = $$[INSTALL_ROOT]/
5965
INSTALLS += target
6066
}
6167

62-
!isEmpty(FILES_TO_COPY) {
63-
win32 {
64-
QMAKE_POST_LINK = "xcopy $$replace(FILES_TO_COPY, /, \\) $$replace(DESTDIR, /, \\) /s /e /q /y /i"
65-
} else {
66-
QMAKE_POST_LINK = "cp -rf $$FILES_TO_COPY $$DESTDIR"
68+
QMAKE_CXXFLAGS += -std=c++11
69+
QMAKE_CXXFLAGS += -Wextra -Wcast-qual -Wwrite-strings -Wredundant-decls -Wunreachable-code -Wnon-virtual-dtor -Woverloaded-virtual
70+
71+
GLOBAL_PWD = $$PWD
72+
73+
# Useful function to copy additional files to destination,
74+
# from http://stackoverflow.com/questions/3984104/qmake-how-to-copy-a-file-to-the-output
75+
defineTest(copyToDestdir) {
76+
FILES = $$1
77+
78+
for(FILE, FILES) {
79+
# This ugly code is needed because xcopy requires to add source directory name to target directory name when copying directories
80+
win32:AFTER_SLASH = $$section(FILE, "/", -1, -1)
81+
win32:BASE_NAME = $$section(FILE, "/", -2, -2)
82+
win32:equals(AFTER_SLASH, ""):DESTDIR_SUFFIX = /$$BASE_NAME
83+
84+
win32:FILE ~= s,/$,,g
85+
86+
win32:FILE ~= s,/,\,g
87+
DDIR = $$DESTDIR$$DESTDIR_SUFFIX/
88+
win32:DDIR ~= s,/,\,g
89+
90+
QMAKE_POST_LINK += $(COPY_DIR) $$quote($$FILE) $$quote($$DDIR) $$escape_expand(\\n\\t)
91+
}
92+
93+
export(QMAKE_POST_LINK)
94+
}
95+
96+
defineTest(uses) {
97+
LIBS += -L$$DESTDIR
98+
PROJECTS = $$1
99+
100+
for(PROJECT, PROJECTS) {
101+
LIBS += -l$$PROJECT$$CONFIGURATION_SUFFIX
102+
INCLUDEPATH += $$GLOBAL_PWD/$$PROJECT/include
67103
}
104+
105+
export(LIBS)
106+
export(INCLUDEPATH)
68107
}

runVera++.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tclsh vera++/generatePaths.tcl
2+
vera++ --error -p allRules --root vera++ <vera++/params

runVera++.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
tclsh vera++/generatePaths.tcl
3+
vera++ --error -p allRules --root vera++ <vera++/params

trikCommunicator/include/trikCommunicator/trikCommunicator.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class TrikScriptRunner;
2727

2828
namespace trikCommunicator {
2929

30-
class ScriptRunnerWrapper;
3130
class Connection;
3231

3332
/// Class that enables connection with a client running on computer (TrikLab or remote control).
@@ -41,7 +40,8 @@ class TrikCommunicator : public QTcpServer
4140
public:
4241
/// Constructor that creates its own instance of a script runner.
4342
/// @param configPath - path to config file for trikControl, for example, /home/root/trik/.
44-
explicit TrikCommunicator(QString const &configFilePath);
43+
/// @param startDirPath - path to the directory from which the application was executed.
44+
explicit TrikCommunicator(QString const &configFilePath, QString const &startDirPath);
4545

4646
/// Constructor that accepts external script runner and issues commands to it.
4747
explicit TrikCommunicator(trikScriptRunner::TrikScriptRunner &runner);
@@ -73,7 +73,12 @@ private slots:
7373
void init();
7474

7575
/// Script runner object common to all connections.
76-
QScopedPointer<ScriptRunnerWrapper> mScriptRunnerWrapper;
76+
/// Ownership depends on mHasScriptRunnerOwnership flag, if we received runner belonging to other object or created
77+
/// our own.
78+
trikScriptRunner::TrikScriptRunner *mTrikScriptRunner;
79+
80+
/// True, if we created our own script runner, false if we got it from someone.
81+
bool const mHasScriptRunnerOwnership;
7782

7883
/// Maps thread object to corresponding connection worker object, to be able to correctly stop and delete them all.
7984
QHash<QThread *, Connection *> mConnections; // Has ownership over threads and connections.

trikCommunicator/src/connection.cpp

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@
1717
#include <QtCore/QTextStream>
1818
#include <QtCore/QThread>
1919

20+
#include <trikKernel/fileUtils.h>
21+
#include <trikScriptRunner/trikScriptRunner.h>
22+
2023
#include "src/connection.h"
21-
#include "src/scriptRunnerWrapper.h"
2224

2325
using namespace trikCommunicator;
2426

2527
Connection::Connection()
26-
: mScriptRunnerWrapper(NULL)
28+
: mTrikScriptRunner(NULL)
2729
{
2830
}
2931

30-
void Connection::init(int socketDescriptor, ScriptRunnerWrapper *scriptRunnerWrapper)
32+
void Connection::init(int socketDescriptor, trikScriptRunner::TrikScriptRunner *trikScriptRunner)
3133
{
32-
mScriptRunnerWrapper = scriptRunnerWrapper;
34+
mTrikScriptRunner = trikScriptRunner;
3335
mSocket.reset(new QTcpSocket());
3436

3537
if (!mSocket->setSocketDescriptor(socketDescriptor)) {
@@ -67,17 +69,17 @@ void Connection::onReadyRead()
6769

6870
QString const fileName = command.left(separatorPosition);
6971
QString const fileContents = command.mid(separatorPosition + 1);
70-
writeToFile(fileName, fileContents);
72+
trikKernel::FileUtils::writeToFile(fileName, fileContents);
7173
} else if (command.startsWith("run")) {
7274
command.remove(0, QString("run:").length());
73-
QString const fileContents = readFromFile(command);
74-
QMetaObject::invokeMethod(mScriptRunnerWrapper, "run", Q_ARG(QString, fileContents));
75+
QString const fileContents = trikKernel::FileUtils::readFromFile(command);
76+
QMetaObject::invokeMethod(mTrikScriptRunner, "run", Q_ARG(QString, fileContents));
7577
emit startedScript(command);
7678
} else if (command == "stop") {
77-
QMetaObject::invokeMethod(mScriptRunnerWrapper, "stop");
79+
QMetaObject::invokeMethod(mTrikScriptRunner, "abort");
7880
} else if (command.startsWith("direct")) {
7981
command.remove(0, QString("direct:").length());
80-
QMetaObject::invokeMethod(mScriptRunnerWrapper, "run", Q_ARG(QString, command));
82+
QMetaObject::invokeMethod(mTrikScriptRunner, "run", Q_ARG(QString, command));
8183
emit startedDirectScript();
8284
}
8385
}
@@ -87,33 +89,3 @@ void Connection::disconnected()
8789
qDebug() << "Disconnected.";
8890
thread()->quit();
8991
}
90-
91-
QString Connection::readFromFile(QString const &fileName)
92-
{
93-
QFile file(fileName);
94-
file.open(QIODevice::ReadOnly | QIODevice::Text);
95-
if (!file.isOpen()) {
96-
throw "Reading failed";
97-
}
98-
99-
QTextStream input;
100-
input.setDevice(&file);
101-
input.setCodec("UTF-8");
102-
QString const result = input.readAll();
103-
file.close();
104-
return result;
105-
}
106-
107-
void Connection::writeToFile(QString const &fileName, QString const &contents)
108-
{
109-
QFile file(fileName);
110-
file.open(QIODevice::WriteOnly | QIODevice::Text);
111-
if (!file.isOpen()) {
112-
throw "File open operation failed";
113-
}
114-
115-
QTextStream stream(&file);
116-
stream.setCodec("UTF-8");
117-
stream << contents;
118-
file.close();
119-
}

trikCommunicator/src/connection.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
#include <QtCore/QScopedPointer>
1919
#include <QtNetwork/QTcpSocket>
2020

21-
namespace trikCommunicator {
21+
namespace trikScriptRunner {
22+
class TrikScriptRunner;
23+
}
2224

23-
class ScriptRunnerWrapper;
25+
namespace trikCommunicator {
2426

2527
/// Class that serves one client of TrikCommunicator. Meant to work in separate thread. Creates its own socket and
2628
/// handles all incoming messages, calling ScriptRunnerWrapper for brick functionality.
@@ -48,7 +50,7 @@ public slots:
4850
/// Creates socket and initializes connection, shall be called when Connection is already in its own thread.
4951
/// @param socketDescriptor - native socket descriptor.
5052
/// @param scriptRunnerWrapper - instance of script runner object.
51-
void init(int socketDescriptor, ScriptRunnerWrapper *scriptRunnerWrapper);
53+
void init(int socketDescriptor, trikScriptRunner::TrikScriptRunner *trikScriptRunner);
5254

5355
private slots:
5456
/// New data is ready on a socket.
@@ -58,14 +60,12 @@ private slots:
5860
void disconnected();
5961

6062
private:
61-
static QString readFromFile(QString const &fileName);
62-
static void writeToFile(QString const &fileName, QString const &contents);
63-
6463
/// Socket for this connection.
6564
QScopedPointer<QTcpSocket> mSocket;
6665

6766
/// Common script runner object, located in another thread.
68-
ScriptRunnerWrapper *mScriptRunnerWrapper; // Does not have ownership.
67+
/// Does not have ownership.
68+
trikScriptRunner::TrikScriptRunner *mTrikScriptRunner;
6969
};
7070

7171
}

trikCommunicator/src/scriptRunnerWrapper.cpp

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)