diff options
author | Rashed Abdel-Tawab <rashed@linux.com> | 2017-09-19 20:58:14 -0400 |
---|---|---|
committer | Davide Garberi <dade.garberi@gmail.com> | 2017-12-12 20:00:16 +0100 |
commit | a940046ff57e019a91c91d6d87f04b513d13b733 (patch) | |
tree | 3c0e92fd01a5d58723cfce3f45631be851298d9a /gps/core/data-items | |
parent | 675df1371342e43a0c51a4a7ff99c5da78f0b884 (diff) |
msm8996-common: Import gps from LA.UM.6.5.r1-02500-8x96.0
Signed-off-by: Davide Garberi <dade.garberi@gmail.com>
Diffstat (limited to 'gps/core/data-items')
-rw-r--r-- | gps/core/data-items/DataItemId.h | 73 | ||||
-rw-r--r-- | gps/core/data-items/DataItemsFactoryProxy.cpp | 99 | ||||
-rw-r--r-- | gps/core/data-items/DataItemsFactoryProxy.h | 55 | ||||
-rw-r--r-- | gps/core/data-items/IDataItemCore.h | 82 | ||||
-rw-r--r-- | gps/core/data-items/common/ClientIndex.cpp | 171 | ||||
-rw-r--r-- | gps/core/data-items/common/ClientIndex.h | 70 | ||||
-rw-r--r-- | gps/core/data-items/common/DataItemIndex.cpp | 202 | ||||
-rw-r--r-- | gps/core/data-items/common/DataItemIndex.h | 70 | ||||
-rw-r--r-- | gps/core/data-items/common/IClientIndex.h | 83 | ||||
-rw-r--r-- | gps/core/data-items/common/IDataItemIndex.h | 94 | ||||
-rw-r--r-- | gps/core/data-items/common/IndexFactory.cpp | 64 | ||||
-rw-r--r-- | gps/core/data-items/common/IndexFactory.h | 48 |
12 files changed, 1111 insertions, 0 deletions
diff --git a/gps/core/data-items/DataItemId.h b/gps/core/data-items/DataItemId.h new file mode 100644 index 0000000..1bf132a --- /dev/null +++ b/gps/core/data-items/DataItemId.h @@ -0,0 +1,73 @@ +/* Copyright (c) 2015-2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __DATAITEMID_H__ +#define __DATAITEMID_H__ + +/** + * Enumeration of Data Item types + * When add/remove/update changes are made to Data Items, this file needs to be updated + * accordingly + */ +typedef enum e_DataItemId { + INVALID_DATA_ITEM_ID = -1, + // 0 - 4 + AIRPLANEMODE_DATA_ITEM_ID, + ENH_DATA_ITEM_ID, + GPSSTATE_DATA_ITEM_ID, + NLPSTATUS_DATA_ITEM_ID, + WIFIHARDWARESTATE_DATA_ITEM_ID, + // 5 - 9 + NETWORKINFO_DATA_ITEM_ID, + RILVERSION_DATA_ITEM_ID, + RILSERVICEINFO_DATA_ITEM_ID, + RILCELLINFO_DATA_ITEM_ID, + SERVICESTATUS_DATA_ITEM_ID, + // 10 - 14 + MODEL_DATA_ITEM_ID, + MANUFACTURER_DATA_ITEM_ID, + VOICECALL_DATA_ITEM, + ASSISTED_GPS_DATA_ITEM_ID, + SCREEN_STATE_DATA_ITEM_ID, + // 15 - 19 + POWER_CONNECTED_STATE_DATA_ITEM_ID, + TIMEZONE_CHANGE_DATA_ITEM_ID, + TIME_CHANGE_DATA_ITEM_ID, + WIFI_SUPPLICANT_STATUS_DATA_ITEM_ID, + SHUTDOWN_STATE_DATA_ITEM_ID, + // 20 - 24 + TAC_DATA_ITEM_ID, + MCCMNC_DATA_ITEM_ID, + BTLE_SCAN_DATA_ITEM_ID, + BT_SCAN_DATA_ITEM_ID, + OEM_GTP_UPLOAD_TRIGGER_READY_ITEM_ID, + MAX_DATA_ITEM_ID +} DataItemId; + +#endif // #ifndef __DATAITEMID_H__ diff --git a/gps/core/data-items/DataItemsFactoryProxy.cpp b/gps/core/data-items/DataItemsFactoryProxy.cpp new file mode 100644 index 0000000..130eecf --- /dev/null +++ b/gps/core/data-items/DataItemsFactoryProxy.cpp @@ -0,0 +1,99 @@ +/* Copyright (c) 2017, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#define LOG_TAG "DataItemsFactoryProxy" + +#include <dlfcn.h> +#include <DataItemId.h> +#include <IDataItemCore.h> +#include <DataItemsFactoryProxy.h> +#include <platform_lib_log_util.h> + +namespace loc_core +{ +void* DataItemsFactoryProxy::dataItemLibHandle = NULL; +get_concrete_data_item_fn* DataItemsFactoryProxy::getConcreteDIFunc = NULL; + +IDataItemCore* DataItemsFactoryProxy::createNewDataItem(DataItemId id) +{ + IDataItemCore *mydi = nullptr; + + if (NULL != getConcreteDIFunc) { + mydi = (*getConcreteDIFunc)(id); + } + else { + // first call to this function, symbol not yet loaded + if (NULL == dataItemLibHandle) { + LOC_LOGD("Loaded library %s",DATA_ITEMS_LIB_NAME); + dataItemLibHandle = dlopen(DATA_ITEMS_LIB_NAME, RTLD_NOW); + if (NULL == dataItemLibHandle) { + // dlopen failed. + const char * err = dlerror(); + if (NULL == err) + { + err = "Unknown"; + } + LOC_LOGE("%s:%d]: failed to load library %s; error=%s", + __func__, __LINE__, DATA_ITEMS_LIB_NAME, err); + } + } + + // load sym - if dlopen handle is obtained and symbol is not yet obtained + if (NULL != dataItemLibHandle) { + getConcreteDIFunc = (get_concrete_data_item_fn * ) + dlsym(dataItemLibHandle, DATA_ITEMS_GET_CONCRETE_DI); + if (NULL != getConcreteDIFunc) { + LOC_LOGD("Loaded function %s : %x",DATA_ITEMS_GET_CONCRETE_DI,getConcreteDIFunc); + mydi = (*getConcreteDIFunc)(id); + } + else { + // dlysm failed. + const char * err = dlerror(); + if (NULL == err) + { + err = "Unknown"; + } + LOC_LOGE("%s:%d]: failed to find symbol %s; error=%s", + __func__, __LINE__, DATA_ITEMS_GET_CONCRETE_DI, err); + } + } + } + return mydi; +} + +void DataItemsFactoryProxy::closeDataItemLibraryHandle() +{ + if (NULL != dataItemLibHandle) { + dlclose(dataItemLibHandle); + dataItemLibHandle = NULL; + } +} + +} // namespace loc_core + + diff --git a/gps/core/data-items/DataItemsFactoryProxy.h b/gps/core/data-items/DataItemsFactoryProxy.h new file mode 100644 index 0000000..cfd447d --- /dev/null +++ b/gps/core/data-items/DataItemsFactoryProxy.h @@ -0,0 +1,55 @@ +/* Copyright (c) 2017, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __DATAITEMFACTORYBASE__ +#define __DATAITEMFACTORYBASE__ + +#include <DataItemId.h> +#include <IDataItemCore.h> + +namespace loc_core +{ + +#define DATA_ITEMS_LIB_NAME "libdataitems.so" +#define DATA_ITEMS_GET_CONCRETE_DI "getConcreteDataItem" + +typedef IDataItemCore * (get_concrete_data_item_fn)(DataItemId); + +class DataItemsFactoryProxy { +public: + static IDataItemCore* createNewDataItem(DataItemId id); + static void closeDataItemLibraryHandle(); + static void *dataItemLibHandle; + static get_concrete_data_item_fn *getConcreteDIFunc; +}; + +} // namespace loc_core + +#endif //__DATAITEMFACTORYBASE__ + diff --git a/gps/core/data-items/IDataItemCore.h b/gps/core/data-items/IDataItemCore.h new file mode 100644 index 0000000..6084c92 --- /dev/null +++ b/gps/core/data-items/IDataItemCore.h @@ -0,0 +1,82 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __IDATAITEMCORE_H__ +#define __IDATAITEMCORE_H__ + +#include <string> +#include <DataItemId.h> + +namespace loc_core { + +using namespace std; + +/** + * @brief IDataItemCore interface. + * @details IDataItemCore interface. + * + */ +class IDataItemCore { +public: + /** + * @brief Gets Data item id. + * @details Gets Data item id. + * @return Data item id. + */ + virtual DataItemId getId () = 0; + + /** + * @brief Stringify. + * @details Stringify. + * + * @param valueStr Reference to string. + */ + virtual void stringify (string & valueStr) = 0; + + /** + * @brief copy. + * @details copy. + * + * @param src Where to copy from. + * @param dataItemCopied Boolean flag indicated whether or not copied. + * + * @return Zero for success or non zero for failure. + */ + virtual int32_t copy (IDataItemCore * src, bool *dataItemCopied = nullptr) = 0; + + /** + * @brief Destructor. + * @details Destructor. + */ + virtual ~IDataItemCore () {} +}; + +} // namespace loc_core + +#endif // __IDATAITEMCORE_H__ diff --git a/gps/core/data-items/common/ClientIndex.cpp b/gps/core/data-items/common/ClientIndex.cpp new file mode 100644 index 0000000..ffb5e1d --- /dev/null +++ b/gps/core/data-items/common/ClientIndex.cpp @@ -0,0 +1,171 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#include <algorithm> +#include <iterator> +#include <string> +#include <platform_lib_log_util.h> +#include <ClientIndex.h> +#include <IDataItemObserver.h> +#include <DataItemId.h> + +using namespace std; +using namespace loc_core; + +template <typename CT, typename DIT> +inline ClientIndex <CT,DIT> :: ClientIndex () {} + +template <typename CT, typename DIT> +inline ClientIndex <CT,DIT> :: ~ClientIndex () {} + +template <typename CT, typename DIT> +bool ClientIndex <CT,DIT> :: isSubscribedClient (CT client) { + bool result = false; + ENTRY_LOG (); + typename map < CT, list <DIT> > :: iterator it = + mDataItemsPerClientMap.find (client); + if (it != mDataItemsPerClientMap.end ()) { + result = true; + } + EXIT_LOG_WITH_ERROR ("%d",result); + return result; +} + +template <typename CT, typename DIT> +void ClientIndex <CT,DIT> :: getSubscribedList (CT client, list <DIT> & out) { + ENTRY_LOG (); + typename map < CT, list <DIT> > :: iterator it = + mDataItemsPerClientMap.find (client); + if (it != mDataItemsPerClientMap.end ()) { + out = it->second; + } + EXIT_LOG_WITH_ERROR ("%d",0); +} + +template <typename CT, typename DIT> +int ClientIndex <CT,DIT> :: remove (CT client) { + int result = 0; + ENTRY_LOG (); + mDataItemsPerClientMap.erase (client); + EXIT_LOG_WITH_ERROR ("%d",result); + return result; +} + +template <typename CT, typename DIT> +void ClientIndex <CT,DIT> :: remove (const list <DIT> & r, list <CT> & out) { + ENTRY_LOG (); + typename map < CT, list <DIT> > :: iterator dicIter = + mDataItemsPerClientMap.begin (); + while (dicIter != mDataItemsPerClientMap.end()) { + typename list <DIT> :: const_iterator it = r.begin (); + for (; it != r.end (); ++it) { + typename list <DIT> :: iterator iter = + find (dicIter->second.begin (), dicIter->second.end (), *it); + if (iter != dicIter->second.end ()) { + dicIter->second.erase (iter); + } + } + if (dicIter->second.empty ()) { + out.push_back (dicIter->first); + // Post-increment operator increases the iterator but returns the + // prevous one that will be invalidated by erase() + mDataItemsPerClientMap.erase (dicIter++); + } else { + ++dicIter; + } + } + EXIT_LOG_WITH_ERROR ("%d",0); +} + +template <typename CT, typename DIT> +void ClientIndex <CT,DIT> :: remove +( + CT client, + const list <DIT> & r, + list <DIT> & out +) +{ + ENTRY_LOG (); + typename map < CT, list <DIT> > :: iterator dicIter = + mDataItemsPerClientMap.find (client); + if (dicIter != mDataItemsPerClientMap.end ()) { + set_intersection (dicIter->second.begin (), dicIter->second.end (), + r.begin (), r.end (), + inserter (out,out.begin ())); + if (!out.empty ()) { + typename list <DIT> :: iterator it = out.begin (); + for (; it != out.end (); ++it) { + dicIter->second.erase (find (dicIter->second.begin (), + dicIter->second.end (), + *it)); + } + } + if (dicIter->second.empty ()) { + mDataItemsPerClientMap.erase (dicIter); + EXIT_LOG_WITH_ERROR ("%d",0); + } + } + EXIT_LOG_WITH_ERROR ("%d",0); +} + +template <typename CT, typename DIT> +void ClientIndex <CT,DIT> :: add +( + CT client, + const list <DIT> & l, + list <DIT> & out +) +{ + ENTRY_LOG (); + list <DIT> difference; + typename map < CT, list <DIT> > :: iterator dicIter = + mDataItemsPerClientMap.find (client); + if (dicIter != mDataItemsPerClientMap.end ()) { + set_difference (l.begin (), l.end (), + dicIter->second.begin (), dicIter->second.end (), + inserter (difference,difference.begin ())); + if (!difference.empty ()) { + difference.sort (); + out = difference; + dicIter->second.merge (difference); + dicIter->second.unique (); + } + } else { + out = l; + pair < CT, list <DIT> > dicnpair (client, out); + mDataItemsPerClientMap.insert (dicnpair); + } + EXIT_LOG_WITH_ERROR ("%d",0); +} + +// Explicit instantiation must occur in same namespace where class is defined +namespace loc_core +{ + template class ClientIndex <IDataItemObserver *, DataItemId>; + template class ClientIndex <string, DataItemId>; +} diff --git a/gps/core/data-items/common/ClientIndex.h b/gps/core/data-items/common/ClientIndex.h new file mode 100644 index 0000000..feccb05 --- /dev/null +++ b/gps/core/data-items/common/ClientIndex.h @@ -0,0 +1,70 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef __CLIENTINDEX_H__ +#define __CLIENTINDEX_H__ + +#include <list> +#include <map> +#include <IClientIndex.h> + +using loc_core::IClientIndex; + +namespace loc_core +{ + +template <typename CT, typename DIT> + +class ClientIndex : public IClientIndex <CT, DIT> { + +public: + + ClientIndex (); + + ~ClientIndex (); + + bool isSubscribedClient (CT client); + + void getSubscribedList (CT client, std :: list <DIT> & out); + + int remove (CT client); + + void remove (const std :: list <DIT> & r, std :: list <CT> & out); + + void remove (CT client, const std :: list <DIT> & r, std :: list <DIT> & out); + + void add (CT client, const std :: list <DIT> & l, std :: list <DIT> & out); + +private: + //Data members + std :: map < CT , std :: list <DIT> > mDataItemsPerClientMap; +}; + +} // namespace loc_core + +#endif // #ifndef __CLIENTINDEX_H__ diff --git a/gps/core/data-items/common/DataItemIndex.cpp b/gps/core/data-items/common/DataItemIndex.cpp new file mode 100644 index 0000000..7869b43 --- /dev/null +++ b/gps/core/data-items/common/DataItemIndex.cpp @@ -0,0 +1,202 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <string> +#include <algorithm> +#include <iterator> +#include <DataItemIndex.h> +#include <platform_lib_log_util.h> +#include <IDataItemObserver.h> +#include <DataItemId.h> + +using namespace std; +using namespace loc_core; + +template <typename CT, typename DIT> +inline DataItemIndex <CT,DIT> :: DataItemIndex () {} + +template <typename CT, typename DIT> +inline DataItemIndex <CT,DIT> :: ~DataItemIndex () {} + +template <typename CT, typename DIT> +void DataItemIndex <CT,DIT> :: getListOfSubscribedClients + ( + DIT id, + list <CT> & out +) +{ + typename map < DIT, list <CT> > :: iterator cdiIter = + mClientsPerDataItemMap.find (id); + if (cdiIter != mClientsPerDataItemMap.end ()) { + out = cdiIter->second; + } +} + + +template <typename CT, typename DIT> +int DataItemIndex <CT,DIT> :: remove (DIT id) { + int result = 0; + ENTRY_LOG (); + mClientsPerDataItemMap.erase (id); + EXIT_LOG_WITH_ERROR ("%d",result); + return result; +} + +template <typename CT, typename DIT> +void DataItemIndex <CT,DIT> :: remove (const list <CT> & r, list <DIT> & out) { + ENTRY_LOG (); + typename map < DIT, list <CT> > :: iterator cdiIter = + mClientsPerDataItemMap.begin (); + while (cdiIter != mClientsPerDataItemMap.end()) { + typename list <CT> :: const_iterator it = r.begin (); + for (; it != r.end (); ++it) { + typename list <CT> :: iterator iter = + find + ( + cdiIter->second.begin (), + cdiIter->second.end (), + *it + ); + if (iter != cdiIter->second.end ()) { + cdiIter->second.erase (iter); + } + } + + if (cdiIter->second.empty ()) { + out.push_back (cdiIter->first); + // Post-increment operator increases the iterator but returns the + // prevous one that will be invalidated by erase() + mClientsPerDataItemMap.erase (cdiIter++); + } else { + ++cdiIter; + } + } + EXIT_LOG_WITH_ERROR ("%d",0); +} + +template <typename CT, typename DIT> +void DataItemIndex <CT,DIT> :: remove +( + DIT id, + const list <CT> & r, + list <CT> & out +) +{ + ENTRY_LOG (); + + typename map < DIT, list <CT> > :: iterator cdiIter = + mClientsPerDataItemMap.find (id); + if (cdiIter != mClientsPerDataItemMap.end ()) { + set_intersection (cdiIter->second.begin (), cdiIter->second.end (), + r.begin (), r.end (), + inserter (out, out.begin ())); + if (!out.empty ()) { + typename list <CT> :: iterator it = out.begin (); + for (; it != out.end (); ++it) { + cdiIter->second.erase (find (cdiIter->second.begin (), + cdiIter->second.end (), + *it)); + } + } + if (cdiIter->second.empty ()) { + mClientsPerDataItemMap.erase (cdiIter); + EXIT_LOG_WITH_ERROR ("%d",0); + } + } + EXIT_LOG_WITH_ERROR ("%d",0); +} + +template <typename CT, typename DIT> +void DataItemIndex <CT,DIT> :: add +( + DIT id, + const list <CT> & l, + list <CT> & out +) +{ + ENTRY_LOG (); + list <CT> difference; + typename map < DIT, list <CT> > :: iterator cdiIter = + mClientsPerDataItemMap.find (id); + if (cdiIter != mClientsPerDataItemMap.end ()) { + set_difference (l.begin (), l.end (), + cdiIter->second.begin (), cdiIter->second.end (), + inserter (difference, difference.begin ())); + if (!difference.empty ()) { + difference.sort (); + out = difference; + cdiIter->second.merge (difference); + } + } else { + out = l; + pair < DIT, list <CT> > cndipair (id, out); + mClientsPerDataItemMap.insert (cndipair); + } + EXIT_LOG_WITH_ERROR ("%d",0); +} + +template <typename CT, typename DIT> +void DataItemIndex <CT,DIT> :: add +( + CT client, + const list <DIT> & l, + list <DIT> & out +) +{ + ENTRY_LOG (); + typename map < DIT, list <CT> > :: iterator cdiIter; + typename list <DIT> :: const_iterator it = l.begin (); + for (; it != l.end (); ++it) { + cdiIter = mClientsPerDataItemMap.find (*it); + if (cdiIter == mClientsPerDataItemMap.end ()) { + out.push_back (*it); + pair < DIT, list <CT> > cndiPair (*it, list <CT> (1, client)); + mClientsPerDataItemMap.insert (cndiPair); + } else { + typename list<CT> :: iterator clientIter = + find + ( + cdiIter->second.begin (), + cdiIter->second.end (), + client + ); + if (clientIter == cdiIter->second.end()) { + cdiIter->second.push_back (client); + } + } + } + EXIT_LOG_WITH_ERROR ("%d",0); +} + +// Explicit instantiation must occur in same namespace where class is defined +namespace loc_core +{ + template class DataItemIndex <IDataItemObserver *, DataItemId>; + template class DataItemIndex <string, DataItemId>; +} diff --git a/gps/core/data-items/common/DataItemIndex.h b/gps/core/data-items/common/DataItemIndex.h new file mode 100644 index 0000000..d72e89e --- /dev/null +++ b/gps/core/data-items/common/DataItemIndex.h @@ -0,0 +1,70 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __DATAITEMINDEX_H__ +#define __DATAITEMINDEX_H__ + +#include <list> +#include <map> +#include <IDataItemIndex.h> + +using loc_core::IDataItemIndex; + +namespace loc_core +{ + +template <typename CT, typename DIT> + +class DataItemIndex : public IDataItemIndex <CT, DIT> { + +public: + + DataItemIndex (); + + ~DataItemIndex (); + + void getListOfSubscribedClients (DIT id, std :: list <CT> & out); + + int remove (DIT id); + + void remove (const std :: list <CT> & r, std :: list <DIT> & out); + + void remove (DIT id, const std :: list <CT> & r, std :: list <CT> & out); + + void add (DIT id, const std :: list <CT> & l, std :: list <CT> & out); + + void add (CT client, const std :: list <DIT> & l, std :: list <DIT> & out); + +private: + std :: map < DIT, std :: list <CT> > mClientsPerDataItemMap; +}; + +} // namespace loc_core + +#endif // #ifndef __DATAITEMINDEX_H__ diff --git a/gps/core/data-items/common/IClientIndex.h b/gps/core/data-items/common/IClientIndex.h new file mode 100644 index 0000000..0272e7b --- /dev/null +++ b/gps/core/data-items/common/IClientIndex.h @@ -0,0 +1,83 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __ICLIENTINDEX_H__ +#define __ICLIENTINDEX_H__ + +#include <list> + +namespace loc_core +{ + +template <typename CT, typename DIT> + +class IClientIndex { +public: + + // Checks if client is subscribed + virtual bool isSubscribedClient (CT client) = 0; + + // gets subscription list + virtual void getSubscribedList (CT client, std :: list <DIT> & out) = 0; + + // removes an entry + virtual int remove (CT client) = 0; + + // removes std :: list of data items and returns a list of clients + // removed if any. + virtual void remove + ( + const std :: list <DIT> & r, + std :: list <CT> & out + ) = 0; + + // removes list of data items indexed by client and returns list + // of data items removed if any. + virtual void remove + ( + CT client, + const std :: list <DIT> & r, + std :: list <DIT> & out + ) = 0; + + // adds/modifies entry in map and returns new data items added. + virtual void add + ( + CT client, + const std :: list <DIT> & l, + std :: list <DIT> & out + ) = 0; + + // dtor + virtual ~IClientIndex () {} +}; + +} // namespace loc_core + +#endif // #ifndef __ICLIENTINDEX_H__ diff --git a/gps/core/data-items/common/IDataItemIndex.h b/gps/core/data-items/common/IDataItemIndex.h new file mode 100644 index 0000000..9185582 --- /dev/null +++ b/gps/core/data-items/common/IDataItemIndex.h @@ -0,0 +1,94 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __IDATAITEMINDEX_H__ +#define __IDATAITEMINDEX_H__ + +#include <list> + +namespace loc_core +{ + +template <typename CT, typename DIT> + +class IDataItemIndex { + +public: + + // gets std :: list of subscribed clients + virtual void getListOfSubscribedClients + ( + DIT id, + std :: list <CT> & out + ) = 0; + + // removes an entry from + virtual int remove (DIT id) = 0; + + // removes list of clients and returns a list of data items + // removed if any. + virtual void remove + ( + const std :: list <CT> & r, + std :: list <DIT> & out + ) = 0; + + // removes list of clients indexed by data item and returns list of + // clients removed if any. + virtual void remove + ( + DIT id, + const std :: list <CT> & r, + std :: list <CT> & out + ) = 0; + + // adds/modifies entry and returns new clients added + virtual void add + ( + DIT id, + const std :: list <CT> & l, + std :: list <CT> & out + ) = 0; + + // adds/modifies entry and returns yet to subscribe list of data items + virtual void add + ( + CT client, + const std :: list <DIT> & l, + std :: list <DIT> & out + ) = 0; + + // dtor + virtual ~IDataItemIndex () {} +}; + +} // namespace loc_core + +#endif // #ifndef __IDATAITEMINDEX_H__ + diff --git a/gps/core/data-items/common/IndexFactory.cpp b/gps/core/data-items/common/IndexFactory.cpp new file mode 100644 index 0000000..cf49475 --- /dev/null +++ b/gps/core/data-items/common/IndexFactory.cpp @@ -0,0 +1,64 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <string> +#include <IndexFactory.h> +#include <IClientIndex.h> +#include <ClientIndex.h> +#include <IDataItemIndex.h> +#include <DataItemIndex.h> +#include <IDataItemObserver.h> +#include <DataItemId.h> + +using namespace std; +using loc_core::IClientIndex; +using loc_core::IDataItemIndex; +using loc_core::IDataItemObserver; +using namespace loc_core; + +template <typename CT, typename DIT> +inline IClientIndex <CT, DIT> * IndexFactory <CT, DIT> :: createClientIndex +() +{ + return new (nothrow) ClientIndex <CT, DIT> (); +} + +template <typename CT, typename DIT> +inline IDataItemIndex <CT, DIT> * IndexFactory <CT, DIT> :: createDataItemIndex +() +{ + return new (nothrow) DataItemIndex <CT, DIT> (); +} + +// Explicit instantiation must occur in same namespace where class is defined +namespace loc_core +{ + template class IndexFactory <IDataItemObserver *, DataItemId>; + template class IndexFactory <string, DataItemId>; +} diff --git a/gps/core/data-items/common/IndexFactory.h b/gps/core/data-items/common/IndexFactory.h new file mode 100644 index 0000000..9a2070e --- /dev/null +++ b/gps/core/data-items/common/IndexFactory.h @@ -0,0 +1,48 @@ +/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __INDEXFACTORY_H__ +#define __INDEXFACTORY_H__ + +#include <IClientIndex.h> +#include <IDataItemIndex.h> + +namespace loc_core +{ +template <typename CT, typename DIT> +class IndexFactory { + +public: + static IClientIndex <CT, DIT> * createClientIndex (); + static IDataItemIndex <CT, DIT> * createDataItemIndex (); +}; + +} // namespace loc_core + +#endif // #ifndef __INDEXFACTORY_H__ |