1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "storage.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 struct watcher;
26 
27 /**
28  * watch_start() - Create a watcher for a storage request
29  * @id:        Identifier string to distinguish watchers
30  * @request:   Incoming request from Trusty storage service
31  *
32  * Create a watcher that will start logging if not finished before a timeout.
33  * Only one watcher may be active at a time, and this function may only be
34  * called from a single thread.
35  */
36 struct watcher* watch_start(const char* id, const struct storage_msg* request);
37 
38 /**
39  * watch_progress() - Note progress on servicing the current request
40  * @watcher:   Current watcher, created by watch()
41  *
42  * Sets the current progress state of the watcher, to allow for more granular
43  * reporting of what exactly is stuck if the timeout is reached.
44  */
45 void watch_progress(struct watcher* watcher, const char* state);
46 
47 /**
48  * watch_finish() - Finish watching and unregister the watch
49  * @watcher:   Current watcher, created by watch(). Takes ownership of this pointer.
50  *
51  * Finish the current watch task. This function takes ownership of the watcher
52  * and destroys it, so @watcher must not be used again after calling this
53  * function.
54  */
55 void watch_finish(struct watcher* watcher);
56 
57 #ifdef __cplusplus
58 }
59 #endif
60