OpendTect  6.6
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  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 
15 #include "networkcommon.h"
16 
17 #include "threadlock.h"
18 #include "uistring.h"
19 
20 template <class T> class DataInterpreter;
21 mFDQtclass(QLocalSocket)
22 mFDQtclass(QObject)
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 islocal,bool haveeventloop=true);
49  explicit Socket(mQtclass(QTcpSocket)*,bool haveeventloop=true);
50  explicit Socket(mQtclass(QLocalSocket)*,bool haveeventloop=true);
51  ~Socket();
52 
53  void setTimeout(int ms) { timeout_ = ms; }
54 
55  static const char* sKeyLocalHost() { return "localhost"; }
56 
57  bool connectToHost(const Authority&,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  bool isLocal() const { return qlocalsocket_; }
66 
67  bool writeChar(char);
68  bool writeShort(short);
69  bool writeInt32(od_int32);
70  bool writeInt64(od_int64);
71  bool writeFloat(float);
72  bool writeDouble(double);
73  bool write(const OD::String&);
74  bool write(const IOPar&);
75 
76  bool write(const Network::RequestPacket&,bool wait=false);
77 
78  bool writeArray(const void*,od_int64,bool wait=false);
79  bool writeShortArray(const short*,od_int64,bool wait=false);
80  bool writeInt32Array(const od_int32*,od_int64,bool wait=false);
81  bool writeInt64Array(const od_int64*,od_int64,bool wait=false);
82  bool writeFloatArray(const float*,od_int64,bool wait=false);
83  bool writeDoubleArray(const double*,od_int64,bool wait=false);
84 
85  enum ReadStatus { ReadOK, Timeout, ReadError };
86  bool readChar(char&) const;
87  bool readShort(short&) const;
88  bool readInt32(od_int32&) const;
89  bool readInt64(od_int64&) const;
90  bool readFloat(float&) const;
91  bool readDouble(double&) const;
92  bool read(BufferString&) const;
93  bool read(IOPar&) const;
94  ReadStatus read(Network::RequestPacket&) const;
95 
96  ReadStatus readArray(void*,od_int64) const;
97  bool readShortArray(short*,od_int64) const;
98  bool readInt32Array(od_int32*,od_int64) const;
99  bool readInt64Array(od_int64*,od_int64) const;
100  bool readFloatArray(float*,od_int64) const;
101  bool readDoubleArray(double*,od_int64) const;
102 
103  Notifier<Socket> disconnected;
104  Notifier<Socket> readyRead;
107  Notifier<Socket> error;
108 
109 
110  Threads::ThreadID thread() const { return thread_; }
111 
112  mQtclass(QObject)* qSocket();
113 private:
114 
115  bool waitForConnected() const;
117  bool waitForNewData() const;
119  bool waitForWrite(bool all) const;
121 
122  mutable uiString errmsg_;
123  QString getSocketErrMsg() const;
124  mutable Threads::Lock lock_;
125 
126  int timeout_ = 30000;
127  bool noeventloop_;
128 
129  mQtclass(QTcpSocket)* qtcpsocket_ = nullptr;
130  mQtclass(QLocalSocket)* qlocalsocket_ = nullptr;
131  bool ownssocket_;
132 
133  mQtclass(QTcpSocketComm)* socketcomm_;
134 
135  uiString readErrMsg() const;
136  uiString noConnErrMsg() const;
137 
138  const Threads::ThreadID thread_;
139 };
140 
141 
142 } // namespace Network
Network::RequestPacket
Definition: netreqpacket.h:53
MPE::errMsg
const char * errMsg() const
Definition: horizontracker.h:60
uistring.h
od_int64
#define od_int64
Definition: plftypes.h:35
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
Network
Definition: jobcommunic.h:22
CallBacker
Inherit from this class to be able to send and/or receive CallBacks.
Definition: callback.h:185
DataInterpreter
Byte-level data interpreter.
Definition: cbvswriter.h:21
mODTextTranslationClass
#define mODTextTranslationClass(clss)
Definition: uistring.h:40
System::bytesAvailable
od_int64 bytesAvailable(const char *path)
Threads::ThreadID
void * ThreadID
Definition: thread.h:34
Notifier
Class to help setup a callback handling.
Definition: notify.h:126
all
@ all
Definition: i_layout.h:35
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
networkcommon.h
mQtclass
#define mQtclass(cls)
Definition: commondefs.h:234
uiString
String that is able to hold international (UTF-8) strings for the user interface.
Definition: uistring.h:121
mFDQtclass
mFDQtclass(QLocalSocket) mFDQtclass(QObject) mFDQtclass(QTcpSocket) mFDQtclass(QTcpSocketComm) namespace Network
Definition: netsocket.h:21
od_int32
#define od_int32
Definition: plftypes.h:30
OD::String
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:31
MPE::errmsg_
BufferString errmsg_
Definition: horizontracker.h:118
threadlock.h
StrmOper::readChar
bool readChar(std::istream &, char &, bool allowreadingnewlines=false)
Threads::Lock
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class.
Definition: threadlock.h:53
IOPar
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:55
QTcpSocketComm
Definition: qtcpsocketcomm.h:27

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