2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <sys/types.h>
25 mtp_bool _util_msgq_init(msgq_id_t *mq_id, mtp_uint32 flags)
27 *mq_id = msgget(IPC_PRIVATE, 0666 | IPC_CREAT);
36 mtp_bool _util_msgq_send(msgq_id_t mq_id, void *buf, mtp_uint32 size,
39 if (-1 == msgsnd(mq_id, buf, size, flags)) {
40 ERR("msgsnd() Fail : mq_id = [%d]", mq_id);
47 mtp_bool _util_msgq_receive(msgq_id_t mq_id, void *buf, mtp_uint32 size,
48 mtp_uint32 flags, mtp_int32 *nbytes)
53 ret = msgrcv(mq_id, buf, size, 0, IPC_NOWAIT);
55 ret = msgrcv(mq_id, buf, size, 0, 0);
68 mtp_bool _util_msgq_deinit(msgq_id_t *msgq_id)
70 if (-1 == msgctl(*msgq_id, IPC_RMID, 0)) {
71 ERR("msgctl(IPC_RMID) Fail");
77 mtp_bool _util_msgq_set_size(msgq_id_t mq_id, mtp_uint32 nbytes)
81 /* Getting the attributes of Message Queue */
82 if (msgctl(mq_id, MSG_STAT, &attr) == -1) {
83 ERR("msgctl(MSG_STAT) Fail");
87 attr.msg_qbytes = nbytes;
89 /* Setting the message queue size */
90 if (msgctl(mq_id, IPC_SET, &attr) == -1) {
91 ERR("msgctl(IPC_SET) Fail");
98 * _util_rcv_msg_from_mq
100 * This function receives a message pointer from Message Queue
101 * @param[in] mq_id Message Queue Id
102 * @param[out] pkt Shall be assigned with received buffer ptr
103 * @param[out] pkt_len Will hold the length of received data
104 * @param[out] mtype Will be assigned the type of message received
106 mtp_bool _util_rcv_msg_from_mq(msgq_id_t mq_id, unsigned char **pkt,
107 mtp_uint32 *pkt_len, msg_type_t *mtype)
109 msgq_ptr_t msg = { 0 };
110 mtp_int32 nbytes = 0;
112 if (FALSE == _util_msgq_receive(mq_id, (void *)&msg,
113 sizeof(msgq_ptr_t) - sizeof(long), 0, &nbytes)) {
114 ERR("_util_msgq_receive() Fail : mq_id = [%d]", mq_id);
118 *pkt_len = msg.length;