4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <phDal4Nfc.h>
21 #include <phOsalNfc.h>
22 #include <phOsalNfc_Timer.h>
23 #include <phDal4Nfc_DeferredCall.h>
24 #include <phDal4Nfc_messageQueueLib.h>
30 static int g_msg_q_id = -1;
31 pthread_mutex_t * _nfc_get_fri_lock ();
33 typedef struct phOsalNfc_Message_Wrapper{
35 phOsalNfc_Message_t msg;
36 }phOsalNfc_Message_Wrapper_t;
38 gboolean DeferredCallback(gpointer data)
40 phOsalNfc_Message_Wrapper_t wrapper;
41 phOsalNfc_Message_t OsalMsg;
43 phDal4Nfc_msgrcv(g_msg_q_id, (void *)&wrapper, sizeof(phOsalNfc_Message_t), 0, 0);
45 memcpy(&OsalMsg, &wrapper.msg, sizeof(phOsalNfc_Message_t));
47 if(OsalMsg.eMsgType == PH_DAL4NFC_MESSAGE_BASE)
49 phDal4Nfc_DeferredCall_Msg_t* defer_msg = NULL;
50 defer_msg = (phDal4Nfc_DeferredCall_Msg_t *)(OsalMsg.pMsgData);
52 if((defer_msg != NULL) && (defer_msg->pCallback != NULL))
54 pthread_mutex_lock (_nfc_get_fri_lock());
55 defer_msg->pCallback(defer_msg->pParameter);
56 pthread_mutex_unlock (_nfc_get_fri_lock());
62 else if(OsalMsg.eMsgType == PH_OSALNFC_TIMER_MSG)
64 phOsalNfc_Timer_Msg_t *timer_msg = NULL;
65 timer_msg = (phOsalNfc_Timer_Msg_t *)(OsalMsg.pMsgData);
67 if (timer_msg != NULL && timer_msg->pCallBck !=NULL)
69 pthread_mutex_lock (_nfc_get_fri_lock());
70 timer_msg->pCallBck (timer_msg->TimerId, timer_msg->pContext);
71 pthread_mutex_unlock (_nfc_get_fri_lock());
80 int InitMessageQueue()
84 g_msg_q_id = phDal4Nfc_msgget(IPC_PRIVATE, 0666 | IPC_CREAT);
91 void DeleteMessageQeueu()
93 phDal4Nfc_msgctl(g_msg_q_id, IPC_RMID, NULL);
98 void PostMessage(void* msgp, size_t msgsz, int msgflg)
100 phDal4Nfc_msgsnd(g_msg_q_id, msgp, msgsz, msgflg);
102 if(g_idle_add(DeferredCallback, NULL))
104 g_main_context_wakeup(g_main_context_default()) ;
109 if(g_idle_add_full(G_PRIORITY_HIGH_IDLE, DeferredCallback, NULL, NULL))
111 g_main_context_wakeup(g_main_context_default()) ;