aboutsummaryrefslogtreecommitdiff
path: root/platform/include/chre/platform/platform_nanoapp.h
blob: 4a7994d74d6befd46c9ce035aeddef32b074bbc2 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef CHRE_PLATFORM_PLATFORM_NANOAPP_H_
#define CHRE_PLATFORM_PLATFORM_NANOAPP_H_

#include <cstddef>
#include <cstdint>

#include "chre/target_platform/platform_nanoapp_base.h"
#include "chre/util/non_copyable.h"
#include "chre/util/system/debug_dump.h"

namespace chre {

/**
 * The common interface to Nanoapp functionality that has platform-specific
 * implementation but must be supported for every platform.
 */
class PlatformNanoapp : public PlatformNanoappBase, public NonCopyable {
 public:
  /**
   * Calls the start function of the nanoapp. For dynamically loaded nanoapps,
   * this must also result in calling through to any of the nanoapp's static
   * global constructors/init functions, etc., prior to invoking the
   * nanoappStart.
   *
   * @return true if the app was able to start successfully
   *
   * @see nanoappStart
   */
  bool start();

  /**
   * Passes an event to the nanoapp.
   *
   * @see nanoappHandleEvent
   */
  void handleEvent(uint32_t senderInstanceId, uint16_t eventType,
                   const void *eventData);

  /**
   * Calls the nanoapp's end callback. For dynamically loaded nanoapps, this
   * must also result in calling through to any of the nanoapp's static global
   * destructors, atexit functions, etc., after nanoappEnd returns. This is only
   * valid to call after start() has returned true.
   *
   * This function must leave the nanoapp in a state where it can be started
   * again via start().
   *
   * @see nanoappEnd
   */
  void end();

  /**
   * Retrieves the nanoapp's 64-bit identifier. This function must always return
   * a valid identifier - either the one supplied by the host via the HAL (from
   * the header), or the authoritative value inside the nanoapp binary if one
   * exists. In the event that both are available and they do not match, the
   * platform implementation must return false from start().
   */
  uint64_t getAppId() const;

  /**
   * Retrieves the nanoapp's own version number. The same restrictions apply
   * here as for getAppId().
   *
   * @see #getAppId
   */
  uint32_t getAppVersion() const;

  /**
   * Retrieves the API version that this nanoapp was compiled against. This
   * function must only be called while the nanoapp is running (i.e. between
   * calls to start() and end()).
   */
  uint32_t getTargetApiVersion() const;

  /**
   * Retrieves the human-friendly name for the nanoapp (null-terminated string).
   */
  const char *getAppName() const;

  /**
   * Returns true if the nanoapp should not appear in the context hub HAL list
   * of nanoapps, e.g. because it implements some device functionality purely
   * beneath the HAL.
   */
  bool isSystemNanoapp() const;

  /**
   * Prints state in a string buffer. Must only be called from the context of
   * the main CHRE thread.
   *
   * @param debugDump The debug dump wrapper object where logs are printed
   * into.
   */
  void logStateToBuffer(DebugDumpWrapper &debugDump) const;

 protected:
  /**
   * PlatformNanoapp's constructor is protected, as it must only exist within
   * the context of the derived class chre::Nanoapp.
   */
  PlatformNanoapp() = default;

  /**
   * Unloads the nanoapp from memory.
   */
  ~PlatformNanoapp();
};

}  // namespace chre

#endif  // CHRE_PLATFORM_PLATFORM_NANOAPP_H_