0.01.00
tasklet.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, The OpenThread Authors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
34 #ifndef TASKLET_HPP_
35 #define TASKLET_HPP_
36 
37 #include "openthread-core-config.h"
38 
39 #include <stdio.h>
40 
41 #include <openthread/tasklet.h>
42 
43 #include "common/context.hpp"
44 #include "common/locator.hpp"
45 
46 namespace ot {
47 
48 class TaskletScheduler;
49 
64 class Tasklet: public InstanceLocator, public Context
65 {
66  friend class TaskletScheduler;
67 
68 public:
75  typedef void (*Handler)(Tasklet &aTasklet);
76 
85  Tasklet(otInstance &aInstance, Handler aHandler, void *aContext);
86 
91  otError Post(void);
92 
93 private:
94  void RunTask(void) { mHandler(*this); }
95 
96  Handler mHandler;
97  Tasklet *mNext;
98 };
99 
105 {
106 public:
111  TaskletScheduler(void);
112 
121  otError Post(Tasklet &aTasklet);
122 
130  bool AreTaskletsPending(void) { return mHead != NULL; }
131 
136  void ProcessQueuedTasklets(void);
137 
138 private:
139  Tasklet *PopTasklet(void);
140  Tasklet *mHead;
141  Tasklet *mTail;
142 };
143 
149 } // namespace ot
150 
151 #endif // TASKLET_HPP_
This type represents all the static / global variables used by OpenThread allocated in one place...
Definition: openthread-instance.h:59
Definition: cli.cpp:90
This file includes definitions for locator class for OpenThread objects.
This class is used to represent a tasklet.
Definition: tasklet.hpp:64
This file includes definitions for maintaining a pointer to arbitrary context information.
void(* Handler)(Tasklet &aTasklet)
This function pointer is called when the tasklet is run.
Definition: tasklet.hpp:75
This class implements definitions for maintaining a pointer to arbitrary context information.
Definition: context.hpp:61
This class implements locator for otInstance object.
Definition: locator.hpp:63
This file defines the OpenThread API for Tasklets.
This class implements the tasklet scheduler.
Definition: tasklet.hpp:104
otError Post(void)
This method puts the tasklet on the run queue.
Definition: tasklet.cpp:53
otError
This enumeration represents error codes used throughout OpenThread.
Definition: types.h:107
This file includes compile-time configuration constants for OpenThread.
Tasklet(otInstance &aInstance, Handler aHandler, void *aContext)
This constructor creates a tasklet instance.
Definition: tasklet.cpp:45
bool AreTaskletsPending(void)
This method indicates whether or not there are tasklets pending.
Definition: tasklet.hpp:130