cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsSocketProxyClient.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Peter Kazanzides
7  Created on: 2013-08-06
8 
9  (C) Copyright 2013-2014 Johns Hopkins University (JHU), All Rights Reserved.
10 
11 --- begin cisst license - do not edit ---
12 
13 This software is provided "as is" under an open source license, with
14 no warranty. The complete license can be found in license.txt and
15 http://www.cisst.org/cisst/license.txt.
16 
17 --- end cisst license ---
18 */
19 
20 
27 #ifndef _mtsSocketProxyClient_h
28 #define _mtsSocketProxyClient_h
29 
32 
35 
36 class CommandWrapperBase;
37 class mtsCommandBase;
38 
40 
42 {
44 public:
45  std::string Name;
46  std::string IP;
47  short Port;
48 
50  mtsSocketProxyClientConstructorArg(const std::string &name, const std::string &ip, short port) :
51  mtsGenericObject(), Name(name), IP(ip), Port(port) {}
53  Name(other.Name), IP(other.IP), Port(other.Port) {}
55 
56  void SerializeRaw(std::ostream & outputStream) const;
57  void DeSerializeRaw(std::istream & inputStream);
58 
59  void ToStream(std::ostream & outputStream) const;
60 
62  virtual void ToStreamRaw(std::ostream & outputStream, const char delimiter = ' ',
63  bool headerOnly = false, const std::string & headerPrefix = "") const;
64 
67  virtual bool FromStreamRaw(std::istream & inputStream, const char delimiter = ' ');
68 };
69 
71 
73 {
75 
76  protected:
77 
79  mtsProxySerializer *Serializer;
80 
82 
83  // For memory cleanup
84  std::vector<mtsCommandBase *> EventGenerators;
85 
88  void LocalUnblockingHandler(const mtsGenericObject &arg);
89  // Returns false if timed out
90  bool WaitForResponse(double timeoutInSec);
91 
96  bool CreateClientProxy(const std::string & providedInterfaceName);
97 
98  // For use by MulticastCommandVoidProxy and MulticastCommandWriteProxy
101  void EventEnable(const std::string &eventName, const char *handle);
102  void EventDisable(const std::string &eventName, const char *handle);
103 
104  void CheckForEvents(double timeoutInSec);
105 
106  friend class CommandWrapperBase;
107  friend class MulticastCommandVoidProxy;
108  friend class MulticastCommandWriteProxy;
109 
110  public:
116  mtsSocketProxyClient(const std::string &name, const std::string &ip, short port);
117 
119 
120 
122  virtual ~mtsSocketProxyClient();
123 
124  void Configure(const std::string &) {}
125 
126  void Startup(void);
127 
128  void Run(void);
129 
130  void Cleanup(void);
131 
132  // Following used by command wrappers
133  bool CheckForEventsImmediate(double timeoutInSec);
134  bool Serialize(const mtsGenericObject & originalObject, std::string & serializedObject);
135  bool DeSerialize(const std::string & serializedObject, mtsGenericObject & originalObject);
136  mtsGenericObject * DeSerialize(const std::string & serializedObject);
137 };
138 
140 
141 #endif // _mtsSocketProxyClient_h
std::vector< mtsCommandBase * > EventGenerators
Definition: mtsSocketProxyClient.h:84
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
mtsProxySerializer * Serializer
Definition: mtsSocketProxyClient.h:79
bool LocalWaiting
Definition: mtsSocketProxyClient.h:86
Definition: mtsSocketProxyClient.h:72
mtsSocketProxyClientConstructorArg(const mtsSocketProxyClientConstructorArg &other)
Definition: mtsSocketProxyClient.h:52
std::string IP
Definition: mtsSocketProxyClient.h:46
~mtsSocketProxyClientConstructorArg()
Definition: mtsSocketProxyClient.h:54
short Port
Definition: mtsSocketProxyClient.h:47
virtual void SerializeRaw(std::ostream &outputStream) const
virtual void DeSerializeRaw(std::istream &inputStream)
virtual void ToStream(std::ostream &outputStream) const
std::string Name
Definition: mtsSocketProxyClient.h:45
Base class for data object in cisstMultiTask.
Definition: mtsGenericObject.h:56
const int CMN_DYNAMIC_CREATION_ONEARG
Definition: cmnClassRegisterMacros.h:333
virtual bool FromStreamRaw(std::istream &inputStream, const char delimiter= ' ')
mtsSocketProxyClientConstructorArg(const std::string &name, const std::string &ip, short port)
Definition: mtsSocketProxyClient.h:50
Defines a continuously executing task.
mtsSocketProxyClientConstructorArg()
Definition: mtsSocketProxyClient.h:49
virtual void Startup(void)
Definition: mtsComponent.h:262
mtsCommandWriteBase * EventDisableCommand
Definition: mtsSocketProxyClient.h:100
mtsCommandWriteBase * EventEnableCommand
Definition: mtsSocketProxyClient.h:99
CMN_DECLARE_SERVICES_INSTANTIATION(mtsSocketProxyClientConstructorArg)
Definition: mtsCommandWriteBase.h:40
Definition: mtsSocketProxyCommon.h:79
Forward declarations and #define for cisstMultiTask.
Definition: mtsSocketProxyClient.h:41
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
mtsCommandWriteBase * localUnblockingCommand
Definition: mtsSocketProxyClient.h:87
virtual void Run(void)=0
Declaration of osaSocketThis is a cross-platform socket library with basic support for UDP (datagram)...
Definition: osaSocket.h:171
Rules of exporting.
osaSocket Socket
Definition: mtsSocketProxyClient.h:78
Common definitions for mtsSocketProxyClient and mtsSocketProxyServer.
Definition: mtsCommandBase.h:43
Definition: mtsTaskContinuous.h:77
const int CMN_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:331
virtual void ToStreamRaw(std::ostream &outputStream, const char delimiter= ' ', bool headerOnly=false, const std::string &headerPrefix="") const
virtual void Cleanup(void)
Definition: mtsComponent.h:267
void Configure(const std::string &)
Definition: mtsSocketProxyClient.h:124
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76
mtsSocketProxyInitData ServerData
Definition: mtsSocketProxyClient.h:81