1 /*
2  * Copyright (C) 2017 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 obtian a copy of the License at
7  *
8  *      http://www.apache.org/licensed/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 _GTS_NANOAPPS_GENERAL_TEST_NANOAPP_INFO_EVENTS_TEST_OBSERVER_H_
18 #define _GTS_NANOAPPS_GENERAL_TEST_NANOAPP_INFO_EVENTS_TEST_OBSERVER_H_
19 
20 #include <general_test/test.h>
21 
22 #include <cstdint>
23 
24 #include <chre.h>
25 
26 namespace general_test {
27 
28 /**
29  * Monitor CHRE_EVENT_NANOAPP_STARTED/CHRE_EVENT_NANOAPP_STOPPED events.
30  *
31  * This is the OBSERVER nanoapp for ContextHubNanoAppInfoEventsNanoAppTest
32  *
33  * Protocol:
34  * Host to observer: NANOAPP_INFO_EVENT, no data
35  * observer to Host: CONTINUE
36  * [Host starts performer]
37  * ...
38  * [Host stops performer]
39  * Host to observer: CONTINUE, performer's 32-bit instance ID
40  * observer to host: SUCCESS
41  */
42 struct HostActionMetadata {
43   uint32_t instanceId;
44   uint16_t eventType;
45 };
46 
47 class NanoAppInfoEventsTestObserver : public Test {
48  public:
49   NanoAppInfoEventsTestObserver();
50 
51  protected:
52   void handleEvent(uint32_t senderInstanceId, uint16_t eventType,
53                    const void *eventData) override;
54   void setUp(uint32_t messageSize, const void *message) override;
55 
56  private:
57   /**
58    * Search the Start/Stop message history looking for a Start/Stop
59    * pair from a given instance id
60    *
61    * @param performerInstanceId The instance Id to look for
62    */
63   void processStartStopHistory(uint32_t performerInstanceId);
64 
65   static constexpr uint32_t kHistorySize = 8;
66   HostActionMetadata mStartStopHistory[kHistorySize];
67   uint32_t mHistoryIndex = 0;
68 };
69 
70 } // namespace general_test
71 
72 #endif // _GTS_NANOAPPS_GENERAL_TEST_NANOAPP_INFO_EVENTS_TEST_OBSERVER_H_
73