1 /* 2 * Copyright (c) 2021 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 16 #ifndef IEVENT_LOOP_H 17 #define IEVENT_LOOP_H 18 19 #include "ref_object.h" 20 #include "macro_utils.h" 21 22 namespace DistributedDB { 23 class IEvent; 24 25 // Abstract of event loop. 26 class IEventLoop : public virtual RefObject { 27 public: 28 IEventLoop() = default; 29 30 DISABLE_COPY_ASSIGN_MOVE(IEventLoop); 31 32 // Add an event object to the loop. 33 virtual int Add(IEvent *event) = 0; 34 35 // Remove an event object from the loop. 36 virtual int Remove(IEvent *event) = 0; 37 38 // Run the loop. 39 virtual int Run() = 0; 40 41 virtual int Stop() = 0; 42 43 // Create a loop object. 44 static IEventLoop *CreateEventLoop(int &errCode); 45 46 protected: ~IEventLoop()47 virtual ~IEventLoop() {}; 48 }; 49 } 50 51 #endif // IEVENT_LOOP_H 52