Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains basic functions common to different Mojo system APIs. | 5 // This file contains basic functions common to different Mojo system APIs. |
| 6 // | 6 // |
| 7 // Note: This header should be compilable as C. | 7 // Note: This header should be compilable as C. |
| 8 | 8 |
| 9 #ifndef MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ | 9 #ifndef MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ |
| 10 #define MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ | 10 #define MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ |
| 11 | 11 |
| 12 #include <stddef.h> | |
| 12 #include <stdint.h> | 13 #include <stdint.h> |
| 13 | 14 |
| 14 #include "mojo/public/c/system/system_export.h" | 15 #include "mojo/public/c/system/system_export.h" |
| 15 #include "mojo/public/c/system/types.h" | 16 #include "mojo/public/c/system/types.h" |
| 16 | 17 |
| 17 #ifdef __cplusplus | 18 #ifdef __cplusplus |
| 18 extern "C" { | 19 extern "C" { |
| 19 #endif | 20 #endif |
| 20 | 21 |
| 22 // A callback used to notify watchers registered via |MojoWatch()|. Called when | |
| 23 // some watched signals are satisfied or become unsatisfiable. See the | |
| 24 // documentation for |MojoWatch()| for more details. | |
| 25 typedef void (*MojoWatchCallback)(uintptr_t context, | |
| 26 MojoResult result, | |
| 27 struct MojoHandleSignalsState signals_state); | |
| 28 | |
| 21 // Note: Pointer parameters that are labelled "optional" may be null (at least | 29 // Note: Pointer parameters that are labelled "optional" may be null (at least |
| 22 // under some circumstances). Non-const pointer parameters are also labeled | 30 // under some circumstances). Non-const pointer parameters are also labeled |
| 23 // "in", "out", or "in/out", to indicate how they are used. (Note that how/if | 31 // "in", "out", or "in/out", to indicate how they are used. (Note that how/if |
| 24 // such a parameter is used may depend on other parameters or the requested | 32 // such a parameter is used may depend on other parameters or the requested |
| 25 // operation's success/failure. E.g., a separate |flags| parameter may control | 33 // operation's success/failure. E.g., a separate |flags| parameter may control |
| 26 // whether a given "in/out" parameter is used for input, output, or both.) | 34 // whether a given "in/out" parameter is used for input, output, or both.) |
| 27 | 35 |
| 28 // Returns the time, in microseconds, since some undefined point in the past. | 36 // Returns the time, in microseconds, since some undefined point in the past. |
| 29 // The values are only meaningful relative to other values that were obtained | 37 // The values are only meaningful relative to other values that were obtained |
| 30 // from the same device without an intervening system restart. Such values are | 38 // from the same device without an intervening system restart. Such values are |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 // |MOJO_RESULT_FAILED_PRECONDITION| if it is or becomes impossible that SOME | 130 // |MOJO_RESULT_FAILED_PRECONDITION| if it is or becomes impossible that SOME |
| 123 // |handle[i]| will ever satisfy any of the signals in |signals[i]|. | 131 // |handle[i]| will ever satisfy any of the signals in |signals[i]|. |
| 124 MOJO_SYSTEM_EXPORT MojoResult | 132 MOJO_SYSTEM_EXPORT MojoResult |
| 125 MojoWaitMany(const MojoHandle* handles, | 133 MojoWaitMany(const MojoHandle* handles, |
| 126 const MojoHandleSignals* signals, | 134 const MojoHandleSignals* signals, |
| 127 uint32_t num_handles, | 135 uint32_t num_handles, |
| 128 MojoDeadline deadline, | 136 MojoDeadline deadline, |
| 129 uint32_t* result_index, // Optional out | 137 uint32_t* result_index, // Optional out |
| 130 struct MojoHandleSignalsState* signals_states); // Optional out | 138 struct MojoHandleSignalsState* signals_states); // Optional out |
| 131 | 139 |
| 140 // Watches the given handle for one of the following events to happen: | |
| 141 // - A signal indicated by |signals| is satisfied. | |
| 142 // - It becomes known that no signal indicated by |signals| will ever be | |
| 143 // satisfied. (See the description of the |MOJO_RESULT_CANCELLED| and | |
| 144 // |MOJO_RESULT_FAILED_PRECONDITION| return values below.) | |
| 145 // - The handle is closed. | |
| 146 // | |
| 147 // |handle|: The handle to watch. Must be an open message pipe handle. | |
| 148 // TODO: Perhaps we could also support data pipes here. | |
|
Anand Mistry (off Chromium)
2016/02/29 12:03:35
If you want to replace wait, you need to support d
Ken Rockot(use gerrit already)
2016/02/29 20:59:06
Yeah, was just trying to avoid more noise in the C
| |
| 149 // |signals|: The signals to watch for. | |
| 150 // |callback|: A function to be called any time one of the above events happens. | |
| 151 // The function must be safe to call from any thread. | |
| 152 // |context|: User-provided context passed to |callback| when called. |context| | |
| 153 // is used to uniquely identify a registered watch and can be used to cancel | |
| 154 // the watch later using |MojoCancelWatch().| | |
|
Anand Mistry (off Chromium)
2016/02/29 12:03:35
nit: |MojoCancelWatch()|.
Ken Rockot(use gerrit already)
2016/02/29 20:59:06
Done
| |
| 155 // | |
| 156 // Returns: | |
| 157 // |MOJO_RESULT_OK| if the watch has been successfully registered. Note that | |
| 158 // if the signals are already satisfied this may synchronously invoke | |
| 159 // |callback| before returning. | |
| 160 // |MOJO_RESULT_CANCELLED| if the watch was cancelled. In this case it is not | |
| 161 // necessary to explicitly call |MojoCancelWatch()|, and in fact it may be | |
| 162 // an error to do so as the handle may have been closed. | |
| 163 // |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not an open message pipe | |
| 164 // handle. | |
| 165 // |MOJO_RESULT_FAILED_PRECONDITION| if it is already known that |signals| can | |
| 166 // never be satisfied. | |
| 167 // |MOJO_RESULT_ALREADY_EXISTS| if there is already a watch registered for | |
| 168 // the same combination of |handle| and |context|. | |
| 169 // | |
| 170 // Callback result codes: | |
| 171 // The callback may be called at any time with one of the following result | |
|
Anand Mistry (off Chromium)
2016/02/29 12:03:35
at any time... on any thread...
I think. I didn't
Ken Rockot(use gerrit already)
2016/02/29 20:59:06
Done
| |
| 172 // codes to indicate various events: | |
| 173 // | |
| 174 // |MOJO_RESULT_OK| indicates that some signal in |signals| has been | |
| 175 // satisfied. | |
| 176 // |MOJO_RESULT_FAILED_PRECONDITION| indicates that no signals in |signals| | |
| 177 // can ever be satisfied again. | |
| 178 // |MOJO_RESULT_CANCELLED| indicates that the handle has been closed. In this | |
| 179 // case the watch is implicitly cancelled and there is no need to call | |
| 180 // |MojoCancelWatch()|. | |
| 181 MOJO_SYSTEM_EXPORT MojoResult | |
| 182 MojoWatch(MojoHandle handle, | |
| 183 MojoHandleSignals signals, | |
| 184 MojoWatchCallback callback, | |
| 185 uintptr_t context); | |
| 186 | |
| 187 // Cancels a handle watch corresponding to some prior call to |MojoWatch()|. | |
| 188 // | |
| 189 // |context|: The same user-provided context given to some prior call to | |
| 190 // |MojoWatch()|. Only the watch corresponding to this context will be | |
| 191 // cancelled. | |
| 192 // | |
| 193 // Returns: | |
| 194 // |MOJO_RESULT_OK| if the watch corresponding to |context| was cancelled. | |
|
Anand Mistry (off Chromium)
2016/02/29 12:03:35
Can you clarify what happens if the watch is in th
Ken Rockot(use gerrit already)
2016/02/29 20:59:06
Done
| |
| 195 // |MOJO_RESULT_INVALID_ARGUMENT| if no watch was registered with |context| | |
| 196 // for the given |handle|, or if |handle| is invalid. | |
| 197 MOJO_SYSTEM_EXPORT MojoResult | |
| 198 MojoCancelWatch(MojoHandle handle, uintptr_t context); | |
| 199 | |
| 132 #ifdef __cplusplus | 200 #ifdef __cplusplus |
| 133 } // extern "C" | 201 } // extern "C" |
| 134 #endif | 202 #endif |
| 135 | 203 |
| 136 #endif // MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ | 204 #endif // MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ |
| OLD | NEW |