YARP
Yet Another Robot Platform
ServerGrabber.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 YARP_DEV_SERVERGRABBER_H
11 #define YARP_DEV_SERVERGRABBER_H
12 
13 #include <cstdio>
14 
20 #include <yarp/dev/PolyDriver.h>
22 #include <yarp/os/BufferedPort.h>
23 #include <yarp/os/Time.h>
24 #include <yarp/os/Network.h>
25 #include <yarp/os/PeriodicThread.h>
26 #include <yarp/os/Vocab.h>
27 #include <yarp/os/Bottle.h>
29 #include <yarp/dev/IWrapper.h>
31 
32 
33 class ServerGrabber;
34 
35 class DC1394Parser :
37 {
38 private:
39  yarp::dev::IFrameGrabberControlsDC1394 *fgCtrl_DC1394{nullptr};
40 
41 public:
42  DC1394Parser() = default;
43  ~DC1394Parser() override = default;
45  bool respond(const yarp::os::Bottle& cmd, yarp::os::Bottle& response) override;
46 };
47 
48 
51 {
52 private:
53  bool left{false};
54  ServerGrabber* server{nullptr};
55 public:
56  ServerGrabberResponder(bool _left = false);
57  ~ServerGrabberResponder() override = default;
58  bool configure(ServerGrabber* _server);
59  bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply) override;
60 };
61 
62 
64 {
65 // AV,
67  RAW,
68 };
69 
70 
72 {
73  bool spoke{false}; // location of this variable tickles bug on Solaris/gcc3.2
74  bool canDrop{true};
75  bool addStamp{false};
76  bool active{false};
77  bool singleThreaded{false};
78  bool twoCameras{false};
79  bool split{false};
80  bool splitterMode{false};
81  bool hasAudio{false};
83 };
84 
85 
86 #define DEFAULT_THREAD_PERIOD 0.03 //s
87 
88 
181  public yarp::dev::IWrapper,
184 {
185 private:
186  double period{DEFAULT_THREAD_PERIOD};
187  int count{0};
188  int count2{0};
189  ServerGrabberResponder* responder{nullptr};
190  ServerGrabberResponder* responder2{nullptr};
193  yarp::dev::IRgbVisualParams* rgbVis_p{nullptr};
194  yarp::dev::IRgbVisualParams* rgbVis_p2{nullptr};
195  std::string rpcPort_Name;
196  std::string rpcPort2_Name;
197  yarp::os::Port rpcPort;
198  yarp::os::Port rpcPort2;
199  std::string pImg_Name;
200  std::string pImg2_Name;
203  yarp::os::Port *p2{nullptr};//audio
204  yarp::dev::PolyDriver* poly{nullptr}; //subDeviceOwned convert to pointer
205  yarp::dev::PolyDriver* poly2{nullptr};
206  yarp::dev::IFrameGrabberImage *fgImage{nullptr};
207  yarp::dev::IFrameGrabberImage *fgImage2{nullptr};
208  yarp::dev::IFrameGrabberImageRaw *fgImageRaw{nullptr};
209  yarp::dev::IFrameGrabberImageRaw *fgImageRaw2{nullptr};
210  //yarp::sig::FlexImage doubleImage, doubleImage2;
211 // IAudioVisualGrabber *fgAv{nullptr}; //TODO: manage the AV
212  yarp::dev::IFrameGrabberControls *fgCtrl{nullptr};
213  yarp::dev::IFrameGrabberControls *fgCtrl2{nullptr};
214  yarp::dev::IFrameGrabberControlsDC1394* fgCtrl_DC1394{nullptr};
215  yarp::dev::IFrameGrabberControlsDC1394* fgCtrl2_DC1394{nullptr};
216  yarp::dev::IPreciselyTimed *fgTimed{nullptr};
219  DC1394Parser ifgCtrl_DC1394_Parser;
220  DC1394Parser ifgCtrl2_DC1394_Parser;
221  Configuration param;
225  yarp::sig::ImageOf<yarp::sig::PixelMono>* img2_Raw{nullptr};
226 
227  // Open the wrapper only, the attach method needs to be called before using it
228  // Typical usage: yarprobotinterface
229  bool openDeferredAttach(yarp::os::Searchable& prop);
230 
231  // If a subdevice parameter is given, the wrapper will open it(or them) and attach to immediately.
232  // Typical usage: simulator or command line
233  bool isSubdeviceOwned{false};
234  bool openAndAttachSubDevice(yarp::os::Searchable& prop);
235 
236 public:
237  ServerGrabber();
238  ServerGrabber(const ServerGrabber&) = delete;
242  ~ServerGrabber() override;
243 
244  //DeviceDriver
245  bool close() override;
251  bool open(yarp::os::Searchable& config) override;
252 
253  //bool read(ConnectionReader& connection) override;
254 
255  //DeviceResponder
256  bool respond(const yarp::os::Bottle& command,
257  yarp::os::Bottle& reply, bool left, bool both);
258  // IMultipleWrapper interface
259  bool attachAll(const yarp::dev::PolyDriverList &device2attach) override;
260 
261  bool detachAll() override;
262 
263  // IWrapper interface
264  bool attach(yarp::dev::PolyDriver *poly) override;
265 
266  bool detach() override;
267 
268  //RateThread
269  bool threadInit() override;
270 
271  void threadRelease() override;
272 
273  void run() override;
274 protected:
275 
276  bool fromConfig(yarp::os::Searchable &config);
277 
279 
280  void stopThread();
281 
282  void setupFlexImage(const yarp::sig::Image& img, yarp::sig::FlexImage& flex_i);
283 
285 
286  void cleanUp();
287 };
288 
289 #endif // YARP_DEV_SERVERGRABBER_H
define common interfaces to discover remote camera capabilities
Capabilities
Definition: ServerGrabber.h:64
@ COLOR
Definition: ServerGrabber.h:66
@ RAW
Definition: ServerGrabber.h:67
#define DEFAULT_THREAD_PERIOD
Definition: ServerGrabber.h:86
~DC1394Parser() override=default
DC1394Parser()=default
bool configure(yarp::dev::IFrameGrabberControlsDC1394 *interface)
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
ServerGrabberResponder(bool _left=false)
bool configure(ServerGrabber *_server)
bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply) override
Respond to a message.
~ServerGrabberResponder() override=default
void threadRelease() override
Release method.
~ServerGrabber() override
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
ServerGrabber & operator=(ServerGrabber &&)=delete
bool detach() override
Detach the object (you must have first called attach).
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
ServerGrabber(const ServerGrabber &)=delete
bool close() override
Close the DeviceDriver.
void setupFlexImage(const yarp::sig::Image &img, yarp::sig::FlexImage &flex_i)
void shallowCopyImages(const yarp::sig::FlexImage &src, yarp::sig::FlexImage &dest)
void run() override
Loop function.
ServerGrabber(ServerGrabber &&)=delete
bool detachAll() override
Detach the object (you must have first called attach).
ServerGrabber & operator=(const ServerGrabber &)=delete
bool initialize_YARP(yarp::os::Searchable &params)
bool attachAll(const yarp::dev::PolyDriverList &device2attach) override
Attach to a list of objects.
bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply, bool left, bool both)
bool fromConfig(yarp::os::Searchable &config)
bool threadInit() override
Initialization method.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
A cheap and cheerful framework for human readable/writable forms of messages to devices.
Definition: DeviceDriver.h:134
Control interface for frame grabber devices.
Read a YARP-format image from a device.
Read a YARP-format image from a device.
Interface for an object that can wrap/attach to to another.
An interface for retrieving intrinsic parameter from a rgb camera.
Definition: IVisualParams.h:73
Interface for an object that can wrap/or "attach" to another.
Definition: IWrapper.h:29
A container for a device driver.
Definition: PolyDriver.h:27
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
An abstraction for a periodic thread.
A mini-server for network communication.
Definition: Port.h:50
A base class for nested structures that can be searched.
Definition: Searchable.h:69
Image class with user control of representation details.
Definition: Image.h:403
Base class for storing images.
Definition: Image.h:85
Capabilities cap
Definition: ServerGrabber.h:82