YARP
Yet Another Robot Platform
WireBottle.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP2_WIREBOTTLE
11 #define YARP2_WIREBOTTLE
12 
13 #include <yarp/os/SizedWriter.h>
14 
16 
17 namespace yarp {
18 namespace wire_rep_utils {
19 
22 {
23 private:
24  yarp::os::SizedWriter *delegate;
25  size_t payload_index, payload_offset;
26 public:
27  void setDelegate(yarp::os::SizedWriter *delegate, int index,
28  int offset) {
29  this->delegate = delegate;
30  payload_index = index;
31  payload_offset = offset;
32  }
33 
34  size_t length() const override {
35  return delegate->length()-payload_index;
36  }
37 
38  size_t headerLength() const override {
39  return 0; // not supported
40  }
41 
42  size_t length(size_t index) const override {
43  index += payload_index;
44  if (index==payload_index) return delegate->length(index)-payload_offset;
45  return delegate->length(index);
46  }
47 
48  const char *data(size_t index) const override {
49  index += payload_index;
50  if (index==payload_index) return delegate->data(index)+payload_offset;
51  return delegate->data(index);
52  }
53 
55  return delegate->getReplyHandler();
56  }
57 
59  return delegate->getReference();
60  }
61 
62  bool dropRequested() override { return false; }
63 
64 
65  void startWrite() const override {
66  }
67 
68  void stopWrite() const override {
69  }
70 };
71 
73 {
74 public:
75  static bool checkBottle(void *cursor, int len);
76  static bool extractBlobFromBottle(yarp::os::SizedWriter& src,
77  SizedWriterTail& dest);
78 };
79 
80 } // namespace wire_rep_utils
81 } // namespace yarp
82 
83 #endif
yarp::wire_rep_utils::SizedWriterTail::stopWrite
void stopWrite() const override
Call when all writing is finished.
Definition: WireBottle.h:68
yarp::os::SizedWriter::length
virtual size_t length() const =0
YARP_wire_rep_utils_API
#define YARP_wire_rep_utils_API
Definition: api.h:15
yarp::os::Portable
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:29
yarp::wire_rep_utils::SizedWriterTail::headerLength
size_t headerLength() const override
Definition: WireBottle.h:38
yarp::wire_rep_utils::SizedWriterTail::dropRequested
bool dropRequested() override
Definition: WireBottle.h:62
yarp::wire_rep_utils::SizedWriterTail::length
size_t length() const override
Definition: WireBottle.h:34
yarp::os::SizedWriter::getReference
virtual Portable * getReference()=0
yarp::wire_rep_utils::SizedWriterTail
Definition: WireBottle.h:22
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
api.h
yarp::wire_rep_utils::SizedWriterTail::setDelegate
void setDelegate(yarp::os::SizedWriter *delegate, int index, int offset)
Definition: WireBottle.h:27
checkBottle
static char * checkBottle(char *cursor, int &remaining, int ct, int list_tag)
Definition: WireBottle.cpp:25
yarp::wire_rep_utils::SizedWriterTail::getReplyHandler
yarp::os::PortReader * getReplyHandler() override
Definition: WireBottle.h:54
yarp::os::SizedWriter::getReplyHandler
virtual PortReader * getReplyHandler()=0
yarp::wire_rep_utils::SizedWriterTail::startWrite
void startWrite() const override
Call when writing is about to begin.
Definition: WireBottle.h:65
yarp::wire_rep_utils::SizedWriterTail::getReference
yarp::os::Portable * getReference() override
Definition: WireBottle.h:58
yarp::wire_rep_utils::SizedWriterTail::data
const char * data(size_t index) const override
Definition: WireBottle.h:48
yarp::wire_rep_utils::WireBottle
Definition: WireBottle.h:73
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::SizedWriter::data
virtual const char * data(size_t index) const =0
yarp::wire_rep_utils::SizedWriterTail::length
size_t length(size_t index) const override
Definition: WireBottle.h:42
SizedWriter.h
yarp::os::SizedWriter
Minimal requirements for an efficient Writer.
Definition: SizedWriter.h:36