LocDualContext.cpp revision ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1
1/* Copyright (c) 2011-2013, The Linux Foundation. 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 The Linux Foundation, 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#define LOG_NDDEBUG 0
30#define LOG_TAG "LocSvc_DualCtx"
31
32#include <cutils/sched_policy.h>
33#include <unistd.h>
34#include <LocDualContext.h>
35#include <msg_q.h>
36#include <log_util.h>
37#include <loc_log.h>
38
39namespace loc_core {
40
41// nothing exclude for foreground
42const LOC_API_ADAPTER_EVENT_MASK_T
43LocDualContext::mFgExclMask = 0;
44// excluded events for background clients
45const LOC_API_ADAPTER_EVENT_MASK_T
46LocDualContext::mBgExclMask =
47    (LOC_API_ADAPTER_BIT_SATELLITE_REPORT |
48     LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT |
49     LOC_API_ADAPTER_BIT_NMEA_POSITION_REPORT |
50     LOC_API_ADAPTER_BIT_IOCTL_REPORT |
51     LOC_API_ADAPTER_BIT_STATUS_REPORT |
52     LOC_API_ADAPTER_BIT_GEOFENCE_GEN_ALERT);
53
54const MsgTask* LocDualContext::mMsgTask = NULL;
55ContextBase* LocDualContext::mFgContext = NULL;
56ContextBase* LocDualContext::mBgContext = NULL;
57
58// the name must be shorter than 15 chars
59const char* LocDualContext::mLocationHalName = "Loc_hal_worker";
60const char* LocDualContext::mIzatLibName = "libizat_core.so";
61
62const MsgTask* LocDualContext::getMsgTask(MsgTask::tCreate tCreator,
63                                          const char* name)
64{
65    if (NULL == mMsgTask) {
66        mMsgTask = new MsgTask(tCreator, name);
67    }
68    return mMsgTask;
69}
70
71const MsgTask* LocDualContext::getMsgTask(MsgTask::tAssociate tAssociate,
72                                          const char* name)
73{
74    if (NULL == mMsgTask) {
75        mMsgTask = new MsgTask(tAssociate, name);
76    }
77    return mMsgTask;
78}
79
80ContextBase* LocDualContext::getLocFgContext(MsgTask::tCreate tCreator,
81                                             const char* name)
82{
83    if (NULL == mFgContext) {
84        const MsgTask* msgTask = getMsgTask(tCreator, name);
85        mFgContext = new LocDualContext(msgTask,
86                                        mFgExclMask);
87    }
88    return mFgContext;
89}
90
91ContextBase* LocDualContext::getLocFgContext(MsgTask::tAssociate tAssociate,
92                                        const char* name)
93{
94    if (NULL == mFgContext) {
95        const MsgTask* msgTask = getMsgTask(tAssociate, name);
96        mFgContext = new LocDualContext(msgTask,
97                                        mFgExclMask);
98    }
99    return mFgContext;
100
101}
102
103ContextBase* LocDualContext::getLocBgContext(MsgTask::tCreate tCreator,
104                                             const char* name)
105{
106    if (NULL == mBgContext) {
107        const MsgTask* msgTask = getMsgTask(tCreator, name);
108        mBgContext = new LocDualContext(msgTask,
109                                        mBgExclMask);
110    }
111    return mBgContext;
112}
113
114ContextBase* LocDualContext::getLocBgContext(MsgTask::tAssociate tAssociate,
115                                             const char* name)
116{
117    if (NULL == mBgContext) {
118        const MsgTask* msgTask = getMsgTask(tAssociate, name);
119        mBgContext = new LocDualContext(msgTask,
120                                        mBgExclMask);
121    }
122    return mBgContext;
123}
124
125LocDualContext::LocDualContext(const MsgTask* msgTask,
126                               LOC_API_ADAPTER_EVENT_MASK_T exMask) :
127    ContextBase(msgTask, exMask, mIzatLibName)
128{
129}
130
131}
132