Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
VILLAScommon
Commits
90ff2f70
Commit
90ff2f70
authored
Oct 27, 2019
by
Steffen Vogel
🎅🏼
Browse files
more refactoring to C++
parent
051bab81
Changes
36
Hide whitespace changes
Inline
Side-by-side
include/villas/advio.h
→
include/villas/advio.h
pp
View file @
90ff2f70
...
...
@@ -27,6 +27,7 @@
#include
<curl/curl.h>
#include
<villas/utils.hpp>
#include
<villas/exceptions.hpp>
struct
advio
{
CURL
*
curl
;
...
...
include/villas/buffer.h
→
include/villas/buffer.h
pp
View file @
90ff2f70
...
...
@@ -27,24 +27,28 @@
#include
<jansson.h>
#include
<villas/common.h>
#include
<villas/common.h
pp
>
struct
buffer
{
enum
State
state
;
namespace
villas
{
class
Buffer
{
public:
char
*
buf
;
size_t
len
;
size_t
size
;
};
int
buffer_init
(
struct
buffer
*
b
,
size_t
size
);
Buffer
(
size_t
size
);
int
buffer_destroy
(
struct
buffer
*
b
);
~
Buffer
(
);
void
buffer_clear
(
struct
buffer
*
b
);
void
clear
(
);
int
buffer_append
(
struct
buffer
*
b
,
const
char
*
data
,
size_t
len
);
int
append
(
const
char
*
data
,
size_t
len
);
int
buffer_parse_json
(
struct
buffer
*
b
,
json_t
**
j
);
int
parseJson
(
json_t
**
j
);
int
appendJson
(
json_t
*
j
);
};
int
buffer_append_json
(
struct
buffer
*
b
,
json_t
*
j
);
}
/* namespace villas */
include/villas/common.h
→
include/villas/common.h
pp
View file @
90ff2f70
...
...
@@ -31,7 +31,7 @@ enum class State {
CHECKED
=
3
,
STARTED
=
4
,
LOADED
=
4
,
/* alias for STARTED used by struct plugin */
OPENED
=
4
,
/* alias for STARTED used by
struct io
*/
OPENED
=
4
,
/* alias for STARTED used by
IO
*/
STOPPED
=
5
,
UNLOADED
=
5
,
/* alias for STARTED used by struct plugin */
CLOSED
=
5
,
/* alias for STARTED used by struct io */
...
...
include/villas/compat.h
→
include/villas/compat.h
pp
View file @
90ff2f70
File moved
include/villas/dsp/window.hpp
View file @
90ff2f70
...
...
@@ -45,14 +45,14 @@ protected:
public:
Window
(
size_type
s
=
0
,
T
i
=
0
)
:
init
(
i
)
init
(
i
),
steps
(
s
)
{
size_type
len
=
LOG2_CEIL
(
s
);
/* Allocate memory for circular history buffer */
data
=
std
::
vector
<
T
>
(
len
,
i
);
steps
=
s
;
pos
=
len
;
mask
=
len
-
1
;
}
...
...
include/villas/json_buffer.hpp
View file @
90ff2f70
...
...
@@ -31,17 +31,7 @@
namespace
villas
{
class
Buffer
:
public
std
::
vector
<
char
>
{
public:
void
append
(
const
char
*
data
,
size_t
len
)
{
insert
(
end
(),
data
,
data
+
len
);
}
};
class
JsonBuffer
:
public
Buffer
class
JsonBuffer
:
public
std
::
vector
<
char
>
{
protected:
...
...
@@ -53,6 +43,11 @@ public:
/** Decode JSON document from the beginning of the buffer */
json_t
*
decode
();
void
append
(
const
char
*
data
,
size_t
len
)
{
insert
(
end
(),
data
,
data
+
len
);
}
};
}
/* namespace villas */
include/villas/kernel/kernel.h
deleted
100644 → 0
View file @
051bab81
/** Linux kernel related functions.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
* @license GNU General Public License (version 3)
*
* VILLAScommon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
/** @addtogroup kernel Kernel
* @{
*/
#pragma once
#include
<cstring>
#include
<cstdint>
#if WITH_CAP
#include
<sys/capability.h>
/** Check if current process has capability \p cap.
*
* @retval 0 If capabilty is present.
* @retval <0 If capability is not present.
*/
int
kernel_check_cap
(
cap_value_t
cap
);
#endif
/** Get number of reserved hugepages. */
int
kernel_get_nr_hugepages
();
/** Set number of reserved hugepages. */
int
kernel_set_nr_hugepages
(
int
nr
);
/** Get kernel cmdline parameter
*
* See https://www.kernel.org/doc/Documentation/kernel-parameters.txt
*
* @param param The cmdline parameter to look for.
* @param buf The string buffer to which the parameter value will be copied to.
* @param len The length of the buffer \p value
* @retval 0 Parameter \p key was found and value was copied to \p value
* @reval <>0 Kernel was not booted with parameter \p key
*/
int
kernel_get_cmdline_param
(
const
char
*
param
,
char
*
buf
,
size_t
len
);
/** Checks if a kernel module is loaded
*
* @param module the name of the module
* @retval 0 Module is loaded.
* @reval <>0 Module is not loaded.
*/
int
kernel_module_loaded
(
const
char
*
module
);
/** Load kernel module via modprobe */
int
kernel_module_load
(
const
char
*
module
);
/** Set parameter of loaded kernel module */
int
kernel_module_set_param
(
const
char
*
module
,
const
char
*
param
,
const
char
*
value
);
/** Get cacheline size in bytes */
int
kernel_get_cacheline_size
();
/** Get the size of a standard page in bytes. */
int
kernel_get_page_size
();
/** Get the size of a huge page in bytes. */
int
kernel_get_hugepage_size
();
/** Get CPU base frequency */
int
kernel_get_cpu_frequency
(
uint64_t
*
freq
);
/** Set SMP affinity of IRQ */
int
kernel_irq_setaffinity
(
unsigned
irq
,
uintmax_t
aff
,
uintmax_t
*
old
);
/** @} */
include/villas/kernel/kernel.hpp
View file @
90ff2f70
...
...
@@ -23,6 +23,8 @@
#pragma once
#include
<cstddef>
#include
<villas/version.hpp>
namespace
villas
{
...
...
@@ -31,5 +33,63 @@ namespace kernel {
/** Get the version of the kernel. */
utils
::
Version
getVersion
();
#if WITH_CAP
#include
<sys/capability.h>
/** Check if current process has capability \p cap.
*
* @retval 0 If capabilty is present.
* @retval <0 If capability is not present.
*/
int
check_cap
(
cap_value_t
cap
);
#endif
/** Get number of reserved hugepages. */
int
get_nr_hugepages
();
/** Set number of reserved hugepages. */
int
set_nr_hugepages
(
int
nr
);
/** Get kernel cmdline parameter
*
* See https://www.kernel.org/doc/Documentation/kernel-parameters.txt
*
* @param param The cmdline parameter to look for.
* @param buf The string buffer to which the parameter value will be copied to.
* @param len The length of the buffer \p value
* @retval 0 Parameter \p key was found and value was copied to \p value
* @reval <>0 Kernel was not booted with parameter \p key
*/
int
get_cmdline_param
(
const
char
*
param
,
char
*
buf
,
size_t
len
);
/** Checks if a kernel module is loaded
*
* @param module the name of the module
* @retval 0 Module is loaded.
* @reval <>0 Module is not loaded.
*/
int
module_loaded
(
const
char
*
module
);
/** Load kernel module via modprobe */
int
module_load
(
const
char
*
module
);
/** Set parameter of loaded kernel module */
int
module_set_param
(
const
char
*
module
,
const
char
*
param
,
const
char
*
value
);
/** Get cacheline size in bytes */
int
get_cacheline_size
();
/** Get the size of a standard page in bytes. */
int
get_page_size
();
/** Get the size of a huge page in bytes. */
int
get_hugepage_size
();
/** Get CPU base frequency */
int
get_cpu_frequency
(
uint64_t
*
freq
);
/** Set SMP affinity of IRQ */
int
irq_setaffinity
(
unsigned
irq
,
uintmax_t
aff
,
uintmax_t
*
old
);
}
/* namespace villas */
}
/* namespace kernel */
include/villas/list.h
View file @
90ff2f70
...
...
@@ -31,7 +31,7 @@
#include
<sys/types.h>
#include
<pthread.h>
#include
<villas/common.h>
#include
<villas/common.h
pp
>
#define LIST_CHUNKSIZE 16
...
...
@@ -76,7 +76,7 @@ int vlist_init(struct vlist *l);
* @param dtor A function pointer to a desctructor which will be called for every list item when the list is destroyed.
* @param l A pointer to the list data structure.
*/
int
vlist_destroy
(
struct
vlist
*
l
,
dtor_cb_t
dtor
,
bool
free
);
int
vlist_destroy
(
struct
vlist
*
l
,
dtor_cb_t
dtor
=
nullptr
,
bool
free
=
false
);
/** Append an element to the end of the list */
void
vlist_push
(
struct
vlist
*
l
,
void
*
p
);
...
...
@@ -101,7 +101,7 @@ int vlist_insert(struct vlist *l, size_t idx, void *p);
*/
void
*
vlist_lookup
(
struct
vlist
*
l
,
const
char
*
name
);
ssize_t
vlist_lookup_index
(
struct
vlist
*
l
,
const
char
*
name
);
ssize_t
vlist_lookup_index
(
struct
vlist
*
l
,
const
void
*
ptr
);
/** Return the first element of the list for which cmp returns zero */
void
*
vlist_search
(
struct
vlist
*
l
,
cmp_cb_t
cmp
,
void
*
ctx
);
...
...
include/villas/log.hpp
View file @
90ff2f70
...
...
@@ -33,8 +33,6 @@
#include
<jansson.h>
#include
<villas/terminal.hpp>
namespace
villas
{
/* Forward declarations */
...
...
include/villas/plugin.hpp
View file @
90ff2f70
...
...
@@ -29,7 +29,7 @@
#include
<jansson.h>
#include
<villas/log.hpp>
#include
<villas/common.h>
#include
<villas/common.h
pp
>
namespace
villas
{
namespace
plugin
{
...
...
@@ -120,8 +120,8 @@ public:
virtual
void
dump
();
std
::
string
getName
();
std
::
string
getDescription
();
const
std
::
string
&
getName
()
const
;
const
std
::
string
&
getDescription
()
const
;
protected:
std
::
string
name
;
...
...
include/villas/task.h
→
include/villas/task.h
pp
View file @
90ff2f70
...
...
@@ -47,7 +47,7 @@
#include
<villas/tsc.h>
#endif
struct
t
ask
{
struct
T
ask
{
int
clock
;
/**< CLOCK_{MONOTONIC,REALTIME} */
#if PERIODIC_TASK_IMPL == RDTSC
/* We use cycle counts in RDTSC mode */
...
...
@@ -63,26 +63,28 @@ struct task {
#elif PERIODIC_TASK_IMPL == RDTSC
struct
tsc
tsc
;
/**< Initialized by tsc_init(). */
#endif
};
/** Create a new task with the given rate. */
int
task_init
(
struct
task
*
t
,
double
rate
,
int
clock
);
/** Create a new task with the given rate. */
Task
(
int
clock
=
CLOCK_REALTIME
);
int
task_destroy
(
struct
task
*
t
);
~
Task
(
);
/** Wait until task elapsed
*
* @retval 0 An error occured. Maybe the task was stopped.
* @retval >0 The nummer of runs this task already fired.
*/
uint64_t
task_wait
(
struct
task
*
t
);
/** Wait until task elapsed
*
* @retval 0 An error occured. Maybe the task was stopped.
* @retval >0 The nummer of runs this task already fired.
*/
uint64_t
wait
(
);
int
task_
set
_n
ext
(
struct
task
*
t
,
struct
timespec
*
next
);
int
task_
set
_t
imeout
(
struct
task
*
t
,
double
to
);
int
task_
set
_r
ate
(
struct
task
*
t
,
double
rate
);
void
set
N
ext
(
const
struct
timespec
*
next
);
void
set
T
imeout
(
double
to
);
void
set
R
ate
(
double
rate
);
/** Returns a poll'able file descriptor which becomes readable when the timer expires.
*
* Note: currently not supported on all platforms.
*/
int
task_fd
(
struct
task
*
t
);
void
stop
();
/** Returns a poll'able file descriptor which becomes readable when the timer expires.
*
* Note: currently not supported on all platforms.
*/
int
getFD
()
const
;
};
include/villas/tsc.h
View file @
90ff2f70
...
...
@@ -35,7 +35,7 @@
#include
<sys/sysctl.h>
#endif
#include
<villas/kernel/kernel.h>
#include
<villas/kernel/kernel.h
pp
>
#ifndef bit_TSC
#define bit_TSC (1 << 4)
...
...
lib/CMakeLists.txt
View file @
90ff2f70
...
...
@@ -28,7 +28,6 @@ add_library(villas-common SHARED
hist.cpp
dsp/pid.cpp
kernel/kernel.cpp
kernel/kernel.cpp
kernel/rt.cpp
list.cpp
log.cpp
...
...
lib/advio.cpp
View file @
90ff2f70
...
...
@@ -41,8 +41,9 @@
#include
<villas/utils.hpp>
#include
<villas/config.h>
#include
<villas/advio.h>
#include
<villas/advio.h
pp
>
using
namespace
villas
;
using
namespace
villas
::
utils
;
#define BAR_WIDTH 60
/**< How wide you want the progress meter to be. */
...
...
@@ -209,6 +210,10 @@ AFILE * afopen(const char *uri, const char *mode)
const
char
*
sep
;
AFILE
*
af
=
new
AFILE
;
if
(
!
af
)
throw
RuntimeError
(
"Failed to allocate memory!"
);
memset
(
af
,
0
,
sizeof
(
AFILE
));
snprintf
(
af
->
mode
,
sizeof
(
af
->
mode
),
"%s"
,
mode
);
...
...
lib/buffer.cpp
View file @
90ff2f70
...
...
@@ -22,78 +22,74 @@
#include
<cstring>
#include
<villas/compat.h>
#include
<villas/buffer.h>
#include
<villas/common.h>
#include
<villas/compat.hpp>
#include
<villas/buffer.hpp>
#include
<villas/common.hpp>
#include
<villas/exceptions.hpp>
int
buffer_init
(
struct
buffer
*
b
,
size_t
size
)
{
b
->
len
=
0
;
b
->
size
=
size
;
b
->
buf
=
new
char
[
size
];
if
(
!
b
->
buf
)
return
-
1
;
using
namespace
villas
;
b
->
state
=
State
::
INITIALIZED
;
Buffer
::
Buffer
(
size_t
sz
)
:
len
(
0
),
size
(
sz
)
{
buf
=
new
char
[
size
];
if
(
!
buf
)
throw
RuntimeError
(
"Failed to allocate memory"
);
return
0
;
memset
(
buf
,
0
,
size
)
;
}
int
buffer_destroy
(
struct
b
uffer
*
b
)
Buffer
::~
B
uffer
(
)
{
if
(
b
->
buf
)
delete
[]
b
->
buf
;
b
->
state
=
State
::
DESTROYED
;
return
0
;
delete
[]
buf
;
}
void
b
uffer
_
clear
(
struct
buffer
*
b
)
void
B
uffer
::
clear
()
{
b
->
len
=
0
;
len
=
0
;
}
int
b
uffer
_
append
(
struct
buffer
*
b
,
const
char
*
data
,
size_t
l
en
)
int
B
uffer
::
append
(
const
char
*
data
,
size_t
l
)
{
if
(
b
->
len
+
l
en
>
b
->
size
)
{
b
->
size
=
b
->
len
+
l
en
;
b
->
buf
=
(
char
*
)
realloc
(
b
->
buf
,
b
->
size
);
if
(
!
b
->
buf
)
if
(
len
+
l
>
size
)
{
size
=
len
+
l
;
buf
=
(
char
*
)
realloc
(
buf
,
size
);
if
(
!
buf
)
return
-
1
;
}
memcpy
(
b
->
buf
+
b
->
len
,
data
,
l
en
);
memcpy
(
buf
+
len
,
data
,
l
);
b
->
len
+=
l
en
;
len
+=
l
;
return
0
;
}
int
b
uffer
_
parse
_j
son
(
struct
buffer
*
b
,
json_t
**
j
)
int
B
uffer
::
parse
J
son
(
json_t
**
j
)
{
*
j
=
json_loadb
(
b
->
buf
,
b
->
len
,
0
,
nullptr
);
*
j
=
json_loadb
(
buf
,
len
,
0
,
nullptr
);
if
(
!*
j
)
return
-
1
;
return
0
;
}
int
b
uffer
_
append
_j
son
(
struct
buffer
*
b
,
json_t
*
j
)
int
B
uffer
::
append
J
son
(
json_t
*
j
)
{
size_t
l
en
;
size_t
l
;
retry:
l
en
=
json_dumpb
(
j
,
b
->
buf
+
b
->
len
,
b
->
size
-
b
->
len
,
0
);
if
(
b
->
size
<
b
->
len
+
l
en
)
{
b
->
buf
=
(
char
*
)
realloc
(
b
->
buf
,
b
->
len
+
l
en
);
if
(
!
b
->
buf
)
retry:
l
=
json_dumpb
(
j
,
buf
+
len
,
size
-
len
,
0
);
if
(
size
<
len
+
l
)
{
buf
=
(
char
*
)
realloc
(
buf
,
len
+
l
);
if
(
!
buf
)
return
-
1
;
b
->
size
=
b
->
len
+
l
en
;
size
=
len
+
l
;
goto
retry
;
}
b
->
len
+=
l
en
;
len
+=
l
;
return
0
;
}
lib/common.cpp
View file @
90ff2f70
...
...
@@ -21,7 +21,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#include
<villas/common.h>
#include
<villas/common.h
pp
>
#include
<cstdlib>
...
...
lib/compat.cpp
View file @
90ff2f70
...
...
@@ -24,7 +24,7 @@
#include
<jansson.h>
#include
<unistd.h>
#include
<villas/compat.h>
#include
<villas/compat.h
pp
>
#if JANSSON_VERSION_HEX < 0x020A00
size_t
json_dumpb
(
const
json_t
*
json
,
char
*
buffer
,
size_t
size
,
size_t
flags
)
...
...
lib/hist.cpp
View file @
90ff2f70
...
...
@@ -28,6 +28,7 @@
#include
<villas/hist.hpp>
#include
<villas/config.h>
#include
<villas/table.hpp>
#include
<villas/exceptions.hpp>
using
namespace
villas
::
utils
;
...
...
@@ -188,6 +189,10 @@ void Hist::plot() const
char
*
Hist
::
dump
()
const
{
char
*
buf
=
new
char
[
128
];
if
(
!
buf
)
throw
RuntimeError
(
"Failed to allocate memory!"
);
memset
(
buf
,
0
,
128
);
strcatf
(
&
buf
,
"[ "
);
...
...
lib/json_buffer.cpp
View file @
90ff2f70
...
...
@@ -20,7 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#include
<villas/compat.h>
#include
<villas/compat.h
pp
>
#include
<villas/json_buffer.hpp>
using
namespace
villas
;
...
...
@@ -47,7 +47,7 @@ int JsonBuffer::encode(json_t *j)
int
JsonBuffer
::
callback
(
const
char
*
data
,
size_t
len
,
void
*
ctx
)
{
Buffer
*
b
=
static_cast
<
Buffer
*>
(
ctx
);
Json
Buffer
*
b
=
static_cast
<
Json
Buffer
*>
(
ctx
);
/* Append junk of JSON to buffer */
b
->
insert
(
b
->
end
(),
&
data
[
0
],
&
data
[
len
]);
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment