Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Redis Receiver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
BIAS
Receivers
Redis Receiver
Compare revisions
0c403c8b46b3379ae7fe777e518124e9e2477eb1 to c2d49ee2a1096498b8c06b469829dd11ef1c7246
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
bias/connection-protocols/redis-receiver
Select target project
No results found
c2d49ee2a1096498b8c06b469829dd11ef1c7246
Select Git revision
Swap
Target
bias/connection-protocols/redis-receiver
Select target project
bias/connection-protocols/redis-receiver
1 result
0c403c8b46b3379ae7fe777e518124e9e2477eb1
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
adding doxygen
· 5d6891df
Valerio Pastore
authored
1 year ago
5d6891df
.
· c2d49ee2
Valerio Pastore
authored
1 year ago
c2d49ee2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CMakeLists.txt
+1
-1
1 addition, 1 deletion
CMakeLists.txt
deps/Base-DAQ
+1
-1
1 addition, 1 deletion
deps/Base-DAQ
include/Redis_Receiver.h
+145
-18
145 additions, 18 deletions
include/Redis_Receiver.h
src/Redis_Receiver.cpp
+7
-9
7 additions, 9 deletions
src/Redis_Receiver.cpp
with
154 additions
and
29 deletions
CMakeLists.txt
View file @
c2d49ee2
cmake_minimum_required
(
VERSION 3.9
)
project
(
Redis_Receiver
)
set
(
CMAKE_CXX_STANDARD
17
)
set
(
CMAKE_CXX_STANDARD
20
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wall"
)
option
(
REDISRECEIVER_BUILD_SHARED
"Build Redisreceiver as a shared library."
OFF
)
...
...
This diff is collapsed.
Click to expand it.
Base-DAQ
@
a00f9a27
Compare
8a0ea2d0
...
a00f9a27
Subproject commit
8
a0
ea2d0e699863df5fe1c91caf2d7b0855957be
Subproject commit a0
0f9a27afbf5f75dab7db2368b9b9b6fcb395e1
This diff is collapsed.
Click to expand it.
include/Redis_Receiver.h
View file @
c2d49ee2
#pragma once
#include
<Base_Configurator.h>
#include
<hiredis/hiredis.h>
#include
<Base_Receiver.h>
/**
* @brief Namespace containing classes related to receiving data from Redis.
*/
namespace
inaf
::
oasbo
::
Receivers
{
/**
* @brief Class for receiving data from Redis.
* @details This class inherits from BaseReceiver and provides functionality to connect to a Redis server,
* receive data from it, and manage the connection.
* check the Base_Receiver.h file for more information.
*/
class
RedisReceiver
:
public
BaseReceiver
{
protected:
redisContext
*
context
=
nullptr
;
std
::
string
ip
{
};
int
port
;
std
::
string
key
;
redisContext
*
context
=
nullptr
;
/**< Pointer to the Redis context. */
std
::
string
ip
{
};
/**< IP address of the Redis server. */
int
port
;
/**< Port number of the Redis server. */
std
::
string
key
;
/**< Key used to access data in the Redis server. */
/**
* @brief Constructor for RedisReceiver.
* @param ip The IP address of the Redis server.
* @param prt The port number of the Redis server.
* @param key The key used to access data in the Redis server.
*/
RedisReceiver
(
std
::
string
ip
,
int
prt
,
std
::
string
key
);
/**
* @brief Default constructor for RedisReceiver.
*/
RedisReceiver
();
/**
* @brief Splits the IP address, port number, and key from a string.
* @param ip_port_key The string containing the IP address, port number, and key.
* @param ip The extracted IP address.
* @param port The extracted port number.
* @param key The extracted key.
* @return True if the string was successfully split, false otherwise.
*/
bool
split_ip_port_key
(
const
std
::
string
&
ip_port_key
,
std
::
string
&
ip
,
int
&
port
,
std
::
string
&
key
);
void
resetPacket
(
PacketLib
::
BasePacket
&
,
int
bytes
);
/**
* @brief Resets the first bytes of the packet to 0.
* @param pack The packet to reset.
* @param bytes The number of bytes to reset.
*/
void
resetPacket
(
Packets
::
BasePacket
&
packet
,
int
bytes
);
public
:
/**
* @brief Destructor for RedisReceiver.
*/
~
RedisReceiver
();
int
check_interval
;
int
check_interval
;
/**< The interval at which to check for new data in Redis. */
/**
* @brief Get the host name of the Redis server.
* @return The host name.
*/
std
::
string
getHost
()
override
;
/**
* @brief Set the host name of the Redis server.
* @param host The host name to set.
*/
void
setHost
(
std
::
string
host
)
override
;
void
setIp
(
std
::
string
);
/**
* @brief Set the IP address of the Redis server.
* @param ip The IP address to set.
*/
void
setIp
(
std
::
string
ip
);
/**
* @brief Get the IP address of the Redis server.
* @return The IP address.
*/
std
::
string
getIp
()
{
return
this
->
ip
;
}
void
setPort
(
int
);
/**
* @brief Set the port number of the Redis server.
* @param port The port number to set.
*/
void
setPort
(
int
port
);
/**
* @brief Get the port number of the Redis server.
* @return The port number.
*/
int
getPort
()
{
return
this
->
port
;
}
void
setKey
(
std
::
string
);
/**
* @brief Set the key used to access data in the Redis server.
* @param key The key to set.
*/
void
setKey
(
std
::
string
key
);
/**
* @brief Get the key used to access data in the Redis server.
* @return The key.
*/
std
::
string
getKey
()
{
return
this
->
key
;
}
int
connectToClient
()
override
;
int
closeConnectionToClient
()
override
;
bool
isConnectedToClient
()
const
override
;
int
receiveFromClient
(
PacketLib
::
BasePacket
&
)
override
;
int
receiveFromClient
(
Packets
::
BasePacket
&
packet
)
override
;
friend
class
RedisReceiverBuilder
;
};
/**
* @brief Builder class for creating RedisReceiver objects.
*/
class
RedisReceiverBuilder
{
protected:
RedisReceiver
*
receiver
;
RedisReceiver
*
receiver
;
/**< Pointer to the RedisReceiver object being built. */
public:
std
::
string
config_target
{
"redisreceiver"
};
std
::
string
ip_key
{
"ip"
};
std
::
string
port_key
{
"port"
};
std
::
string
key_key
{
"key"
};
std
::
string
checkinterval_key
{
"checkinterval"
};
std
::
string
config_target
{
"redisreceiver"
};
/**< The configuration target for the builder. */
std
::
string
ip_key
{
"ip"
};
/**< The configuration key for the IP address. */
std
::
string
port_key
{
"port"
};
/**< The configuration key for the port number. */
std
::
string
key_key
{
"key"
};
/**< The configuration key for the Redis key. */
std
::
string
checkinterval_key
{
"checkinterval"
};
/**< The configuration key for the check interval. */
/**
* @brief Default constructor for RedisReceiverBuilder.
*/
RedisReceiverBuilder
();
/**
* @brief Constructor for RedisReceiverBuilder.
* @param ip The IP address of the Redis server.
* @param port The port number of the Redis server.
* @param key The key used to access data in the Redis server.
*/
RedisReceiverBuilder
(
std
::
string
ip
,
int
port
,
std
::
string
key
);
/**
* @brief Destructor for RedisReceiverBuilder.
*/
~
RedisReceiverBuilder
();
/**
* @brief Reset the builder to its initial state.
*/
void
reset
();
/**
* @brief Configure the builder from a configurator object.
* @param conf The configurator object to configure from.
* @return A pointer to the builder.
*/
RedisReceiverBuilder
*
configFrom
(
Configurators
::
BaseConfigurator
&
conf
);
/**
* @brief Set the IP address of the Redis server.
* @param ip The IP address to set.
* @return A pointer to the builder.
*/
RedisReceiverBuilder
*
setIp
(
std
::
string
ip
);
/**
* @brief Set the port number of the Redis server.
* @param port The port number to set.
* @return A pointer to the builder.
*/
RedisReceiverBuilder
*
setPort
(
int
port
);
/**
* @brief Set the key used to access data in the Redis server.
* @param key The key to set.
* @return A pointer to the builder.
*/
RedisReceiverBuilder
*
setKey
(
std
::
string
key
);
/**
* @brief Get the built RedisReceiver object.
* @return A pointer to the RedisReceiver object.
*/
RedisReceiver
*
getReceiver
();
};
}
This diff is collapsed.
Click to expand it.
src/Redis_Receiver.cpp
View file @
c2d49ee2
...
...
@@ -51,8 +51,7 @@ int RedisReceiver::connectToClient() {
}
time_t
now
=
time
(
nullptr
);
std
::
cout
<<
"["
<<
std
::
put_time
(
localtime
(
&
now
),
"%Y-%m-%d %H:%M:%S"
)
<<
"]
\t
[Redis Receiver]
\t
"
<<
"Connected"
<<
std
::
endl
;
<<
"]
\t
[Redis Receiver]
\t
"
<<
"Connected"
<<
std
::
endl
;
return
1
;
}
...
...
@@ -68,7 +67,7 @@ bool RedisReceiver::isConnectedToClient() const {
return
!
(
context
==
nullptr
||
context
->
err
);
}
int
RedisReceiver
::
receiveFromClient
(
Packet
Lib
::
BasePacket
&
pack
)
{
int
RedisReceiver
::
receiveFromClient
(
Packet
s
::
BasePacket
&
pack
)
{
if
(
!
isConnectedToClient
())
{
if
(
context
)
{
time_t
now
=
time
(
nullptr
);
...
...
@@ -92,25 +91,24 @@ int RedisReceiver::receiveFromClient(PacketLib::BasePacket &pack) {
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
this
->
check_interval
));
return
-
1
;
}
if
(
r
->
type
==
REDIS_REPLY_NIL
){
if
(
r
->
type
==
REDIS_REPLY_NIL
)
{
freeReplyObject
(
r
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
this
->
check_interval
));
return
0
;
}
if
(
r
->
type
==
REDIS_REPLY_ERROR
)
{
if
(
r
->
type
==
REDIS_REPLY_ERROR
)
{
freeReplyObject
(
r
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
this
->
check_interval
));
return
-
1
;
}
if
(
r
->
type
==
REDIS_REPLY_STRING
&&
r
->
type
!=
REDIS_REPLY_NIL
)
{
if
(
r
->
type
==
REDIS_REPLY_STRING
&&
r
->
type
!=
REDIS_REPLY_NIL
)
{
// Received
int
size
=
r
->
len
;
ssize_t
header_size
=
pack
.
getHeaderSize
();
if
(
size
<
header_size
)
{
freeReplyObject
(
r
);
return
-
1
;
}
pack
.
copyToMemory
(
reinterpret_cast
<
uint8_t
*>
(
r
->
str
),
header_size
);
pack
.
copyToMemory
(
reinterpret_cast
<
uint8_t
*>
(
r
->
str
),
header_size
);
ssize_t
tot_packet_size
=
pack
.
getHeaderSize
()
+
pack
.
getPayloadSize
()
+
pack
.
getTailSize
();
...
...
@@ -203,7 +201,7 @@ bool RedisReceiver::split_ip_port_key(const std::string &ip_port_key,
return
true
;
}
void
RedisReceiver
::
resetPacket
(
Packet
Lib
::
BasePacket
&
pack
,
int
bytes
)
{
void
RedisReceiver
::
resetPacket
(
Packet
s
::
BasePacket
&
pack
,
int
bytes
)
{
uint8_t
*
buff
=
new
uint8_t
[
bytes
];
std
::
memset
(
buff
,
0
,
bytes
);
int
toBeReset
=
std
::
min
(
...
...
This diff is collapsed.
Click to expand it.