1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491 */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG. */
5 /* This program is free software: you can redistribute it and/or modify */
6 /* it under the terms of the GNU General Public License as published by */
7 /* the Free Software Foundation, either version 2 of the License, or */
8 /* (at your option) any later version. */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU General Public License for more details. */
15 /* You should have received a copy of the GNU General Public License */
16 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* You may also obtain this software under a propriety license from Microchip. */
19 /* Please contact Microchip for further information. */
20 /*------------------------------------------------------------------------------------------------*/
24 * \brief Implementation of the Connection Storage Pool.
26 * \cond UCS_INTERNAL_DOC
27 * \addtogroup G_UCS_XRM_INT
31 /*------------------------------------------------------------------------------------------------*/
33 /*------------------------------------------------------------------------------------------------*/
34 #include "ucs_xrmpool.h"
35 #include "ucs_xrm_pv.h"
37 /*------------------------------------------------------------------------------------------------*/
38 /* Implementation of class XrmPool */
39 /*------------------------------------------------------------------------------------------------*/
40 /*------------------------------------------------------------------------------------------------*/
41 /* Initialization Methods */
42 /*------------------------------------------------------------------------------------------------*/
43 /*! \brief Constructor of the XrmPool class.
44 * \param self Instance pointer
46 void Xrmp_Ctor(CXrmPool * self)
49 MISC_MEM_SET(self, 0, sizeof(CXrmPool));
51 /* Initialize resource handle list */
52 for(i=0U; i<XRM_NUM_RESOURCE_HANDLES; i++)
54 self->resource_handle_list[i].resource_handle = XRM_INVALID_RESOURCE_HANDLE;
55 self->resource_handle_list[i].job_ptr = NULL;
56 self->resource_handle_list[i].resource_object_ptr = NULL;
60 /*------------------------------------------------------------------------------------------------*/
62 /*------------------------------------------------------------------------------------------------*/
63 /*! \brief Stores the given resource handle in the resource handle list.
64 * \param self_ptr XrmPool Instance pointer
65 * \param resource_handle Resource handle to save
66 * \param job_ptr Reference to job
67 * \param resource_object_ptr Reference to resource object
68 * \return \c true if free slot in handle list was found, otherwise \c false
70 bool Xrmp_StoreResourceHandle(CXrmPool * self_ptr, uint16_t resource_handle, Xrm_Job_t * job_ptr, UCS_XRM_CONST Ucs_Xrm_ResObject_t * resource_object_ptr)
75 for(i=0U; i<XRM_NUM_RESOURCE_HANDLES; i++)
77 if(self_ptr->resource_handle_list[i].job_ptr == NULL)
79 self_ptr->resource_handle_list[i].job_ptr = job_ptr;
80 self_ptr->resource_handle_list[i].resource_object_ptr = resource_object_ptr;
81 self_ptr->resource_handle_list[i].resource_handle = resource_handle;
90 /*! \brief Retrieves the resource handle identified by the given job reference and the given
91 * resource object reference.
92 * \param self Instance pointer
93 * \param job_ptr Reference to the job. Use NULL as wildcard.
94 * \param resource_object_ptr Reference to the resource object
95 * \param func_ptr Optional function pointer in order to check whether the found job belongs to the provided XRM instance.
96 * \param usr_ptr User pointer used to store the XRM instance to be looked for
97 * \return Resource handle if handle was found, otherwise XRM_INVALID_RESOURCE_HANDLE.
99 uint16_t Xrmp_GetResourceHandle(CXrmPool * self, Xrm_Job_t * job_ptr, UCS_XRM_CONST Ucs_Xrm_ResObject_t * resource_object_ptr, Xrmp_CheckJobListFunc_t func_ptr, void * usr_ptr)
101 uint16_t ret_val = XRM_INVALID_RESOURCE_HANDLE;
103 bool job_found = true;
105 for(i=0U; i<XRM_NUM_RESOURCE_HANDLES; i++)
107 if(((self->resource_handle_list[i].job_ptr == job_ptr) || (job_ptr == NULL)) &&
108 (self->resource_handle_list[i].resource_object_ptr == resource_object_ptr))
110 if ((func_ptr != NULL) && (usr_ptr != NULL))
112 job_found = func_ptr(usr_ptr, self->resource_handle_list[i].job_ptr);
117 ret_val = self->resource_handle_list[i].resource_handle;
126 /*! \brief Returns the table index of the given resource object.
127 * \param self Instance pointer
128 * \param job_ptr Reference to job
129 * \param obj_pptr Reference to array of references to INIC resource objects
130 * \return Table index of the given resource object. If entry is not found 0xFF is returned.
132 uint8_t Xrmp_GetResourceHandleIdx(CXrmPool *self, Xrm_Job_t *job_ptr, UCS_XRM_CONST Ucs_Xrm_ResObject_t **obj_pptr)
135 uint8_t ret_val = 0xFFU;
139 while(job_ptr->resource_object_list_ptr[i] != NULL)
141 if(job_ptr->resource_object_list_ptr[i] == *obj_pptr)
152 /*! \brief Returns the reference of the job that is identified by the given resource object list.
153 * \param self Instance pointer
154 * \param resource_object_list[] Reference to array of references to INIC resource objects
155 * \return Reference to the desired job if the job was found, otherwise NULL.
157 Xrm_Job_t * Xrmp_GetJob(CXrmPool * self, UCS_XRM_CONST Ucs_Xrm_ResObject_t * resource_object_list[])
160 Xrm_Job_t *ret_ptr = NULL;
162 for(i=0U; i<(uint8_t)XRM_NUM_JOBS; i++)
164 if(self->job_list[i].resource_object_list_ptr == resource_object_list)
166 ret_ptr = &self->job_list[i];
169 else if((self->job_list[i].resource_object_list_ptr == NULL) && (ret_ptr == NULL))
171 ret_ptr = &self->job_list[i];
178 /*! \brief Calls the given function for each node in the resource list. If the func_ptr
179 * returns true the loop is stopped.
180 * \param self Instance pointer
181 * \param func_ptr Reference of the callback function which is called for each node
182 * \param user_data_ptr1 Reference of optional user data 1 pass to func_ptr
183 * \param user_data_ptr2 Reference of optional user data 2 pass to func_ptr
184 * \param user_data_ptr3 Reference of optional user data 3 pass to func_ptr
186 void Xrmp_Foreach(CXrmPool *self, Xrmp_ForeachFunc_t func_ptr, void *user_data_ptr1, void *user_data_ptr2, void *user_data_ptr3)
190 for(j=0U; j<XRM_NUM_RESOURCE_HANDLES; j++)
192 if (self->resource_handle_list[j].job_ptr != NULL)
194 if (func_ptr(&self->resource_handle_list[j], user_data_ptr1, user_data_ptr2, user_data_ptr3) != false)
207 /*------------------------------------------------------------------------------------------------*/
209 /*------------------------------------------------------------------------------------------------*/