-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_qrtr.h
69 lines (50 loc) · 1.79 KB
/
socket_qrtr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2018 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef HERMES_SOCKET_QRTR_H_
#define HERMES_SOCKET_QRTR_H_
#include <memory>
#include <base/files/file_descriptor_watcher_posix.h>
#include <base/files/scoped_file.h>
#include "hermes/socket_interface.h"
namespace hermes {
class SocketQrtr : public SocketInterface {
public:
struct PacketMetadata {
uint32_t port;
uint32_t node;
bool operator==(const PacketMetadata& rhs) const;
};
SocketQrtr();
void SetDataAvailableCallback(DataAvailableCallback cb) override;
bool Open() override;
void Close() override;
bool IsValid() const override { return socket_.is_valid(); }
Type GetType() const override { return Type::kQrtr; }
bool StartService(uint32_t service,
uint16_t version_major,
uint16_t version_minor) override;
bool StopService(uint32_t service,
uint16_t version_major,
uint16_t version_minor) override;
// If the metadata ptr is not null, it must point to a
// SocketQrtr::PacketMetadata instance.
int Recv(void* buf, size_t size, void* metadata) override;
int Send(const void* data, size_t size, const void* metadata) override;
private:
void OnFileCanReadWithoutBlocking();
private:
base::ScopedFD socket_;
std::unique_ptr<base::FileDescriptorWatcher::Controller> watcher_;
DataAvailableCallback cb_;
};
} // namespace hermes
namespace std {
template <>
struct std::hash<hermes::SocketQrtr::PacketMetadata> {
std::size_t operator()(const hermes::SocketQrtr::PacketMetadata& key) const {
return std::hash<uint32_t>()(key.node) ^ std::hash<uint32_t>()(key.port);
}
};
} // namespace std
#endif // HERMES_SOCKET_QRTR_H_