casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
grpcViewerAdaptor.qo.h
Go to the documentation of this file.
1 //# grpcViewerAdaptor.h: provides viewer services via grpc
2 //# Copyright (C) 2019
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef GRPCVIEWERADAPTOR_H_
29 #define GRPCVIEWERADAPTOR_H_
30 
31 #include <map>
32 #include <list>
33 #include <memory>
34 #include <functional>
36 #include <casagrpc/protos/img.grpc.pb.h>
37 #include <casagrpc/protos/shutdown.grpc.pb.h>
38 #include <grpc++/grpc++.h>
39 
40 namespace casa { //# NAMESPACE CASA - BEGIN
41 
42  class grpcShutdown : public QObject, public ::casatools::rpc::Shutdown::Service {
43 
44  Q_OBJECT //# Allows slot/signal definition. Must only occur in
45  //# implement/.../*.h files
46  public:
47  grpcShutdown( QtViewer *qtv );
48  ::grpc::Status now(::grpc::ServerContext*, const ::google::protobuf::Empty*, ::google::protobuf::Empty*);
49 
50  signals:
51  void exit_now( );
52 
53  private:
55 
56  };
57 
58  class grpcImageViewer : public QObject, public ::rpc::img::view::Service {
59 
60  Q_OBJECT //# Allows slot/signal definition. Must only occur in
61  //# implement/.../*.h files
62  protected:
63  void qtGO( std::function<void()> );
64 
65  private:
66 
67  class data_desc {
68  public:
69  data_desc( int idx, const std::string &pathx, const std::string &typex,
70  QtDisplayData *ddx, QtDisplayPanelGui *dpx ) :
71  id_(idx), path_(pathx), type_(typex), dd_(ddx), dp_(dpx) { }
72 
73  data_desc( int idx ) : id_(idx), dd_(0) { }
74  data_desc( ) : id_(0), dd_(0) { }
75 
76  int &id( ) {
77  return id_;
78  }
79  int id( ) const {
80  return id_;
81  }
82  std::string &path( ) {
83  return path_;
84  }
85  const std::string &path( ) const {
86  return path_;
87  }
88  std::string &type( ) {
89  return type_;
90  }
91  const std::string &type( ) const {
92  return type_;
93  }
95  return dd_;
96  }
97  const QtDisplayData *data( ) const {
98  return dd_;
99  }
101  return dp_;
102  }
103  const QtDisplayPanelGui *panel( ) const {
104  return dp_;
105  }
106 
107  private:
108  int id_;
109  std::string path_;
110  std::string type_;
113 
114  // QtDisplayData does not have a copy constructor...
115  // wonder if we'll need to copy our descriptor...
116  data_desc( const data_desc &other);
117  data_desc &operator=( const data_desc &);
118  };
119 
120 
121  class panel_desc {
122  public:
123 
124  panel_desc( ) : panel_(0) { }
125 
127 
128  std::list<int> &data( ) {
129  return data_;
130  }
131  const std::list<int> &data( ) const {
132  return data_;
133  }
135  return panel_;
136  }
137  const QtDisplayPanelGui *panel( ) const {
138  return panel_;
139  }
140 
141  private:
142  std::list<int> data_;
144  };
145 
146  public:
147 
148  // Constructor which takes the application.
150 
151  ::grpc::Status panel( ::grpc::ServerContext *context,
152  const ::rpc::img::NewPanel *req,
153  ::rpc::img::Id *reply );
154  ::grpc::Status hide( ::grpc::ServerContext *context,
155  const ::rpc::img::Id *req,
156  ::google::protobuf::Empty* );
157  ::grpc::Status show( ::grpc::ServerContext *context,
158  const ::rpc::img::Id *req,
159  ::google::protobuf::Empty* );
160  ::grpc::Status freeze( ::grpc::ServerContext *context,
161  const ::rpc::img::Id *req,
162  ::google::protobuf::Empty* );
163  ::grpc::Status unfreeze( ::grpc::ServerContext *context,
164  const ::rpc::img::Id *req,
165  ::google::protobuf::Empty* );
166  ::grpc::Status close( ::grpc::ServerContext *context,
167  const ::rpc::img::Id *req,
168  ::google::protobuf::Empty* );
169  ::grpc::Status release( ::grpc::ServerContext *context,
170  const ::rpc::img::Id *req,
171  ::google::protobuf::Empty* );
172 
173  ::grpc::Status axes( ::grpc::ServerContext *context,
174  const ::rpc::img::Axes *req,
175  ::google::protobuf::Empty* );
176 
177  ::grpc::Status popup( ::grpc::ServerContext *context,
178  const ::rpc::img::PopUp *req,
179  ::google::protobuf::Empty* );
180 
181  ::grpc::Status load( ::grpc::ServerContext *context,
182  const ::rpc::img::NewData *req,
183  ::rpc::img::Id *reply );
184  ::grpc::Status reload( ::grpc::ServerContext *context,
185  const ::rpc::img::Id *req,
186  ::google::protobuf::Empty* );
187  ::grpc::Status unload( ::grpc::ServerContext *context,
188  const ::rpc::img::Id *req,
189  ::google::protobuf::Empty* );
190 
191  ::grpc::Status restore( ::grpc::ServerContext *context,
192  const ::rpc::img::Restore *req,
193  ::rpc::img::Id *reply );
194 
195  ::grpc::Status colormap( ::grpc::ServerContext *context,
196  const ::rpc::img::ColorMap *req,
197  ::google::protobuf::Empty* );
198 
199  ::grpc::Status colorwedge( ::grpc::ServerContext *context,
200  const ::rpc::img::Toggle *req,
201  ::google::protobuf::Empty* );
202 
203  ::grpc::Status datarange( ::grpc::ServerContext *context,
204  const ::rpc::img::DataRange *req,
205  ::google::protobuf::Empty* );
206 
207  ::grpc::Status contourlevels( ::grpc::ServerContext *context,
208  const ::rpc::img::ContourLevels *req,
209  ::google::protobuf::Empty* );
210  ::grpc::Status contourthickness( ::grpc::ServerContext *context,
211  const ::rpc::img::ContourThickness *req,
212  ::google::protobuf::Empty* );
213  ::grpc::Status contourcolor( ::grpc::ServerContext *context,
214  const ::rpc::img::ContourColor *req,
215  ::google::protobuf::Empty* );
216 
217  ::grpc::Status channel( ::grpc::ServerContext *context,
218  const ::rpc::img::SetChannel *req,
219  ::google::protobuf::Empty* );
220  ::grpc::Status zoomlevel( ::grpc::ServerContext *context,
221  const ::rpc::img::SetZoomLevel *req,
222  ::google::protobuf::Empty* );
223  ::grpc::Status zoombox( ::grpc::ServerContext *context,
224  const ::rpc::img::SetZoomBox *req,
225  ::google::protobuf::Empty* );
226 
227  ::grpc::Status output( ::grpc::ServerContext *context,
228  const ::rpc::img::Output *req,
229  ::google::protobuf::Empty* );
230 
231 
232  ::grpc::Status fileinfo( ::grpc::ServerContext *context,
233  const ::rpc::img::Path *req,
234  ::rpc::img::FileInfo *reply );
235  ::grpc::Status keyinfo( ::grpc::ServerContext *context,
236  const ::rpc::img::Id *req,
237  ::rpc::img::KeyInfo *reply );
238  // if path is null string, return current path
239  // if path is not null (and represents a valid dir),
240  // cd to new path && return new path
241  ::grpc::Status cwd( ::grpc::ServerContext *context,
242  const ::rpc::img::Path *req,
243  ::rpc::img::Path *reply );
244  // duplicates the shutdown::now rpc call...
245  // duplicates grpcShutdown::now(...)
246  ::grpc::Status done( ::grpc::ServerContext*,
247  const ::google::protobuf::Empty*,
248  ::google::protobuf::Empty* );
249 
250  int get_id( QtDisplayPanelGui* );
251  int get_id( QtDisplayPanelGui *, QtDisplayData *, const std::string &path, const std::string &type );
252 
253  QtDisplayData *finddata( int key );
254  QtDisplayPanelGui *findpanel( int key /*, bool create=true*/ );
255  void erase_panel( int panel );
256  void erase_data( int );
257 
258  bool load_data( QtDisplayPanelGui*, int );
259  bool unload_data( QtDisplayPanelGui*, int, bool = true );
260 
261  bool printraster( QtDisplayPanel *panel, const QString &type,
262  const QString &file, double scale );
263  bool printps( QtDisplayPanel *panel, const QString &type, const QString &file,
264  int dpi, const QString &orientation, const QString &media );
265  void adjusteps( const char *from, const char *to,
266  const QSize &wcmax, const QRect &viewport );
267 
268  signals:
269 
270  void exit_now( );
271  void new_op( );
272 
273  public slots:
274 
275  void handle_destroyed_panel(QObject*);
276 
277  private:
278  typedef std::map<int,panel_desc*> panelmap;
279  std::recursive_mutex managed_panels_mutex;
281 
282  typedef std::map<int,data_desc*> datamap;
283  std::recursive_mutex managed_datas_mutex;
285 
287 
288  };
289 
291  public:
294  shutdown_service(new grpcShutdown(v)) { }
295 
296  std::string uri;
297 
298  std::unique_ptr<grpc::Server> server;
299 
300  std::unique_ptr<grpcImageViewer> viewer_service;
301  std::unique_ptr<grpcShutdown> shutdown_service;
302 
304  if (getenv("GRPC_DEBUG")) {
305  fprintf(stdout, "stopping grpc server...\n");
306  fflush(stdout);
307  }
308  if ( server ) server->Shutdown( );
309  }
310  };
311 
312 }
313 
314 #endif
bool printps(QtDisplayPanel *panel, const QString &type, const QString &file, int dpi, const QString &orientation, const QString &media)
QtDisplayPanelGui * findpanel(int key)
const std::list< int > & data() const
void handle_destroyed_panel(QObject *)
::grpc::Status load(::grpc::ServerContext *context, const ::rpc::img::NewData *req,::rpc::img::Id *reply)
const std::string & type() const
grpcShutdown(QtViewer *qtv)
::grpc::Status now(::grpc::ServerContext *, const ::google::protobuf::Empty *,::google::protobuf::Empty *)
Qt implementation of main viewer supervisory object – Gui level.
Definition: QtViewer.qo.h:79
::grpc::Status keyinfo(::grpc::ServerContext *context, const ::rpc::img::Id *req,::rpc::img::KeyInfo *reply)
void adjusteps(const char *from, const char *to, const QSize &wcmax, const QRect &viewport)
::grpc::Status panel(::grpc::ServerContext *context, const ::rpc::img::NewPanel *req,::rpc::img::Id *reply)
::grpc::Status unfreeze(::grpc::ServerContext *context, const ::rpc::img::Id *req,::google::protobuf::Empty *)
data_desc & operator=(const data_desc &)
virtual Type type()
Return the type enum.
::grpc::Status fileinfo(::grpc::ServerContext *context, const ::rpc::img::Path *req,::rpc::img::FileInfo *reply)
::grpc::Status contourlevels(::grpc::ServerContext *context, const ::rpc::img::ContourLevels *req,::google::protobuf::Empty *)
std::unique_ptr< grpcImageViewer > viewer_service
const QtDisplayPanelGui * panel() const
bool load_data(QtDisplayPanelGui *, int)
::grpc::Status restore(::grpc::ServerContext *context, const ::rpc::img::Restore *req,::rpc::img::Id *reply)
std::recursive_mutex managed_panels_mutex
grpcImageViewer(QtViewer *)
Constructor which takes the application.
::grpc::Status zoomlevel(::grpc::ServerContext *context, const ::rpc::img::SetZoomLevel *req,::google::protobuf::Empty *)
int get_id(QtDisplayPanelGui *)
::grpc::Status datarange(::grpc::ServerContext *context, const ::rpc::img::DataRange *req,::google::protobuf::Empty *)
const std::string & path() const
const QtDisplayPanelGui * panel() const
void erase_panel(int panel)
std::string path(const std::string &name)
::grpc::Status reload(::grpc::ServerContext *context, const ::rpc::img::Id *req,::google::protobuf::Empty *)
::grpc::Status show(::grpc::ServerContext *context, const ::rpc::img::Id *req,::google::protobuf::Empty *)
bool printraster(QtDisplayPanel *panel, const QString &type, const QString &file, double scale)
::grpc::Status freeze(::grpc::ServerContext *context, const ::rpc::img::Id *req,::google::protobuf::Empty *)
The main display window for the Qt version of the viewer.
::grpc::Status colormap(::grpc::ServerContext *context, const ::rpc::img::ColorMap *req,::google::protobuf::Empty *)
::grpc::Status popup(::grpc::ServerContext *context, const ::rpc::img::PopUp *req,::google::protobuf::Empty *)
const QtDisplayData * data() const
::grpc::Status channel(::grpc::ServerContext *context, const ::rpc::img::SetChannel *req,::google::protobuf::Empty *)
::grpc::Status cwd(::grpc::ServerContext *context, const ::rpc::img::Path *req,::rpc::img::Path *reply)
if path is null string, return current path if path is not null (and represents a valid dir)...
std::map< int, data_desc * > datamap
::grpc::Status release(::grpc::ServerContext *context, const ::rpc::img::Id *req,::google::protobuf::Empty *)
::grpc::Status axes(::grpc::ServerContext *context, const ::rpc::img::Axes *req,::google::protobuf::Empty *)
std::map< int, panel_desc * > panelmap
::grpc::Status contourthickness(::grpc::ServerContext *context, const ::rpc::img::ContourThickness *req,::google::protobuf::Empty *)
::grpc::Status contourcolor(::grpc::ServerContext *context, const ::rpc::img::ContourColor *req,::google::protobuf::Empty *)
::grpc::Status done(::grpc::ServerContext *, const ::google::protobuf::Empty *,::google::protobuf::Empty *)
duplicates the shutdown::now rpc call...
QtDisplayData * finddata(int key)
bool unload_data(QtDisplayPanelGui *, int, bool=true)
::grpc::Status zoombox(::grpc::ServerContext *context, const ::rpc::img::SetZoomBox *req,::google::protobuf::Empty *)
::grpc::Status output(::grpc::ServerContext *context, const ::rpc::img::Output *req,::google::protobuf::Empty *)
data_desc(int idx, const std::string &pathx, const std::string &typex, QtDisplayData *ddx, QtDisplayPanelGui *dpx)
::grpc::Status unload(::grpc::ServerContext *context, const ::rpc::img::Id *req,::google::protobuf::Empty *)
void qtGO(std::function< void()>)
::grpc::Status hide(::grpc::ServerContext *context, const ::rpc::img::Id *req,::google::protobuf::Empty *)
std::recursive_mutex managed_datas_mutex
std::unique_ptr< grpcShutdown > shutdown_service
::grpc::Status colorwedge(::grpc::ServerContext *context, const ::rpc::img::Toggle *req,::google::protobuf::Empty *)
std::unique_ptr< grpc::Server > server
::grpc::Status close(::grpc::ServerContext *context, const ::rpc::img::Id *req,::google::protobuf::Empty *)
T getenv(const char *name, const T defaultVal)
Defines nreal time structures used by the VLA table filler.
Definition: nreal.h:100