Re-organized sub-directory by category
[staging/basesystem.git] / service / system / resource_manager / client / src / #resmgr_api_lib.c#
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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 #include <other_service/rpc.h>
18 #include "resm_internal.h"
19 #include "resmgr_api.h"
20 #include "resmgr_api_resourcemanagerlog.h"
21
22 /**********************************************
23  * External variable definitions
24  **********************************************/
25 RPC_ID __thread rpcId;
26
27 /*******************************************************************************
28  * RPC public API
29  *******************************************************************************/
30 /* Connection */
31 RESM_ERR_t
32 RESM_Open(const RESM_RSV_t* p_prim, uint32_t* p_ssnId)
33 {
34
35   RESM_ERR_t resmRet;
36   EV_ERR evRet;
37
38   // Argument check
39   if( p_ssnId == NULL ) {
40     return RESM_E_PAR;
41   }
42
43   // RPC resources
44   if( RPC_OK != RPC_START_CLIENT(&rpcId) ) {
45     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "[RESM_ERR]ResMgr Open: RPC_START Error"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
46     return RESM_E_NG;
47   }
48
49
50   // Session connection
51   resmRet = RESM_SV_Open(p_prim, p_ssnId);
52   if( resmRet != RESM_E_OK ) {
53     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "[RESM_ERR]ResMgr Open: Open Session Error. ret[%d]", resmRet); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
54     return RESM_E_NG;
55   }
56
57   // Create Event Flag
58   evRet = EV_create_flag(Resm_Flag_ID_Base + *p_ssnId);
59   if( evRet != EV_OK ) {
60     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "[RESM_ERR]ResMgr Open: create_flag Error. ret[%d]", evRet);
61     return RESM_E_NG;
62   }
63
64   return RESM_E_OK;
65 }
66
67 /* Disconnection */
68 RESM_ERR_t
69 RESM_Close(uint32_t ssnId)
70 {
71
72   RESM_ERR_t resmRet;
73
74   // Disconnect session
75   resmRet = RESM_SV_Close(ssnId);
76   if( resmRet != RESM_E_OK ) {
77     return resmRet;
78   }
79
80   // Destroy RPC Resources
81   RPC_end(rpcId);
82
83   return RESM_E_OK;
84 }
85
86 /* Get event FD */
87 RESM_ERR_t
88 RESM_GetEventFd(uint32_t ssnId, int32_t* p_fd)
89 {
90
91   RESM_ERR_t resmRet;
92
93   // Argument check
94   if( p_fd == NULL ) {
95     return RESM_E_PAR;
96   }
97   // Session ID check
98   resmRet = RESM_SV_ChkSsnId(ssnId);
99   if( resmRet != RESM_E_OK ) {
100     return RESM_E_PAR;
101   }
102
103   if( EV_OK  != EV_get_flag_fd(Resm_Flag_ID_Base + ssnId, p_fd) ) {
104     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "[RESM_ERR]ResMgr GetEventFd Error");
105     return RESM_E_NG;
106   }
107
108   return RESM_E_OK;
109 }
110
111 /* Get event */
112 RESM_ERR_t
113 RESM_GetEvent(uint32_t ssnId, RESM_EV_t* p_evFlag)
114 {
115
116   RESM_ERR_t resmRet;
117   EV_Flag flag;
118
119   // Argument check
120   if( p_evFlag == NULL ) {
121     return RESM_E_PAR;
122   }
123   // Session ID Check
124   resmRet = RESM_SV_ChkSsnId(ssnId);
125   if( resmRet != RESM_E_OK ) {
126     return RESM_E_PAR;
127   }
128
129   if( EV_OK != EV_get_flag(Resm_Flag_ID_Base + ssnId, &flag)) {
130     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "[RESM_ERR]ResMgr GetEvent(get_flag) Error");
131     return RESM_E_NG;
132   }
133
134   if( flag.bits == 0 ) {
135     // No event
136     return RESM_E_NG;
137   }
138
139   *p_evFlag = flag.bits;
140
141   return RESM_E_OK;
142 }