1 /* 2 * Copyright (C) 2022 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_UTIL_PIGWEED_PERMISSION_H_ 18 #define CHRE_UTIL_PIGWEED_PERMISSION_H_ 19 20 #include <cstdint> 21 #include <optional> 22 23 #include "chre/util/nanoapp/assert.h" 24 #include "chre/util/non_copyable.h" 25 #include "chre/util/optional.h" 26 #include "chre_api/chre.h" 27 28 namespace chre { 29 30 /** 31 * Holds the permission for the next message sent by a server. 32 */ 33 class RpcPermission : public NonCopyable { 34 public: set(uint32_t permission)35 void set(uint32_t permission) { 36 mPermission = permission; 37 } 38 getAndReset()39 uint32_t getAndReset() { 40 CHRE_ASSERT(mPermission.has_value()); 41 uint32_t permission = mPermission.has_value() 42 ? mPermission.value() 43 : CHRE_MESSAGE_PERMISSION_NONE; 44 mPermission.reset(); 45 return permission; 46 } 47 48 private: 49 /** Bitmasked CHRE_MESSAGE_PERMISSION_ */ 50 Optional<uint32_t> mPermission; 51 }; 52 53 } // namespace chre 54 55 #endif // CHRE_UTIL_PIGWEED_PERMISSION_H_