DLS  1.6
Dir.h
1 /*****************************************************************************
2  *
3  * This file is part of the Data Logging Service (DLS).
4  *
5  * DLS is free software: you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version.
9  *
10  * DLS is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with DLS. If not, see <http://www.gnu.org/licenses/>.
17  *
18  ****************************************************************************/
19 
20 #ifndef LibDLSDirH
21 #define LibDLSDirH
22 
23 /****************************************************************************/
24 
25 #include <string>
26 #include <list>
27 
28 #ifdef _WIN32
29 #include <ws2tcpip.h>
30 #endif
31 
32 #include "globals.h"
33 #include "Exception.h"
34 #include "Job.h"
35 
36 /****************************************************************************/
37 
38 namespace DlsProto {
39  class Request;
40  class Response;
41  class DirInfo;
42 }
43 
44 namespace google {
45  namespace protobuf {
46  class Message;
47  }
48 }
49 
50 namespace LibDLS {
51 
52 /****************************************************************************/
53 
57  public Exception
58 {
59  public:
60  DirectoryException(const std::string &pmsg):
61  Exception(pmsg) {};
62 };
63 
64 /****************************************************************************/
65 
69 {
70  public:
71  virtual void update() = 0;
72 };
73 
74 /****************************************************************************/
75 
76 class SocketStream;
77 
78 /****************************************************************************/
79 
83 {
84  friend class Job;
85  friend class Channel;
86 
87  public:
88  Directory(const std::string & = std::string());
89  ~Directory();
90 
91  void set_uri(const std::string &);
92  const std::string &uri() const { return _uri_text; }
93 
94  enum Access {
95  Unknown,
96  Local,
97  Network
98  };
99  Access access() const { return _access; }
100 
101  const std::string &path() const { return _path; }
102  const std::string &host() const { return _host; }
103  const std::string &port() const { return _port; }
104 
105  void import();
106 
107  bool connected() const {
108 #ifdef _WIN32
109  return _sock != INVALID_SOCKET;
110 #else
111  return _sock != -1;
112 #endif
113  }
114 
115  std::list<Job *> &jobs() { return _jobs; }
116  Job *job(unsigned int);
117  Job *find_job(unsigned int);
118 
119  void set_dir_info(DlsProto::DirInfo *) const;
120 
121  void attach_observer(Observer *);
122  void remove_observer(Observer *);
123 
124  const std::string &error_msg() const { return _error_msg; }
125  bool serverSupportsMessages();
126 
127  private:
128  std::string _uri_text;
129  Access _access;
130 
131  /* Local access. */
132  std::string _path;
134  /* Network access */
135  std::string _host;
136  std::string _port;
137 #ifdef _WIN32
138  SOCKET _sock;
139 #else
140  int _sock;
141 #endif
142  std::string _receive_buffer;
143  int _protocol_version;
144  bool _proto_messages_warning_given;
146  std::list<Job *> _jobs;
148  std::set<Observer *> _observers;
149 
150  std::string _error_msg;
152  void _importLocal();
153  void _importNetwork();
154 
155  void _connect();
156  void _disconnect();
157  void _send_data(const char *, size_t);
158  void _send_message(const DlsProto::Request &);
159  void _receive_data();
160  void _receive_message(google::protobuf::Message &, bool debug = 1);
161  void _receive_hello();
162 
163  void _notify_observers();
164 };
165 
166 /****************************************************************************/
167 
168 } // namespace
169 
170 /****************************************************************************/
171 
172 #endif
DLS Data Directory.
Definition: Dir.h:82
DLS Observer class.
Definition: Dir.h:68
Base class for all LibDLS exceptions.
Definition: Exception.h:36
Darstellung eines Kanals in der Anzeige.
Definition: Channel.h:71
Global data structures and functions.
DLS Directory Exception.
Definition: Dir.h:56
Measuring job.
Definition: Job.h:63
Definition: Channel.h:44
#define DLS_PUBLIC
Macro for public method definitions (empty on non-win32).
Definition: globals.h:57
Definition: Dir.h:44