Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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*,
84  ::google::protobuf::Closure* done) override
85  {
86  app_name = request->application_name();
87  done->Run();
88  }
89 
90  virtual void disconnect(google::protobuf::RpcController* /*controller*/,
91  const mir::protobuf::Void* /*request*/,
92  mir::protobuf::Void* /*response*/,
93  google::protobuf::Closure* done) override
94  {
95  std::unique_lock<std::mutex> lock(guard);
96  wait_condition.notify_one();
97  done->Run();
98  }
99 
100  virtual void drm_auth_magic(google::protobuf::RpcController* /*controller*/,
101  const mir::protobuf::DRMMagic* request,
102  mir::protobuf::DRMAuthMagicStatus* response,
103  google::protobuf::Closure* done) override
104  {
105  std::unique_lock<std::mutex> lock(guard);
106  drm_magic = request->magic();
107  response->set_status_code(0);
108  wait_condition.notify_one();
109  done->Run();
110  }
111 
112  virtual void configure_display(::google::protobuf::RpcController*,
113  const ::mir::protobuf::DisplayConfiguration*,
114  ::mir::protobuf::DisplayConfiguration*,
115  ::google::protobuf::Closure* done) override
116  {
117  done->Run();
118  }
119 
120  std::mutex guard;
121  std::string surface_name;
122  std::condition_variable wait_condition;
123  std::string app_name;
124  unsigned int drm_magic;
125 };
126 
127 }
128 }
129 #endif /* MIR_TEST_STUB_SERVER_TOOL_H_ */

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Oct 15 00:23:28 UTC 2013