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

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