24 "yarp.carrier.portmonitor.bottle_zlib",
32void split(
const std::string& s,
char delim, std::vector<std::string>& elements)
34 std::istringstream iss(s);
36 while (std::getline(iss, item, delim)) {
37 elements.push_back(item);
44 std::vector<std::string> parameters;
45 split(carrierString,
'+', parameters);
48 for (std::string param : parameters)
51 auto pointPosition = param.find(
'.');
52 if (pointPosition == std::string::npos)
58 std::string paramKey = param.substr(0, pointPosition);
60 std::string s = param.substr(pointPosition + 1, param.length());
64 prop.
put(paramKey, paramValue);
71 std::string options_string=options.
toString();
72 m_shouldCompress = (options.
find(
"sender_side").
asBool());
79 m_debug_compression_size = m_user_params.
check(
"debug_compression_info");
136 size_t sizeUncompressed = 0;
137 const unsigned char* uncompressedData = (
const unsigned char*)(b.
toBinary(&sizeUncompressed));
139 size_t sizeCompressed = (sizeUncompressed * 1.1) + 12;
140 unsigned char* compressedData = (
unsigned char*) malloc (sizeCompressed);
143 bool ret=
compressData(uncompressedData, sizeUncompressed, compressedData, sizeCompressed);
147 yCError(BOTTLE_ZLIB_MONITOR,
"Failed to compress, exiting...");
148 free(compressedData);
153 Value v(compressedData, sizeCompressed);
158 if (m_debug_compression_size)
160 yCDebug(BOTTLE_ZLIB_MONITOR) <<
"uncompressed size:" << sizeUncompressed
161 <<
"compressed size" << sizeCompressed
162 <<
"ratio:" << (double)sizeUncompressed/(
double)sizeCompressed <<
":1"
163 <<
"time:" << end_time - start_time;
166 free(compressedData);
173 size_t sizeUncompressed = b->
get(0).
asInt32();
175 const unsigned char* CompressedData = (
const unsigned char*) b->
get(1).
asBlob();
177 unsigned char* uncompressedData = (
unsigned char*)malloc(sizeUncompressed);
180 bool ret =
decompressData(CompressedData, sizeCompressed, uncompressedData, sizeUncompressed);
184 yCError(BOTTLE_ZLIB_MONITOR,
"Failed to decompress, exiting...");
185 free(uncompressedData);
189 m_data.
fromBinary((
const char*)(uncompressedData),sizeUncompressed);
192 if (m_debug_compression_size)
194 yCDebug(BOTTLE_ZLIB_MONITOR) <<
"uncompressed size:" << sizeUncompressed
195 <<
"compressed size" << sizeCompressed
196 <<
"ratio:" << (double)sizeUncompressed / (
double)sizeCompressed <<
":1"
197 <<
"time:" << end_time - start_time;
200 free(uncompressedData);
208 int z_result = compress((Bytef*)out, (uLongf*)&out_size, (Bytef*)in, in_size);
215 yCError(BOTTLE_ZLIB_MONITOR,
"zlib compression: out of memory");
220 yCError(BOTTLE_ZLIB_MONITOR,
"zlib compression: output buffer wasn't large enough");
230 int z_result = uncompress((Bytef*)out, (uLongf*)&out_size, (
const Bytef*)in, in_size);
237 yCError(BOTTLE_ZLIB_MONITOR,
"zlib compression: out of memory");
242 yCError(BOTTLE_ZLIB_MONITOR,
"zlib compression: output buffer wasn't large enough");
247 yCError(BOTTLE_ZLIB_MONITOR,
"zlib compression: file contains corrupted data");
void getParamsFromCommandLine(std::string carrierString, yarp::os::Property &prop)
void split(const std::string &s, char delim, std::vector< std::string > &elements)
bool setparam(const yarp::os::Property ¶ms) override
This will be called when the portmonitor carrier parameters are set via YARP admin port.
int decompressData(const unsigned char *in, const size_t &in_size, unsigned char *out, size_t &out_size)
int compressData(const unsigned char *in, const size_t &in_size, unsigned char *out, size_t &out_size)
void destroy() override
This will be called when the portmonitor object destroyes.
bool getparam(yarp::os::Property ¶ms) override
This will be called when the portmonitor carrier parameters are requested via YARP admin port.
bool accept(yarp::os::Things &thing) override
This will be called when the data reach the portmonitor object.
yarp::os::Things & update(yarp::os::Things &thing) override
After data get accpeted in the accept() callback, an instance of that is given to the update function...
bool create(const yarp::os::Property &options) override
This will be called when the dll is properly loaded by the portmonitor carrier.
A simple collection of objects that can be described and transmitted in a portable way.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void clear()
Empties the bottle of any objects it contains.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
const char * toBinary(size_t *size=nullptr)
Returns binary representation of bottle.
void fromBinary(const char *buf, size_t len)
Initializes bottle from a binary representation.
static LogCallback printCallback()
Get current print callback.
static LogType minimumPrintLevel()
Get current minimum print level.
This is a base class for objects that can be both read from and be written to the YARP network.
static bool copyPortable(const PortWriter &writer, PortReader &reader)
Copy one portable to another, via writing and reading.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
std::string toString() const override
Return a standard text representation of the content of the object.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Base class for generic things.
yarp::os::PortWriter * getPortWriter()
void setPortWriter(yarp::os::PortWriter *writer)
Set the reference to a PortWriter object.
A single value (typically within a Bottle).
virtual bool asBool() const
Get boolean value.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual size_t asBlobLength() const
Get binary data length.
virtual const char * asBlob() const
Get binary data value.
void fromString(const char *str)
Set value to correspond to a textual representation.
virtual std::string asString() const
Get string value.
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.