Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
File 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
File Receiver
Compare revisions
e06b5132e2da1e49d4338be58d913b6304e5df8a to a5881a457f74ea6f5b9b1320d02cc4fda2046821
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/file-receiver
Select target project
No results found
a5881a457f74ea6f5b9b1320d02cc4fda2046821
Select Git revision
Branches
main
Tags
v1.0
Swap
Target
bias/connection-protocols/file-receiver
Select target project
bias/connection-protocols/file-receiver
1 result
e06b5132e2da1e49d4338be58d913b6304e5df8a
Select Git revision
Branches
main
Tags
v1.0
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
adding doxygen
· 1e787d85
Valerio Pastore
authored
1 year ago
1e787d85
.
· a5881a45
Valerio Pastore
authored
1 year ago
a5881a45
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
deps/Base-DAQ
+1
-1
1 addition, 1 deletion
deps/Base-DAQ
include/File_Receiver.h
+95
-14
95 additions, 14 deletions
include/File_Receiver.h
src/Builder.cpp
+5
-4
5 additions, 4 deletions
src/Builder.cpp
src/File_Receiver.cpp
+21
-15
21 additions, 15 deletions
src/File_Receiver.cpp
with
122 additions
and
34 deletions
Base-DAQ
@
a00f9a27
Compare
8a0ea2d0
...
a00f9a27
Subproject commit
8
a0
ea2d0e699863df5fe1c91caf2d7b0855957be
Subproject commit a0
0f9a27afbf5f75dab7db2368b9b9b6fcb395e1
This diff is collapsed.
Click to expand it.
include/File_Receiver.h
View file @
a5881a45
#pragma once
#include
<Base_Receiver.h>
...
...
@@ -9,24 +8,66 @@
#define RAW_FILES_PATH std::string(std::getenv("HOME")).append("/BIAS/config/RawTestFiles")
#endif
/**
* @brief The namespace inaf::oasbo::Receivers contains classes related to receiving data.
*/
namespace
inaf
::
oasbo
::
Receivers
{
/**
* @brief The FileReceiver class is a derived class of BaseReceiver and is responsible for receiving packets from files.
* check the Base_Receiver.h file for more information.
*/
class
FileReceiver
:
public
BaseReceiver
{
protected:
/**
* @brief Constructs a FileReceiver object with a source and a rate.
* @param source The source files to receive.
* @param rate The rate at which the packets are received.
*/
FileReceiver
(
std
::
string
source
,
int
rate
);
/**
* @brief Constructs a FileReceiver object with a source.
* @param source The source files to receive.
*/
FileReceiver
(
std
::
string
source
);
/**
* @brief Constructs a FileReceiver object.
*/
FileReceiver
();
std
::
ifstream
*
ifile
=
nullptr
;
ssize_t
filesize
=
0
;
std
::
vector
<
std
::
string
>
filesToProcess
;
size_t
filesCount
=
0
;
std
::
ifstream
*
ifile
=
nullptr
;
/**< Pointer to the input file stream. */
ssize_t
filesize
=
0
;
/**< The size of the file being received. */
std
::
vector
<
std
::
string
>
filesToProcess
;
/**< Vector of files to process. */
size_t
filesCount
=
0
;
/**< The number of files to process. */
/**
* @brief Opens the next file to process.
* @return integer representing the status of the operation.
*/
int
openNextFile
();
void
resetPacket
(
PacketLib
::
BasePacket
&
pack
,
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
&
pack
,
int
bytes
);
/**
* @brief Resolves the environment variable in the given path.
* @param path The path containing the environment variable.
* @return The resolved path.
*/
std
::
string
resolveEnvVar
(
std
::
string
path
);
public:
int
rate
;
int
rate
;
/**< The rate at which the packets are received. */
/**
* @brief Destructor for the FileReceiver class.
*/
~
FileReceiver
();
std
::
string
getHost
()
override
;
...
...
@@ -35,25 +76,65 @@ public:
int
connectToClient
()
override
;
int
closeConnectionToClient
()
override
;
bool
isConnectedToClient
()
const
override
;
int
receiveFromClient
(
Packet
Lib
::
BasePacket
&
)
override
;
int
receiveFromClient
(
Packet
s
::
BasePacket
&
)
override
;
friend
class
FileReceiverBuilder
;
};
/**
* @brief The FileReceiverBuilder class is responsible for building FileReceiver objects.
*/
class
FileReceiverBuilder
{
protected:
FileReceiver
*
rcv
;
std
::
string
sourceFile
;
FileReceiver
*
rcv
;
/**< Pointer to the FileReceiver object being built. */
std
::
string
sourceFile
;
/**< The source file for the FileReceiver object. */
public:
std
::
string
config_target
{
"filereceiver"
};
std
::
string
source_key
{
"source"
};
std
::
string
rate_key
{
"rate"
};
std
::
string
config_target
{
"filereceiver"
};
/**< The configuration target for the FileReceiverBuilder. */
std
::
string
source_key
{
"source"
};
/**< The source key for the FileReceiverBuilder. */
std
::
string
rate_key
{
"rate"
};
/**< The rate key for the FileReceiverBuilder. */
/**
* @brief Constructs a FileReceiverBuilder object.
*/
FileReceiverBuilder
();
/**
* @brief Destructor for the FileReceiverBuilder class.
*/
~
FileReceiverBuilder
();
/**
* @brief Resets the FileReceiverBuilder object.
*/
void
reset
();
/**
* @brief Configures the FileReceiverBuilder object from a BaseConfigurator object.
* @param conf The BaseConfigurator object to configure from.
* @return A pointer to the FileReceiverBuilder object.
*/
FileReceiverBuilder
*
configFrom
(
Configurators
::
BaseConfigurator
&
conf
);
/**
* @brief Sets the source for the FileReceiverBuilder object.
* @param source The source of the files to receive.
* @return A pointer to the FileReceiverBuilder object.
*/
FileReceiverBuilder
*
setSource
(
std
::
string
source
);
/**
* @brief Sets the rate for the FileReceiverBuilder object.
* @param rate The rate at which the files are received.
* @return A pointer to the FileReceiverBuilder object.
*/
FileReceiverBuilder
*
setRate
(
int
rate
);
/**
* @brief Gets the built FileReceiver object.
* @return A pointer to the built FileReceiver object.
*/
FileReceiver
*
getReceiver
();
};
}
}
// namespace inaf::oasbo::Receivers
This diff is collapsed.
Click to expand it.
src/Builder.cpp
View file @
a5881a45
...
...
@@ -13,16 +13,17 @@ void FileReceiverBuilder::reset() {
this
->
rcv
=
new
FileReceiver
();
}
FileReceiverBuilder
*
FileReceiverBuilder
::
configFrom
(
Configurators
::
BaseConfigurator
&
conf
)
{
FileReceiverBuilder
*
FileReceiverBuilder
::
configFrom
(
Configurators
::
BaseConfigurator
&
conf
)
{
conf
.
readConfigFromSource
(
config_target
);
std
::
map
<
std
::
string
,
std
::
string
>
params
=
conf
.
getConfig
();
std
::
string
key
=
config_target
+
"_"
+
source_key
;
std
::
string
key
=
config_target
+
"_"
+
source_key
;
if
(
params
.
count
(
key
)
>
0
)
rcv
->
setHost
(
params
[
key
]);
key
=
config_target
+
"_"
+
rate_key
;
if
(
params
.
count
(
key
)
>
0
){
key
=
config_target
+
"_"
+
rate_key
;
if
(
params
.
count
(
key
)
>
0
)
{
rcv
->
rate
=
std
::
stoi
(
params
[
key
]);
}
return
this
;
...
...
This diff is collapsed.
Click to expand it.
src/File_Receiver.cpp
View file @
a5881a45
...
...
@@ -31,7 +31,7 @@ FileReceiver::FileReceiver(std::string source, int rate) :
this
->
setHost
(
source
);
}
int
FileReceiver
::
receiveFromClient
(
Packet
Lib
::
BasePacket
&
pack
)
{
int
FileReceiver
::
receiveFromClient
(
Packet
s
::
BasePacket
&
pack
)
{
if
(
ifile
->
tellg
()
==
filesize
)
{
// end of file, open next
if
(
!
openNextFile
())
{
// all file processed
closeConnectionToClient
();
...
...
@@ -75,18 +75,21 @@ int FileReceiver::connectToClient() {
namespace
fs
=
std
::
filesystem
;
std
::
string
s
=
resolveEnvVar
(
host
);
fs
::
path
source
(
s
);
if
(
!
std
::
filesystem
::
exists
(
source
))
{
time_t
now
=
time
(
nullptr
);
std
::
cerr
<<
"["
<<
std
::
put_time
(
localtime
(
&
now
),
"%Y-%m-%d %H:%M:%S"
)
<<
"]
\t
[File Receiver]
\t
"
<<
host
<<
" does not exists!"
<<
std
::
endl
;
return
-
1
;
}
if
(
!
std
::
filesystem
::
exists
(
source
))
{
time_t
now
=
time
(
nullptr
);
std
::
cerr
<<
"["
<<
std
::
put_time
(
localtime
(
&
now
),
"%Y-%m-%d %H:%M:%S"
)
<<
"]
\t
[File Receiver]
\t
"
<<
host
<<
" does not exists!"
<<
std
::
endl
;
return
-
1
;
}
if
(
std
::
filesystem
::
is_regular_file
(
source
))
{
// host is only one file, not a folder.
filesToProcess
.
push_back
(
source
);
}
else
{
// host is a folder, so iterates over all files into the folder
for
(
const
auto
&
entry
:
std
::
filesystem
::
recursive_directory_iterator
(
source
))
{
for
(
const
auto
&
entry
:
std
::
filesystem
::
recursive_directory_iterator
(
source
))
{
if
(
entry
.
is_regular_file
())
{
filesToProcess
.
push_back
(
entry
.
path
().
string
());
}
...
...
@@ -94,7 +97,7 @@ int FileReceiver::connectToClient() {
}
// sort alphabetically
std
::
sort
(
filesToProcess
.
begin
(),
filesToProcess
.
end
());
std
::
sort
(
filesToProcess
.
begin
(),
filesToProcess
.
end
());
if
(
!
openNextFile
())
// try to open first file
return
-
1
;
...
...
@@ -127,7 +130,7 @@ FileReceiver::~FileReceiver() {
}
}
void
FileReceiver
::
resetPacket
(
Packet
Lib
::
BasePacket
&
pack
,
int
bytes
)
{
void
FileReceiver
::
resetPacket
(
Packet
s
::
BasePacket
&
pack
,
int
bytes
)
{
uint8_t
*
buff
=
new
uint8_t
[
bytes
];
std
::
memset
(
buff
,
0
,
bytes
);
int
toBeReset
=
std
::
min
(
...
...
@@ -141,27 +144,30 @@ int FileReceiver::openNextFile() {
ifile
=
new
std
::
ifstream
(
filesToProcess
.
at
(
filesCount
),
std
::
ios
::
binary
);
if
(
!
ifile
->
is_open
())
{
time_t
now
=
time
(
nullptr
);
std
::
cerr
<<
"["
<<
std
::
put_time
(
localtime
(
&
now
),
"%Y-%m-%d %H:%M:%S"
)
<<
"]
\t
[File Receiver]
\t
"
<<
"Cannot open "
time_t
now
=
time
(
nullptr
);
std
::
cerr
<<
"["
<<
std
::
put_time
(
localtime
(
&
now
),
"%Y-%m-%d %H:%M:%S"
)
<<
"]
\t
[File Receiver]
\t
"
<<
"Cannot open "
<<
filesToProcess
.
at
(
filesCount
)
<<
std
::
endl
;
ifile
=
nullptr
;
filesCount
+=
1
;
continue
;
// go to next file
}
time_t
now
=
time
(
nullptr
);
std
::
cout
<<
"["
<<
std
::
put_time
(
localtime
(
&
now
),
"%Y-%m-%d %H:%M:%S"
)
<<
"]
\t
[File Receiver]
\t
"
<<
"Processing "
<<
filesToProcess
.
at
(
filesCount
)
<<
std
::
endl
;
time_t
now
=
time
(
nullptr
);
std
::
cout
<<
"["
<<
std
::
put_time
(
localtime
(
&
now
),
"%Y-%m-%d %H:%M:%S"
)
<<
"]
\t
[File Receiver]
\t
"
<<
"Processing "
<<
filesToProcess
.
at
(
filesCount
)
<<
std
::
endl
;
// compute filesize
ifile
->
seekg
(
0
,
std
::
ios
::
end
);
filesize
=
ifile
->
tellg
();
ifile
->
seekg
(
0
,
std
::
ios
::
beg
);
filesCount
+=
1
;
return
1
;
}
return
0
;
// all file processed
}
std
::
string
FileReceiver
::
resolveEnvVar
(
std
::
string
path
)
{
// resolve env var if present
if
(
path
.
at
(
0
)
==
'$'
)
{
...
...
This diff is collapsed.
Click to expand it.