1 /* 2 * Copyright (C) 2020 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 obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/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 CHRE_TEST_SHARED_SEND_MESSAGE_H_ 18 #define CHRE_TEST_SHARED_SEND_MESSAGE_H_ 19 20 #include <pb_encode.h> 21 #include <cinttypes> 22 23 #include "chre/util/system/napp_permissions.h" 24 #include "chre_test_common.nanopb.h" 25 26 namespace chre { 27 28 namespace test_shared { 29 30 chre_test_common_TestResult makeTestResultProtoMessage( 31 bool success, const char *errMessage = nullptr); 32 33 /** 34 * Same as sendTestResultWithMsgToHost, but doesn't accept an error message and 35 * uses the free callback specified in chre/util/nanoapp/callbacks.h 36 */ 37 void sendTestResultToHost(uint16_t hostEndpointId, uint32_t messageType, 38 bool success, bool abortOnFailure = true); 39 40 /** 41 * Sends a test result to the host using the chre_test_common.TestResult 42 * message. 43 * 44 * @param hostEndpointId The endpoint ID of the host to send the result to. 45 * @param messageType The message type to associate with the test result. 46 * @param success True if the test succeeded. 47 * @param errMessage Nullable error message to send to the host. Error message 48 * will only be sent if success is false. 49 * @param abortOnFailure If true, calls chreAbort() if success is false. 50 */ 51 void sendTestResultWithMsgToHost(uint16_t hostEndpointId, uint32_t messageType, 52 bool success, const char *errMessage, 53 bool abortOnFailure = true); 54 55 /** 56 * Sends a message to the host with an empty payload. 57 * 58 * @param hostEndpointId The endpoint Id of the host to send the message to. 59 * @param messageType The message type. 60 */ 61 void sendEmptyMessageToHost(uint16_t hostEndpointId, uint32_t messageType); 62 63 /** 64 * Sends a message to the host with default NanoappPermissions (CHRE_PERMS_NONE) 65 * 66 * @param hostEndpointId The endpoint Id of the host to send the message to. 67 * @param message The proto message struct pointer. 68 * @param fields The fields descriptor of the proto message to encode. 69 * @param messageType The message type of the message. 70 */ 71 void sendMessageToHost(uint16_t hostEndpointId, const void *message, 72 const pb_field_t *fields, uint32_t messageType); 73 74 /** 75 * Sends a message to the host with the provided NanoappPermissions. 76 * 77 * @param hostEndpointId The endpoint Id of the host to send the message to. 78 * @param message The proto message struct pointer. 79 * @param fields The fields descriptor of the proto message to encode. 80 * @param messageType The message type of the message. 81 @param perms The NanoappPermissions associated with the message. 82 */ 83 void sendMessageToHostWithPermissions(uint16_t hostEndpointId, 84 const void *message, 85 const pb_field_t *fields, 86 uint32_t messageType, 87 chre::NanoappPermissions perms); 88 89 } // namespace test_shared 90 91 } // namespace chre 92 93 #endif // CHRE_TEST_SHARED_SEND_MESSAGE_H_ 94