Add initial version
[src/drm-lease-manager.git] / libdlmclient / dlmclient.h
1 /* Copyright 2020-2021 IGEL Co., Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 /**
17  * @file dlmclient.h
18  */
19 #ifndef DLM_CLIENT_H
20 #define DLM_CLIENT_H
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #include <stdbool.h>
27
28 /**
29  * @brief Enable debug logging
30  *
31  * @param[in] enable enable/disable debug logging
32  */
33 void dlm_enable_debug_log(bool enable);
34
35 /**
36  * @brief lease handle
37  */
38 struct dlm_lease;
39
40 /**
41  * @brief  Get a DRM lease from the lease manager
42  *
43  * @param[in] name requested lease
44  * @return A pointer to a lease handle on success.
45  *         On error this function returns NULL and errno is set accordingly.
46  *
47  *  Possible errors:
48  *
49  *  errno        |  Meaning
50  *  -------------|-------------------------------------------------------------
51  *  EACCESS      |  Cannot access lease manager socket directory
52  *  EACCESS      |  Lease request denied by lease manager
53  *  ENAMETOOLONG |  The path to the lease manager socket directory is too long
54  *  ENOENT       |  Lease manager or requested lease not available
55  *  ENOMEM       |  Out of memory during operation
56  *  EPROTO       |  Protocol error in communication with lease manager
57  *
58  *  This list is not exhaustive, and errno may be set to other error codes,
59  *  especially those related to socket communication.
60  */
61 struct dlm_lease *dlm_get_lease(const char *name);
62
63 /**
64  * @brief  Release a lease handle
65  *
66  * @details Release a lease handle.  The lease handle will be invalidated and
67  *          the associated DRM lease wil be revoked.  Any fd's retrieved from
68  *          dlm_lease_fd() will be closed.
69  * @param[in] lease pointer to lease handle
70  */
71 void dlm_release_lease(struct dlm_lease *lease);
72
73 /**
74  * @brief Get a DRM Master fd from a valid lease handle
75  *
76  * @param[in] lease pointer to a lease handle
77  * @return A DRM Master file descriptor for the lease on success.
78  *         -1 is returned when called with a NULL lease handle.
79  */
80 int dlm_lease_fd(struct dlm_lease *lease);
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif