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