1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #ifndef GOLDFISH_OPENGL_SYSTEM_HALS_HOST_CONNECTION_SESSION_H_INCLUDED
18 #define GOLDFISH_OPENGL_SYSTEM_HALS_HOST_CONNECTION_SESSION_H_INCLUDED
19 
20 #include "HostConnection.h"
21 
22 class HostConnectionSession {
23 public:
HostConnectionSession(HostConnection * hc)24     explicit HostConnectionSession(HostConnection* hc) : conn(hc) {
25         hc->lock();
26     }
27 
~HostConnectionSession()28     ~HostConnectionSession() {
29         if (conn) {
30             conn->unlock();
31         }
32      }
33 
HostConnectionSession(HostConnectionSession && rhs)34     HostConnectionSession(HostConnectionSession&& rhs) : conn(rhs.conn) {
35         rhs.conn = nullptr;
36     }
37 
38     HostConnectionSession& operator=(HostConnectionSession&& rhs) {
39         if (this != &rhs) {
40             std::swap(conn, rhs.conn);
41         }
42         return *this;
43     }
44 
45     HostConnectionSession(const HostConnectionSession&) = delete;
46     HostConnectionSession& operator=(const HostConnectionSession&) = delete;
47 
getRcEncoder()48     ExtendedRCEncoderContext* getRcEncoder() const {
49         return conn->rcEncoder();
50     }
51 
52 private:
53     HostConnection* conn;
54 };
55 
56 #endif  // GOLDFISH_OPENGL_SYSTEM_HALS_HOST_CONNECTION_SESSION_H_INCLUDED
57