Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
behavior_loader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bioroboticslab
biotracker
behavior_loader
Commits
717bfa09
Commit
717bfa09
authored
6 years ago
by
moenck
Browse files
Options
Downloads
Patches
Plain Diff
Removed factory method. Fixed packaging
parent
012cec06
No related branches found
No related tags found
No related merge requests found
Pipeline
#12425
failed
6 years ago
Stage: build
Stage: package
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+7
-12
7 additions, 12 deletions
.gitlab-ci.yml
SrcBehaviorLoader/PluginLoader.cpp
+198
-10
198 additions, 10 deletions
SrcBehaviorLoader/PluginLoader.cpp
SrcBehaviorLoader/PluginLoader.h
+10
-4
10 additions, 4 deletions
SrcBehaviorLoader/PluginLoader.h
with
215 additions
and
26 deletions
.gitlab-ci.yml
+
7
−
12
View file @
717bfa09
...
@@ -57,18 +57,19 @@ build windows:
...
@@ -57,18 +57,19 @@ build windows:
-
cmake -Bbuild "-H." -DCMAKE_BUILD_TYPE=Release -G Ninja -DCMAKE_PREFIX_PATH="$Env:VCPKG_INSTALL_DIR"
-
cmake -Bbuild "-H." -DCMAKE_BUILD_TYPE=Release -G Ninja -DCMAKE_PREFIX_PATH="$Env:VCPKG_INSTALL_DIR"
-
ninja -C build
-
ninja -C build
build windows[cuda]
:
<<
:
*build_windows
script
:
-
cmake -Bbuild "-H." -DCMAKE_BUILD_TYPE=Release -G Ninja -DCMAKE_PREFIX_PATH="$Env:VCPKG_CUDA_INSTALL_DIR"
-
ninja -C build
.package
:
&package
.package
:
&package
stage
:
package
stage
:
package
artifacts
:
artifacts
:
paths
:
paths
:
-
build/*.tar.xz
-
build/*.tar.xz
expire_in
:
1 week
expire_in
:
1 week
before_script
:
-
'
curl.exe
-o
artifacts.zip
--header
"JOB-TOKEN:
$CI_JOB_TOKEN"
"https://git.imp.fu-berlin.de/api/v4/projects/2576/jobs/artifacts/master/download?job=package%20windows%5bcuda%5d"'
-
7z e artifacts.zip; 7z e *.tar.xz; Remove-Item -Force *.tar.xz; 7z x *.tar; Remove-Item -Force *.tar
-
New-Item -ItemType Directory -Force 'dependencies'
-
$name='RF_Interfaces'; Move-Item -Force "$name-*" dependencies/$name
-
$env:CMAKE_PREFIX_PATH="$((Get-Item -Path '.').FullName)/dependencies;$env:VCPKG_CUDA_INSTALL_DIR"
-
C:/VsDevEnv.ps1 -arch=amd64
script
:
script
:
-
ninja -C build package
-
ninja -C build package
...
@@ -84,12 +85,6 @@ package windows:
...
@@ -84,12 +85,6 @@ package windows:
-
build windows
-
build windows
<<
:
*package
<<
:
*package
package windows[cuda]
:
<<
:
*base_windows
dependencies
:
-
build windows[cuda]
<<
:
*package
trigger dependents
:
trigger dependents
:
stage
:
deploy
stage
:
deploy
<<
:
*base_ubuntu_18_04
<<
:
*base_ubuntu_18_04
...
...
This diff is collapsed.
Click to expand it.
SrcBehaviorLoader/PluginLoader.cpp
+
198
−
10
View file @
717bfa09
#include
"PluginLoader.h"
#include
"PluginLoader.h"
#include
<QDebug>
#include
<vector>
#include
<filesystem>
#ifdef _WIN32
#include
<stdio.h>
#include
<tchar.h>
#include
<string.h>
#include
<atlbase.h>
#include
<QDebug>
#include
<QDebug>
#include
<QFileInfo>
#define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383
std
::
vector
<
std
::
string
>
QueryKey
(
HKEY
hKey
,
std
::
string
path
)
{
//See https://docs.microsoft.com/en-us/windows/desktop/sysinfo/enumerating-registry-subkeys
std
::
vector
<
std
::
string
>
list
;
TCHAR
achClass
[
MAX_PATH
]
=
TEXT
(
""
);
// buffer for class name
DWORD
cchClassName
=
MAX_PATH
;
// size of class string
DWORD
cSubKeys
=
0
;
// number of subkeys
DWORD
cbMaxSubKey
;
// longest subkey size
DWORD
cchMaxClass
;
// longest class string
DWORD
cValues
;
// number of values for key
DWORD
cchMaxValue
;
// longest value name
DWORD
cbMaxValueData
;
// longest value data
DWORD
cbSecurityDescriptor
;
// size of security descriptor
FILETIME
ftLastWriteTime
;
// last write time
DWORD
i
,
retCode
;
TCHAR
achValue
[
MAX_VALUE_NAME
];
DWORD
cchValue
=
MAX_VALUE_NAME
;
// Get the class name and the value count.
retCode
=
RegQueryInfoKey
(
hKey
,
// key handle
achClass
,
// buffer for class name
&
cchClassName
,
// size of class string
NULL
,
// reserved
&
cSubKeys
,
// number of subkeys
&
cbMaxSubKey
,
// longest subkey size
&
cchMaxClass
,
// longest class string
&
cValues
,
// number of values for this key
&
cchMaxValue
,
// longest value name
&
cbMaxValueData
,
// longest value data
&
cbSecurityDescriptor
,
// security descriptor
&
ftLastWriteTime
);
// last write time
// Enumerate the key values.
if
(
cValues
)
{
//printf( "\nNumber of values: %d\n", cValues);
for
(
i
=
0
,
retCode
=
ERROR_SUCCESS
;
i
<
cValues
;
i
++
)
{
cchValue
=
MAX_VALUE_NAME
;
achValue
[
0
]
=
'\0'
;
retCode
=
RegEnumValue
(
hKey
,
i
,
achValue
,
&
cchValue
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
retCode
==
ERROR_SUCCESS
)
{
CRegKey
regKey
;
CHAR
szBuffer
[
512
];
ULONG
dwBufferSize
=
sizeof
(
szBuffer
);
if
(
ERROR_SUCCESS
!=
regKey
.
Open
(
HKEY_LOCAL_MACHINE
,
path
.
c_str
()))
{
qWarning
()
<<
"Error opening registry path "
<<
path
.
c_str
();
regKey
.
Close
();
}
if
(
ERROR_SUCCESS
!=
regKey
.
QueryStringValue
(
achValue
,
szBuffer
,
&
dwBufferSize
))
{
qWarning
()
<<
"Error opening registry value "
<<
achValue
;
regKey
.
Close
();
}
std
::
string
fp
=
szBuffer
;
std
::
replace
(
fp
.
begin
(),
fp
.
end
(),
'\\'
,
'/'
);
list
.
push_back
(
fp
);
}
}
}
return
list
;
}
#endif
std
::
vector
<
std
::
string
>
PluginLoader
::
queryRegistryBehaviors
(
std
::
string
path
)
{
std
::
vector
<
std
::
string
>
list
;
#ifdef _WIN32
HKEY
hTestKey
;
if
(
RegOpenKeyEx
(
HKEY_LOCAL_MACHINE
,
TEXT
(
path
.
c_str
()),
0
,
KEY_READ
,
&
hTestKey
)
==
ERROR_SUCCESS
)
{
list
=
QueryKey
(
hTestKey
,
path
);
}
RegCloseKey
(
hTestKey
);
#endif
return
list
;
}
#ifdef _WIN32
const
char
*
WinGetEnv
(
const
char
*
name
)
{
const
DWORD
buffSize
=
65535
;
static
char
buffer
[
buffSize
];
if
(
GetEnvironmentVariableA
(
name
,
buffer
,
buffSize
))
{
return
buffer
;
}
else
{
return
0
;
}
}
bool
WinSetEnv
(
const
char
*
name
,
const
char
*
toWhat
){
return
SetEnvironmentVariableA
(
name
,
toWhat
);
}
#endif
const
char
*
PluginLoader
::
addDllPath
(
std
::
string
f
)
{
//Get the directory of the DLL/*.so and add it to the PATH env variable.
//This way dependencies can be shipped in the same directory
#ifdef _WIN32
QFileInfo
finf
(
f
.
c_str
());
//rather than the buggy _getenv: https://docs.microsoft.com/de-de/windows/desktop/api/winbase/nf-winbase-getenvironmentvariable
auto
old_path
=
WinGetEnv
(
"PATH"
);
auto
path
=
std
::
ostringstream
();
if
(
old_path
){
path
<<
old_path
<<
";"
<<
finf
.
absolutePath
().
toStdString
().
c_str
();
WinSetEnv
(
"PATH"
,
path
.
str
().
c_str
());
}
else
{
qWarning
()
<<
"Failed to get and modify PATH enviromental variable."
;
}
return
old_path
;
#endif
return
""
;
}
void
PluginLoader
::
delDllPath
(
const
char
*
oldPath
){
//reset path. We don't want some weird cross-effects
#ifdef _WIN32
if
(
oldPath
){
WinSetEnv
(
"PATH"
,
oldPath
);
}
#endif
}
bool
endsWith
(
std
::
string
value
,
std
::
string
ending
)
{
std
::
transform
(
value
.
begin
(),
value
.
end
(),
value
.
begin
(),
::
tolower
);
std
::
transform
(
ending
.
begin
(),
ending
.
end
(),
ending
.
begin
(),
::
tolower
);
if
(
ending
.
size
()
>
value
.
size
())
return
false
;
return
std
::
equal
(
ending
.
rbegin
(),
ending
.
rend
(),
value
.
rbegin
());
}
std
::
vector
<
std
::
string
>
PluginLoader
::
searchDirectoriesForPlugins
(
std
::
vector
<
std
::
string
>
list
){
//Search directories
std
::
vector
<
std
::
string
>
filesFromFolders
;
for
(
auto
f
:
list
)
{
std
::
string
file
=
f
;
try
{
if
(
!
file
.
empty
()
&&
file
[
file
.
size
()
-
1
]
==
'/'
)
{
for
(
auto
&
p
:
std
::
filesystem
::
directory_iterator
(
file
))
{
std
::
string
s
=
p
.
path
().
string
();
if
(
endsWith
(
s
,
".robo_tracker.dll"
)
||
endsWith
(
s
,
".robo_tracker.so"
))
filesFromFolders
.
push_back
(
s
);
}
}
else
{
if
(
endsWith
(
f
,
".robo_tracker.dll"
)
||
endsWith
(
f
,
".robo_tracker.so"
))
filesFromFolders
.
push_back
(
f
);
}
}
catch
(...){
qWarning
()
<<
"Could not read file/directory: "
<<
file
.
c_str
();
}
}
return
filesFromFolders
;
}
PluginLoader
::
PluginLoader
(
QObject
*
parent
)
PluginLoader
::
PluginLoader
(
QObject
*
parent
)
{
{
m_PluginLoader
=
new
QPluginLoader
(
this
);
m_PluginLoader
=
new
QPluginLoader
(
this
);
}
}
/*---------------------------------------*/
bool
PluginLoader
::
loadPluginFromFilename
(
QString
const
&
filename
)
bool
PluginLoader
::
loadPluginFromFilename
(
QString
const
&
filename
)
{
{
bool
retval
=
false
;
bool
retval
=
false
;
...
@@ -28,7 +224,7 @@ bool PluginLoader::loadPluginFromFilename(QString const& filename)
...
@@ -28,7 +224,7 @@ bool PluginLoader::loadPluginFromFilename(QString const& filename)
QString
s
=
m_PluginLoader
->
errorString
();
QString
s
=
m_PluginLoader
->
errorString
();
std
::
string
ss
=
s
.
toStdString
();
std
::
string
ss
=
s
.
toStdString
();
if
(
!
m_PluginLoader
->
isLoaded
())
if
(
!
m_PluginLoader
->
isLoaded
())
{
{
qWarning
()
<<
ss
.
c_str
();
qWarning
()
<<
ss
.
c_str
();
}
}
...
@@ -40,19 +236,11 @@ bool PluginLoader::loadPluginFromFilename(QString const& filename)
...
@@ -40,19 +236,11 @@ bool PluginLoader::loadPluginFromFilename(QString const& filename)
return
retval
;
return
retval
;
}
}
/*---------------------------------------*/
IBehaviourFactory
*
PluginLoader
::
getPluginInstance
()
{
return
qobject_cast
<
IBehaviourFactory
*>
(
m_PluginLoader
->
instance
());
}
/*---------------------------------------*/
QJsonObject
PluginLoader
::
getPluginMetaData
()
const
QJsonObject
PluginLoader
::
getPluginMetaData
()
const
{
{
return
m_MetaData
;
return
m_MetaData
;
}
}
/*---------------------------------------*/
void
PluginLoader
::
readMetaDataFromPlugin
()
void
PluginLoader
::
readMetaDataFromPlugin
()
{
{
m_MetaData
=
m_PluginLoader
->
metaData
().
value
(
"MetaData"
).
toObject
();
m_MetaData
=
m_PluginLoader
->
metaData
().
value
(
"MetaData"
).
toObject
();
...
...
This diff is collapsed.
Click to expand it.
SrcBehaviorLoader/PluginLoader.h
+
10
−
4
View file @
717bfa09
#ifndef PLUGINLOADER_H
#ifndef PLUGINLOADER_H
#define PLUGINLOADER_H
#define PLUGINLOADER_H
#include
"QPluginLoader"
#include
"QPluginLoader"
#include
"QStringListModel"
#include
"QStringListModel"
#include
"IBehaviourFactory.h"
#include
"QPointer"
#include
"QPointer"
class
PluginLoader
:
QObject
class
PluginLoader
:
QObject
{
{
Q_OBJECT
Q_OBJECT
public:
public:
explicit
PluginLoader
(
QObject
*
parent
=
0
);
explicit
PluginLoader
(
QObject
*
parent
=
0
);
bool
loadPluginFromFilename
(
QString
const
&
filename
);
bool
loadPluginFromFilename
(
QString
const
&
filename
);
IBehaviourFactory
*
getPluginInstance
();
QJsonObject
getPluginMetaData
()
const
;
QJsonObject
getPluginMetaData
()
const
;
static
std
::
vector
<
std
::
string
>
queryRegistryBehaviors
(
std
::
string
path
);
static
std
::
vector
<
std
::
string
>
searchDirectoriesForPlugins
(
std
::
vector
<
std
::
string
>
list
);
//return oldPath
static
const
char
*
addDllPath
(
std
::
string
file
);
static
void
delDllPath
(
const
char
*
oldPath
);
private:
private:
void
readMetaDataFromPlugin
();
void
readMetaDataFromPlugin
();
...
@@ -23,4 +29,4 @@ private:
...
@@ -23,4 +29,4 @@ private:
QJsonObject
m_MetaData
;
QJsonObject
m_MetaData
;
};
};
#endif // PLUGINLOADER_H
#endif // PLUGINLOADER_H
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment