• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of Code Aurora Forum, Inc. nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 #include <fcntl.h>
30 #include "loc_eng_msg.h"
31 #include "loc_eng_dmn_conn_glue_msg.h"
32 
33 #ifdef _ANDROID_
34 
35 #define LOC_ENG_MSG_REQ_Q_PATH "/data/misc/gpsone_d/loc_eng_msg_req_q"
36 
37 #else
38 
39 #define LOC_ENG_MSG_REQ_Q_PATH "/tmp/loc_eng_msg_req_q"
40 
41 #endif
42 
loc_eng_msgget(int * p_req_msgq)43 int loc_eng_msgget(int * p_req_msgq)
44 {
45     * p_req_msgq = loc_eng_dmn_conn_glue_msgget(LOC_ENG_MSG_REQ_Q_PATH, O_RDWR);
46     return 0;
47 }
48 
loc_eng_msgremove(int req_msgq)49 int loc_eng_msgremove(int req_msgq)
50 {
51     loc_eng_dmn_conn_glue_piperemove(LOC_ENG_MSG_REQ_Q_PATH, req_msgq);
52     return 0;
53 }
54 
loc_eng_msgsnd(int msgqid,void * msgp)55 int loc_eng_msgsnd(int msgqid, void * msgp)
56 {
57     int ret = loc_eng_dmn_conn_glue_pipewrite(msgqid, msgp, sizeof(void*));
58     return ret;
59 }
60 
loc_eng_msgsnd_raw(int msgqid,void * msgp,unsigned int msgsz)61 int loc_eng_msgsnd_raw(int msgqid, void * msgp, unsigned int msgsz)
62 {
63     int result;
64 
65     struct msgbuf * pmsg = (struct msgbuf *) msgp;
66 
67     if (msgsz < sizeof(struct msgbuf)) {
68         LOC_LOGE("%s:%d] msgbuf is too small %d\n", __func__, __LINE__, msgsz);
69         return -1;
70     }
71 
72     pmsg->msgsz = msgsz;
73 
74     result = loc_eng_dmn_conn_glue_pipewrite(msgqid, msgp, msgsz);
75     if (result != (int) msgsz) {
76         LOC_LOGE("%s:%d] pipe broken %d, msgsz = %d\n", __func__, __LINE__, result, (int) msgsz);
77         return -1;
78     }
79     return result;
80 }
81 
loc_eng_msgrcv(int msgqid,void ** msgp)82 int loc_eng_msgrcv(int msgqid, void ** msgp)
83 {
84     int ret = loc_eng_dmn_conn_glue_piperead(msgqid, msgp, sizeof(void*));
85     return ret;
86 }
87 
loc_eng_msgrcv_raw(int msgqid,void * msgp,unsigned int msgsz)88 int loc_eng_msgrcv_raw(int msgqid, void *msgp, unsigned int msgsz)
89 {
90     int result;
91     struct msgbuf * pmsg = (struct msgbuf *) msgp;
92 
93     if (msgsz < sizeof(struct msgbuf)) {
94         LOC_LOGE("%s:%d] msgbuf is too small %d\n", __func__, __LINE__, msgsz);
95         return -1;
96     }
97 
98     result = loc_eng_dmn_conn_glue_piperead(msgqid, msgp, sizeof(struct msgbuf));
99     if (result != sizeof(struct msgbuf)) {
100         LOC_LOGE("%s:%d] pipe broken %d\n", __func__, __LINE__, result);
101         return -1;
102     }
103 
104     if (msgsz < pmsg->msgsz) {
105         LOC_LOGE("%s:%d] msgbuf is too small %d < %d\n", __func__, __LINE__, (int) msgsz, (int) pmsg->msgsz);
106         return -1;
107     }
108 
109     if (pmsg->msgsz > sizeof(struct msgbuf)) {
110         /* there is msg body */
111         msgp += sizeof(struct msgbuf);
112 
113         result = loc_eng_dmn_conn_glue_piperead(msgqid, msgp, pmsg->msgsz - sizeof(struct msgbuf));
114 
115         if (result != (int) (pmsg->msgsz - sizeof(struct msgbuf))) {
116             LOC_LOGE("%s:%d] pipe broken %d, msgid = %p, msgsz = %d\n", __func__, __LINE__, result,
117                     (pmsg->msgid), (int) pmsg->msgsz);
118             return -1;
119         }
120     }
121 
122     return pmsg->msgsz;
123 }
124 
loc_eng_msgflush(int msgqid)125 int loc_eng_msgflush(int msgqid)
126 {
127     return loc_eng_dmn_conn_glue_msgflush(msgqid);
128 }
129 
loc_eng_msgunblock(int msgqid)130 int loc_eng_msgunblock(int msgqid)
131 {
132     return loc_eng_dmn_conn_glue_pipeunblock(msgqid);
133 }
134