Initial Commit
[apps/agl-service-unicens.git] / ucs2-lib / src / ucs_telqueue.c
1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491                                                                            */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
4 /*                                                                                                */
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.                                                            */
9 /*                                                                                                */
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.                                                   */
14 /*                                                                                                */
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/>.                          */
17 /*                                                                                                */
18 /* You may also obtain this software under a propriety license from Microchip.                    */
19 /* Please contact Microchip for further information.                                              */
20 /*------------------------------------------------------------------------------------------------*/
21
22 /*!
23  * \file
24  * \brief Implementation of class CTelQueue
25  *
26  * \cond UCS_INTERNAL_DOC
27  * \addtogroup  G_MSG_QUEUE
28  * @{
29  */
30
31 /*------------------------------------------------------------------------------------------------*/
32 /* Includes                                                                                       */
33 /*------------------------------------------------------------------------------------------------*/
34 #include "ucs_telqueue.h"
35 #include "ucs_misc.h"
36
37 /*------------------------------------------------------------------------------------------------*/
38 /* Internal constants                                                                             */
39 /*------------------------------------------------------------------------------------------------*/
40
41 /*------------------------------------------------------------------------------------------------*/
42 /* Implementation                                                                                 */
43 /*------------------------------------------------------------------------------------------------*/
44 /*! \brief  Constructor of class CTelQueue
45  *  \param  self            The instance
46  *  \param  ucs_user_ptr User reference that needs to be passed in every callback function
47  */
48 void Telq_Ctor(CTelQueue *self, void *ucs_user_ptr)
49 {
50     self->ucs_user_ptr = ucs_user_ptr;
51     Dl_Ctor(&self->list, self->ucs_user_ptr);
52 }
53
54 /*! \brief  Retrieves the head object of the telegram queue
55  *  \param  self    The instance
56  *  \return Reference to the telegram if a telegram object is available.
57  *          Otherwise \c NULL.
58  */
59 Msg_MostTel_t* Telq_Dequeue(CTelQueue *self)
60 {
61     Msg_MostTel_t *tel_ptr = NULL;
62     CDlNode *node_ptr = Dl_PopHead(&self->list);
63
64     if (node_ptr != NULL)
65     {
66         tel_ptr = (Msg_MostTel_t*)Dln_GetData(node_ptr);
67     }
68
69     return tel_ptr;
70 }
71
72 /*! \brief  Retrieves a reference to the head object 
73  *          without removing it from the telegram queue
74  *  \param  self    The instance
75  *  \return Reference to the telegram if a telegram object is available.
76  *          Otherwise \c NULL.
77  */
78 Msg_MostTel_t* Telq_Peek(CTelQueue *self)
79 {
80     Msg_MostTel_t *tel_ptr = NULL;
81     CDlNode *node_ptr = Dl_PeekHead(&self->list);
82
83     if (node_ptr != NULL)
84     {
85         tel_ptr = (Msg_MostTel_t*)Dln_GetData(node_ptr);
86     }
87
88     return tel_ptr;
89 }
90
91 /*! \brief  Adds a telegram to the tail of the queue
92  *  \param  self    The instance
93  *  \param  tel_ptr Reference to the telegram 
94  */
95 void Telq_Enqueue(CTelQueue *self, Msg_MostTel_t *tel_ptr)
96 {
97     Dl_InsertTail(&self->list, Msg_GetNode((CMessage*)(void*)tel_ptr));
98 }
99
100 /*! \brief  Retrieves the current number of objects in the telegram queue 
101  *  \param  self    The instance
102  *  \return The current number of available telegram objects in the pool
103  */
104 uint8_t Telq_GetSize(CTelQueue *self)
105 {
106     return (uint8_t)Dl_GetSize(&self->list);
107 }
108
109 /*!
110  * @}
111  * \endcond
112  */
113
114 /*------------------------------------------------------------------------------------------------*/
115 /* End of file                                                                                    */
116 /*------------------------------------------------------------------------------------------------*/
117