1 #define LOG_TAG "hidl_test"
2
3 #include "Graph.h"
4
5 #include <log/log.h>
6
7 #include <hidl-test/PointerHelper.h>
8
9 #define PUSH_ERROR_IF(__cond__) if(__cond__) { errors.push_back(std::to_string(__LINE__) + ": " + #__cond__); }
10
11 namespace android {
12 namespace hardware {
13 namespace tests {
14 namespace pointer {
15 namespace V1_0 {
16 namespace implementation {
17
18 // Methods from ::android::hardware::tests::pointer::V1_0::IGraph follow.
passAGraph(const IGraph::Graph & g)19 Return<void> Graph::passAGraph(const IGraph::Graph& g) {
20 ALOGI("SERVER(Graph) passAGraph start.");
21 PUSH_ERROR_IF(!isSimpleGraph(g));
22 // logSimpleGraph("SERVER(Graph) passAGraph:", g);
23 return Void();
24 }
25
giveAGraph(giveAGraph_cb _cb)26 Return<void> Graph::giveAGraph(giveAGraph_cb _cb) {
27 IGraph::Graph g;
28 simpleGraph(g);
29 _cb(g);
30 return Void();
31 }
32
passANode(const IGraph::Node & n)33 Return<void> Graph::passANode(const IGraph::Node& n) {
34 PUSH_ERROR_IF(n.data != 10);
35 return Void();
36 }
37
passTwoGraphs(IGraph::Graph const * g1,IGraph::Graph const * g2)38 Return<void> Graph::passTwoGraphs(IGraph::Graph const* g1, IGraph::Graph const* g2) {
39 PUSH_ERROR_IF(g1 != g2);
40 PUSH_ERROR_IF(!isSimpleGraph(*g1));
41 logSimpleGraph("SERVER(Graph): passTwoGraphs", *g2);
42 return Void();
43 }
44
passAGamma(const IGraph::Gamma & c)45 Return<void> Graph::passAGamma(const IGraph::Gamma& c) {
46 if(c.a_ptr == nullptr && c.b_ptr == nullptr)
47 return Void();
48 ALOGI("SERVER(Graph) passAGamma received c.a = %p, c.b = %p, c.a->s = %p, c.b->s = %p",
49 c.a_ptr, c.b_ptr, c.a_ptr->s_ptr, c.b_ptr->s_ptr);
50 ALOGI("SERVER(Graph) passAGamma received data %d, %d",
51 (int)c.a_ptr->s_ptr->data, (int)c.b_ptr->s_ptr->data);
52 PUSH_ERROR_IF(c.a_ptr->s_ptr != c.b_ptr->s_ptr);
53 return Void();
54 }
passASimpleRef(const IGraph::Alpha * a_ptr)55 Return<void> Graph::passASimpleRef(const IGraph::Alpha * a_ptr) {
56 ALOGI("SERVER(Graph) passASimpleRef received %d", a_ptr->s_ptr->data);
57 PUSH_ERROR_IF(a_ptr->s_ptr->data != 500);
58 return Void();
59 }
passASimpleRefS(const IGraph::Theta * s_ptr)60 Return<void> Graph::passASimpleRefS(const IGraph::Theta * s_ptr) {
61 ALOGI("SERVER(Graph) passASimpleRefS received %d @ %p", s_ptr->data, s_ptr);
62 PUSH_ERROR_IF(s_ptr->data == 10);
63 return Void();
64 }
giveASimpleRef(giveASimpleRef_cb _cb)65 Return<void> Graph::giveASimpleRef(giveASimpleRef_cb _cb) {
66 IGraph::Theta s; s.data = 500;
67 IGraph::Alpha a; a.s_ptr = &s;
68 _cb(&a);
69 return Void();
70 }
71
getErrors()72 Return<int32_t> Graph::getErrors() {
73 if(!errors.empty()) {
74 for(const auto& e : errors)
75 ALOGW("SERVER(Graph) error: %s", e.c_str());
76 }
77 return errors.size();
78 }
79
HIDL_FETCH_IGraph(const char *)80 IGraph* HIDL_FETCH_IGraph(const char* /* name */) {
81 return new Graph();
82 }
83
84 } // namespace implementation
85 } // namespace V1_0
86 } // namespace pointer
87 } // namespace tests
88 } // namespace hardware
89 } // namespace android
90