1 /** 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef RUNTIME_INCLUDE_CALLBACK_QUEUE_H 16 #define RUNTIME_INCLUDE_CALLBACK_QUEUE_H 17 18 #include "runtime/include/mem/panda_containers.h" 19 #include "runtime/include/mem/panda_smart_pointers.h" 20 21 namespace ark { 22 class Callback { 23 public: 24 Callback() = default; 25 DEFAULT_COPY_SEMANTIC(Callback); 26 DEFAULT_MOVE_SEMANTIC(Callback); 27 virtual ~Callback() = default; 28 29 virtual void Run() = 0; 30 }; 31 32 class CallbackQueue { 33 public: 34 CallbackQueue() = default; 35 NO_COPY_SEMANTIC(CallbackQueue); 36 NO_MOVE_SEMANTIC(CallbackQueue); 37 virtual ~CallbackQueue() = default; 38 39 /// Post callback to the queue 40 virtual void Post(PandaUniquePtr<Callback> callback) = 0; 41 42 /// Post sequence of callbacks to the queue PostSequence(PandaList<PandaUniquePtr<Callback>> callbacks)43 virtual void PostSequence(PandaList<PandaUniquePtr<Callback>> callbacks) 44 { 45 while (!callbacks.empty()) { 46 Post(std::move(callbacks.front())); 47 callbacks.pop_front(); 48 } 49 } 50 51 /// Process the queue callbacks until it is empty Process()52 virtual void Process() {} 53 54 /// Get status of queue IsEmpty()55 virtual bool IsEmpty() 56 { 57 return true; 58 } 59 60 /// Destroy callback queue Destroy()61 virtual void Destroy() {} 62 }; 63 64 } // namespace ark 65 66 #endif // RUNTIME_INCLUDE_CALLBACK_QUEUE_H 67