• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 __VTS_DRIVER_COMM_UTIL_H_
18 #define __VTS_DRIVER_COMM_UTIL_H_
19 
20 #include <string>
21 
22 #include "test/vts/proto/VtsDriverControlMessage.pb.h"
23 
24 using namespace std;
25 
26 namespace android {
27 namespace vts {
28 
29 class VtsDriverCommUtil {
30  public:
VtsDriverCommUtil()31   VtsDriverCommUtil() : sockfd_(-1) {}
32 
VtsDriverCommUtil(int sockfd)33   explicit VtsDriverCommUtil(int sockfd) : sockfd_(sockfd) {}
34 
~VtsDriverCommUtil()35   ~VtsDriverCommUtil() {
36     //    if (sockfd_ != -1) Close();
37   }
38 
39   // returns true if connection to the server is successful, false otherwise.
40   bool Connect(const string& socket_name);
41 
42   // sets sockfd_
SetSockfd(int sockfd)43   void SetSockfd(int sockfd) {
44     sockfd_ = sockfd;
45   }
46 
47   // closes the channel. returns 0 if success or socket already closed
48   int Close();
49 
50   // Sends a message using the VTS's protocol for socket communication.
51   bool VtsSocketSendBytes(const string& message);
52 
53   // Receives a message using the VTS's protocol for socket communication.
54   string VtsSocketRecvBytes();
55 
56   // Sends a protobuf message.
57   bool VtsSocketSendMessage(const google::protobuf::Message& message);
58 
59   // Receives a protobuf message.
60   bool VtsSocketRecvMessage(google::protobuf::Message* message);
61 
62  private:
63   // sockfd
64   int sockfd_;
65 };
66 
67 }  // namespace vts
68 }  // namespace android
69 
70 #endif  // __VTS_DRIVER_COMM_UTIL_H_
71