xref: /aosp_15_r20/external/libchrome/mojo/public/c/system/functions.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2014 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker // This file contains basic functions common to different Mojo system APIs.
6*635a8641SAndroid Build Coastguard Worker //
7*635a8641SAndroid Build Coastguard Worker // Note: This header should be compilable as C.
8*635a8641SAndroid Build Coastguard Worker 
9*635a8641SAndroid Build Coastguard Worker #ifndef MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_
10*635a8641SAndroid Build Coastguard Worker #define MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_
11*635a8641SAndroid Build Coastguard Worker 
12*635a8641SAndroid Build Coastguard Worker #include <stddef.h>
13*635a8641SAndroid Build Coastguard Worker #include <stdint.h>
14*635a8641SAndroid Build Coastguard Worker 
15*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/system_export.h"
16*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/types.h"
17*635a8641SAndroid Build Coastguard Worker 
18*635a8641SAndroid Build Coastguard Worker #ifdef __cplusplus
19*635a8641SAndroid Build Coastguard Worker extern "C" {
20*635a8641SAndroid Build Coastguard Worker #endif
21*635a8641SAndroid Build Coastguard Worker 
22*635a8641SAndroid Build Coastguard Worker // Initializes Mojo in the calling application.
23*635a8641SAndroid Build Coastguard Worker //
24*635a8641SAndroid Build Coastguard Worker // With the exception of Mojo Core embedders, applications using Mojo APIs must
25*635a8641SAndroid Build Coastguard Worker // call this function before any others.
26*635a8641SAndroid Build Coastguard Worker //
27*635a8641SAndroid Build Coastguard Worker // |options| may be null.
28*635a8641SAndroid Build Coastguard Worker //
29*635a8641SAndroid Build Coastguard Worker // Returns:
30*635a8641SAndroid Build Coastguard Worker //   |MOJO_RESULT_OK| if Mojo intiailization was successful.
31*635a8641SAndroid Build Coastguard Worker //   |MOJO_RESULT_INVALID_ARGUMENT| if |options| was null or invalid.
32*635a8641SAndroid Build Coastguard Worker //   |MOJO_RESULT_FAILED_PRECONDITION| if |MojoInitialize()| was already called
33*635a8641SAndroid Build Coastguard Worker //       once or if the application already explicitly initialized a Mojo Core
34*635a8641SAndroid Build Coastguard Worker //       environment as an embedder.
35*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoResult
36*635a8641SAndroid Build Coastguard Worker MojoInitialize(const struct MojoInitializeOptions* options);
37*635a8641SAndroid Build Coastguard Worker 
38*635a8641SAndroid Build Coastguard Worker // Returns the time, in microseconds, since some undefined point in the past.
39*635a8641SAndroid Build Coastguard Worker // The values are only meaningful relative to other values that were obtained
40*635a8641SAndroid Build Coastguard Worker // from the same device without an intervening system restart. Such values are
41*635a8641SAndroid Build Coastguard Worker // guaranteed to be monotonically non-decreasing with the passage of real time.
42*635a8641SAndroid Build Coastguard Worker // Although the units are microseconds, the resolution of the clock may vary and
43*635a8641SAndroid Build Coastguard Worker // is typically in the range of ~1-15 ms.
44*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoTimeTicks MojoGetTimeTicksNow(void);
45*635a8641SAndroid Build Coastguard Worker 
46*635a8641SAndroid Build Coastguard Worker // Closes the given |handle|.
47*635a8641SAndroid Build Coastguard Worker //
48*635a8641SAndroid Build Coastguard Worker // Returns:
49*635a8641SAndroid Build Coastguard Worker //   |MOJO_RESULT_OK| on success.
50*635a8641SAndroid Build Coastguard Worker //   |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle.
51*635a8641SAndroid Build Coastguard Worker //
52*635a8641SAndroid Build Coastguard Worker // Concurrent operations on |handle| may succeed (or fail as usual) if they
53*635a8641SAndroid Build Coastguard Worker // happen before the close, be cancelled with result |MOJO_RESULT_CANCELLED| if
54*635a8641SAndroid Build Coastguard Worker // they properly overlap (this is likely the case with traps), or fail with
55*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_INVALID_ARGUMENT| if they happen after.
56*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoResult MojoClose(MojoHandle handle);
57*635a8641SAndroid Build Coastguard Worker 
58*635a8641SAndroid Build Coastguard Worker // Queries the last known signals state of a handle.
59*635a8641SAndroid Build Coastguard Worker //
60*635a8641SAndroid Build Coastguard Worker // Note that no guarantees can be made about the accuracy of the returned
61*635a8641SAndroid Build Coastguard Worker // signals state by the time this returns, as other threads in the system may
62*635a8641SAndroid Build Coastguard Worker // change the handle's state at any time. Use with appropriate discretion.
63*635a8641SAndroid Build Coastguard Worker //
64*635a8641SAndroid Build Coastguard Worker // Returns:
65*635a8641SAndroid Build Coastguard Worker //   |MOJO_RESULT_OK| on success. |*signals_state| is populated with the
66*635a8641SAndroid Build Coastguard Worker //       last known signals state of |handle|.
67*635a8641SAndroid Build Coastguard Worker //   |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle or
68*635a8641SAndroid Build Coastguard Worker //       |signals_state| is null.
69*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoResult
70*635a8641SAndroid Build Coastguard Worker MojoQueryHandleSignalsState(MojoHandle handle,
71*635a8641SAndroid Build Coastguard Worker                             struct MojoHandleSignalsState* signals_state);
72*635a8641SAndroid Build Coastguard Worker 
73*635a8641SAndroid Build Coastguard Worker #ifdef __cplusplus
74*635a8641SAndroid Build Coastguard Worker }  // extern "C"
75*635a8641SAndroid Build Coastguard Worker #endif
76*635a8641SAndroid Build Coastguard Worker 
77*635a8641SAndroid Build Coastguard Worker #endif  // MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_
78