Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
6be3b8de
Commit
6be3b8de
authored
Aug 08, 2016
by
Michael Ott
Browse files
Add SensorCache class to store latest sample of a sensor reading
parent
1978fdb2
Changes
3
Hide whitespace changes
Inline
Side-by-side
CollectAgent/Makefile
View file @
6be3b8de
...
...
@@ -2,6 +2,7 @@ include ../config.mk
CXXFLAGS
=
-O2
-g
--std
=
c++11
-Wall
-Wno-unused-local-typedefs
-Wno-deprecated-declarations
-Wno-unknown-warning-option
-fmessage-length
=
0
-I
$(DCDBDEPLOYPATH)
/include/
-I
$(DCDBBASEPATH)
/include/
-DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
OBJS
=
collectagent.o
\
sensorcache.o
\
simplemqttserver.o
\
simplemqttserverthread.o
\
simplemqttservermessage.o
...
...
CollectAgent/sensorcache.cpp
0 → 100644
View file @
6be3b8de
/*
* SensorCache.cpp
*
* Created on: 3 Aug 2016
* Author: ottmi
*/
#include
"sensorcache.h"
#include
<exception>
#include
<iostream>
namespace
DCDB
{
SensorCache
::
SensorCache
()
{
// TODO Auto-generated constructor stub
}
SensorCache
::~
SensorCache
()
{
// TODO Auto-generated destructor stub
}
void
SensorCache
::
storeSensor
(
SensorId
sid
,
uint64_t
ts
,
uint64_t
val
)
{
cacheEntry_t
e
(
val
,
ts
);
/* Remove the reserved bytes to leverage the standard find function */
sid
.
setRsvd
(
0
);
sensorCache
[
sid
]
=
e
;
}
uint64_t
SensorCache
::
getSensor
(
SensorId
sid
)
{
/* Remove the reserved bytes to leverage the standard find function */
sid
.
setRsvd
(
0
);
sensorCache_t
::
iterator
it
=
sensorCache
.
find
(
sid
);
if
(
it
==
sensorCache
.
end
())
{
throw
std
::
out_of_range
(
"Sid not found"
);
}
return
it
->
second
.
first
;
}
void
SensorCache
::
dump
()
{
sensorCache_t
::
iterator
it
;
std
::
cout
<<
"SensorCache Dump:"
<<
std
::
endl
;
for
(
it
=
sensorCache
.
begin
();
it
!=
sensorCache
.
end
();
it
++
)
{
std
::
cout
<<
" id="
<<
it
->
first
.
toString
()
<<
" val="
<<
it
->
second
.
first
<<
" ts="
<<
it
->
second
.
second
<<
std
::
endl
;
}
}
}
/* namespace DCDB */
CollectAgent/sensorcache.h
0 → 100644
View file @
6be3b8de
/*
* SensorCache.h
*
* Created on: 3 Aug 2016
* Author: ottmi
*/
#ifndef COLLECTAGENT_SENSORCACHE_H_
#define COLLECTAGENT_SENSORCACHE_H_
#include
<map>
#include
<utility>
#include
<dcdb/sensorid.h>
namespace
DCDB
{
typedef
std
::
pair
<
uint64_t
,
uint64_t
>
cacheEntry_t
;
typedef
std
::
map
<
SensorId
,
cacheEntry_t
>
sensorCache_t
;
class
SensorCache
{
public:
SensorCache
();
virtual
~
SensorCache
();
void
storeSensor
(
SensorId
sid
,
uint64_t
ts
,
uint64_t
val
);
uint64_t
getSensor
(
SensorId
sid
);
void
dump
();
private:
sensorCache_t
sensorCache
;
};
}
/* namespace DCDB */
#endif
/* COLLECTAGENT_SENSORCACHE_H_ */
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment