libdoip  0.1.0
DoIP (Diagnostics over Internet Protocol) ISO 13400 C++17 Library
IUdsServiceHandler.h
Go to the documentation of this file.
1 #ifndef IUDSSERVICEHANDLER_H
2 #define IUDSSERVICEHANDLER_H
3 
4 #include "UdsResponseCode.h"
5 #include "DoIPMessage.h"
6 #include <memory>
7 
8 namespace doip::uds {
9 
10 using UdsResponse = std::pair<UdsResponseCode, ByteArray>;
11 
12 inline std::ostream &operator<<(std::ostream &os, const UdsResponse &response) {
13  std::ios_base::fmtflags flags(os.flags());
14 
15  os << response.first << " [";
16  os << std::hex << std::uppercase << std::setw(2) << std::setfill('0');
17 
18  for (size_t i = 0; i < response.second.size(); ++i) {
19  if (i > 0) {
20  os << '.';
21  }
22  os << std::hex << std::uppercase << std::setw(2) << std::setfill('0')
23  << static_cast<unsigned int>(response.second[i]);
24  }
25 
26  os.flags(flags);
27  return os;
28 }
29 
31 public:
32  virtual ~IUdsServiceHandler() = default;
33  virtual UdsResponse handle(const ByteArray &request) = 0;
34 };
35 
36 using IUdsServiceHandlerPtr = std::unique_ptr<IUdsServiceHandler>;
37 
38 } // namespace doip::uds
39 
40 #endif // IUDSSERVICEHANDLER_H
virtual ~IUdsServiceHandler()=default
virtual UdsResponse handle(const ByteArray &request)=0
std::unique_ptr< IUdsServiceHandler > IUdsServiceHandlerPtr
std::ostream & operator<<(std::ostream &os, const UdsResponse &response)
std::pair< UdsResponseCode, ByteArray > UdsResponse
A dynamic array of bytes with utility methods for network protocol handling.
Definition: ByteArray.h:60