Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stub_server_tool.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voss <thomas.voss@canonical.com>
17  * Alan Griffiths <alan@octopull.co.uk>
18  */
19 
20 #ifndef MIR_TEST_STUB_SERVER_TOOL_H_
21 #define MIR_TEST_STUB_SERVER_TOOL_H_
22 
23 #include "mir_protobuf.pb.h"
24 #include <condition_variable>
25 #include <mutex>
26 
27 namespace mir
28 {
29 namespace test
30 {
31 
32 struct StubServerTool : mir::protobuf::DisplayServer
33 {
35  : drm_magic{0}
36  {
37  }
38 
39  virtual void create_surface(google::protobuf::RpcController* /*controller*/,
40  const mir::protobuf::SurfaceParameters* request,
41  mir::protobuf::Surface* response,
42  google::protobuf::Closure* done) override
43  {
44  response->mutable_id()->set_value(13); // TODO distinct numbers & tracking
45  response->set_width(request->width());
46  response->set_height(request->height());
47  response->set_pixel_format(request->pixel_format());
48  response->mutable_buffer()->set_buffer_id(22);
49 
50  std::unique_lock<std::mutex> lock(guard);
51  surface_name = request->surface_name();
52  wait_condition.notify_one();
53 
54  done->Run();
55  }
56 
57  virtual void next_buffer(
58  ::google::protobuf::RpcController* /*controller*/,
59  ::mir::protobuf::SurfaceId const* /*request*/,
60  ::mir::protobuf::Buffer* response,
61  ::google::protobuf::Closure* done) override
62  {
63  response->set_buffer_id(22);
64 
65  std::unique_lock<std::mutex> lock(guard);
66  wait_condition.notify_one();
67  done->Run();
68  }
69 
70 
71  virtual void release_surface(::google::protobuf::RpcController* /*controller*/,
73  ::mir::protobuf::Void* /*response*/,
74  ::google::protobuf::Closure* done) override
75  {
76  done->Run();
77  }
78 
79 
80  virtual void connect(
81  ::google::protobuf::RpcController*,
82  const ::mir::protobuf::ConnectParameters* request,
83  ::mir::protobuf::Connection* connect_msg,
84  ::google::protobuf::Closure* done) override
85  {
86  app_name = request->application_name();
87  connect_msg->set_error("");
88  done->Run();
89  }
90 
91  virtual void disconnect(google::protobuf::RpcController* /*controller*/,
92  const mir::protobuf::Void* /*request*/,
93  mir::protobuf::Void* /*response*/,
94  google::protobuf::Closure* done) override
95  {
96  std::unique_lock<std::mutex> lock(guard);
97  wait_condition.notify_one();
98  done->Run();
99  }
100 
101  virtual void drm_auth_magic(google::protobuf::RpcController* /*controller*/,
102  const mir::protobuf::DRMMagic* request,
103  mir::protobuf::DRMAuthMagicStatus* response,
104  google::protobuf::Closure* done) override
105  {
106  std::unique_lock<std::mutex> lock(guard);
107  drm_magic = request->magic();
108  response->set_status_code(0);
109  wait_condition.notify_one();
110  done->Run();
111  }
112 
113  virtual void configure_display(::google::protobuf::RpcController*,
114  const ::mir::protobuf::DisplayConfiguration*,
115  ::mir::protobuf::DisplayConfiguration*,
116  ::google::protobuf::Closure* done) override
117  {
118  done->Run();
119  }
120 
121  std::mutex guard;
122  std::string surface_name;
123  std::condition_variable wait_condition;
124  std::string app_name;
125  unsigned int drm_magic;
126 };
127 
128 }
129 }
130 #endif /* MIR_TEST_STUB_SERVER_TOOL_H_ */
IntWrapper< detail::SessionsSurfaceIdTag > SurfaceId
Definition: surface_id.h:29
virtual void create_surface(google::protobuf::RpcController *, const mir::protobuf::SurfaceParameters *request, mir::protobuf::Surface *response, google::protobuf::Closure *done) override
Definition: stub_server_tool.h:39
virtual void release_surface(::google::protobuf::RpcController *, const ::mir::protobuf::SurfaceId *,::mir::protobuf::Void *,::google::protobuf::Closure *done) override
Definition: stub_server_tool.h:71
std::string app_name
Definition: stub_server_tool.h:124
virtual void drm_auth_magic(google::protobuf::RpcController *, const mir::protobuf::DRMMagic *request, mir::protobuf::DRMAuthMagicStatus *response, google::protobuf::Closure *done) override
Definition: stub_server_tool.h:101
StubServerTool()
Definition: stub_server_tool.h:34
std::condition_variable wait_condition
Definition: stub_server_tool.h:123
std::string surface_name
Definition: stub_server_tool.h:122
virtual void next_buffer(::google::protobuf::RpcController *,::mir::protobuf::SurfaceId const *,::mir::protobuf::Buffer *response,::google::protobuf::Closure *done) override
Definition: stub_server_tool.h:57
Definition: stub_server_tool.h:32
unsigned int drm_magic
Definition: stub_server_tool.h:125
virtual void connect(::google::protobuf::RpcController *, const ::mir::protobuf::ConnectParameters *request,::mir::protobuf::Connection *connect_msg,::google::protobuf::Closure *done) override
Definition: stub_server_tool.h:80
virtual void configure_display(::google::protobuf::RpcController *, const ::mir::protobuf::DisplayConfiguration *,::mir::protobuf::DisplayConfiguration *,::google::protobuf::Closure *done) override
Definition: stub_server_tool.h:113
virtual void disconnect(google::protobuf::RpcController *, const mir::protobuf::Void *, mir::protobuf::Void *, google::protobuf::Closure *done) override
Definition: stub_server_tool.h:91
std::mutex guard
Definition: stub_server_tool.h:121

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Apr 11 21:14:53 UTC 2014