1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef FOGIPC_h__
7 #define FOGIPC_h__
8 
9 #include <functional>
10 
11 #include "mozilla/Maybe.h"
12 #include "mozilla/MozPromise.h"
13 #include "nsTArrayForwardDeclare.h"
14 
15 namespace mozilla {
16 namespace ipc {
17 class ByteBuf;
18 }  // namespace ipc
19 }  // namespace mozilla
20 
21 // This module provides the interface for FOG to communicate between processes.
22 
23 namespace mozilla {
24 namespace glean {
25 
26 /**
27  * The parent process is asking you to flush your data ASAP.
28  *
29  * @param aResolver - The function you need to call with the bincoded,
30  *                    serialized payload that the Rust impl hands you.
31  */
32 void FlushFOGData(std::function<void(ipc::ByteBuf&&)>&& aResolver);
33 
34 /**
35  * Called by FOG on the parent process when it wants to flush all its
36  * children's data.
37  * @param aResolver - The function that'll be called with the results.
38  */
39 void FlushAllChildData(
40     std::function<void(nsTArray<ipc::ByteBuf>&&)>&& aResolver);
41 
42 /**
43  * A child process has sent you this buf as a treat.
44  * @param buf - a bincoded serialized payload that the Rust impl understands.
45  */
46 void FOGData(ipc::ByteBuf&& buf);
47 
48 /**
49  * Called by FOG on a child process when it wants to send a buf to the parent.
50  * @param buf - a bincoded serialized payload that the Rust impl understands.
51  */
52 void SendFOGData(ipc::ByteBuf&& buf);
53 
54 /**
55  * Called on the parent process to ask all child processes for data,
56  * sending it all down into Rust to be used.
57  *
58  * @returns a Promise that resolves when the data has made it to the parent.
59  */
60 RefPtr<GenericPromise> FlushAndUseFOGData();
61 
62 }  // namespace glean
63 }  // namespace mozilla
64 
65 #endif  // FOGIPC_h__
66