]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blob - qnx/src/ipc3x_dev/ti/syslink/ipc/hlos/knl/Qnx/messageq_devctl.c
Re-work MessageQ_put to eliminate transport recursion
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / ipc / hlos / knl / Qnx / messageq_devctl.c
1 /*
2  *  @file   messageq_devctl.c
3  *
4  *  @brief      OS-specific implementation of Messageq driver for Qnx
5  *
6  *
7  *  ============================================================================
8  *
9  *  Copyright (c) 2013-2015, Texas Instruments Incorporated
10  *
11  *  Redistribution and use in source and binary forms, with or without
12  *  modification, are permitted provided that the following conditions
13  *  are met:
14  *
15  *  *  Redistributions of source code must retain the above copyright
16  *     notice, this list of conditions and the following disclaimer.
17  *
18  *  *  Redistributions in binary form must reproduce the above copyright
19  *     notice, this list of conditions and the following disclaimer in the
20  *     documentation and/or other materials provided with the distribution.
21  *
22  *  *  Neither the name of Texas Instruments Incorporated nor the names of
23  *     its contributors may be used to endorse or promote products derived
24  *     from this software without specific prior written permission.
25  *
26  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28  *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
33  *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *  Contact information for paper mail:
38  *  Texas Instruments
39  *  Post Office Box 655303
40  *  Dallas, Texas 75265
41  *  Contact information:
42  *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
43  *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
44  *  ============================================================================
45  *
46  */
49 /* Standard headers */
50 #include <ti/syslink/Std.h>
52 /* OSAL & Utils headers */
53 #include <ti/syslink/utils/List.h>
54 #include <ti/syslink/utils/Trace.h>
55 #include <ti/syslink/utils/Memory.h>
57 /* QNX specific header include */
58 #include <ti/syslink/build/Qnx/resmgr/proto.h>
59 #include <ti/syslink/build/Qnx/resmgr/dcmd_syslink.h>
61 /* Module specific header files */
62 #include <ti/ipc/MessageQ.h>
63 #include <ti/syslink/inc/MessageQDrvDefs.h>
64 #include <ti/syslink/inc/_MessageQ_daemon.h>
66 /* Function prototypes */
67 int ipc_messageq_getconfig(resmgr_context_t *ctp, io_devctl_t *msg,
68     ipc_ocb_t *ocb);
69 int ipc_messageq_setup(resmgr_context_t *ctp, io_devctl_t *msg,
70     ipc_ocb_t *ocb);
71 int ipc_messageq_destroy(resmgr_context_t *ctp, io_devctl_t *msg,
72     ipc_ocb_t *ocb);
73 int ipc_messageq_create(resmgr_context_t *ctp, io_devctl_t *msg,
74     ipc_ocb_t *ocb);
75 int ipc_messageq_delete(resmgr_context_t *ctp, io_devctl_t *msg,
76     ipc_ocb_t *ocb);
78 /**
79  * Handler for devctl() messages for messageQ module.
80  *
81  * Handles special devctl() messages that we export for control.
82  *
83  * \param ctp   Thread's associated context information.
84  * \param msg   The actual devctl() message.
85  * \param ocb   OCB associated with client's session.
86  *
87  * \return POSIX errno value.
88  *
89  * \retval EOK      Success.
90  * \retval ENOTSUP  Unsupported devctl().
91  */
92 int ipc_messageq_devctl(resmgr_context_t *ctp, io_devctl_t *msg,
93     ipc_ocb_t *ocb)
94 {
95     switch (msg->i.dcmd)
96     {
97           case DCMD_MESSAGEQ_CREATE:
98           {
99                 return ipc_messageq_create( ctp, msg, ocb);
100           }
101           break;
103           case DCMD_MESSAGEQ_DELETE:
104           {
105                 return ipc_messageq_delete( ctp, msg, ocb);
106           }
107           break;
109           case DCMD_MESSAGEQ_GETCONFIG:
110           {
111                 return ipc_messageq_getconfig( ctp, msg, ocb);
112           }
113           break;
115           case DCMD_MESSAGEQ_SETUP:
116           {
117                 return ipc_messageq_setup( ctp, msg, ocb);
118           }
119           break;
121           case DCMD_MESSAGEQ_DESTROY:
122           {
123                 return ipc_messageq_destroy( ctp, msg, ocb);
124           }
125           break;
127      default:
128         fprintf( stderr, "Invalid DEVCTL for messageQ 0x%x \n", msg->i.dcmd);
129         break;
131     }
133     return (_RESMGR_PTR(ctp, &msg->o, sizeof(msg->o) +
134         sizeof(MessageQDrv_CmdArgs)));
137 /**
138  * Handler for messageq create API.
139  *
140  * \param ctp   Thread's associated context information.
141  * \param msg   The actual devctl() message.
142  * \param ocb   OCB associated with client's session.
143  *
144  * \return POSIX errno value.
145  *
146  * \retval EOK      Success.
147  * \retval ENOTSUP  Unsupported devctl().
148  */
149 int ipc_messageq_create(resmgr_context_t *ctp, io_devctl_t *msg,
150     ipc_ocb_t *ocb)
152     MessageQDrv_CmdArgs *       cargs = (MessageQDrv_CmdArgs *)
153         (_DEVCTL_DATA (msg->i));
154     MessageQDrv_CmdArgs *       out   = (MessageQDrv_CmdArgs *)
155         (_DEVCTL_DATA (msg->o));
156     MessageQ_Params *local_createparams = NULL;
157     String local_createname = NULL;
158     UInt32 local_queueId;
160     out->apiStatus = MessageQ_S_SUCCESS;
162     if (cargs->args.create.params) {
163         local_createparams = (MessageQ_Params *)(cargs+1);
164         if (cargs->args.create.name)
165             local_createname = (String)(local_createparams+1);
166     }
167     else {
168         if (cargs->args.create.name)
169             local_createname = (String)(cargs+1);
170     }
172     local_queueId = cargs->args.create.queueId;
174     /* Force MessageQ to use the id passed in as the bottom 16-bit of its queue id */
175     out->args.create.handle = MessageQ_createWithQueueId(local_createname,
176         local_createparams, local_queueId);
177     GT_assert (curTrace, (out->args.create.handle != NULL));
179     /* Set failure status if create has failed. */
180     if (out->args.create.handle == NULL) {
181         out->apiStatus = MessageQ_E_FAIL;
182     }
183     else {
184         out->apiStatus = MessageQ_S_SUCCESS;
185     }
187     if (out->args.create.handle != NULL) {
188         out->args.create.queueId = MessageQ_getQueueId(out->args.create.handle);
189         /*
190          * TODO: Need to implement cleanup of queues for processes that departed
191          */
192         /* MessageQ_setQueueOwner(out->args.create.handle,clientPID[clientId])*/
193     }
195     SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) +
196         sizeof(MessageQDrv_CmdArgs));
197     return _RESMGR_NPARTS(1);
200 /**
201  * Handler for messageq delete API.
202  *
203  * \param ctp   Thread's associated context information.
204  * \param msg   The actual devctl() message.
205  * \param ocb   OCB associated with client's session.
206  *
207  * \return POSIX errno value.
208  *
209  * \retval EOK      Success.
210  * \retval ENOTSUP  Unsupported devctl().
211  */
212 int ipc_messageq_delete(resmgr_context_t *ctp, io_devctl_t *msg,
213     ipc_ocb_t *ocb)
215     MessageQDrv_CmdArgs * cargs = (MessageQDrv_CmdArgs *)
216         (_DEVCTL_DATA (msg->i));
217     MessageQDrv_CmdArgs * out  = (MessageQDrv_CmdArgs *)(_DEVCTL_DATA (msg->o));
219     out->apiStatus = MessageQ_delete ((MessageQ_Handle *)
220         &(cargs->args.deleteMessageQ.handle));
221     GT_assert (curTrace, (out->apiStatus >= 0));
223     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
224         sizeof(MessageQDrv_CmdArgs)));
227 /**
228  * Handler for messageq getconfig API.
229  *
230  * \param ctp   Thread's associated context information.
231  * \param msg   The actual devctl() message.
232  * \param ocb   OCB associated with client's session.
233  *
234  * \return POSIX errno value.
235  *
236  * \retval EOK      Success.
237  * \retval ENOTSUP  Unsupported devctl().
238  */
239 int ipc_messageq_getconfig(resmgr_context_t *ctp, io_devctl_t *msg,
240     ipc_ocb_t *ocb)
242     MessageQDrv_CmdArgs * cargs = (MessageQDrv_CmdArgs *)
243         (_DEVCTL_DATA (msg->i));
244     MessageQ_Config local_config;
245     MessageQ_getConfig (&local_config);
247     cargs->apiStatus = MessageQ_S_SUCCESS;
248     SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) +
249         sizeof(MessageQDrv_CmdArgs));
250     SETIOV(&ctp->iov[1], &local_config, sizeof(MessageQ_Config));
252     return _RESMGR_NPARTS(2);
256 /**
257  * Handler for messageq setup API.
258  *
259  * \param ctp   Thread's associated context information.
260  * \param msg   The actual devctl() message.
261  * \param ocb   OCB associated with client's session.
262  *
263  * \return POSIX errno value.
264  *
265  * \retval EOK      Success.
266  * \retval ENOTSUP  Unsupported devctl().
267  */
268 int ipc_messageq_setup(resmgr_context_t *ctp, io_devctl_t *msg,
269     ipc_ocb_t *ocb)
271     MessageQDrv_CmdArgs * cargs = (MessageQDrv_CmdArgs *)
272         (_DEVCTL_DATA (msg->i));
273     MessageQDrv_CmdArgs * out  = (MessageQDrv_CmdArgs *)(_DEVCTL_DATA (msg->o));
275     MessageQ_Config *     local_setupconfig;
276     local_setupconfig = (MessageQ_Config *)(cargs+1);
278     out->apiStatus = MessageQ_setup (local_setupconfig);
279     out->args.setup.nameServerHandle  = MessageQ_getNameServerHandle();
281     GT_assert (curTrace, (out->apiStatus  >= 0));
282     GT_assert (curTrace, (out->args.setup.nameServerHandle  != NULL));
284     SETIOV(&ctp->iov[0], &msg->o, sizeof(msg->o) +
285         sizeof(MessageQDrv_CmdArgs));
287     return _RESMGR_NPARTS(1);
291 /**
292  * Handler for messageq destroy API.
293  *
294  * \param ctp   Thread's associated context information.
295  * \param msg   The actual devctl() message.
296  * \param ocb   OCB associated with client's session.
297  *
298  * \return POSIX errno value.
299  *
300  * \retval EOK      Success.
301  * \retval ENOTSUP  Unsupported devctl().
302  */
303 int ipc_messageq_destroy(resmgr_context_t *ctp, io_devctl_t *msg,
304     ipc_ocb_t *ocb)
306     MessageQDrv_CmdArgs * out = (MessageQDrv_CmdArgs *)(_DEVCTL_DATA (msg->o));
308     out->apiStatus = MessageQ_destroy();
309     GT_assert(curTrace, (out->apiStatus  >= 0));
311     return (_RESMGR_PTR (ctp, &msg->o, sizeof(msg->o) +
312         sizeof(MessageQDrv_CmdArgs)));