OpendTect-6_4  6.4
netsocket.h
Go to the documentation of this file.
1 #ifndef netsocket_h
2 #define netsocket_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: K. Tingdahl
9  Date: August 2014
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 
16 #include "networkmod.h"
17 #include "callback.h"
18 #include "threadlock.h"
19 #include "uistring.h"
20 
21 class BufferString;
22 template <class T> class DataInterpreter;
23 mFDQtclass(QTcpSocket)
25 
26 
27 namespace Network
28 {
29 
30 class RequestPacket;
31 
32 
44 mExpClass(Network) Socket : public CallBacker
45 { mODTextTranslationClass(Socket);
46 
47 public:
48  Socket(bool haveeventloop=true);
49  Socket(mQtclass(QTcpSocket)*,bool haveeventloop=true);
50  ~Socket();
51 
52  void setTimeout(int ms) { timeout_ = ms; }
53 
54  static const char* sKeyLocalHost() { return "localhost"; }
55 
56  bool connectToHost(const char* host,int port,
57  bool wait=true);
58  bool disconnectFromHost(bool wait=false);
59 
60  bool isBad() const;
61  bool isConnected() const;
62  od_int64 bytesAvailable() const;
63  uiString errMsg() const { return errmsg_; }
64  void abort();
65 
66  bool writeChar(char);
67  bool writeShort(short);
68  bool writeInt32(od_int32);
69  bool writeInt64(od_int64);
70  bool writeFloat(float);
71  bool writeDouble(double);
72  bool write(const OD::String&);
73  bool write(const IOPar&);
74 
75  bool write(const Network::RequestPacket&,bool wait=false);
76 
77  bool writeArray(const void*,od_int64,bool wait=false);
78  bool writeShortArray(const short*,od_int64,bool wait=false);
79  bool writeInt32Array(const od_int32*,od_int64,bool wait=false);
80  bool writeInt64Array(const od_int64*,od_int64,bool wait=false);
81  bool writeFloatArray(const float*,od_int64,bool wait=false);
82  bool writeDoubleArray(const double*,od_int64,bool wait=false);
83 
84  enum ReadStatus { ReadOK, Timeout, ReadError };
85  bool readChar(char&) const;
86  bool readShort(short&) const;
87  bool readInt32(od_int32&) const;
88  bool readInt64(od_int64&) const;
89  bool readFloat(float&) const;
90  bool readDouble(double&) const;
91  bool read(BufferString&) const;
92  bool read(IOPar&) const;
93  ReadStatus read(Network::RequestPacket&) const;
94 
95  ReadStatus readArray(void*,od_int64) const;
96  bool readShortArray(short*,od_int64) const;
97  bool readInt32Array(od_int32*,od_int64) const;
98  bool readInt64Array(od_int64*,od_int64) const;
99  bool readFloatArray(float*,od_int64) const;
100  bool readDoubleArray(double*,od_int64) const;
101 
102  Notifier<Socket> disconnected;
103  Notifier<Socket> readyRead;
107  const void* thread() const { return thread_; }
108 private:
109 
110  bool waitForConnected() const;
112  bool waitForNewData() const;
114  bool waitForWrite(bool all) const;
116 
117  mutable uiString errmsg_;
118  mutable Threads::Lock lock_;
119 
120  int timeout_;
121  bool noeventloop_;
122 
123  mQtclass(QTcpSocket)* qtcpsocket_;
124  bool ownssocket_;
125 
126  mQtclass(QTcpSocketComm)* socketcomm_;
127 
128  const void* thread_;
129 };
130 
131 
132 } // namespace Network
133 
134 
135 #endif
#define mExpClass(module)
Definition: commondefs.h:160
To be able to send and/or receive CallBacks, inherit from this class.
Definition: callback.h:272
#define mQtclass(cls)
Definition: commondefs.h:229
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class...
Definition: threadlock.h:53
Definition: jobcommunic.h:24
bool readChar(std::istream &, char &, bool allowreadingnewlines=false)
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
#define od_int64
Definition: plftypes.h:36
Definition: i_layout.h:35
Definition: uistring.h:89
Definition: netreqpacket.h:39
od_int64 bytesAvailable(const char *path)
Definition: callback.h:254
Byte-level data interpreter.
Definition: cbvswriter.h:22
Definition: qtcpsocketcomm.h:25
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:47
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:31
#define mFDQtclass(cls)
Definition: commondefs.h:228
#define od_int32
Definition: plftypes.h:31
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
BufferString errmsg_
Definition: horizontracker.h:119
const char * errMsg() const
Definition: horizontracker.h:61

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019