1 /** 2 * @file mega/waiter.h 3 * @brief Generic waiter interface 4 * 5 * (c) 2013-2014 by Mega Limited, Auckland, New Zealand 6 * 7 * This file is part of the MEGA SDK - Client Access Engine. 8 * 9 * Applications using the MEGA API must present a valid application key 10 * and comply with the the rules set forth in the Terms of Service. 11 * 12 * The MEGA SDK is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 * 16 * @copyright Simplified (2-clause) BSD License. 17 * 18 * You should have received a copy of the license along with this 19 * program. 20 */ 21 22 #ifndef MEGA_WAITER_H 23 #define MEGA_WAITER_H 1 24 25 #include "types.h" 26 27 namespace mega { 28 29 // interface enabling a class to add its wakeup criteria to the waiter 30 struct MEGA_API EventTrigger 31 { 32 // add wakeup criterion 33 virtual void addevents(Waiter*, int) = 0; 34 35 // process events after wakeup checkeventsEventTrigger36 virtual int checkevents(Waiter*) 37 { 38 return 0; 39 } 40 }; 41 42 // wait for events 43 struct MEGA_API Waiter 44 { 45 // current time (processwide) 46 static dstime ds; 47 48 // set ds to current time 49 static void bumpds(); 50 51 // wait ceiling 52 dstime maxds; 53 54 // begin waiting cycle with timeout 55 virtual void init(dstime); 56 57 // add wakeup events 58 void wakeupby(EventTrigger*, int); 59 60 // wait for all added wakeup criteria (plus the host app's own), up to the 61 // specified number of deciseconds 62 virtual int wait() = 0; 63 64 // force a wakeup 65 virtual void notify() = 0; 66 67 static const int NEEDEXEC = 1; 68 static const int HAVESTDIN = 2; 69 ~WaiterWaiter70 virtual ~Waiter() { } 71 }; 72 } // namespace 73 74 #endif 75