FW: [PATCH] OpenSource MamaFieldCache in MAMA 6 - C/CPP
Gary Molloy <GMolloy@...>
Including test strategy:
This is not OS dependant
From: Gary Molloy
Sent: 02 April 2014 16:51 To: openmama-dev@... Subject: [PATCH] OpenSource MamaFieldCache in MAMA 6 - C/CPP
From feb963ab29ec5423822307b18b866f0000fbefd6 Mon Sep 17 00:00:00 2001 From: Gary Molloy <gmolloy@...> Date: Wed, 2 Apr 2014 16:28:43 +0100 Subject: [PATCH] OpenSource MamaFieldCache for C and CPP
Open Source the MAMA FieldCache for C and CPP
[OMAMA-253]
Signed-off-by: Gary Molloy <gmolloy@...> --- mama/c_cpp/configure.ac | 2 + mama/c_cpp/src/c/Makefile.am | 21 +- mama/c_cpp/src/c/SConscript | 22 + mama/c_cpp/src/c/SConscript.win | 14 + mama/c_cpp/src/c/fieldcache/fieldcache.c | 552 ++++ mama/c_cpp/src/c/fieldcache/fieldcachefield.c | 1507 +++++++++++ mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.c | 122 + mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.h | 138 + mama/c_cpp/src/c/fieldcache/fieldcacheimpl.c | 687 +++++ mama/c_cpp/src/c/fieldcache/fieldcacheimpl.h | 92 + mama/c_cpp/src/c/fieldcache/fieldcacheiterator.c | 77 + .../src/c/fieldcache/fieldcacheiteratorimpl.h | 57 + mama/c_cpp/src/c/fieldcache/fieldcachelist.c | 95 + mama/c_cpp/src/c/fieldcache/fieldcachelist.h | 135 + mama/c_cpp/src/c/fieldcache/fieldcachemap.c | 96 + mama/c_cpp/src/c/fieldcache/fieldcachemap.h | 113 + mama/c_cpp/src/c/fieldcache/fieldcachemaparray.c | 263 ++ mama/c_cpp/src/c/fieldcache/fieldcachemaparray.h | 90 + mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.c | 79 + mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.h | 72 + mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.c | 74 + mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.h | 64 + mama/c_cpp/src/c/fieldcache/fieldcacherecord.c | 159 ++ mama/c_cpp/src/c/fieldcache/fieldcacherecordimpl.h | 49 + mama/c_cpp/src/c/fieldcache/fieldcachevector.c | 127 + mama/c_cpp/src/c/fieldcache/fieldcachevector.h | 134 + mama/c_cpp/src/c/mama/fieldcache/fieldcache.h | 368 +++ mama/c_cpp/src/c/mama/fieldcache/fieldcachefield.h | 1093 ++++++++ .../src/c/mama/fieldcache/fieldcacheiterator.h | 102 + .../c_cpp/src/c/mama/fieldcache/fieldcacherecord.h | 152 ++ mama/c_cpp/src/c/mama/fieldcache/fieldcachetypes.h | 52 + mama/c_cpp/src/c/mamac.vcproj | 108 + mama/c_cpp/src/cpp/Makefile.am | 13 +- mama/c_cpp/src/cpp/SConscript | 14 + mama/c_cpp/src/cpp/SConscript.win | 6 + mama/c_cpp/src/cpp/fieldcache/MamaFieldCache.cpp | 310 +++ .../src/cpp/fieldcache/MamaFieldCacheField.cpp | 229 ++ .../cpp/fieldcache/MamaFieldCacheFieldTypes.cpp | 873 ++++++ .../src/cpp/fieldcache/MamaFieldCacheRecord.cpp | 152 ++ .../c_cpp/src/cpp/mama/fieldcache/MamaFieldCache.h | 332 +++ .../src/cpp/mama/fieldcache/MamaFieldCacheField.h | 216 ++ .../cpp/mama/fieldcache/MamaFieldCacheFieldTypes.h | 1079 ++++++++ .../src/cpp/mama/fieldcache/MamaFieldCacheRecord.h | 130 + mama/c_cpp/src/cpp/mamacpp.vcproj | 32 + mama/c_cpp/src/examples/c/Makefile.am | 5 +- mama/c_cpp/src/examples/c/Makefile.sample | 7 +- mama/c_cpp/src/examples/c/SConscript | 3 +- mama/c_cpp/src/examples/c/SConscript.win | 1 + mama/c_cpp/src/examples/c/mamalistencachedc.c | 2839 ++++++++++++++++++++ mama/c_cpp/src/examples/c/mamalistencachedc.vcproj | 373 +++ .../src/examples/c/openmamalistencachedc.vcproj | 365 +++ mama/c_cpp/src/examples/cpp/Makefile.am | 5 +- mama/c_cpp/src/examples/cpp/Makefile.sample | 5 +- mama/c_cpp/src/examples/cpp/SConscript | 2 +- mama/c_cpp/src/examples/cpp/SConscript.win | 1 + .../c_cpp/src/examples/cpp/mamalistencachedcpp.cpp | 2313 ++++++++++++++++ .../src/examples/cpp/mamalistencachedcpp.vcproj | 373 +++ .../examples/cpp/openmamalistencachedcpp.vcproj | 369 +++ mama/c_cpp/src/gunittest/c/Makefile.am | 2 +- mama/c_cpp/src/gunittest/c/SConscript | 7 + mama/c_cpp/src/gunittest/c/fieldcache/Makefile.am | 54 + .../src/gunittest/c/fieldcache/Makefile.sample | 84 + .../gunittest/c/fieldcache/fieldcachefieldtest.cpp | 1726 ++++++++++++ .../c/fieldcache/fieldcacheiteratortest.cpp | 190 ++ .../gunittest/c/fieldcache/fieldcachelisttest.cpp | 165 ++ .../gunittest/c/fieldcache/fieldcachemaptest.cpp | 324 +++ .../c/fieldcache/fieldcacherecordtest.cpp | 228 ++ .../src/gunittest/c/fieldcache/fieldcachetest.cpp | 1090 ++++++++ .../c/fieldcache/fieldcachevectortest.cpp | 264 ++ mama/c_cpp/src/gunittest/cpp/Makefile.am | 2 + .../c_cpp/src/gunittest/cpp/fieldcache/Makefile.am | 52 + .../src/gunittest/cpp/fieldcache/Makefile.sample | 77 + .../cpp/fieldcache/MamaFieldCacheFieldTest.cpp | 225 ++ .../fieldcache/MamaFieldCacheFieldTypesTest.cpp | 1087 ++++++++ .../cpp/fieldcache/MamaFieldCacheIteratorTest.cpp | 290 ++ .../cpp/fieldcache/MamaFieldCacheRecordTest.cpp | 128 + .../cpp/fieldcache/MamaFieldCacheTest.cpp | 351 +++ 77 files changed, 23098 insertions(+), 11 deletions(-) create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcache.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachefield.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.h create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcacheimpl.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcacheimpl.h create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcacheiterator.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcacheiteratorimpl.h create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachelist.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachelist.h create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachemap.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachemap.h create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachemaparray.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachemaparray.h create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.h create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.h create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcacherecord.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcacherecordimpl.h create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachevector.c create mode 100644 mama/c_cpp/src/c/fieldcache/fieldcachevector.h create mode 100644 mama/c_cpp/src/c/mama/fieldcache/fieldcache.h create mode 100644 mama/c_cpp/src/c/mama/fieldcache/fieldcachefield.h create mode 100644 mama/c_cpp/src/c/mama/fieldcache/fieldcacheiterator.h create mode 100644 mama/c_cpp/src/c/mama/fieldcache/fieldcacherecord.h create mode 100644 mama/c_cpp/src/c/mama/fieldcache/fieldcachetypes.h create mode 100644 mama/c_cpp/src/cpp/fieldcache/MamaFieldCache.cpp create mode 100644 mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheField.cpp create mode 100644 mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheFieldTypes.cpp create mode 100644 mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheRecord.cpp create mode 100644 mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCache.h create mode 100644 mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheField.h create mode 100644 mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheFieldTypes.h create mode 100644 mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheRecord.h create mode 100644 mama/c_cpp/src/examples/c/mamalistencachedc.c create mode 100644 mama/c_cpp/src/examples/c/mamalistencachedc.vcproj create mode 100644 mama/c_cpp/src/examples/c/openmamalistencachedc.vcproj create mode 100644 mama/c_cpp/src/examples/cpp/mamalistencachedcpp.cpp create mode 100644 mama/c_cpp/src/examples/cpp/mamalistencachedcpp.vcproj create mode 100644 mama/c_cpp/src/examples/cpp/openmamalistencachedcpp.vcproj create mode 100644 mama/c_cpp/src/gunittest/c/fieldcache/Makefile.am create mode 100644 mama/c_cpp/src/gunittest/c/fieldcache/Makefile.sample create mode 100644 mama/c_cpp/src/gunittest/c/fieldcache/fieldcachefieldtest.cpp create mode 100644 mama/c_cpp/src/gunittest/c/fieldcache/fieldcacheiteratortest.cpp create mode 100644 mama/c_cpp/src/gunittest/c/fieldcache/fieldcachelisttest.cpp create mode 100644 mama/c_cpp/src/gunittest/c/fieldcache/fieldcachemaptest.cpp create mode 100644 mama/c_cpp/src/gunittest/c/fieldcache/fieldcacherecordtest.cpp create mode 100644 mama/c_cpp/src/gunittest/c/fieldcache/fieldcachetest.cpp create mode 100644 mama/c_cpp/src/gunittest/c/fieldcache/fieldcachevectortest.cpp create mode 100644 mama/c_cpp/src/gunittest/cpp/fieldcache/Makefile.am create mode 100644 mama/c_cpp/src/gunittest/cpp/fieldcache/Makefile.sample create mode 100644 mama/c_cpp/src/gunittest/cpp/fieldcache/MamaFieldCacheFieldTest.cpp create mode 100644 mama/c_cpp/src/gunittest/cpp/fieldcache/MamaFieldCacheFieldTypesTest.cpp create mode 100644 mama/c_cpp/src/gunittest/cpp/fieldcache/MamaFieldCacheIteratorTest.cpp create mode 100644 mama/c_cpp/src/gunittest/cpp/fieldcache/MamaFieldCacheRecordTest.cpp create mode 100644 mama/c_cpp/src/gunittest/cpp/fieldcache/MamaFieldCacheTest.cpp
diff --git a/mama/c_cpp/configure.ac b/mama/c_cpp/configure.ac index 824ecc5..1741472 100644 --- a/mama/c_cpp/configure.ac +++ b/mama/c_cpp/configure.ac @@ -422,8 +422,10 @@ AC_OUTPUT([Makefile \ src/gunittest/c/Makefile \ src/gunittest/c/payload/Makefile \ src/gunittest/c/middleware/Makefile \ + src/gunittest/c/fieldcache/Makefile \ src/gunittest/c/mamamsg/Makefile \ src/gunittest/c/mamaprice/Makefile \ src/gunittest/c/mamadatetime/Makefile \ src/gunittest/cpp/Makefile \ + src/gunittest/cpp/fieldcache/Makefile \ ]) diff --git a/mama/c_cpp/src/c/Makefile.am b/mama/c_cpp/src/c/Makefile.am index 64ebac0..ab8b9ca 100644 --- a/mama/c_cpp/src/c/Makefile.am +++ b/mama/c_cpp/src/c/Makefile.am @@ -84,7 +84,12 @@ nobase_include_HEADERS = \ mama/transport.h \ mama/types.h \ mama/conflation/connection.h \ - mama/version.h + mama/version.h \ + mama/fieldcache/fieldcache.h \ + mama/fieldcache/fieldcachefield.h \ + mama/fieldcache/fieldcacheiterator.h \ + mama/fieldcache/fieldcacherecord.h \ + mama/fieldcache/fieldcachetypes.h
CFLAGS += -I${srcdir}/../../../../common/c_cpp/src/c @@ -173,7 +178,19 @@ libmama_la_SOURCES = \ playback/playbackcapture.c \ conflation/connection.c \ conflation/serverconnection.c \ - conflation/manager.c + conflation/manager.c \ + fieldcache/fieldcachevector.c \ + fieldcache/fieldcachelist.c \ + fieldcache/fieldcachemap.c \ + fieldcache/fieldcachemaparray.c \ + fieldcache/fieldcachemapbinary.c \ + fieldcache/fieldcachemapmonitor.c \ + fieldcache/fieldcacheiterator.c \ + fieldcache/fieldcachefieldimpl.c \ + fieldcache/fieldcachefield.c \ + fieldcache/fieldcacherecord.c \ + fieldcache/fieldcacheimpl.c \ + fieldcache/fieldcache.c
nodist_libmama_la_SOURCES = \ @builddir@/version.c diff --git a/mama/c_cpp/src/c/SConscript b/mama/c_cpp/src/c/SConscript index 801944d..5f949c7 100644 --- a/mama/c_cpp/src/c/SConscript +++ b/mama/c_cpp/src/c/SConscript @@ -60,6 +60,14 @@ InstConflInclude = Split(""" mama/conflation/connection.h """)
+InstFieldCacheInclude = Split(""" + mama/fieldcache/fieldcache.h + mama/fieldcache/fieldcachefield.h + mama/fieldcache/fieldcacheiterator.h + mama/fieldcache/fieldcacherecord.h + mama/fieldcache/fieldcachetypes.h +""") + includePath = [] includePath.append('#mama/c_cpp/src/c') includePath.append('$prefix/include') @@ -135,6 +143,18 @@ libmama_sources = \ conflation/connection.c conflation/serverconnection.c conflation/manager.c + fieldcache/fieldcache.c + fieldcache/fieldcachefieldimpl.c + fieldcache/fieldcacheiterator.c + fieldcache/fieldcachemaparray.c + fieldcache/fieldcachemap.c + fieldcache/fieldcacherecord.c + fieldcache/fieldcachefield.c + fieldcache/fieldcacheimpl.c + fieldcache/fieldcachelist.c + fieldcache/fieldcachemapbinary.c + fieldcache/fieldcachemapmonitor.c + fieldcache/fieldcachevector.c """)
objects = [] @@ -160,6 +180,8 @@ Alias('install', env.Install('$libdir', lib)) Alias('install', env.Install('$prefix/include/mama', InstMamaInclude)) Alias('install', env.Install('$prefix/include/mama/conflation', InstConflInclude)) +Alias('install', env.Install('$prefix/include/mama/fieldcache', + InstFieldCacheInclude))
env.SConscript('bridge/SConscript', 'env') env.SConscript('payload/SConscript', 'env') diff --git a/mama/c_cpp/src/c/SConscript.win b/mama/c_cpp/src/c/SConscript.win index 7541c9a..cbae5b1 100644 --- a/mama/c_cpp/src/c/SConscript.win +++ b/mama/c_cpp/src/c/SConscript.win @@ -74,10 +74,23 @@ conflation/serverconnection.c playback/playbackcapture.c playback/playbackFileParser.c playback/playbackpublisher.c +fieldcache/fieldcachefield.c +fieldcache/fieldcachemapbinary.c +fieldcache/fieldcachemaparray.c +fieldcache/fieldcachemapmonitor.c +fieldcache/fieldcacheimpl.c +fieldcache/fieldcachemap.c +fieldcache/fieldcacheiterator.c +fieldcache/fieldcachevector.c +fieldcache/fieldcachefieldimpl.c +fieldcache/fieldcache.c +fieldcache/fieldcachelist.c +fieldcache/fieldcacherecord.c """)
headers = Glob("mama/*.h") playbackHeaders = Glob("mama/playback/*.h") +fieldcacheHeaders = Glob("mama/fieldcache/*.h")
if env['entitled'] == True: EntLIB = posixpath.join( env['entitle_home'], 'lib/%s/liboeac%s.lib' % ( env['build'],env['suffix'])) @@ -94,3 +107,4 @@ if ( env['build'] == 'dynamic' or len(env['buildtype']) == 1): env.Install('$prefix/include/mama',headers) env.Install('$prefix/include/mama/conflation','mama/conflation/connection.h') env.Install('$prefix/include/mama/playback', playbackHeaders) + env.Install('$prefix/include/mama/fieldcache', fieldcacheHeaders) diff --git a/mama/c_cpp/src/c/fieldcache/fieldcache.c b/mama/c_cpp/src/c/fieldcache/fieldcache.c new file mode 100644 index 0000000..9ba6418 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcache.c @@ -0,0 +1,552 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcache.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcacheimpl.h" +#include "fieldcachefieldimpl.h" +#include "fieldcacherecordimpl.h" +#include <mamainternal.h> +#include <mama/fieldcache/fieldcache.h> +#include <mama/fieldcache/fieldcachefield.h> +#include <mama/fieldcache/fieldcacheiterator.h> +#include <mama/fieldcache/fieldcacherecord.h> +#include <mama/price.h> +#include <mama/datetime.h> +#include <mama/msg.h> +#include <stdlib.h> +#include <assert.h> +#include <stdio.h> + +#define FIELD_CACHE_LOCK(cache) if (cache->mUseLock) { wlock_lock(cache->mLock); } +#define FIELD_CACHE_UNLOCK(cache) if (cache->mUseLock) { wlock_unlock(cache->mLock); } + +mama_status mamaFieldCache_create(mamaFieldCache* fieldCache) +{ + mama_status ret = MAMA_STATUS_OK; + mamaFieldCache localCache = NULL; + const char * propstring = NULL; + + if(!fieldCache) + { + return MAMA_STATUS_NULL_ARG; + } + + localCache = (mamaFieldCache)calloc(1, sizeof(mamaFieldCacheImpl)); + if(!localCache) + { + return MAMA_STATUS_NOMEM; + } + + localCache->mLock = wlock_create(); + + propstring = properties_Get (mamaInternal_getProperties (), "mama.fieldcache.type"); + if (propstring != NULL && strcmp (propstring, "payload") == 0) + { + localCache->mCachePayload = 1; + } + else + { + ret = mamaFieldCacheMap_create(&localCache->mMap); + if(ret != MAMA_STATUS_OK) + { + mamaFieldCache_destroy(localCache); + return ret; + } + + mamaFieldCacheList_create(&localCache->mAlwaysPublishFields); + mamaFieldCacheList_create(&localCache->mModifiedFields); + + mamaDateTime_create(&localCache->mReusableDateTime); + mamaPrice_create(&localCache->mReusablePrice); + localCache->mTrackModified = 1; + } + + /* Write back the field cache pointer */ + *fieldCache = localCache; + + return ret; +} + +mama_status mamaFieldCache_destroy(mamaFieldCache fieldCache) +{ + if (!fieldCache) + { + return MAMA_STATUS_NULL_ARG; + } + + if (fieldCache->mCachePayload) + { + if (fieldCache->mCacheMsg) + { + mamaMsg_destroy(fieldCache->mCacheMsg); + } + } + else + { + mamaFieldCacheMap_destroy(fieldCache->mMap); + if (fieldCache->mIterator) + { + mamaMsgIterator_destroy(fieldCache->mIterator); + } + mamaFieldCacheList_destroy(fieldCache->mAlwaysPublishFields); + mamaFieldCacheList_destroy(fieldCache->mModifiedFields); + + mamaDateTime_destroy(fieldCache->mReusableDateTime); + mamaPrice_destroy(fieldCache->mReusablePrice); + } + + wlock_destroy(fieldCache->mLock); + + free(fieldCache); + + return MAMA_STATUS_OK; +} + + +mama_status mamaFieldCache_clear(mamaFieldCache fieldCache) +{ + if (!fieldCache) + { + return MAMA_STATUS_NULL_ARG; + } + FIELD_CACHE_LOCK(fieldCache); + /* TODO: should we implement this function using mamaMsg methods??? */ + if (fieldCache->mCachePayload) + { + if (fieldCache->mCacheMsg) + mamaMsg_clear(fieldCache->mCacheMsg); + } + else + { + mamaFieldCacheMap_clear(fieldCache->mMap); + mamaFieldCacheList_clear(fieldCache->mAlwaysPublishFields); + mamaFieldCacheList_clear(fieldCache->mModifiedFields); + fieldCache->mSize = 0; + } + FIELD_CACHE_UNLOCK(fieldCache); + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_getSize(mamaFieldCache fieldCache, mama_size_t* size) +{ + if (!fieldCache || !size) + { + return MAMA_STATUS_NULL_ARG; + } + *size = fieldCache->mSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_find( + mamaFieldCache fieldCache, + mama_fid_t fid, + const char* name, + mamaFieldCacheField* field) +{ + mama_status ret; + if (!fieldCache || !field) + { + return MAMA_STATUS_NULL_ARG; + } + if (fieldCache->mCachePayload) + { + return MAMA_STATUS_NOT_IMPLEMENTED; + } + FIELD_CACHE_LOCK(fieldCache); + ret = mamaFieldCacheMap_find(fieldCache->mMap, + fid, + MAMA_FIELD_TYPE_UNKNOWN, + name, + field); + FIELD_CACHE_UNLOCK(fieldCache); + return ret; +} + +mama_status mamaFieldCache_findOrAdd( + mamaFieldCache fieldCache, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field, + mama_bool_t* existing) +{ + mama_status ret = MAMA_STATUS_OK; + + if (!fieldCache || !field || !existing) + { + return MAMA_STATUS_NULL_ARG; + } + if (fieldCache->mCachePayload) + { + return MAMA_STATUS_NOT_IMPLEMENTED; + } + + FIELD_CACHE_LOCK(fieldCache); + ret = mamaFieldCacheMap_find(fieldCache->mMap, fid, type, name, field); + if (ret == MAMA_STATUS_OK && *field) + { + *existing = 1; + FIELD_CACHE_UNLOCK(fieldCache); + return ret; + } + *existing = 0; + ret = mamaFieldCacheField_create(field, fid, type, name); + if (ret != MAMA_STATUS_OK) + { + FIELD_CACHE_UNLOCK(fieldCache); + return ret; + } + ret = mamaFieldCacheMap_add(fieldCache->mMap, *field); + if (ret == MAMA_STATUS_OK) + { + fieldCache->mSize++; + } + FIELD_CACHE_UNLOCK(fieldCache); + return ret; +} + +/* There is no check that field is actually present in the field cache */ +mama_status mamaFieldCache_setModified(mamaFieldCache fieldCache, + mamaFieldCacheField field) +{ + if (!fieldCache || !field) + { + return MAMA_STATUS_NULL_ARG; + } + if (fieldCache->mTrackModified == 0 || field->mIsModified) + { + return MAMA_STATUS_OK; + } + + field->mIsModified = 1; + mamaFieldCacheList_add(fieldCache->mModifiedFields, (void*)field); + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_applyField(mamaFieldCache fieldCache, + const mamaFieldCacheField field) +{ + mama_status ret = MAMA_STATUS_OK; + if (!fieldCache || !field) + { + return MAMA_STATUS_NULL_ARG; + } + if (fieldCache->mCachePayload) + { + return MAMA_STATUS_NOT_IMPLEMENTED; + } + FIELD_CACHE_LOCK(fieldCache); + ret = mamaFieldCache_updateCacheFromField(fieldCache, field); + FIELD_CACHE_UNLOCK(fieldCache); + return ret; +} + +mama_status mamaFieldCache_applyMessage( + mamaFieldCache fieldCache, + const mamaMsg message, + mamaDictionary dictionary) +{ + mama_status ret = MAMA_STATUS_OK; + mamaMsgField nextField = NULL; + + if (!fieldCache || !message) + { + return MAMA_STATUS_NULL_ARG; + } + + if (fieldCache->mCachePayload) + { + if (!fieldCache->mCacheMsg) + { + ret=mamaMsg_copy(message, &fieldCache->mCacheMsg); + } + else + { + ret=mamaMsg_applyMsg(fieldCache->mCacheMsg, message); + + } + return ret; + } + + if(!fieldCache->mIterator) + { + ret = mamaMsgIterator_create(&fieldCache->mIterator, dictionary); + if(ret != MAMA_STATUS_OK) + { + return ret; + } + } + + ret = mamaMsgIterator_associate(fieldCache->mIterator, message); + if(ret != MAMA_STATUS_OK) + { + return ret; + } + FIELD_CACHE_LOCK(fieldCache); + nextField = mamaMsgIterator_next(fieldCache->mIterator); + while(nextField && ret == MAMA_STATUS_OK) + { + ret = mamaFieldCache_updateCacheFromMsgField(fieldCache, nextField); + nextField = mamaMsgIterator_next(fieldCache->mIterator); + } + FIELD_CACHE_UNLOCK(fieldCache); + + return ret; +} + +mama_status mamaFieldCache_applyRecord( + mamaFieldCache fieldCache, + const mamaFieldCacheRecord record) +{ + mama_status ret = MAMA_STATUS_OK; + mamaFieldCacheField newField; + mama_size_t size = 0; + mama_size_t counter; + + if (!fieldCache || !record) + { + return MAMA_STATUS_NULL_ARG; + } + if (fieldCache->mCachePayload) + { + return MAMA_STATUS_NOT_IMPLEMENTED; + } + + mamaFieldCacheRecord_getSize(record, &size); + for(counter = 0; counter < size; counter++) + { + /* Reset output parameter, because if it is not found it is not overwritten */ + newField = NULL; + mamaFieldCacheRecord_getField(record, counter, &newField); + if (newField) + { + ret = mamaFieldCache_updateCacheFromField(fieldCache, newField); + } + } + + return ret; +} + +mama_status mamaFieldCache_getFullMessage( + mamaFieldCache fieldCache, + mamaMsg message) +{ + mama_bool_t publish; + mamaFieldCacheField field = NULL; + mamaFieldCacheIterator iterator = NULL; + mama_size_t numFields = 0; + + if (!fieldCache || !message) + { + return MAMA_STATUS_NULL_ARG; + } + + if (fieldCache->mCacheMsg) + { + return mamaMsg_copy (fieldCache->mCacheMsg, &message); + } + + mamaMsg_getNumFields(message, &numFields); + mamaFieldCacheIterator_create(&iterator, fieldCache); + FIELD_CACHE_LOCK(fieldCache); + while (mamaFieldCacheIterator_hasNext(iterator)) + { + field = mamaFieldCacheIterator_next(iterator); + mamaFieldCacheField_getPublish(field, &publish); + if (publish) + { + mamaFieldCache_updateMsgField(fieldCache, field, message, numFields); + } + } + FIELD_CACHE_UNLOCK(fieldCache); + mamaFieldCacheIterator_destroy(iterator); + + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_getDeltaMessage( + mamaFieldCache fieldCache, + mamaMsg message) +{ + mamaFieldCacheField field = NULL; + mama_size_t numFields = 0; + mama_size_t numMsgFields = 0; + mama_size_t i; + + if (!fieldCache || !message) + { + return MAMA_STATUS_NULL_ARG; + } + if (!fieldCache->mTrackModified) + { + return mamaFieldCache_getFullMessage(fieldCache, message); + } + + mamaMsg_getNumFields(message, &numMsgFields); + + FIELD_CACHE_LOCK(fieldCache); + mamaFieldCacheList_getSize(fieldCache->mAlwaysPublishFields, &numFields); + for (i = 0; i < numFields; ++i) + { + void* tmpField = NULL; + mamaFieldCacheList_get(fieldCache->mAlwaysPublishFields, i, &tmpField); + assert(tmpField); + field = (mamaFieldCacheField)tmpField; + mamaFieldCache_updateMsgField(fieldCache, field, message, numMsgFields); + field->mIsModified = 0; + } + + mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &numFields); + for (i = 0; i < numFields; ++i) + { + void* tmpField = NULL; + mamaFieldCacheList_get(fieldCache->mModifiedFields, i, &tmpField); + assert(tmpField); + field = (mamaFieldCacheField)tmpField; + mamaFieldCache_updateMsgField(fieldCache, field, message, numMsgFields); + field->mIsModified = 0; + } + mamaFieldCacheList_clear(fieldCache->mModifiedFields); + FIELD_CACHE_UNLOCK(fieldCache); + + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCache_clearModifiedFields(mamaFieldCache fieldCache) +{ + mamaFieldCacheField field = NULL; + mama_size_t numFields = 0; + mama_size_t i; + + if (!fieldCache) + { + return MAMA_STATUS_NULL_ARG; + } + if (!fieldCache->mTrackModified) + { + return MAMA_STATUS_OK; + } + + mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &numFields); + for (i = 0; i < numFields; ++i) + { + void* tmpField = NULL; + mamaFieldCacheList_get(fieldCache->mModifiedFields, i, &tmpField); + assert(tmpField); + field = (mamaFieldCacheField)tmpField; + field->mIsModified = 0; + } + mamaFieldCacheList_clear(fieldCache->mModifiedFields); + + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_setTrackModified( + mamaFieldCache fieldCache, + mama_bool_t trackModified) +{ + if (!fieldCache) + { + return MAMA_STATUS_NULL_ARG; + } + if (!fieldCache->mCachePayload) + { + fieldCache->mTrackModified = trackModified; + } + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_getTrackModified( + mamaFieldCache fieldCache, + mama_bool_t* trackModified) +{ + if (!fieldCache || !trackModified) + { + return MAMA_STATUS_NULL_ARG; + } + *trackModified = fieldCache->mTrackModified; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_setUseFieldNames( + mamaFieldCache fieldCache, + mama_bool_t useFieldNames) +{ + if (!fieldCache) + { + return MAMA_STATUS_NULL_ARG; + } + fieldCache->mUseFieldNames = useFieldNames; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_getUseFieldNames( + mamaFieldCache fieldCache, + mama_bool_t* useFieldNames) +{ + if (!fieldCache || !useFieldNames) + { + return MAMA_STATUS_NULL_ARG; + } + *useFieldNames = fieldCache->mUseFieldNames; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_setUseLock(mamaFieldCache fieldCache, mama_bool_t enable) +{ + if (!fieldCache) + { + return MAMA_STATUS_NULL_ARG; + } + fieldCache->mUseLock = enable; + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCache_getUseLock(mamaFieldCache fieldCache, mama_bool_t* lockEnabled) +{ + if (!fieldCache || !lockEnabled) + { + return MAMA_STATUS_NULL_ARG; + } + *lockEnabled = fieldCache->mUseLock; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_lock(mamaFieldCache fieldCache) +{ + if (!fieldCache) + { + return MAMA_STATUS_NULL_ARG; + } + FIELD_CACHE_LOCK(fieldCache); + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCache_unlock(mamaFieldCache fieldCache) +{ + if (!fieldCache) + { + return MAMA_STATUS_NULL_ARG; + } + FIELD_CACHE_UNLOCK(fieldCache); + return MAMA_STATUS_OK; +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachefield.c b/mama/c_cpp/src/c/fieldcache/fieldcachefield.c new file mode 100644 index 0000000..7eecda0 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachefield.c @@ -0,0 +1,1507 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachefield.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcachefieldimpl.h" +#include "fieldcachevector.h" +#include <mama/fieldcache/fieldcachefield.h> +#include <mama/price.h> +#include <mama/datetime.h> +#include <stdio.h> + +mama_bool_t mamaFieldCacheField_isSupported(mamaFieldType type) +{ + switch (type) + { + case MAMA_FIELD_TYPE_MSG: + case MAMA_FIELD_TYPE_VECTOR_MSG: + case MAMA_FIELD_TYPE_UNKNOWN: + case MAMA_FIELD_TYPE_COLLECTION: + case MAMA_FIELD_TYPE_OPAQUE: + return 0; + default: + return 1; + } +} + +mama_status mamaFieldCacheField_create(mamaFieldCacheField* field, + mama_fid_t fid, + mamaFieldType type, + const char* name) +{ + mamaFieldCacheField localField = NULL; + + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + + if (!mamaFieldCacheField_isSupported(type)) + { + return MAMA_STATUS_INVALID_ARG; + } + + localField = (mamaFieldCacheField)calloc(1, sizeof(mamaFieldCacheFieldImpl)); + if (!localField) + { + return MAMA_STATUS_NOMEM; + } + + localField->mFid = fid; + localField->mType = type; + if (name) + { + localField->mName = strdup(name); + } + localField->mPublish = 1; + localField->mCheckModified = 1; + + *field = localField; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_destroy(mamaFieldCacheField field) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + + if (field->mName) + { + free((void*)field->mName); + } + + if (field->mDataSize) + { + free(field->mData.data); + } + else + { + switch (field->mType) + { + case MAMA_FIELD_TYPE_PRICE: + mamaPrice_destroy((mamaPrice)field->mData.data); + break; + case MAMA_FIELD_TYPE_TIME: + mamaDateTime_destroy((mamaDateTime)field->mData.data); + break; + case MAMA_FIELD_TYPE_VECTOR_STRING: + if (field->mData.data) + { + mamaFieldCacheVector_free((mamaFieldCacheVector)field->mData.data); + mamaFieldCacheVector_destroy((mamaFieldCacheVector)field->mData.data); + } + break; + case MAMA_FIELD_TYPE_VECTOR_PRICE: + if (field->mData.data) + { + mamaFieldCacheField_destroyPriceVector( + (mamaFieldCacheVector)field->mData.data); + } + break; + case MAMA_FIELD_TYPE_VECTOR_TIME: + if (field->mData.data) + { + mamaFieldCacheField_destroyDateTimeVector( + (mamaFieldCacheVector)field->mData.data); + } + break; + default: /* something is wrong here */ + break; + } + } + + free(field); + + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheField_copy(const mamaFieldCacheField field, mamaFieldCacheField copy) +{ + if (!field || !copy) + { + return MAMA_STATUS_NULL_ARG; + } + if (field == copy) + { + return MAMA_STATUS_OK; + } + if (field->mFid != copy->mFid || field->mType != copy->mType) + { + return MAMA_STATUS_INVALID_ARG; + } + + copy->mIsModified = field->mIsModified; + copy->mPublish = field->mPublish; + copy->mCheckModified = field->mCheckModified; + copy->mDescriptor = field->mDescriptor; + if (field->mName) + { + if (copy->mName) + { + free((void*)copy->mName); + } + copy->mName = strdup(field->mName); + } + switch (field->mType) + { + case MAMA_FIELD_TYPE_BOOL: + { + mama_bool_t result; + mamaFieldCacheField_getBool(field, &result); + mamaFieldCacheField_setBool(copy, result); + break; + } + case MAMA_FIELD_TYPE_CHAR: + { + char value; + mamaFieldCacheField_getChar(field, &value); + mamaFieldCacheField_setChar(copy, value); + break; + } + case MAMA_FIELD_TYPE_I8: + { + mama_i8_t value; + mamaFieldCacheField_getI8(field, &value); + mamaFieldCacheField_setI8(copy, value); + break; + } + case MAMA_FIELD_TYPE_U8: + { + mama_u8_t value; + mamaFieldCacheField_getU8(field, &value); + mamaFieldCacheField_setU8(copy, value); + break; + } + case MAMA_FIELD_TYPE_I16: + { + mama_i16_t value; + mamaFieldCacheField_getI16(field, &value); + mamaFieldCacheField_setI16(copy, value); + break; + } + case MAMA_FIELD_TYPE_U16: + { + mama_u16_t value; + mamaFieldCacheField_getU16(field, &value); + mamaFieldCacheField_setU16(copy, value); + break; + } + case MAMA_FIELD_TYPE_I32: + { + mama_i32_t value; + mamaFieldCacheField_getI32(field, &value); + mamaFieldCacheField_setI32(copy, value); + break; + } + case MAMA_FIELD_TYPE_U32: + { + mama_u32_t value; + mamaFieldCacheField_getU32(field, &value); + mamaFieldCacheField_setU32(copy, value); + break; + } + case MAMA_FIELD_TYPE_I64: + { + mama_i64_t value; + mamaFieldCacheField_getI64(field, &value); + mamaFieldCacheField_setI64(copy, value); + break; + } + case MAMA_FIELD_TYPE_U64: + { + mama_u64_t value; + mamaFieldCacheField_getU64(field, &value); + mamaFieldCacheField_setU64(copy, value); + break; + } + case MAMA_FIELD_TYPE_F32: + { + mama_f32_t value; + mamaFieldCacheField_getF32(field, &value); + mamaFieldCacheField_setF32(copy, value); + break; + } + case MAMA_FIELD_TYPE_QUANTITY: + case MAMA_FIELD_TYPE_F64: + { + mama_f64_t value; + mamaFieldCacheField_getF64(field, &value); + mamaFieldCacheField_setF64(copy, value); + break; + } + case MAMA_FIELD_TYPE_STRING: + { + const char* value; + mama_size_t len; + mamaFieldCacheField_getString(field, &value, &len); + mamaFieldCacheField_setString(copy, value, len); + break; + } + case MAMA_FIELD_TYPE_PRICE: + { + mamaPrice value = NULL; + const mamaPrice* pvalue = &value; + mamaFieldCacheField_getPrice(field, pvalue); + mamaFieldCacheField_setPrice(copy, value); + break; + } + case MAMA_FIELD_TYPE_TIME: + { + mamaDateTime value = NULL; + const mamaDateTime* pvalue = &value; + mamaFieldCacheField_getDateTime(field, pvalue); + mamaFieldCacheField_setDateTime(copy, value); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I8: + { + const mama_i8_t* values = NULL; + mama_size_t size; + mamaFieldCacheField_getI8Vector(field, &values, &size); + mamaFieldCacheField_setI8Vector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U8: + { + const mama_u8_t* values = NULL; + mama_size_t size; + mamaFieldCacheField_getU8Vector(field, &values, &size); + mamaFieldCacheField_setU8Vector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I16: + { + const mama_i16_t* values = NULL; + mama_size_t size; + mamaFieldCacheField_getI16Vector(field, &values, &size); + mamaFieldCacheField_setI16Vector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U16: + { + const mama_u16_t* values = NULL; + mama_size_t size; + mamaFieldCacheField_getU16Vector(field, &values, &size); + mamaFieldCacheField_setU16Vector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I32: + { + const mama_i32_t* values = NULL; + mama_size_t size; + mamaFieldCacheField_getI32Vector(field, &values, &size); + mamaFieldCacheField_setI32Vector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U32: + { + const mama_u32_t* values = NULL; + mama_size_t size; + mamaFieldCacheField_getU32Vector(field, &values, &size); + mamaFieldCacheField_setU32Vector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I64: + { + const mama_i64_t* values = NULL; + mama_size_t size; + mamaFieldCacheField_getI64Vector(field, &values, &size); + mamaFieldCacheField_setI64Vector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U64: + { + const mama_u64_t* values = NULL; + mama_size_t size; + mamaFieldCacheField_getU64Vector(field, &values, &size); + mamaFieldCacheField_setU64Vector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_F32: + { + const mama_f32_t* values = NULL; + mama_size_t size; + mamaFieldCacheField_getF32Vector(field, &values, &size); + mamaFieldCacheField_setF32Vector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_F64: + { + const mama_f64_t* values = NULL; + mama_size_t size; + mamaFieldCacheField_getF64Vector(field, &values, &size); + mamaFieldCacheField_setF64Vector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_STRING: + { + const char** values = NULL; + mama_size_t size; + mamaFieldCacheField_getStringVector(field, &values, &size); + mamaFieldCacheField_setStringVector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_PRICE: + { + const mamaPrice* values = NULL; + mama_size_t size; + mamaFieldCacheField_getPriceVector(field, &values, &size); + mamaFieldCacheField_setPriceVector(copy, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_TIME: + { + const mamaDateTime* values = NULL; + mama_size_t size; + mamaFieldCacheField_getDateTimeVector(field, &values, &size); + mamaFieldCacheField_setDateTimeVector(copy, values, size); + break; + } + default: + break; + } + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getFid(mamaFieldCacheField field, mama_fid_t* fid) +{ + if (!field || !fid) + { + return MAMA_STATUS_NULL_ARG; + } + *fid = field->mFid; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getType(mamaFieldCacheField field, mamaFieldType* type) +{ + if (!field || !type) + { + return MAMA_STATUS_NULL_ARG; + } + *type = field->mType; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getName(mamaFieldCacheField field, const char** name) +{ + if (!field || !name) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mName) + { + *name = field->mName; + } + else if (field->mDescriptor) + { + *name = mamaFieldDescriptor_getName(field->mDescriptor); + } + else + { + *name = NULL; + } + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setDescriptor(mamaFieldCacheField field, + const mamaFieldDescriptor desc) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + field->mDescriptor = desc; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getDescriptor(mamaFieldCacheField field, + const mamaFieldDescriptor* desc) +{ + if (!field || !desc) + { + return MAMA_STATUS_NULL_ARG; + } + *(mamaFieldDescriptor*)desc = field->mDescriptor; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_isModified(mamaFieldCacheField field, + mama_bool_t* modified) +{ + if (!field || !modified) + { + return MAMA_STATUS_NULL_ARG; + } + *modified = field->mIsModified; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setPublish(mamaFieldCacheField field, + mama_bool_t publish) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + field->mPublish = publish; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getPublish(mamaFieldCacheField field, + mama_bool_t* publish) +{ + if (!field || !publish) + { + return MAMA_STATUS_NULL_ARG; + } + *publish = field->mPublish; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setCheckModified(mamaFieldCacheField field, + mama_bool_t check) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + field->mCheckModified = check; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getCheckModified(mamaFieldCacheField field, + mama_bool_t* check) +{ + if (!field || !check) + { + return MAMA_STATUS_NULL_ARG; + } + *check = field->mCheckModified; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getBool(const mamaFieldCacheField field, + mama_bool_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_BOOL) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.abool; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getChar(const mamaFieldCacheField field, + char* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_CHAR) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.chr; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getI8(const mamaFieldCacheField field, + mama_i8_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_I8) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.i8; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getU8(const mamaFieldCacheField field, + mama_u8_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_U8) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.u8; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getI16(const mamaFieldCacheField field, + mama_i16_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_I16) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.i16; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getU16(const mamaFieldCacheField field, + mama_u16_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_U16) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.u16; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getI32(const mamaFieldCacheField field, + mama_i32_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_I32) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.i32; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getU32(const mamaFieldCacheField field, + mama_u32_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_U32) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.u32; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getI64(const mamaFieldCacheField field, + mama_i64_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_I64) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.i64; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getU64(const mamaFieldCacheField field, + mama_u64_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_U64) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.u64; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getF32(const mamaFieldCacheField field, + mama_f32_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_F32) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.f32; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getF64(const mamaFieldCacheField field, + mama_f64_t* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_F64) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.f64; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getString(const mamaFieldCacheField field, + const char** result, + mama_size_t* len) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_STRING) + { + return MAMA_STATUS_INVALID_ARG; + } + *result = field->mData.str; /* NOT COPYING */ + *len = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getPrice(const mamaFieldCacheField field, + const mamaPrice* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_PRICE) + { + return MAMA_STATUS_INVALID_ARG; + } + *(mamaPrice*)result = (mamaPrice)field->mData.data; /* NOT COPYING */ + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getDateTime(const mamaFieldCacheField field, + const mamaDateTime* result) +{ + if (!field || !result) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_TIME) + { + return MAMA_STATUS_INVALID_ARG; + } + *(mamaDateTime*)result = (mamaDateTime)field->mData.data; /* NOT COPYING */ + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getI8Vector(const mamaFieldCacheField field, + const mama_i8_t** values, + mama_size_t* size) +{ + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_I8) + { + return MAMA_STATUS_INVALID_ARG; + } + *values = (mama_i8_t*)field->mData.data; /* NOT COPYING */ + *size = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getU8Vector(const mamaFieldCacheField field, + const mama_u8_t** values, + mama_size_t* size) +{ + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_U8) + { + return MAMA_STATUS_INVALID_ARG; + } + *values = (mama_u8_t*)field->mData.data; /* NOT COPYING */ + *size = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getI16Vector(const mamaFieldCacheField field, + const mama_i16_t** values, + mama_size_t* size) +{ + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_I16) + { + return MAMA_STATUS_INVALID_ARG; + } + *values = (mama_i16_t*)field->mData.data; /* NOT COPYING */ + *size = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getU16Vector(const mamaFieldCacheField field, + const mama_u16_t** values, + mama_size_t* size) +{ + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_U16) + { + return MAMA_STATUS_INVALID_ARG; + } + *values = (mama_u16_t*)field->mData.data; /* NOT COPYING */ + *size = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getI32Vector(const mamaFieldCacheField field, + const mama_i32_t** values, + mama_size_t* size) +{ + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_I32) + { + return MAMA_STATUS_INVALID_ARG; + } + *values = (mama_i32_t*)field->mData.data; /* NOT COPYING */ + *size = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getU32Vector(const mamaFieldCacheField field, + const mama_u32_t** values, + mama_size_t* size) +{ + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_U32) + { + return MAMA_STATUS_INVALID_ARG; + } + *values = (mama_u32_t*)field->mData.data; /* NOT COPYING */ + *size = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getI64Vector(const mamaFieldCacheField field, + const mama_i64_t** values, + mama_size_t* size) +{ + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_I64) + { + return MAMA_STATUS_INVALID_ARG; + } + *values = (mama_i64_t*)field->mData.data; /* NOT COPYING */ + *size = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getU64Vector(const mamaFieldCacheField field, + const mama_u64_t** values, + mama_size_t* size) +{ + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_U64) + { + return MAMA_STATUS_INVALID_ARG; + } + *values = (mama_u64_t*)field->mData.data; /* NOT COPYING */ + *size = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getF32Vector(const mamaFieldCacheField field, + const mama_f32_t** values, + mama_size_t* size) +{ + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_F32) + { + return MAMA_STATUS_INVALID_ARG; + } + *values = (mama_f32_t*)field->mData.data; /* NOT COPYING */ + *size = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getF64Vector(const mamaFieldCacheField field, + const mama_f64_t** values, + mama_size_t* size) +{ + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_F64) + { + return MAMA_STATUS_INVALID_ARG; + } + *values = (mama_f64_t*)field->mData.data; /* NOT COPYING */ + *size = field->mVectorSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getStringVector(const mamaFieldCacheField field, + const char*** values, + mama_size_t* size) +{ + mamaFieldCacheVector vector = NULL; + + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_STRING) + { + return MAMA_STATUS_INVALID_ARG; + } + vector = (mamaFieldCacheVector)field->mData.data; + if (vector) + { + *values = (const char**)vector->mData; /* NOT COPYING */ + *size = field->mVectorSize; + } + else + { + *values = NULL; + *size = 0; + } + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getPriceVector(const mamaFieldCacheField field, + const mamaPrice** values, + mama_size_t* size) +{ + mamaFieldCacheVector vector = NULL; + + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_PRICE) + { + return MAMA_STATUS_INVALID_ARG; + } + vector = (mamaFieldCacheVector)field->mData.data; + if (vector) + { + *values = (mamaPrice*)vector->mData; /* NOT COPYING */ + *size = field->mVectorSize; + } + else + { + *values = NULL; + *size = 0; + } + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_getDateTimeVector(const mamaFieldCacheField field, + const mamaDateTime** values, + mama_size_t* size) +{ + mamaFieldCacheVector vector = NULL; + + if (!field || !values || !size) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_TIME) + { + return MAMA_STATUS_INVALID_ARG; + } + vector = (mamaFieldCacheVector)field->mData.data; + if (vector) + { + *values = (mamaDateTime*)vector->mData; /* NOT COPYING */ + *size = field->mVectorSize; + } + else + { + *values = NULL; + *size = 0; + } + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setBool(mamaFieldCacheField field, mama_bool_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_BOOL) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.abool = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setChar(mamaFieldCacheField field, char value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_CHAR) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.chr = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setI8(mamaFieldCacheField field, mama_i8_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_I8) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.i8 = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setU8(mamaFieldCacheField field, mama_u8_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_U8) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.u8 = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setI16(mamaFieldCacheField field, mama_i16_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_I16) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.i16 = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setU16(mamaFieldCacheField field, mama_u16_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_U16) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.u16 = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setI32(mamaFieldCacheField field, mama_i32_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_I32) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.i32 = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setU32(mamaFieldCacheField field, mama_u32_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_U32) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.u32 = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setI64(mamaFieldCacheField field, mama_i64_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_I64) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.i64 = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setU64(mamaFieldCacheField field, mama_u64_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_U64) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.u64 = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setF32(mamaFieldCacheField field, mama_f32_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_F32) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.f32 = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setF64(mamaFieldCacheField field, mama_f64_t value) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_F64) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mData.f64 = value; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setString(const mamaFieldCacheField field, + const char* value, + mama_size_t len) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_STRING) + { + return MAMA_STATUS_INVALID_ARG; + } + if (len == 0 && value) + { + len = strlen(value); + } + field->mVectorSize = len; + return mamaFieldCacheField_setDataValue( + field, + value,/* Copy also string terminator */ + value ? len + 1 : 0); +} + +mama_status mamaFieldCacheField_setPrice(const mamaFieldCacheField field, + const mamaPrice value) +{ + mamaPrice price = NULL; + void* old = NULL; + + if (!field || !value) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_PRICE) + { + return MAMA_STATUS_INVALID_ARG; + } + + if (!field->mData.data) + { + mamaPrice_create(&price); + mamaFieldCacheField_setDataPointer(field, (void*)price, &old); + } + mamaPrice_copy((mamaPrice)field->mData.data, value); + + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setDateTime(const mamaFieldCacheField field, + const mamaDateTime value) +{ + mamaDateTime dateTime = NULL; + void* old = NULL; + + if (!field || !value) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_TIME) + { + return MAMA_STATUS_INVALID_ARG; + } + + if (!field->mData.data) + { + mamaDateTime_create(&dateTime); + mamaFieldCacheField_setDataPointer(field, (void*)dateTime, &old); + } + mamaDateTime_copy((mamaDateTime)field->mData.data, value); + + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setI8Vector(const mamaFieldCacheField field, + const mama_i8_t* values, + mama_size_t size) +{ + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_I8) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mVectorSize = size; + return mamaFieldCacheField_setDataValue(field, values, size * sizeof(mama_i8_t)); +} + +mama_status mamaFieldCacheField_setU8Vector(const mamaFieldCacheField field, + const mama_u8_t* values, + mama_size_t size) +{ + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_U8) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mVectorSize = size; + return mamaFieldCacheField_setDataValue(field, values, size * sizeof(mama_i8_t)); +} + +mama_status mamaFieldCacheField_setI16Vector(const mamaFieldCacheField field, + const mama_i16_t* values, + mama_size_t size) +{ + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_I16) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mVectorSize = size; + return mamaFieldCacheField_setDataValue(field, values, size * sizeof(mama_i16_t)); +} + +mama_status mamaFieldCacheField_setU16Vector(const mamaFieldCacheField field, + const mama_u16_t* values, + mama_size_t size) +{ + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_U16) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mVectorSize = size; + return mamaFieldCacheField_setDataValue(field, values, size * sizeof(mama_u16_t)); +} + +mama_status mamaFieldCacheField_setI32Vector(const mamaFieldCacheField field, + const mama_i32_t* values, + mama_size_t size) +{ + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_I32) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mVectorSize = size; + return mamaFieldCacheField_setDataValue(field, values, size * sizeof(mama_i32_t)); +} + +mama_status mamaFieldCacheField_setU32Vector(const mamaFieldCacheField field, + const mama_u32_t* values, + mama_size_t size) +{ + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_U32) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mVectorSize = size; + return mamaFieldCacheField_setDataValue(field, values, size * sizeof(mama_u32_t)); +} + +mama_status mamaFieldCacheField_setI64Vector(const mamaFieldCacheField field, + const mama_i64_t* values, + mama_size_t size) +{ + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_I64) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mVectorSize = size; + return mamaFieldCacheField_setDataValue(field, values, size * sizeof(mama_i64_t)); +} + +mama_status mamaFieldCacheField_setU64Vector(const mamaFieldCacheField field, + const mama_u64_t* values, + mama_size_t size) +{ + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_U64) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mVectorSize = size; + return mamaFieldCacheField_setDataValue(field, values, size * sizeof(mama_u64_t)); +} + +mama_status mamaFieldCacheField_setF32Vector(const mamaFieldCacheField field, + const mama_f32_t* values, + mama_size_t size) +{ + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_F32) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mVectorSize = size; + return mamaFieldCacheField_setDataValue(field, values, size * sizeof(mama_f32_t)); +} + +mama_status mamaFieldCacheField_setF64Vector(const mamaFieldCacheField field, + const mama_f64_t* values, + mama_size_t size) +{ + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_F64) + { + return MAMA_STATUS_INVALID_ARG; + } + field->mVectorSize = size; + return mamaFieldCacheField_setDataValue(field, values, size * sizeof(mama_f64_t)); +} + +mama_status mamaFieldCacheField_setStringVector(const mamaFieldCacheField field, + const char** values, + mama_size_t size) +{ + mama_size_t counter; + mamaFieldCacheVector vector = NULL; + void* string = NULL; + + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_STRING) + { + return MAMA_STATUS_INVALID_ARG; + } + + if (!field->mData.data) + { + mamaFieldCacheVector_create(&vector); + field->mData.data = (void*)vector; + } + mamaFieldCacheVector_grow(field->mData.data, size); + for (counter = 0; counter < size; counter++) + { + mamaFieldCacheVector_get((mamaFieldCacheVector)field->mData.data, counter, &string); + if (string) + { + free(string); + } + mamaFieldCacheVector_set((mamaFieldCacheVector)field->mData.data, + counter, + (void*)strdup(values[counter])); + } + field->mVectorSize = size; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setPriceVector(const mamaFieldCacheField field, + const mamaPrice* values, + mama_size_t size) +{ + mama_size_t index; + mamaFieldCacheVector vector = NULL; + mamaPrice price = NULL; + + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_PRICE) + { + return MAMA_STATUS_INVALID_ARG; + } + + if (!field->mData.data) + { + mamaFieldCacheVector_create(&vector); + field->mData.data = (void*)vector; + } + mamaFieldCacheVector_grow(field->mData.data, size); + for (index = 0; index < size; index++) + { + mamaFieldCacheVector_get((mamaFieldCacheVector)field->mData.data, + index, + (void**)&price); + if (!price) + { + mamaPrice_create(&price); + } + mamaPrice_copy(price, values[index]); + mamaFieldCacheVector_set((mamaFieldCacheVector)field->mData.data, + index, + (void*)price); + + } + field->mVectorSize = size; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setDateTimeVector(const mamaFieldCacheField field, + const mamaDateTime* values, + mama_size_t size) +{ + mama_size_t index; + mamaFieldCacheVector vector = NULL; + void* item = NULL; + mamaDateTime dateTime = NULL; + + if (!field || !values) + { + return MAMA_STATUS_NULL_ARG; + } + if (field->mType != MAMA_FIELD_TYPE_VECTOR_TIME) + { + return MAMA_STATUS_INVALID_ARG; + } + + if (!field->mData.data) + { + mamaFieldCacheVector_create(&vector); + field->mData.data = (void*)vector; + } + mamaFieldCacheVector_grow(field->mData.data, size); + for (index = 0; index < size; index++) + { + mamaFieldCacheVector_get((mamaFieldCacheVector)field->mData.data, + index, + &item); + dateTime = (mamaDateTime)item; + if (!dateTime) + { + mamaDateTime_create(&dateTime); + } + mamaDateTime_copy(dateTime, values[index]); + mamaFieldCacheVector_set((mamaFieldCacheVector)field->mData.data, + index, + (void*)dateTime); + } + field->mVectorSize = size; + return MAMA_STATUS_OK; +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.c b/mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.c new file mode 100644 index 0000000..06d02c4 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.c @@ -0,0 +1,122 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcachefieldimpl.h" +#include <mama/price.h> +#include <mama/datetime.h> +#include <string.h> /* For memcpy */ + +/* Private functions - not exposed through the API interface */ +/* +mama_status mamaFieldCacheField_getData( + const mamaFieldCacheField field, + void** data, + mama_u32_t* size) +{ + if (!field) + { + return MAMA_STATUS_NULL_ARG; + } + + *data = field->mData; + *size = field->mDataSize; + + return MAMA_STATUS_OK; +} +*/ +mama_status mamaFieldCacheField_setDataValue(mamaFieldCacheField field, + const void* data, + mama_size_t size) +{ + if (field->mData.data && field->mDataSize != size) + { + free(field->mData.data); + field->mData.data = NULL; + field->mDataSize = 0; + } + if (data && size) + { + if (field->mDataSize != size) + { + field->mData.data = malloc(size); + field->mDataSize = size; + } + if (field->mData.data) + { + memcpy(field->mData.data, data, size); + } + } + + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheField_setDataPointer(mamaFieldCacheField field, + void* data, + void** old) +{ + if (field->mData.data) + { + *old = field->mData.data; + field->mData.data = NULL; + field->mDataSize = 0; + } + if (data) + { + field->mData.data = data; + field->mDataSize = 0; + } + + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheField_destroyPriceVector(mamaFieldCacheVector priceVector) +{ + mama_size_t i; + mama_size_t size = 0; + void* price = NULL; + + mamaFieldCacheVector_getSize(priceVector, &size); + for (i = 0; i < size; i++) + { + mamaFieldCacheVector_get(priceVector, i, &price); + mamaPrice_destroy((mamaPrice)price); + } + mamaFieldCacheVector_destroy(priceVector); + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheField_destroyDateTimeVector(mamaFieldCacheVector dateTimeVector) +{ + mama_size_t i; + mama_size_t size = 0; + void* dateTime = NULL; + + mamaFieldCacheVector_getSize(dateTimeVector, &size); + for (i = 0; i < size; i++) + { + mamaFieldCacheVector_get(dateTimeVector, i, &dateTime); + mamaDateTime_destroy((mamaDateTime)dateTime); + } + mamaFieldCacheVector_destroy(dateTimeVector); + return MAMA_STATUS_OK; +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.h b/mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.h new file mode 100644 index 0000000..c75c51a --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.h @@ -0,0 +1,138 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachefieldimpl.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheFieldImplH__ +#define MamaFieldCacheFieldImplH__ + +#include <mama/config.h> +#include <mama/fielddesc.h> +#include <mama/types.h> +#include <mama/fieldcache/fieldcachetypes.h> +#include "fieldcachevector.h" + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + + /* This structure describes a field that is held in the field cache, it is used + * when invoking ultraFast calls on the cache to provide direct read only access + * to field data. + */ + +typedef union cacheData_ +{ + mama_i8_t i8; + mama_u8_t u8; + mama_i16_t i16; + mama_u16_t u16; + mama_i32_t i32; + mama_u32_t u32; + mama_i64_t i64; + mama_u64_t u64; + mama_f32_t f32; + mama_f64_t f64; + mama_bool_t abool; + char chr; + char* str; + void* data; +} cacheData; + +typedef struct mamaFieldCacheFieldImpl_ +{ + /* DO NOT CHANGE THE ORDER - IT CAN BREAK THE MEMORY ALIGNMENT */ + + /* Field identification */ + mamaFieldType mType; /* 4 bytes */ + mama_fid_t mFid; /* 2 bytes */ + + /* This flag specifies if the field must never be published (0) or can be + * published (1) + */ + mama_bool_t mPublish; /* 1 byte */ + + /* This flag specifies if the field should be checked for modifications (1) + * to decide if it must be published + */ + mama_bool_t mCheckModified; /* 1 byte */ + + /* This is a pointer to the actual field data */ + cacheData mData; + + /* This is the size of the memory allocated for the data */ + mama_size_t mDataSize; + + /* This is only used for a vector data type and will contain the number of + * elements in the vector. For any other type this value will be 0. + * If the type is an opaque then it will contain the number of bytes. + */ + mama_size_t mVectorSize; + + /* Pointer to a field descriptor - NO COPY */ + mamaFieldDescriptor mDescriptor; + + /* Explicit field name - overrides the field descriptor name */ + const char* mName; + + /* The current modification state of the field. */ + mama_bool_t mIsModified; /* 1 byte */ +} mamaFieldCacheFieldImpl; + +/* Get the pointer to the internal data and the size of the memory allocated */ +/* +mama_status +mamaFieldCacheField_getData( + const mamaFieldCacheField field, + void** data, + mama_u32_t* size); +*/ +/* Copy size byte starting at pointer data to field to the internal field data. + * New memory is allocated with malloc and old one is freed with free (if needed). + */ +mama_status +mamaFieldCacheField_setDataValue( + mamaFieldCacheField field, + const void* data, + mama_size_t size); + +/* Copy pointer data to internal data pointer in field. + * Returns a pointer to the old data pointer so that old data can be destroyed + * and freed. + */ +mama_status +mamaFieldCacheField_setDataPointer(mamaFieldCacheField field, + void* data, + void** old); + +/* Price vector type requires a special function to be destroyed and freed. + */ +mama_status +mamaFieldCacheField_destroyPriceVector(mamaFieldCacheVector priceVector); + +/* DateTime vector type requires a special function to be destroyed and freed. + */ +mama_status +mamaFieldCacheField_destroyDateTimeVector(mamaFieldCacheVector dateTimeVector); + +#if defined(__cplusplus) +} +#endif + +#endif /* MamaFieldCacheFieldImplH__ */ diff --git a/mama/c_cpp/src/c/fieldcache/fieldcacheimpl.c b/mama/c_cpp/src/c/fieldcache/fieldcacheimpl.c new file mode 100644 index 0000000..27630a7 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcacheimpl.c @@ -0,0 +1,687 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcacheimpl.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcacheimpl.h" +#include "fieldcachefieldimpl.h" +#include <mama/fieldcache/fieldcachefield.h> +#include <mama/msg.h> +#include <mama/msgfield.h> + +mama_status mamaFieldCache_updateCacheFromMsgField(mamaFieldCache fieldCache, + const mamaMsgField messageField) +{ + mama_status ret; + mama_fid_t fid; + mamaFieldType type = MAMA_FIELD_TYPE_UNKNOWN; + const char* name = NULL; + mamaFieldDescriptor descriptor = NULL; + mamaFieldCacheField field = NULL; + + ret = mamaMsgField_getFid(messageField, &fid); + if (ret != MAMA_STATUS_OK) + { + return ret; + } + + if (MAMA_STATUS_OK != mamaFieldCacheMap_find(fieldCache->mMap, fid, type, name, &field)) + { + ret = mamaMsgField_getType(messageField, &type); + if (ret != MAMA_STATUS_OK) + { + return ret; + } + if (fieldCache->mUseFieldNames) + { + mamaMsgField_getName(messageField, &name); + } + mamaFieldCacheField_create(&field, fid, type, name); + ret = mamaFieldCacheMap_add(fieldCache->mMap, field); + if (ret != MAMA_STATUS_OK) + { + return ret; + } + fieldCache->mSize++; + + mamaMsgField_getDescriptor(messageField, &descriptor); + if (descriptor) + { + mamaFieldCacheField_setDescriptor(field, descriptor); + } + } + else + { + type = field->mType; + } + + if (fieldCache->mTrackModified && field->mPublish && !field->mIsModified) + { + field->mIsModified = 1; + mamaFieldCacheList_add(fieldCache->mModifiedFields, (void*)field); + } + + switch (type) + { + case MAMA_FIELD_TYPE_BOOL: + { + mama_bool_t result; + mamaMsgField_getBool(messageField, &result); + mamaFieldCacheField_setBool(field, result); + break; + } + case MAMA_FIELD_TYPE_CHAR: + { + char value; + mamaMsgField_getChar(messageField, &value); + mamaFieldCacheField_setChar(field, value); + break; + } + case MAMA_FIELD_TYPE_I8: + { + mama_i8_t value; + mamaMsgField_getI8(messageField, &value); + mamaFieldCacheField_setI8(field, value); + break; + } + case MAMA_FIELD_TYPE_U8: + { + mama_u8_t value; + mamaMsgField_getU8(messageField, &value); + mamaFieldCacheField_setU8(field, value); + break; + } + case MAMA_FIELD_TYPE_I16: + { + mama_i16_t value; + mamaMsgField_getI16(messageField, &value); + mamaFieldCacheField_setI16(field, value); + break; + } + case MAMA_FIELD_TYPE_U16: + { + mama_u16_t value; + mamaMsgField_getU16(messageField, &value); + mamaFieldCacheField_setU16(field, value); + break; + } + case MAMA_FIELD_TYPE_I32: + { + mama_i32_t value; + mamaMsgField_getI32(messageField, &value); + mamaFieldCacheField_setI32(field, value); + break; + } + case MAMA_FIELD_TYPE_U32: + { + mama_u32_t value; + mamaMsgField_getU32(messageField, &value); + mamaFieldCacheField_setU32(field, value); + break; + } + case MAMA_FIELD_TYPE_I64: + { + mama_i64_t value; + mamaMsgField_getI64(messageField, &value); + mamaFieldCacheField_setI64(field, value); + break; + } + case MAMA_FIELD_TYPE_U64: + { + mama_u64_t value; + mamaMsgField_getU64(messageField, &value); + mamaFieldCacheField_setU64(field, value); + break; + } + case MAMA_FIELD_TYPE_F32: + { + mama_f32_t value; + mamaMsgField_getF32(messageField, &value); + mamaFieldCacheField_setF32(field, value); + break; + } + case MAMA_FIELD_TYPE_QUANTITY: + case MAMA_FIELD_TYPE_F64: + { + mama_f64_t value; + mamaMsgField_getF64(messageField, &value); + mamaFieldCacheField_setF64(field, value); + break; + } + case MAMA_FIELD_TYPE_STRING: + { + const char* value = NULL; + mamaMsgField_getString(messageField, &value); + mamaFieldCacheField_setString(field, value, 0); + break; + } + case MAMA_FIELD_TYPE_PRICE: + { + mamaMsgField_getPrice(messageField, fieldCache->mReusablePrice); + mamaFieldCacheField_setPrice(field, fieldCache->mReusablePrice); + break; + } + case MAMA_FIELD_TYPE_TIME: + { + mamaMsgField_getDateTime(messageField, fieldCache->mReusableDateTime); + mamaFieldCacheField_setDateTime(field, fieldCache->mReusableDateTime); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I8: + { + const mama_i8_t* values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorI8(messageField, &values, &size); + mamaFieldCacheField_setI8Vector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U8: + { + const mama_u8_t* values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorU8(messageField, &values, &size); + mamaFieldCacheField_setU8Vector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I16: + { + const mama_i16_t* values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorI16(messageField, &values, &size); + mamaFieldCacheField_setI16Vector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U16: + { + const mama_u16_t* values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorU16(messageField, &values, &size); + mamaFieldCacheField_setU16Vector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I32: + { + const mama_i32_t* values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorI32(messageField, &values, &size); + mamaFieldCacheField_setI32Vector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U32: + { + const mama_u32_t* values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorU32(messageField, &values, &size); + mamaFieldCacheField_setU32Vector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I64: + { + const mama_i64_t* values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorI64(messageField, &values, &size); + mamaFieldCacheField_setI64Vector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U64: + { + const mama_u64_t* values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorU64(messageField, &values, &size); + mamaFieldCacheField_setU64Vector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_F32: + { + const mama_f32_t* values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorF32(messageField, &values, &size); + mamaFieldCacheField_setF32Vector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_F64: + { + const mama_f64_t* values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorF64(messageField, &values, &size); + mamaFieldCacheField_setF64Vector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_STRING: + { + const char** values = NULL; + mama_size_t size = 0; + mamaMsgField_getVectorString(messageField, &values, &size); + mamaFieldCacheField_setStringVector(field, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_PRICE: + { + /* TODO: mamaMsgField does not provide methods to get price vector + const mamaPrice* values = NULL; + mama_size_t size; + mamaMsgField_getVectorPrice(messageField, &values, &size); + mamaFieldCacheField_setPriceVector(field, values, size); + */ + break; + } + case MAMA_FIELD_TYPE_VECTOR_TIME: + { + /* TODO: mamaMsgField does not provide methods to get time vector + const mamaDateTime* values = NULL; + mama_size_t size; + mamaMsgField_getVectorDateTime(messageField, &values, &size); + mamaFieldCacheField_setDateTimeVector(field, values, size); + */ + break; + } + default: + break; + } + return ret; +} + +mama_status mamaFieldCache_updateCacheFromField(mamaFieldCache fieldCache, + const mamaFieldCacheField field) +{ + mama_status ret; + mama_fid_t fid; + mamaFieldType type; + mama_bool_t alreadyModified = 0; + const char* name = NULL; + mamaFieldCacheField cachedField = NULL; + + ret = mamaFieldCacheField_getFid(field, &fid); + if (ret != MAMA_STATUS_OK) + { + return ret; + } + + ret = mamaFieldCacheField_getType(field, &type); + if (ret != MAMA_STATUS_OK) + { + return ret; + } + + mamaFieldCacheField_getName(field, &name); + if (MAMA_STATUS_OK != mamaFieldCacheMap_find(fieldCache->mMap, fid, type, name, &cachedField)) + { + ret = mamaFieldCacheField_create(&cachedField, fid, type, NULL); + if (ret != MAMA_STATUS_OK) + { + return ret; + } + ret = mamaFieldCacheMap_add(fieldCache->mMap, cachedField); + if (ret != MAMA_STATUS_OK) + { + return ret; + } + fieldCache->mSize++; + if (field->mPublish && !field->mCheckModified) + { /* Always publish */ + mamaFieldCacheList_add(fieldCache->mAlwaysPublishFields, (void*)cachedField); + } + alreadyModified = 0; + } + else + { + alreadyModified = cachedField->mIsModified; + } + + mamaFieldCacheField_copy(field, cachedField); + + if (cachedField->mPublish && cachedField->mCheckModified + && !alreadyModified + && fieldCache->mTrackModified) + { + cachedField->mIsModified = 1; + mamaFieldCacheList_add(fieldCache->mModifiedFields, (void*)cachedField); + } + + return ret; +} + +mama_status mamaFieldCache_updateMsgField(mamaFieldCache fieldCache, + mamaFieldCacheField field, + mamaMsg message, + mama_bool_t useUpdate) +{ + mama_status status = MAMA_STATUS_OK; + mama_fid_t fid; + mamaFieldType type; + const char* name = NULL; + + mamaFieldCacheField_getFid(field, &fid); + mamaFieldCacheField_getType(field, &type); + if (fieldCache->mUseFieldNames) + { + mamaFieldCacheField_getName(field, &name); + } + + switch (type) + { + case MAMA_FIELD_TYPE_BOOL: + { + mama_bool_t value; + mamaFieldCacheField_getBool(field, &value); + status = useUpdate ? mamaMsg_updateBool(message, name, fid, value) + : mamaMsg_addBool(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_CHAR: + { + char value; + mamaFieldCacheField_getChar(field, &value); + status = useUpdate ? mamaMsg_updateChar(message, name, fid, value) + : mamaMsg_addChar(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_I8: + { + mama_i8_t value; + mamaFieldCacheField_getI8(field, &value); + status = useUpdate ? mamaMsg_updateI8(message, name, fid, value) + : mamaMsg_addI8(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_U8: + { + mama_u8_t value; + mamaFieldCacheField_getU8(field, &value); + status = useUpdate ? mamaMsg_updateU8(message, name, fid, value) + : mamaMsg_addU8(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_I16: + { + mama_i16_t value; + mamaFieldCacheField_getI16(field, &value); + status = useUpdate ? mamaMsg_updateI16(message, name, fid, value) + : mamaMsg_addI16(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_U16: + { + mama_u16_t value; + mamaFieldCacheField_getU16(field, &value); + status = useUpdate ? mamaMsg_updateU16(message, name, fid, value) + : mamaMsg_addU16(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_I32: + { + mama_i32_t value; + mamaFieldCacheField_getI32(field, &value); + status = useUpdate ? mamaMsg_updateI32(message, name, fid, value) + : mamaMsg_addI32(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_U32: + { + mama_u32_t value; + mamaFieldCacheField_getU32(field, &value); + status = useUpdate ? mamaMsg_updateU32(message, name, fid, value) + : mamaMsg_addU32(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_I64: + { + mama_i64_t value; + mamaFieldCacheField_getI64(field, &value); + status = useUpdate ? mamaMsg_updateI64(message, name, fid, value) + : mamaMsg_addI64(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_U64: + { + mama_u64_t value; + mamaFieldCacheField_getU64(field, &value); + status = useUpdate ? mamaMsg_updateU64(message, name, fid, value) + : mamaMsg_addU64(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_F32: + { + mama_f32_t value; + mamaFieldCacheField_getF32(field, &value); + status = useUpdate ? mamaMsg_updateF32(message, name, fid, value) + : mamaMsg_addF32(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_QUANTITY: + case MAMA_FIELD_TYPE_F64: + { + mama_f64_t value; + mamaFieldCacheField_getF64(field, &value); + status = useUpdate ? mamaMsg_updateF64(message, name, fid, value) + : mamaMsg_addF64(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_STRING: + { + const char* value = NULL; + mama_size_t len; + mamaFieldCacheField_getString(field, &value, &len); + if (!value) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateString(message, name, fid, value) + : mamaMsg_addString(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_PRICE: + { + const mamaPrice value = NULL; + mamaFieldCacheField_getPrice(field, &value); + if (!value) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updatePrice(message, name, fid, value) + : mamaMsg_addPrice(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_TIME: + { + const mamaDateTime value = NULL; + mamaFieldCacheField_getDateTime(field, &value); + if (!value) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateDateTime(message, name, fid, value) + : mamaMsg_addDateTime(message, name, fid, value); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I8: + { + const mama_i8_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getI8Vector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorI8(message, name, fid, values, size) + : mamaMsg_addVectorI8(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U8: + { + const mama_u8_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getU8Vector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorU8(message, name, fid, values, size) + : mamaMsg_addVectorU8(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I16: + { + const mama_i16_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getI16Vector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorI16(message, name, fid, values, size) + : mamaMsg_addVectorI16(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U16: + { + const mama_u16_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getU16Vector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorU16(message, name, fid, values, size) + : mamaMsg_addVectorU16(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I32: + { + const mama_i32_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getI32Vector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorI32(message, name, fid, values, size) + : mamaMsg_addVectorI32(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U32: + { + const mama_u32_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getU32Vector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorU32(message, name, fid, values, size) + : mamaMsg_addVectorU32(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I64: + { + const mama_i64_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getI64Vector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorI64(message, name, fid, values, size) + : mamaMsg_addVectorI64(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U64: + { + const mama_u64_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getU64Vector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorU64(message, name, fid, values, size) + : mamaMsg_addVectorU64(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_F32: + { + const mama_f32_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getF32Vector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorF32(message, name, fid, values, size) + : mamaMsg_addVectorF32(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_F64: + { + const mama_f64_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getF64Vector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorF64(message, name, fid, values, size) + : mamaMsg_addVectorF64(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_STRING: + { + const char** values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getStringVector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = useUpdate ? mamaMsg_updateVectorString(message, name, fid, values, size) + : mamaMsg_addVectorString(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_PRICE: + { + const mamaPrice* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getPriceVector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = /*useUpdate ? mamaMsg_updateVectorPrice(message, name, fid, values, size) + : */mamaMsg_addVectorPrice(message, name, fid, values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_TIME: + { + const mamaDateTime* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getDateTimeVector(field, &values, &size); + if (!values) + { + return MAMA_STATUS_INVALID_ARG; + } + status = /*useUpdate ? mamaMsg_updateVectorTime(message, name, fid, values, size) + : */mamaMsg_addVectorDateTime(message, name, fid, values, size); + break; + } + default: + status = MAMA_STATUS_NOT_FOUND; + break; + } + return status; +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcacheimpl.h b/mama/c_cpp/src/c/fieldcache/fieldcacheimpl.h new file mode 100644 index 0000000..ba7dd71 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcacheimpl.h @@ -0,0 +1,92 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcacheimpl.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheImplH__ +#define MamaFieldCacheImplH__ + +#include <mama/types.h> +#include "fieldcachemap.h" +#include "fieldcachelist.h" +#include <wlock.h> + +#if defined(__cplusplus) +extern "C" { +#endif + +/* This structure contains all of the types required to manage a field cache. + */ +typedef struct mamaFieldCacheImpl_ +{ + /* The map used to search and store entries in the cache. */ + mamaFieldCacheMap mMap; + + /* This iterator is used to iterate through a mama message whenever there + * is no dictionary. + */ + mamaMsgIterator mIterator; + + /* Lock object */ + wLock mLock; + + /* Size of the map */ + mama_size_t mSize; + + /* List of fields which must always be published in a delta msg */ + mamaFieldCacheList mAlwaysPublishFields; + + /* List of modified fields to be able to populate a delta msg without iterating + the entire cache */ + mamaFieldCacheList mModifiedFields; + + /* Reusable mamaDateTime */ + mamaDateTime mReusableDateTime; + + /* Reusable mamaPrice */ + mamaPrice mReusablePrice; + + /* If this value is true, then the cache will keep track of modified fields */ + mama_bool_t mTrackModified; + + /* If this value is true, then the cache will use locking */ + mama_bool_t mUseLock; + + mama_bool_t mUseFieldNames; + + mama_bool_t mCachePayload; + mamaMsg mCacheMsg; +} mamaFieldCacheImpl; + +mama_status mamaFieldCache_updateCacheFromMsgField(mamaFieldCache fieldCache, + const mamaMsgField messageField); + +mama_status mamaFieldCache_updateCacheFromField(mamaFieldCache fieldCache, + const mamaFieldCacheField field); + +mama_status mamaFieldCache_updateMsgField(mamaFieldCache fieldCache, + mamaFieldCacheField field, + mamaMsg message, + mama_bool_t useUpdate); + +#if defined(__cplusplus) +} +#endif + +#endif /* MamaFieldCacheImplH__ */ diff --git a/mama/c_cpp/src/c/fieldcache/fieldcacheiterator.c b/mama/c_cpp/src/c/fieldcache/fieldcacheiterator.c new file mode 100644 index 0000000..2579237 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcacheiterator.c @@ -0,0 +1,77 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcacheiterator.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcacheiteratorimpl.h" +#include "fieldcachemaparray.h" +#include "fieldcacheimpl.h" + +mama_status mamaFieldCacheIterator_create(mamaFieldCacheIterator* iterator, + mamaFieldCache fieldCache) +{ + if (!iterator || !fieldCache) + { + return MAMA_STATUS_NULL_ARG; + } + switch (gMamaFieldCacheMapType) + { + case MAMAFIELDCACHE_MAP_MODE_ARRAY: + return mamaFieldCacheMapIteratorArray_create(iterator, fieldCache->mMap); + default: + break; + } + return MAMA_STATUS_INVALID_ARG; +} + +mama_status mamaFieldCacheIterator_destroy(mamaFieldCacheIterator iterator) +{ + if (!iterator) + { + return MAMA_STATUS_NULL_ARG; + } + return iterator->mDestroyFunction(iterator); +} + +mamaFieldCacheField mamaFieldCacheIterator_next(mamaFieldCacheIterator iterator) +{ + if (!iterator) + { + return NULL; + } + return iterator->mFunctionNext(iterator); +} + +mama_bool_t mamaFieldCacheIterator_hasNext(mamaFieldCacheIterator iterator) +{ + if (!iterator) + { + return MAMA_STATUS_NULL_ARG; + } + return iterator->mFunctionHasNext(iterator); +} + +mamaFieldCacheField mamaFieldCacheIterator_begin(mamaFieldCacheIterator iterator) +{ + if (!iterator) + { + return NULL; + } + return iterator->mFunctionBegin(iterator); +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcacheiteratorimpl.h b/mama/c_cpp/src/c/fieldcache/fieldcacheiteratorimpl.h new file mode 100644 index 0000000..1e1b556 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcacheiteratorimpl.h @@ -0,0 +1,57 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcacheiteratorimpl.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheIteratorImplH__ +#define MamaFieldCacheIteratorImplH__ + +#include <mama/config.h> +#include <mama/status.h> +#include <mama/fieldcache/fieldcacheiterator.h> + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + +/* The following defines are function pointers for use in the FieldCacheIterator + * structure. + */ +typedef mama_status (*fieldCacheIterator_destroy)(mamaFieldCacheIterator); + +typedef mamaFieldCacheField (*fieldCacheIterator_next)(mamaFieldCacheIterator); + +typedef mama_bool_t (*fieldCacheIterator_hasNext)(mamaFieldCacheIterator); + +typedef mamaFieldCacheField (*fieldCacheIterator_begin)(mamaFieldCacheIterator); + +/* Iterator */ +typedef struct mamaFieldCacheIteratorImpl_ +{ + fieldCacheIterator_destroy mDestroyFunction; + fieldCacheIterator_next mFunctionNext; + fieldCacheIterator_hasNext mFunctionHasNext; + fieldCacheIterator_begin mFunctionBegin; +} mamaFieldCacheIteratorImpl; + +#if defined(__cplusplus) +} +#endif /* defined(__cplusplus) */ + +#endif /* MamaFieldCacheIteratorImplH__ */ diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachelist.c b/mama/c_cpp/src/c/fieldcache/fieldcachelist.c new file mode 100644 index 0000000..a4f5ef6 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachelist.c @@ -0,0 +1,95 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachelist.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcachelist.h" + +#define LIST_GROW_CHUNK_SIZE 32 + +mama_status +mamaFieldCacheList_create(mamaFieldCacheList* list) +{ + *list = (mamaFieldCacheList)calloc(1, sizeof(mamaFieldCacheListImpl)); + (*list)->mLast = -1; + return mamaFieldCacheVector_create(&(*list)->mVector); +} + +mama_status +mamaFieldCacheList_destroy(mamaFieldCacheList list) +{ + mamaFieldCacheVector_destroy(list->mVector); + free(list); + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheList_free(mamaFieldCacheList list) +{ + list->mLast = -1; + return mamaFieldCacheVector_free(list->mVector); +} + +mama_status +mamaFieldCacheList_clear(mamaFieldCacheList list) +{ + list->mLast = -1; + return mamaFieldCacheVector_clear(list->mVector); +} + +mama_status +mamaFieldCacheList_add(mamaFieldCacheList list, void* item) +{ + mama_size_t vectorSize = 0; + + mamaFieldCacheVector_getSize(list->mVector, &vectorSize); + ++list->mLast; + if (list->mLast >= vectorSize) + { + mamaFieldCacheVector_grow(list->mVector, vectorSize + LIST_GROW_CHUNK_SIZE); + } + return mamaFieldCacheVector_set(list->mVector, list->mLast, item); +} + +mama_status +mamaFieldCacheList_set(mamaFieldCacheList list, mama_size_t index, void* item) +{ + if (index > list->mLast) + { + return MAMA_STATUS_INVALID_ARG; + } + return mamaFieldCacheVector_set(list->mVector, index, item); +} + +mama_status +mamaFieldCacheList_get(mamaFieldCacheList list, mama_size_t index, void** item) +{ + if (index > list->mLast) + { + return MAMA_STATUS_INVALID_ARG; + } + return mamaFieldCacheVector_get(list->mVector, index, item); +} + +mama_status +mamaFieldCacheList_getSize(mamaFieldCacheList list, mama_size_t* size) +{ + *size = list->mLast + 1; + return MAMA_STATUS_OK; +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachelist.h b/mama/c_cpp/src/c/fieldcache/fieldcachelist.h new file mode 100644 index 0000000..e1e5e63 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachelist.h @@ -0,0 +1,135 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachelist.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheListH__ +#define MamaFieldCacheListH__ + +#include <mama/config.h> +#include <mama/types.h> +#include <mama/status.h> +#include "fieldcachevector.h" + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + +/* This structure describes a generic dynamic list of items + */ +typedef struct mamaFieldCacheListImpl_ +{ + /* Underlying structure */ + mamaFieldCacheVector mVector; + /* Position of the last item */ + mama_size_t mLast; +} mamaFieldCacheListImpl; + +typedef mamaFieldCacheListImpl* mamaFieldCacheList; + +/** + * Create a generic list. + * + * @param lsit (out) The list to create. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheList_create(mamaFieldCacheList* list); + +/** + * Destroy a list. No memory is freed as items might require specific destruction + * functions. If items can be safely destroyed with free, then + * <code>mamaFieldCacheList_free</code> can be used to free all the items. + * In all the other cases, the user is responsible for freeing the item's specific + * allocated memory. + * + * @param list (in) The list to destroy. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheList_destroy(mamaFieldCacheList list); + +/** + * Free all not-NULL items in the list using free. This can be used only if the + * item was allocated with <code>malloc</code> or the like. + * This function does not destroy the list: mamaFieldCacheList_destroy must be called anyway. + * + * @param list (in) The list to free. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheList_free(mamaFieldCacheList list); + +/** + * Set to NULL all items in the lsit. This will not free any memory allocated for + * the items. + * + * @param list (in) The list to clear. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheList_clear(mamaFieldCacheList list); + +/** + * Add an item in the list. + * + * @param list (in) The list to add the value to. + * @param item (in) The item to add. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheList_add(mamaFieldCacheList list, void* item); + +/** + * Set an item in the list. Index must be in range (less than list size). + * + * @param list (in) The list to set the value to. + * @param index (in) The index of the item in the list. + * @param item (in) The item to set. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheList_set(mamaFieldCacheList list, mama_size_t index, void* item); + +/** + * Get an item from the list. Index must be in range (less than list size). + * + * @param list (in) The list to get the value from. + * @param index (in) The index of the item in the list. + * @param item (out) The item in the list. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheList_get(mamaFieldCacheList list, mama_size_t index, void** item); + +/** + * Get the size of the list. + * + * @param list (in) The list to get the size. + * @param size (out) The size of the list. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheList_getSize(mamaFieldCacheList list, mama_size_t* size); + +#if defined(__cplusplus) +} +#endif + +#endif /* MamaFieldCacheListH__ */ diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachemap.c b/mama/c_cpp/src/c/fieldcache/fieldcachemap.c new file mode 100644 index 0000000..64b5844 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachemap.c @@ -0,0 +1,96 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachemap.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcachemap.h" +#include "fieldcachemaparray.h" +#include "fieldcachemapbinary.h" +#include "fieldcachemapmonitor.h" +#include <assert.h> + +const mamaFieldCacheMapType gMamaFieldCacheMapType = MAMAFIELDCACHE_MAP_MODE_ARRAY; +const mama_bool_t gUseMamaFieldCacheMapMonitor = 0; + +mama_status mamaFieldCacheMap_create(mamaFieldCacheMap* map) +{ + mamaFieldCacheMap localMap = NULL; + mamaFieldCacheMap monitorMap = NULL; + mama_status ret = MAMA_STATUS_NULL_ARG; + + assert(map); + ret = MAMA_STATUS_INVALID_ARG; + switch(gMamaFieldCacheMapType) + { + case MAMAFIELDCACHE_MAP_MODE_ARRAY: + ret = mamaFieldCacheMapArray_create(&localMap); + break; + case MAMAFIELDCACHE_MAP_MODE_BINARY: + ret = mamaFieldCacheMapBinary_create(&localMap); + break; + default: + break; + } + + if(ret == MAMA_STATUS_OK && gUseMamaFieldCacheMapMonitor) + { + ret = mamaFieldCacheMapMonitor_create(&monitorMap, localMap); + if(ret == MAMA_STATUS_OK) + { + localMap = monitorMap; + } + /* If something went wrong, go on without the monitor */ + } + + /* Return the map. */ + *map = localMap; + + return ret; +} + +mama_status mamaFieldCacheMap_destroy(mamaFieldCacheMap map) +{ + assert(map); + return map->mDestroyFunction(map); +} + +mama_status +mamaFieldCacheMap_add(mamaFieldCacheMap map,mamaFieldCacheField field) +{ + assert(map); + return map->mAddFunction(map, field); +} + +mama_status +mamaFieldCacheMap_find(mamaFieldCacheMap map, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field) +{ + assert(map); + return map->mFindFunction(map, fid, type, name, (mamaFieldCacheField*)field); +} + +mama_status +mamaFieldCacheMap_clear(mamaFieldCacheMap map) +{ + assert(map); + return map->mClearFunction(map); +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachemap.h b/mama/c_cpp/src/c/fieldcache/fieldcachemap.h new file mode 100644 index 0000000..c0314e2 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachemap.h @@ -0,0 +1,113 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachemap.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldMapH__ +#define MamaFieldMapH__ + +#include <mama/config.h> +#include <mama/status.h> +#include <mama/types.h> +#include <mama/fielddesc.h> +#include <mama/fieldcache/fieldcachetypes.h> + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + +struct mamaFieldCacheMapImpl_; +typedef struct mamaFieldCacheMapImpl_ mamaFieldCacheMapImpl; +typedef mamaFieldCacheMapImpl* mamaFieldCacheMap; + + +/* The following defines are function pointers for use in the FieldCacheMap + * structure. + */ +/* This function is used to destroy a search map. */ +typedef mama_status (* fieldCacheMap_destroy)(mamaFieldCacheMap); + +typedef mama_status (* fieldCacheMap_add)( + mamaFieldCacheMap, + mamaFieldCacheField); +/* This function is used to find fields in a search map. */ +typedef mama_status (* fieldCacheMap_find)( + mamaFieldCacheMap, + mama_fid_t, + mamaFieldType, + const char*, + mamaFieldCacheField*); + +/* This function is used to clear a search map. */ +typedef mama_status (* fieldCacheMap_clear)(mamaFieldCacheMap); + + +/* The search map contains function pointers and members common to the various + * search strategies. + */ +struct mamaFieldCacheMapImpl_ +{ + /* This function is used to clear a map. */ + fieldCacheMap_clear mClearFunction; + + /* This function is used to destroy a map. */ + fieldCacheMap_destroy mDestroyFunction; + + /* This function is used to add new fields to a map. */ + fieldCacheMap_add mAddFunction; + + /* This function is used to find fields in a map. */ + fieldCacheMap_find mFindFunction; +}; + +typedef enum +{ + MAMAFIELDCACHE_MAP_MODE_ARRAY, + MAMAFIELDCACHE_MAP_MODE_BINARY +} mamaFieldCacheMapType; + +extern const mamaFieldCacheMapType gMamaFieldCacheMapType; +extern const mama_bool_t gUseMamaFieldCacheMapMonitor; + +mama_status +mamaFieldCacheMap_create(mamaFieldCacheMap* map); + +mama_status +mamaFieldCacheMap_destroy(mamaFieldCacheMap map); + +mama_status +mamaFieldCacheMap_add(mamaFieldCacheMap map, + mamaFieldCacheField field); + +mama_status +mamaFieldCacheMap_find(mamaFieldCacheMap map, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field); + +mama_status +mamaFieldCacheMap_clear(mamaFieldCacheMap map); + + +#if defined(__cplusplus) +} +#endif /* defined(__cplusplus) */ + +#endif /* MamaFieldMapH__ */ diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachemaparray.c b/mama/c_cpp/src/c/fieldcache/fieldcachemaparray.c new file mode 100644 index 0000000..d85a141 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachemaparray.c @@ -0,0 +1,263 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachemaparray.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcachemaparray.h" +#include "fieldcacheimpl.h" +#include "fieldcachefieldimpl.h" +#include <mama/fieldcache/fieldcachefield.h> +#include <stdlib.h> + +static const mama_u16_t MAP_ARRAY_CHUNK_SIZE = 64; + +static mama_fid_t mamaFieldCacheMapArray_convertFid(mama_fid_t fid) +{ + static mama_fid_t mFields[0xFFFF]; + static mama_u16_t mCounter = 0; + + mama_fid_t ret = mFields[fid]; + if (ret != 0) + { + return ret - 1; + } + + mFields[fid] = ++mCounter; + return mCounter - 1; +} + +mama_status mamaFieldCacheMapArray_create(mamaFieldCacheMap* map) +{ + mamaFieldCacheMapArray arrayMap = + (mamaFieldCacheMapArray)calloc(1, sizeof(mamaFieldCacheMapArrayImpl)); + + arrayMap->mFieldArray = + (mamaFieldCacheField*)calloc(MAP_ARRAY_CHUNK_SIZE, sizeof(mamaFieldCacheField)); + if (!arrayMap->mFieldArray) + { + free(arrayMap); + return MAMA_STATUS_NOMEM; + } + arrayMap->mSize = MAP_ARRAY_CHUNK_SIZE; + + arrayMap->mBaseMap.mAddFunction = mamaFieldCacheMapArray_add; + arrayMap->mBaseMap.mClearFunction = mamaFieldCacheMapArray_clear; + arrayMap->mBaseMap.mDestroyFunction = mamaFieldCacheMapArray_destroy; + arrayMap->mBaseMap.mFindFunction = mamaFieldCacheMapArray_find; + + *map = (mamaFieldCacheMap)arrayMap; + + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheMapArray_destroy(mamaFieldCacheMap map) +{ + int i; + + /* Cast the map to an array map. */ + mamaFieldCacheMapArray arrayMap = (mamaFieldCacheMapArray)map; + + for (i = 0; i < arrayMap->mSize; i++) + { + mamaFieldCacheField field = arrayMap->mFieldArray[i]; + if (field) + { + mamaFieldCacheField_destroy(field); + } + } + + free(arrayMap->mFieldArray); + arrayMap->mFieldArray = NULL; + + free((mamaFieldCacheMapArray)map); + + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheMapArray_add(mamaFieldCacheMap map, + mamaFieldCacheField field) +{ + mamaFieldCacheMapArray arrayMap = NULL; + mama_fid_t cacheFid = 0; + mama_u16_t newSize; + mamaFieldCacheField* newArray = NULL; + int i; + + /* Cast the map to an array map. */ + arrayMap = (mamaFieldCacheMapArray)map; + + /* Check to see if the entry has already been added. */ + cacheFid = mamaFieldCacheMapArray_convertFid(field->mFid); + if(cacheFid < arrayMap->mSize && arrayMap->mFieldArray[cacheFid] != NULL) + { + return MAMA_STATUS_INVALID_ARG; + } + + /* Resize the array, if needed */ + if (cacheFid >= arrayMap->mSize) + { + newSize = arrayMap->mSize; + do + { + newSize += MAP_ARRAY_CHUNK_SIZE; + } + while (newSize <= cacheFid); + newArray = (mamaFieldCacheField*)realloc( + (void*)arrayMap->mFieldArray, + newSize * sizeof(mamaFieldCacheField)); + if (!newArray) + { + return MAMA_STATUS_NOMEM; + } + for (i = arrayMap->mSize; i < newSize ; i++) + { + newArray[i] = NULL; + } + arrayMap->mFieldArray = newArray; + arrayMap->mSize = newSize; + } + + arrayMap->mFieldArray[cacheFid] = field; + + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheMapArray_find(mamaFieldCacheMap map, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field) +{ + mamaFieldCacheMapArray arrayMap = NULL; + mama_fid_t cacheFid = 0; + + /* Cast the map to an array map. */ + arrayMap = (mamaFieldCacheMapArray)map; + + cacheFid = mamaFieldCacheMapArray_convertFid(fid); + if (cacheFid >= arrayMap->mSize) + { + return MAMA_STATUS_NOT_FOUND; + } + /* Get the field from the array. */ + *field = arrayMap->mFieldArray[cacheFid]; + return (*field == NULL) ? MAMA_STATUS_NOT_FOUND : MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheMapArray_clear(mamaFieldCacheMap map) +{ + int i; + + /* Cast the map to an array map. */ + mamaFieldCacheMapArray arrayMap = (mamaFieldCacheMapArray)map; + + for (i = 0; i < arrayMap->mSize; i++) + { + mamaFieldCacheField field = arrayMap->mFieldArray[i]; + if (field) + { + mamaFieldCacheField_destroy(field); + arrayMap->mFieldArray[i] = NULL; + } + } + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheMapIteratorArray_create(mamaFieldCacheIterator* iterator, + mamaFieldCacheMap map) +{ + mamaFieldCacheMapArray arrayMap = (mamaFieldCacheMapArray)map; + + mamaFieldCacheMapIteratorArray arrayIterator = + (mamaFieldCacheMapIteratorArray)calloc(1, sizeof(mamaFieldCacheMapIteratorArrayImpl)); + + arrayIterator->mBaseIterator.mDestroyFunction = mamaFieldCacheMapIteratorArray_destroy; + arrayIterator->mBaseIterator.mFunctionNext = mamaFieldCacheMapIteratorArray_next; + arrayIterator->mBaseIterator.mFunctionHasNext = mamaFieldCacheMapIteratorArray_hasNext; + arrayIterator->mBaseIterator.mFunctionBegin = mamaFieldCacheMapIteratorArray_begin; + + arrayIterator->mFieldCacheMap = arrayMap; + arrayIterator->mCurrentIndex = -1; + + *iterator = (mamaFieldCacheIterator)arrayIterator; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheMapIteratorArray_destroy(mamaFieldCacheIterator iterator) +{ + free((mamaFieldCacheMapIteratorArray)iterator); + return MAMA_STATUS_OK; +} + +mamaFieldCacheField mamaFieldCacheMapIteratorArray_next(mamaFieldCacheIterator iterator) +{ + mama_i32_t i; + mamaFieldCacheField nextField = NULL; + mamaFieldCacheMapIteratorArray arrayIterator = + (mamaFieldCacheMapIteratorArray)iterator; + mamaFieldCacheMapArray arrayMap = (mamaFieldCacheMapArray)arrayIterator->mFieldCacheMap; + + for (i = arrayIterator->mCurrentIndex + 1; i < arrayMap->mSize; i++) + { + nextField = arrayMap->mFieldArray[i]; + if (nextField != NULL) + { + arrayIterator->mCurrentIndex = i; + return nextField; + } + } + + return NULL; +} + +mama_bool_t mamaFieldCacheMapIteratorArray_hasNext(mamaFieldCacheIterator iterator) +{ + mama_i32_t i; + mamaFieldCacheMapIteratorArray arrayIterator = + (mamaFieldCacheMapIteratorArray)iterator; + mamaFieldCacheMapArray arrayMap = (mamaFieldCacheMapArray)arrayIterator->mFieldCacheMap; + + for (i = arrayIterator->mCurrentIndex + 1; i < arrayMap->mSize; i++) + { + if (arrayMap->mFieldArray[i] != NULL) + return 1; + } + + return 0; +} + +mamaFieldCacheField mamaFieldCacheMapIteratorArray_begin(mamaFieldCacheIterator iterator) +{ + mama_i32_t i; + mamaFieldCacheField nextField = NULL; + mamaFieldCacheMapIteratorArray arrayIterator = + (mamaFieldCacheMapIteratorArray)iterator; + mamaFieldCacheMapArray arrayMap = (mamaFieldCacheMapArray)arrayIterator->mFieldCacheMap; + + for (i = 0; i < arrayMap->mSize; i++) + { + nextField = arrayMap->mFieldArray[i]; + if (nextField != NULL) + { + return nextField; + } + } + + return NULL; +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachemaparray.h b/mama/c_cpp/src/c/fieldcache/fieldcachemaparray.h new file mode 100644 index 0000000..08c5e28 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachemaparray.h @@ -0,0 +1,90 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachemaparray.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheMapArrayH__ +#define MamaFieldCacheMapArrayH__ + +#include "fieldcachemap.h" +#include "fieldcacheiteratorimpl.h" + +#if defined( __cplusplus ) +extern "C" { +#endif /* defined( __cplusplus ) */ + +typedef struct mamaFieldCacheMapArrayImpl_ +{ + /* The base structure must appear first. */ + mamaFieldCacheMapImpl mBaseMap; + + /* This array contains entries for the fields. */ + mamaFieldCacheField* mFieldArray; + + /* The size of the array. */ + mama_u16_t mSize; +} mamaFieldCacheMapArrayImpl; + +typedef mamaFieldCacheMapArrayImpl* mamaFieldCacheMapArray; + + +typedef struct mamaFieldCacheMapIteratorArrayImpl_ +{ + mamaFieldCacheIteratorImpl mBaseIterator; + mamaFieldCacheMapArray mFieldCacheMap; + mama_i32_t mCurrentIndex; +} mamaFieldCacheMapIteratorArrayImpl; + +typedef mamaFieldCacheMapIteratorArrayImpl* mamaFieldCacheMapIteratorArray; + + +/* Map */ +mama_status mamaFieldCacheMapArray_create(mamaFieldCacheMap* map); + +mama_status mamaFieldCacheMapArray_destroy(mamaFieldCacheMap map); + +mama_status mamaFieldCacheMapArray_add(mamaFieldCacheMap map, + mamaFieldCacheField field); + +mama_status mamaFieldCacheMapArray_find(mamaFieldCacheMap map, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field); + +mama_status mamaFieldCacheMapArray_clear(mamaFieldCacheMap map); + + +/* Iterator */ +mama_status mamaFieldCacheMapIteratorArray_create(mamaFieldCacheIterator* iterator, + mamaFieldCacheMap map); + +mama_status mamaFieldCacheMapIteratorArray_destroy(mamaFieldCacheIterator iterator); + +mamaFieldCacheField mamaFieldCacheMapIteratorArray_next(mamaFieldCacheIterator iterator); + +mama_bool_t mamaFieldCacheMapIteratorArray_hasNext(mamaFieldCacheIterator iterator); + +mamaFieldCacheField mamaFieldCacheMapIteratorArray_begin(mamaFieldCacheIterator iterator); + +#if defined( __cplusplus ) +} +#endif /* defined( __cplusplus ) */ + +#endif /* MamaFieldCacheMapArrayH__ */ diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.c b/mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.c new file mode 100644 index 0000000..9660790 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.c @@ -0,0 +1,79 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcachemapbinary.h" + +mama_status mamaFieldCacheMapBinary_create(mamaFieldCacheMap* map) +{ + return MAMA_STATUS_NOT_IMPLEMENTED; +} + +mama_status mamaFieldCacheMapBinary_destroy(mamaFieldCacheMap map) +{ + return MAMA_STATUS_NOT_IMPLEMENTED; +} + +mama_status mamaFieldCacheMapBinary_add(mamaFieldCacheMap map, + mamaFieldCacheField field) +{ + return MAMA_STATUS_NOT_IMPLEMENTED; +} + +mama_status mamaFieldCacheMapBinary_find(mamaFieldCacheMap map, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field) +{ + return MAMA_STATUS_NOT_IMPLEMENTED; +} + +mama_status mamaFieldCacheMapBinary_clear(mamaFieldCacheMap map) +{ + return MAMA_STATUS_NOT_IMPLEMENTED; +} + +/* Iterator */ +mama_status mamaFieldCacheMapIteratorBinary_create(mamaFieldCacheIterator* iterator, + mamaFieldCacheMap map) +{ + return MAMA_STATUS_NOT_IMPLEMENTED; +} + +mama_status mamaFieldCacheMapIteratorBinary_destroy(mamaFieldCacheIterator iterator) +{ + return MAMA_STATUS_NOT_IMPLEMENTED; +} + +mamaFieldCacheField mamaFieldCacheMapIteratorBinary_next(mamaFieldCacheIterator iterator) +{ + return NULL; +} + +mama_bool_t mamaFieldCacheMapIteratorBinary_hasNext(mamaFieldCacheIterator iterator) +{ + return MAMA_STATUS_NOT_IMPLEMENTED; +} + +mamaFieldCacheField mamaFieldCacheMapIteratorBinary_begin(mamaFieldCacheIterator iterator) +{ + return NULL; +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.h b/mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.h new file mode 100644 index 0000000..0b9c7c0 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.h @@ -0,0 +1,72 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachemapbinary.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheMapBinaryH__ +#define MamaFieldCacheMapBinaryH__ + +#include "fieldcachemap.h" + +#if defined( __cplusplus ) +extern "C" { +#endif /* defined( __cplusplus ) */ + +typedef struct mamaFieldCacheMapBinaryImpl_ +{ + /* The base structure must appear first. */ + mamaFieldCacheMapImpl mBaseMap; + +} mamaFieldCacheMapBinaryImpl; + +typedef struct mamaFieldCacheMapBinaryImpl_* mamaFieldCacheMapBinary; + +/* Map */ +mama_status mamaFieldCacheMapBinary_create(mamaFieldCacheMap* map); + +mama_status mamaFieldCacheMapBinary_destroy(mamaFieldCacheMap map); + +mama_status mamaFieldCacheMapBinary_add(mamaFieldCacheMap map, + mamaFieldCacheField field); + +mama_status mamaFieldCacheMapBinary_find(mamaFieldCacheMap map, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field); + +mama_status mamaFieldCacheMapBinary_clear(mamaFieldCacheMap map); + +/* Iterator */ +mama_status mamaFieldCacheMapIteratorBinary_create(mamaFieldCacheIterator* iterator, + mamaFieldCacheMap map); + +mama_status mamaFieldCacheMapIteratorBinary_destroy(mamaFieldCacheIterator iterator); + +mamaFieldCacheField mamaFieldCacheMapIteratorBinary_next(mamaFieldCacheIterator iterator); + +mama_bool_t mamaFieldCacheMapIteratorBinary_hasNext(mamaFieldCacheIterator iterator); + +mamaFieldCacheField mamaFieldCacheMapIteratorBinary_begin(mamaFieldCacheIterator iterator); + +#if defined( __cplusplus ) +} +#endif /* defined( __cplusplus ) */ + +#endif /* MamaFieldCacheMapBinaryH__ */ diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.c b/mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.c new file mode 100644 index 0000000..47d1979 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.c @@ -0,0 +1,74 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcachemapmonitor.h" + +mama_status mamaFieldCacheMapMonitor_create(mamaFieldCacheMap* map, + mamaFieldCacheMap originalMap) +{ + mamaFieldCacheMapMonitor mapMonitor = + (mamaFieldCacheMapMonitor)calloc(1, sizeof(mamaFieldCacheMapMonitorImpl)); + + if(map == NULL) + { + return MAMA_STATUS_INVALID_ARG; + } + + if(mapMonitor == NULL) + { + return MAMA_STATUS_NOMEM; + } + + mapMonitor->mOriginalMap = originalMap; + *map = (mamaFieldCacheMap)mapMonitor; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheMapMonitor_destroy(mamaFieldCacheMap map) +{ + mamaFieldCacheMapMonitor mapMonitor = (mamaFieldCacheMapMonitor)map; + mamaFieldCacheMap_destroy(mapMonitor->mOriginalMap); + free(mapMonitor); + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheMapMonitor_clear(mamaFieldCacheMap map) +{ + mamaFieldCacheMapMonitor mapMonitor = (mamaFieldCacheMapMonitor)map; + return mamaFieldCacheMap_clear(mapMonitor->mOriginalMap); +} + +mama_status mamaFieldCacheMapMonitor_add(mamaFieldCacheMap map, + mamaFieldCacheField field) +{ + mamaFieldCacheMapMonitor mapMonitor = (mamaFieldCacheMapMonitor)map; + return mamaFieldCacheMap_add(mapMonitor->mOriginalMap, field); +} + +mama_status mamaFieldCacheMapMonitor_find(mamaFieldCacheMap map, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field) +{ + mamaFieldCacheMapMonitor mapMonitor = (mamaFieldCacheMapMonitor)map; + return mamaFieldCacheMap_find(mapMonitor->mOriginalMap, fid, type, name, field); +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.h b/mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.h new file mode 100644 index 0000000..b217793 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.h @@ -0,0 +1,64 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachemapmonitor.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheMapMonitorH__ +#define MamaFieldCacheMapMonitorH__ + +#include "fieldcachemap.h" + +#if defined( __cplusplus ) +extern "C" { +#endif /* defined( __cplusplus ) */ + +typedef struct mamaFieldCacheMapMonitorImpl_ +{ + /* The base structure must appear first. */ + mamaFieldCacheMapImpl mBaseMap; + mamaFieldCacheMap mOriginalMap; +} mamaFieldCacheMapMonitorImpl; + +typedef struct mamaFieldCacheMapMonitorImpl_* mamaFieldCacheMapMonitor; + +/* map will take ownership of originalMap; it will be destroyed when calling + * mamaFieldCacheMapMonitor_destroy + */ +mama_status mamaFieldCacheMapMonitor_create(mamaFieldCacheMap* map, + mamaFieldCacheMap originalMap); + +/* This function will also destroy the original map */ +mama_status mamaFieldCacheMapMonitor_destroy(mamaFieldCacheMap map); + +mama_status mamaFieldCacheMapMonitor_clear(mamaFieldCacheMap map); + +mama_status mamaFieldCacheMapMonitor_add(mamaFieldCacheMap map, + mamaFieldCacheField field); + +mama_status mamaFieldCacheMapMonitor_find(mamaFieldCacheMap map, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field); + +#if defined( __cplusplus ) +} +#endif /* defined( __cplusplus ) */ + +#endif /* MamaFieldCacheMapMonitorH__ */ diff --git a/mama/c_cpp/src/c/fieldcache/fieldcacherecord.c b/mama/c_cpp/src/c/fieldcache/fieldcacherecord.c new file mode 100644 index 0000000..b6c140d --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcacherecord.c @@ -0,0 +1,159 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcacherecord.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <mama/fieldcache/fieldcacherecord.h> +#include "fieldcacherecordimpl.h" + +mama_status mamaFieldCacheRecord_create(mamaFieldCacheRecord* record) +{ + mama_status ret; + mamaFieldCacheRecord localRecord = NULL; + + if (!record) + { + return MAMA_STATUS_NULL_ARG; + } + localRecord = (mamaFieldCacheRecord)calloc(1, sizeof(mamaFieldCacheRecordImpl)); + if (!localRecord) + { + return MAMA_STATUS_NOMEM; + } + ret = mamaFieldCacheVector_create(&localRecord->mFields); + if (ret != MAMA_STATUS_OK) + { + free(localRecord); + return ret; + } + + *record = localRecord; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheRecord_destroy(mamaFieldCacheRecord record) +{ + int i; + void* field = NULL; + + if (!record) + { + return MAMA_STATUS_NULL_ARG; + } + for (i = 0; i < record->mSize; i++) + { + mamaFieldCacheVector_get(record->mFields, i, &field); + mamaFieldCacheField_destroy((mamaFieldCacheField)field); + } + mamaFieldCacheVector_destroy(record->mFields); + free(record); + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheRecord_clear(mamaFieldCacheRecord record) +{ + int i; + void* field = NULL; + + if (!record) + { + return MAMA_STATUS_NULL_ARG; + } + for (i = 0; i < record->mSize; i++) + { + mamaFieldCacheVector_get(record->mFields, i, &field); + mamaFieldCacheField_destroy((mamaFieldCacheField)field); + mamaFieldCacheVector_set(record->mFields, i, NULL); + } + record->mSize = 0; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheRecord_getSize(mamaFieldCacheRecord record, mama_size_t* size) +{ + if (!record || !size) + { + return MAMA_STATUS_NULL_ARG; + } + *size = record->mSize; + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheRecord_add(mamaFieldCacheRecord record, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field) +{ + if (!record || !field) + { + return MAMA_STATUS_NULL_ARG; + } + *field = NULL; + mamaFieldCacheVector_grow(record->mFields, record->mSize + 10); + + mamaFieldCacheField_create(field, fid, type, name); + mamaFieldCacheVector_set(record->mFields, record->mSize, *field); + record->mSize++; + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheRecord_getField(mamaFieldCacheRecord record, + mama_size_t index, + mamaFieldCacheField* field) +{ + if (!record || !field) + { + return MAMA_STATUS_NULL_ARG; + } + if (index >= record->mSize) + { + return MAMA_STATUS_INVALID_ARG; + } + mamaFieldCacheVector_get(record->mFields, index, (void**)field); + return MAMA_STATUS_OK; +} + +mama_status mamaFieldCacheRecord_find(mamaFieldCacheRecord record, + mama_fid_t fid, + const char* name, + mamaFieldCacheField* field) +{ + mama_status ret; + int i; + mama_fid_t fieldId; + + if (!record || !field) + { + return MAMA_STATUS_NULL_ARG; + } + for (i = 0; i < record->mSize; i++) + { + fieldId = 0; + mamaFieldCacheVector_get(record->mFields, i, (void**)field); + ret = mamaFieldCacheField_getFid(*field, &fieldId); + if (ret == MAMA_STATUS_OK && fid == fieldId) + { + return MAMA_STATUS_OK; + } + } + *field = NULL; + return MAMA_STATUS_NOT_FOUND; +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcacherecordimpl.h b/mama/c_cpp/src/c/fieldcache/fieldcacherecordimpl.h new file mode 100644 index 0000000..b9c1adf --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcacherecordimpl.h @@ -0,0 +1,49 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcacherecordimpl.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheRecordImplH__ +#define MamaFieldCacheRecordImplH__ + +#include <mama/config.h> +#include <mama/fielddesc.h> +#include <mama/types.h> +#include <mama/fieldcache/fieldcachetypes.h> +#include "fieldcachevector.h" + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + + /* This structure describes a record of fields + */ +typedef struct mamaFieldCacheRecordImpl_ +{ + /* dynamic resizable vector containing mamaFieldCacheField pointers */ + mamaFieldCacheVector mFields; + /* number of fields stored */ + mama_size_t mSize; +} mamaFieldCacheRecordImpl; + +#if defined(__cplusplus) +} +#endif + +#endif /* MamaFieldCacheRecordImplH__ */ diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachevector.c b/mama/c_cpp/src/c/fieldcache/fieldcachevector.c new file mode 100644 index 0000000..6feb776 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachevector.c @@ -0,0 +1,127 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachevector.c#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "fieldcachevector.h" + +mama_status +mamaFieldCacheVector_create(mamaFieldCacheVector* vector) +{ + *vector = (mamaFieldCacheVector)calloc(1, sizeof(mamaFieldCacheVectorImpl)); + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheVector_destroy(mamaFieldCacheVector vector) +{ + if (vector->mData) + { + free(vector->mData); + } + free(vector); + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheVector_free(mamaFieldCacheVector vector) +{ + int i; + + if (!vector->mData) + return MAMA_STATUS_OK; + + for (i = 0; i < vector->mSize; i++) + { + if (vector->mData[i]) + free(vector->mData[i]); + } + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheVector_clear(mamaFieldCacheVector vector) +{ + int i; + + if (!vector->mData) + return MAMA_STATUS_OK; + + for (i = 0; i < vector->mSize; i++) + { + vector->mData[i] = NULL; + } + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheVector_set(mamaFieldCacheVector vector, mama_size_t index, void* item) +{ + if (index >= vector->mSize) + { + return MAMA_STATUS_INVALID_ARG; + } + vector->mData[index] = item; + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheVector_get(mamaFieldCacheVector vector, mama_size_t index, void** item) +{ + if (index >= vector->mSize) + { + return MAMA_STATUS_INVALID_ARG; + } + *item = vector->mData[index]; + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheVector_getSize(mamaFieldCacheVector vector, mama_size_t* size) +{ + *size = vector->mSize; + return MAMA_STATUS_OK; +} + +mama_status +mamaFieldCacheVector_grow(mamaFieldCacheVector vector, mama_size_t newAllocSize) +{ + int i; + + if (vector->mSize > newAllocSize) + { + return MAMA_STATUS_OK; + } + if (!vector->mData) + { + vector->mData = (void**) + malloc(sizeof(void*)*newAllocSize); + } + else + { + vector->mData = (void**) + realloc((void*)vector->mData, sizeof(void*)*newAllocSize); + } + for (i = vector->mSize; i < newAllocSize; i++) + { + vector->mData[i] = NULL; + } + vector->mSize = newAllocSize; + return MAMA_STATUS_OK; +} diff --git a/mama/c_cpp/src/c/fieldcache/fieldcachevector.h b/mama/c_cpp/src/c/fieldcache/fieldcachevector.h new file mode 100644 index 0000000..bd02f57 --- /dev/null +++ b/mama/c_cpp/src/c/fieldcache/fieldcachevector.h @@ -0,0 +1,134 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachevector.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheVectorH__ +#define MamaFieldCacheVectorH__ + +#include <mama/config.h> +#include <mama/types.h> +#include <mama/status.h> + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + +/* This structure describes a generic dynamic vector of items + */ +typedef struct mamaFieldCacheVectorImpl_ +{ + /* Pointer to void* data */ + void** mData; + /* size of the allocated array */ + mama_size_t mSize; +} mamaFieldCacheVectorImpl; + +typedef mamaFieldCacheVectorImpl* mamaFieldCacheVector; + +/** + * Create a generic dynamic vector. + * + * @param vector (out) The vector to create. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheVector_create(mamaFieldCacheVector* vector); + +/** + * Destroy a vector. No memory is freed as items might require specific destruction + * functions. If items can be safely destroyed with free, then + * <code>mamaFieldCacheVector_free</code> can be used to free all the items. + * In all the other cases, the user is responsible for freeing the item's specific + * allocated memory. + * + * @param vector (in) The vector to destroy. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheVector_destroy(mamaFieldCacheVector vector); + +/** + * Free all not-NULL items in the vector using free. This can be used only if the + * item was allocated with <code>malloc</code> or the like. + * This function does not destroy the vector: mamaFieldCacheVector_destroy must be called anyway. + * + * @param vector (in) The vector to free. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheVector_free(mamaFieldCacheVector vector); + +/** + * Set to NULL all items in the vector. This will not free any memory allocated for + * the items. The size of the vector will not be modified. + * + * @param vector (in) The vector to clear. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheVector_clear(mamaFieldCacheVector vector); + +/** + * Set an item in the vector. Index must be in range (less than vector size). + * + * @param vector (in) The vector to set the value to. + * @param index (in) The index of the item in the vector. + * @param item (in) The item to set. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheVector_set(mamaFieldCacheVector vector, mama_size_t index, void* item); + +/** + * Get an item from the vector. Index must be in range (less than vector size). + * + * @param vector (in) The vector to get the value from. + * @param index (in) The index of the item in the vector. + * @param item (out) The item in the vector. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheVector_get(mamaFieldCacheVector vector, mama_size_t index, void** item); + +/** + * Get the size of the vector. + * + * @param vector (in) The vector to get the size. + * @param size (out) The size of the vector. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheVector_getSize(mamaFieldCacheVector vector, mama_size_t* size); + +/** + * Reallocate the vector to be able to contain at least newAllocSize. + * + * @param vector (in) The vector to resize. + * @param newAllocSize (in) The new size. + * @return Result of the operation. + */ +mama_status +mamaFieldCacheVector_grow(mamaFieldCacheVector vector, mama_size_t newAllocSize); + +#if defined(__cplusplus) +} +#endif + +#endif /* MamaFieldCacheVectorH__ */ diff --git a/mama/c_cpp/src/c/mama/fieldcache/fieldcache.h b/mama/c_cpp/src/c/mama/fieldcache/fieldcache.h new file mode 100644 index 0000000..0fb6502 --- /dev/null +++ b/mama/c_cpp/src/c/mama/fieldcache/fieldcache.h @@ -0,0 +1,368 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcache.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheH__ +#define MamaFieldCacheH__ + +#include <mama/config.h> +#include <mama/fielddesc.h> +#include <mama/status.h> +#include <mama/types.h> +#include <mama/fieldcache/fieldcachetypes.h> + +#if defined(__cplusplus) +extern "C" { +#endif + +/** + * This function will create the field cache and allocate all associated memory. + * If this function succeeds then the cache should be destroyed by calling + * mamaFieldCache_destroy. + * + * @param fieldCache (out) To return the field cache. + * @return Resulting status of the call which can be + * MAMA_STATUS_NOMEM + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_create(mamaFieldCache* fieldCache); + +/** + * This function will destroy a field cache previously allocated by a call to + * mamaFieldCache_create. + * + * @param fieldCache (in) The field cache to destroy. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_destroy(mamaFieldCache fieldCache); + +/** + * This function will clear the field cache. The result is that the cache will + * be empty (no fields). + * + * @param fieldCache (in) The field cache to clear. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_clear(mamaFieldCache fieldCache); + +/** + * This function will return the number of fields in the cache. + * + * @param fieldCache (in) The field cache. + * @param size (out) The number of fields in the cache. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_getSize(mamaFieldCache fieldCache, mama_size_t* size); + +/** + * This function will retrieve a field from the cache. If the field is not found, + * the output parameter will be set to NULL and MAMA_STATUS_NOT_FOUND is returned. + * + * @param fieldCache (in) The field cache. + * @param fid (in) The field id to look up. + * @param name (in) The field name. + * @param field (out) The field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_NOT_FOUND + * MAMA_STATUS_OK + * Other error codes from the mama functions. + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_find(mamaFieldCache fieldCache, + mama_fid_t fid, + const char* name, + mamaFieldCacheField* field); + +/** + * This function will retrieve a field from the cache. If it does not exist, a + * new one is created, added to the cache and returned. + * + * @param fieldCache (in) The field cache. + * @param fid (in) The field id to look up. + * @param type (in) The field type. + * @param name (in) The field name. + * @param field (out) The existing field, if found or new one, if not found. + * @param existing (out) Flag to indicate whether the field was already present in the cache. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_NOMEM + * MAMA_STATUS_OK + * Other error codes from the mama functions. + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_findOrAdd(mamaFieldCache fieldCache, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field, + mama_bool_t* existing); + +/** + * This function will set the modified flag for a field in the cache even if the + * value has not changed. + * The field must be present in the cache (No automatic check is performed). + * + * @param fieldCache (in) The field cache. + * @param field (in) The field to set to modified. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_setModified(mamaFieldCache fieldCache, + mamaFieldCacheField field); + +/** + * Update the cache content with the field given. + * If the field is already present, it will be updated, otherwise it will be + * added to the cache. + * + * @param fieldCache (in) The field cache. + * @param field (in) The field to get the content to update in the cache. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_applyField(mamaFieldCache fieldCache, + const mamaFieldCacheField field); +/* + * This function will automatically populate the field cache from the contents + * of the supplied message. Fields within the messages will be added to the cache + * if not already present. If the field is already present then the data will be + * updated. + * + * @param fieldCache (in) The field cache to populate. + * @param message (in) The <code>mamaMsg</code> to use to populate the cache. + * @param dictionary (in) The dictionary (optional: can be NULL). + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + * Other error codes from the mama functions. + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_applyMessage(mamaFieldCache fieldCache, + const mamaMsg message, + mamaDictionary dictionary); + +/* + * This function will automatically populate the field cache from the contents + * of the supplied mamaFieldCacheRecord. Fields within the record will be added + * to the cache if not already present. If the field is already present then the + * data will be updated. + * + * @param fieldCache (in) The field cache to populate. + * @param record (in) The <code>mamaFieldCacheRecord</code> to use to populate the cache. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + * Other error codes from the mama functions. + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_applyRecord(mamaFieldCache fieldCache, + const mamaFieldCacheRecord record); + +/** + * This function will return all the fields in the cache by updating the provided + * mamaMsg with the fields. + * With this function the provided message will be fully populated with all the + * fields in the cache. + * + * @param fieldCache (in) The field cache to obtain the fields from. + * @param message (in) This <code>mamaMsg</code> will be populated with all the fields. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + * Other mama return codes. + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_getFullMessage(mamaFieldCache fieldCache,mamaMsg message); + +/** + * This function will return the set of fields that have changed since the last time + * this function was called. + * With this function the provided message will be fully populated with only the + * modified fields in the cache. + * + * @param fieldCache (in) The field cache to obtain the modified fields from. + * @param message (in) This <code>mamMsg</code> will be populated with the modified fields. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + * Other mama return codes. + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_getDeltaMessage(mamaFieldCache fieldCache, mamaMsg message); + +/** + * This function will clear the list of all the modified fields and reset the modified flags + * for all the modified fields in the cache. + * + * @param fieldCache (in) The field cache. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_clearModifiedFields(mamaFieldCache fieldCache); + + +/** + * This function will set the value of the track modification state flag; if this + * flag is set then changes to field values will be monitored. See the documentation + * for more information on the operation of the track modification state flag. + * + * @param fieldCache (in) The field cache. + * @param trackModified (in) The track mod state flag, this should be non-zero + * to turn tracking on. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_setTrackModified(mamaFieldCache fieldCache, mama_bool_t trackModified); + +/** + * This function will return the value of the track modification state flag. + * + * @param fieldCache (in) The field cache. + * @param trackModified (out) To return the track mod state flag, this will be + * non-zero if tracking is turned on. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_getTrackModified(mamaFieldCache fieldCache, mama_bool_t *trackModified); + +/** + * This function will set the value of the use-field-names state flag; if this + * flag is set then... See the documentation + * for more information on the operation of the use-field-names state flag. + * + * @param fieldCache (in) The field cache. + * @param useFieldNames (in) The use field names state flag, this should be non-zero + * to turn tracking on. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_setUseFieldNames(mamaFieldCache fieldCache, mama_bool_t useFieldNames); + +/** + * This function will return the value of the use-field-names state flag. + * + * @param fieldCache (in) The field cache. + * @param useFieldNames (out) To return the use-field-names state flag, this will + * be non-zero if use-field-names is turned on. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_getUseFieldNames(mamaFieldCache fieldCache, mama_bool_t *useFieldNames); + +/** + * This function will enable/disable cache locking. + * + * @param fieldCache (in) The field cache. + * @param enable (in) The flag for enabling/disabling locking. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_setUseLock(mamaFieldCache fieldCache, mama_bool_t enable); + +/** + * This function will determine whether the cache is using locking or not. + * + * @param fieldCache (in) The field cache. + * @param locked (out) Indicates whether the cache is using locking or not. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_getUseLock(mamaFieldCache fieldCache, mama_bool_t* lockEnabled); + +/** + * This function will lock the cache. + * + * @param fieldCache (in) The field cache to lock. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_lock(mamaFieldCache fieldCache); + +/** + * This function will unlock the cache. + * + * @param fieldCache (in) The field cache to unlock. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCache_unlock(mamaFieldCache fieldCache); + +#if defined(__cplusplus) +} +#endif + +#endif /* MamaFieldCacheH__ */ diff --git a/mama/c_cpp/src/c/mama/fieldcache/fieldcachefield.h b/mama/c_cpp/src/c/mama/fieldcache/fieldcachefield.h new file mode 100644 index 0000000..2c4e072 --- /dev/null +++ b/mama/c_cpp/src/c/mama/fieldcache/fieldcachefield.h @@ -0,0 +1,1093 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachefield.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheFieldH__ +#define MamaFieldCacheFieldH__ + +#include <mama/config.h> +#include <mama/fielddesc.h> +#include <mama/types.h> +#include <mama/status.h> +#include <mama/fieldcache/fieldcachetypes.h> + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + +/** + * This function will check if a specific mama field type can be used to create + * a <code>mamaFieldCacheField</code>. + * + * @param type (in) The mamaFieldType to check. + * @return Whether the type can be used to create a mamaFieldCache field. + */ +MAMAExpDLL +extern mama_bool_t +mamaFieldCacheField_isSupported(mamaFieldType type); + +/** + * This function will create a mamaFieldCacheField that can be stored in a + * mamaFieldCache. + * + * @param field (out) The mamaFieldCacheField to create. + * @param fid (in) The field id of the new field. + * @param type (in) The type of the new field. + * @param type (in) The name of the new field (optional: can be NULL). + * @return Resulting status of the call which can be + * MAMA_STATUS_NOMEM + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_create(mamaFieldCacheField* field, + mama_fid_t fid, + mamaFieldType type, + const char* name); + +/** + * This function will destroy a <code>mamaFieldCacheField</code> previously + * allocated by a call to <code>mamaFieldCacheField_create</code>. + * + * @param field (in) The field to destroy. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_destroy(mamaFieldCacheField field); + +/** + * This function will copy a <code>mamaFieldCacheField</code> into another one. + * + * @param field (in) The source field to copy from. + * @param copy (out) The destination field to copy to. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_copy(const mamaFieldCacheField field, mamaFieldCacheField copy); + +/** + * This function will get the field id of a <code>mamaFieldCacheField</code>. + * + * @param field (in) The field. + * @param fid (out) The field id of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getFid(mamaFieldCacheField field, mama_fid_t* fid); + +/** + * This function will get the field type of a <code>mamaFieldCacheField</code>. + * + * @param field (in) The field. + * @param type (out) The type of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getType(mamaFieldCacheField field, mamaFieldType* type); + +/** + * This function will get the descriptor of a <code>mamaFieldCacheField</code>, + * if present. + * + * @param field (in) The field. + * @param name (out) The descriptor of the field (can be NULL). + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getName(mamaFieldCacheField field, const char** name); + +/** + * This function will set the descriptor of a <code>mamaFieldCacheField</code>. + * + * @param field (in) The field. + * @param desc (in) The <code>mamaFieldDescriptor</code> of the field (can be NULL). + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setDescriptor(mamaFieldCacheField field, + const mamaFieldDescriptor desc); + +/** + * This function will get the descriptor of a <code>mamaFieldCacheField</code>. + * + * @param field (in) The field. + * @param desc (out) The <code>mamaFieldDescriptor</code> of the field (can be NULL). + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getDescriptor(mamaFieldCacheField field, + const mamaFieldDescriptor* desc); + +/** + * This function will return whether the field has been modified. + * + * @param field (in) The field. + * @param modified (out) The modified state of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_isModified(mamaFieldCacheField field, mama_bool_t* modified); + + +/** + * This function will set the publish flag of a <code>mamaFieldCacheField</code>. + * If set to false, the field will never be published. + * + * @param field (in) The field. + * @param publish (in) The publish flag of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setPublish(mamaFieldCacheField field, mama_bool_t publish); + +/** + * This function will get the publish flag of a <code>mamaFieldCacheField</code>. + * + * @param field (in) The field. + * @param publish (out) The publish flag of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getPublish(mamaFieldCacheField field, mama_bool_t* publish); + +/** + * This function will set the checkModifed flag of a <code>mamaFieldCacheField</code>. + * If set to true, the field will be published only if modified. + * + * @param field (in) The field. + * @param check (in) The checkModified flag. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setCheckModified(mamaFieldCacheField field, mama_bool_t check); + +/** + * The function will get the checkModified flag of a <code>mamaFieldCacheField</code>. + * + * @param field (in) The field. + * @param check (out) The checkModified flag of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getCheckModified(mamaFieldCacheField field, mama_bool_t* check); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type BOOL. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getBool (const mamaFieldCacheField field, mama_bool_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type CHAR. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getChar(const mamaFieldCacheField field, char* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type I8. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getI8(const mamaFieldCacheField field, mama_i8_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type U8. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getU8(const mamaFieldCacheField field, mama_u8_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type I16. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getI16(const mamaFieldCacheField field, mama_i16_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type U16. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getU16(const mamaFieldCacheField field, mama_u16_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type I32. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getI32(const mamaFieldCacheField field, mama_i32_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type U32. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getU32(const mamaFieldCacheField field, mama_u32_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type I64. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getI64(const mamaFieldCacheField field, mama_i64_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type U64. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getU64(const mamaFieldCacheField field, mama_u64_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type F32. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getF32(const mamaFieldCacheField field, mama_f32_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type F64. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getF64(const mamaFieldCacheField field, mama_f64_t* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type STRING. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @param len (out) The length of the string. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getString(const mamaFieldCacheField field, + const char** result, + mama_size_t* len); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type PRICE. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getPrice(const mamaFieldCacheField field, + const mamaPrice* result); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type TIME. + * + * @param field (in) The field. + * @param result (out) The value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getDateTime(const mamaFieldCacheField field, + const mamaDateTime* result); + +/** + * This function will get the values a <code>mamaFieldCacheField</code> of type I8 vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getI8Vector(const mamaFieldCacheField field, + const mama_i8_t** values, + mama_size_t* size); + +/** + * This function will get the values a <code>mamaFieldCacheField</code> of type U8 vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getU8Vector(const mamaFieldCacheField field, + const mama_u8_t** values, + mama_size_t* size); + +/** + * This function will get the values a <code>mamaFieldCacheField</code> of type I16 vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getI16Vector(const mamaFieldCacheField field, + const mama_i16_t** values, + mama_size_t* size); + +/** + * This function will get the values a <code>mamaFieldCacheField</code> of type U16 vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getU16Vector(const mamaFieldCacheField field, + const mama_u16_t** values, + mama_size_t* size); + +/** + * This function will get the values a <code>mamaFieldCacheField</code> of type I32 vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getI32Vector(const mamaFieldCacheField field, + const mama_i32_t** values, + mama_size_t* size); + +/** + * This function will get the values a <code>mamaFieldCacheField</code> of type U32 vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getU32Vector(const mamaFieldCacheField field, + const mama_u32_t** values, + mama_size_t* size); + +/** + * This function will get the values a <code>mamaFieldCacheField</code> of type I64 vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getI64Vector(const mamaFieldCacheField field, + const mama_i64_t** values, + mama_size_t* size); + +/** + * This function will get the values a <code>mamaFieldCacheField</code> of type U64 vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getU64Vector(const mamaFieldCacheField field, + const mama_u64_t** values, + mama_size_t* size); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type F32 vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getF32Vector(const mamaFieldCacheField field, + const mama_f32_t** values, + mama_size_t* size); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type F64 vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getF64Vector(const mamaFieldCacheField field, + const mama_f64_t** values, + mama_size_t* size); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type STRING vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getStringVector(const mamaFieldCacheField field, + const char*** values, + mama_size_t* size); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type PRICE vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getPriceVector(const mamaFieldCacheField field, + const mamaPrice** values, + mama_size_t* size); + +/** + * This function will get the value a <code>mamaFieldCacheField</code> of type TIME vector. + * + * @param field (in) The field. + * @param values (out) The array of values of the field. + * @param size (out) The number of values. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_getDateTimeVector(const mamaFieldCacheField field, + const mamaDateTime** values, + mama_size_t* size); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type BOOL. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setBool(mamaFieldCacheField field, mama_bool_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type CHAR. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setChar(mamaFieldCacheField field, char value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type I8. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setI8(mamaFieldCacheField field, mama_i8_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type U8. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setU8(mamaFieldCacheField field, mama_u8_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type I16. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setI16(mamaFieldCacheField field, mama_i16_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type U16. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setU16(mamaFieldCacheField field, mama_u16_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type I32. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setI32(mamaFieldCacheField field, mama_i32_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type U32. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setU32(mamaFieldCacheField field, mama_u32_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type I64. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setI64(mamaFieldCacheField field, mama_i64_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type U64. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setU64(mamaFieldCacheField field, mama_u64_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type F32. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setF32(mamaFieldCacheField field, mama_f32_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type F64. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setF64(mamaFieldCacheField field, mama_f64_t value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type STRING. + * If parameter len is 0 then the length of the string is automatically computed + * using <code>strlen</code>. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @param len (in) The length of the string. Can be 0. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setString(const mamaFieldCacheField field, + const char* value, + mama_size_t len); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type PRICE. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setPrice(const mamaFieldCacheField field, const mamaPrice value); + +/** + * This function will set the value of a <code>mamaFieldCacheField</code> of type TIME. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setDateTime(const mamaFieldCacheField field, + const mamaDateTime value); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type I8 vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setI8Vector(const mamaFieldCacheField field, + const mama_i8_t* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type U8 vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setU8Vector(const mamaFieldCacheField field, + const mama_u8_t* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type I16 vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setI16Vector(const mamaFieldCacheField field, + const mama_i16_t* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type U16 vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setU16Vector(const mamaFieldCacheField field, + const mama_u16_t* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type I32 vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setI32Vector(const mamaFieldCacheField field, + const mama_i32_t* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type U32 vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setU32Vector(const mamaFieldCacheField field, + const mama_u32_t* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type I64 vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setI64Vector(const mamaFieldCacheField field, + const mama_i64_t* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type U64 vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setU64Vector(const mamaFieldCacheField field, + const mama_u64_t* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type F32 vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setF32Vector(const mamaFieldCacheField field, + const mama_f32_t* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type F64 vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setF64Vector(const mamaFieldCacheField field, + const mama_f64_t* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type STRING vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setStringVector(const mamaFieldCacheField field, + const char** values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type PRICE vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setPriceVector(const mamaFieldCacheField field, + const mamaPrice* values, + mama_size_t size); + +/** + * This function will set the values of a <code>mamaFieldCacheField</code> of type TIME vector. + * + * @param field (in) The field to set the value to. + * @param value (in) The new value of the field. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheField_setDateTimeVector(const mamaFieldCacheField field, + const mamaDateTime* values, + mama_size_t size); + +#if defined(__cplusplus) +} +#endif /* defined(__cplusplus) */ + +#endif /* MamaFieldCacheFieldH__ */ diff --git a/mama/c_cpp/src/c/mama/fieldcache/fieldcacheiterator.h b/mama/c_cpp/src/c/mama/fieldcache/fieldcacheiterator.h new file mode 100644 index 0000000..1606c94 --- /dev/null +++ b/mama/c_cpp/src/c/mama/fieldcache/fieldcacheiterator.h @@ -0,0 +1,102 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcacheiterator.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheIteratorH__ +#define MamaFieldCacheIteratorH__ + +#include <mama/config.h> +#include <mama/status.h> +#include <mama/types.h> +#include <mama/fieldcache/fieldcachetypes.h> + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + +/** + * This function will create an iterator to the given field cache and allocate all + * associated memory. If this function succeeds then the iterator should be destroyed + * by calling mamaFieldCacheIterator_destroy. + * + * @param iterator (out) The iterator to create. + * @param fieldCache (in) The cache to use to iterate. + * @return Resulting status of the call which can be + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheIterator_create(mamaFieldCacheIterator* iterator, + mamaFieldCache fieldCache); + +/** + * This function will destroy a field cache iterator previously allocated by a call + * to mamaFieldCacheIterator_create. + * + * @param iterator (in) The iterator to destroy. + * @return Resulting status of the call which can be + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheIterator_destroy(mamaFieldCacheIterator iterator); + +/** + * This function will return the next field in the cache. If no other fields are + * present it will return NULL. + * + * @param iterator (in) The iterator to get the field from. + * @return A mamaFieldCacheField pointing to the next field. + */ +MAMAExpDLL +extern mamaFieldCacheField +mamaFieldCacheIterator_next(mamaFieldCacheIterator iterator); + +/** + * This function will return a flag indicating if there are remaining fields to + * iterate. + * + * @param iterator (in) The iterator to check for other fields. + * @return A flag indicating if there are other fields to iterate. + */ +MAMAExpDLL +extern mama_bool_t +mamaFieldCacheIterator_hasNext(mamaFieldCacheIterator iterator); + +/** + * This function will return the first field in the cache. If the cache is empty, + * a NULL field is returned. + * + * @param iterator (in) The iterator to get the first field from. + * @return The first field in cache. + */ +MAMAExpDLL +extern mamaFieldCacheField +mamaFieldCacheIterator_begin(mamaFieldCacheIterator iterator); + +#if defined(__cplusplus) +} +#endif /* defined(__cplusplus) */ + +#endif /* MamaFieldCacheIteratorH__ */ diff --git a/mama/c_cpp/src/c/mama/fieldcache/fieldcacherecord.h b/mama/c_cpp/src/c/mama/fieldcache/fieldcacherecord.h new file mode 100644 index 0000000..050b209 --- /dev/null +++ b/mama/c_cpp/src/c/mama/fieldcache/fieldcacherecord.h @@ -0,0 +1,152 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcacherecord.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheRecordH__ +#define MamaFieldCacheRecordH__ + +#include <mama/config.h> +#include <mama/fielddesc.h> +#include <mama/types.h> +#include <mama/status.h> +#include <mama/fieldcache/fieldcachetypes.h> +#include <mama/fieldcache/fieldcachefield.h> + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + +/** + * This function will create a mamaFieldCacheRecord. + * + * @param record (in) The record to create. + * @return Resulting status of the call which can be + * MAMA_STATUS_NOMEM + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheRecord_create(mamaFieldCacheRecord* record); + +/** + * This function will destroy a <code>mamaFieldCacheRecord</code> previously + * allocated by a call to <code>mamaFieldCacheRecord_create</code>. + * Note that all the fields contained in the record will be destroyed. + * + * @param record (in) The record to destroy. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheRecord_destroy(mamaFieldCacheRecord record); + +/** + * This function will clear a <code>mamaFieldCacheRecord</code>. + * Note that all the fields contained in the record will be destroyed. + * + * @param record (in) The record to destroy. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheRecord_clear(mamaFieldCacheRecord record); + +/** + * This function will return the number of fields stored in a record. + * + * @param record (in) The field to destroy. + * @param size (out) The size of the record. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheRecord_getSize(mamaFieldCacheRecord record, mama_size_t* size); + +/** This function will create and add a field to the record; the new field is + * returned. The field will be destroyed when the record is destroyed. + * + * @param record (in) The record to add the field to. + * @param fid (in) The field id of the field to create and add to the record. + * @param type (in) The type of the field to create and add to the record. + * @param name (in) The name of the field to create and add to the record. + * @param field (out) The new field added to the record. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheRecord_add(mamaFieldCacheRecord record, + mama_fid_t fid, + mamaFieldType type, + const char* name, + mamaFieldCacheField* field); + +/** This function will retrieve a field from the record using a position in the Record + * as in a normal C array. + * This can be useful when iterating the fields of the record in a loop. + * Note that position is not significative in a <code>mamaFieldCacheRecord</code>. + * + * @param record (in) The record to get the field from. + * @param index (in) The index of the field to get from the record. + * @param field (out) The field, if found. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheRecord_getField(mamaFieldCacheRecord record, + mama_size_t index, + mamaFieldCacheField* field); + +/** This function will retrieve a field from the record using the field id of the + * field to get. + * + * @param record (in) The record to get the field from. + * @param fid (in) The field id of the field. + * @param field (out) The field, if found. + * @return Resulting status of the call which can be + * MAMA_STATUS_NULL_ARG + * MAMA_STATUS_INVALID_ARG + * MAMA_STATUS_NOT_FOUND + * MAMA_STATUS_OK + */ +MAMAExpDLL +extern mama_status +mamaFieldCacheRecord_find(mamaFieldCacheRecord record, + mama_fid_t fid, + const char* name, + mamaFieldCacheField* field); + +#if defined(__cplusplus) +} +#endif /* defined(__cplusplus) */ + +#endif /* MamaFieldCacheRecordH__ */ diff --git a/mama/c_cpp/src/c/mama/fieldcache/fieldcachetypes.h b/mama/c_cpp/src/c/mama/fieldcache/fieldcachetypes.h new file mode 100644 index 0000000..8b4b82b --- /dev/null +++ b/mama/c_cpp/src/c/mama/fieldcache/fieldcachetypes.h @@ -0,0 +1,52 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/c/fieldcache/fieldcachetypes.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MamaFieldCacheTypesH__ +#define MamaFieldCacheTypesH__ + +#include <wombat/wConfig.h> + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + +/** This structure contains the information of a field cache. + */ +typedef struct mamaFieldCacheImpl_* mamaFieldCache; + +/** This structure contains the information of a field that can be stored in a + * field cache. + */ +typedef struct mamaFieldCacheFieldImpl_* mamaFieldCacheField; + +/** This structure contains the information to store a set of fields. + */ +typedef struct mamaFieldCacheRecordImpl_* mamaFieldCacheRecord; + +/** This structure allows to iterate through a field cache. + */ +typedef struct mamaFieldCacheIteratorImpl_* mamaFieldCacheIterator; + +#if defined(__cplusplus) +} +#endif /* defined(__cplusplus) */ + +#endif /* MamaFieldCacheTypesH__ */ diff --git a/mama/c_cpp/src/c/mamac.vcproj b/mama/c_cpp/src/c/mamac.vcproj index 772dac4..f92aff0 100644 --- a/mama/c_cpp/src/c/mamac.vcproj +++ b/mama/c_cpp/src/c/mamac.vcproj @@ -370,6 +370,54 @@ > </File> <File + RelativePath=".\fieldcache\fieldcache.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachefield.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachefieldimpl.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcacheimpl.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcacheiterator.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachelist.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachemaparray.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachemapbinary.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachemap.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachemapmonitor.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcacherecord.c" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachevector.c" + > + </File> + <File RelativePath=".\datetime.c" > </File> @@ -640,6 +688,66 @@ > </File> <File + RelativePath=".\mama\fieldcache\fieldcache.h" + > + </File> + <File + RelativePath=".\mama\fieldcache\fieldcachetypes.h" + > + </File> + <File + RelativePath=".\mama\fieldcache\fieldcacherecord.h" + > + </File> + <File + RelativePath=".\mama\fieldcache\fieldcacheiterator.h" + > + </File> + <File + RelativePath=".\mama\fieldcache\fieldcachefield.h" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachefieldimpl.h" + > + </File> + <File + RelativePath=".\fieldcache\fieldcacheimpl.h" + > + </File> + <File + RelativePath=".\fieldcache\fieldcacheiteratorimpl.h" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachemap.h" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachelist.h" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachemapmonitor.h" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachemapbinary.h" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachemaparray.h" + > + </File> + <File + RelativePath=".\fieldcache\fieldcacherecordimpl.h" + > + </File> + <File + RelativePath=".\fieldcache\fieldcachevector.h" + > + </File> + <File RelativePath=".\mama\datetime.h" > </File> diff --git a/mama/c_cpp/src/cpp/Makefile.am b/mama/c_cpp/src/cpp/Makefile.am index 1a2593a..0f3adb4 100644 --- a/mama/c_cpp/src/cpp/Makefile.am +++ b/mama/c_cpp/src/cpp/Makefile.am @@ -92,7 +92,11 @@ nobase_include_HEADERS = \ mama/mamacpp.h \ mama/MamaStat.h \ mama/MamaStatsCollector.h \ - mama/MamaReservedFields.h + mama/MamaReservedFields.h \ + mama/fieldcache/MamaFieldCacheField.h \ + mama/fieldcache/MamaFieldCacheFieldTypes.h \ + mama/fieldcache/MamaFieldCacheRecord.h \ + mama/fieldcache/MamaFieldCache.h
CPPFLAGS += -I@srcdir@ \ @@ -148,4 +152,9 @@ libmamacpp_la_SOURCES = \ MamaStat.cpp \ MamaStatsCollector.cpp \ conflation/MamaConnection.cpp \ - conflation/MamaServerConnection.cpp + conflation/MamaServerConnection.cpp \ + fieldcache/MamaFieldCacheField.cpp \ + fieldcache/MamaFieldCacheFieldTypes.cpp \ + fieldcache/MamaFieldCacheRecord.cpp \ + fieldcache/MamaFieldCache.cpp + diff --git a/mama/c_cpp/src/cpp/SConscript b/mama/c_cpp/src/cpp/SConscript index 25ead88..d8bc0b7 100644 --- a/mama/c_cpp/src/cpp/SConscript +++ b/mama/c_cpp/src/cpp/SConscript @@ -71,6 +71,14 @@ InstConflationInclude = \ mama/conflation/MamaConnection.h """)
+InstFieldCacheInclude = \ + Split(""" + mama/fieldcache/MamaFieldCacheField.h + mama/fieldcache/MamaFieldCacheFieldTypes.h + mama/fieldcache/MamaFieldCacheRecord.h + mama/fieldcache/MamaFieldCache.h +""") + includePath = [] includePath.append('.') includePath.append('../c') @@ -121,6 +129,10 @@ libmama_sources = \ MamaStatsCollector.cpp conflation/MamaConnection.cpp conflation/MamaServerConnection.cpp + fieldcache/MamaFieldCacheField.cpp + fieldcache/MamaFieldCacheFieldTypes.cpp + fieldcache/MamaFieldCacheRecord.cpp + fieldcache/MamaFieldCache.cpp """)
env.Append(CPPPATH=includePath, LIBPATH=libPath) @@ -133,3 +145,5 @@ Alias('install', env.Install('$libdir', lib)) Alias('install', env.Install('$prefix/include/mama', InstMamaInclude)) Alias('install', env.Install('$prefix/include/mama/conflation', InstConflationInclude)) +Alias('install', env.Install('$prefix/include/mama/fieldcache', + InstFieldCacheInclude)) diff --git a/mama/c_cpp/src/cpp/SConscript.win b/mama/c_cpp/src/cpp/SConscript.win index dae0764..74c566e 100644 --- a/mama/c_cpp/src/cpp/SConscript.win +++ b/mama/c_cpp/src/cpp/SConscript.win @@ -54,11 +54,17 @@ MamaFt.cpp MamaReservedFields.cpp conflation\MamaConnection.cpp conflation\MamaServerConnection.cpp +fieldcache\MamaFieldCacheField.cpp +fieldcache\MamaFieldCache.cpp +fieldcache\MamaFieldCacheRecord.cpp +fieldcache\MamaFieldCacheFieldTypes.cpp """)
headers = Glob('mama/*.h') +fieldcacheHeaders = Glob('mama/fieldcache/*.h')
env.InstallLibrary(sources, target)
if ( env['build'] == 'dynamic' or len(env['buildtype']) == 1): env.Install('$prefix/include/mama',headers) + env.Install('$prefix/include/mama/fieldcache',fieldcacheHeaders) diff --git a/mama/c_cpp/src/cpp/fieldcache/MamaFieldCache.cpp b/mama/c_cpp/src/cpp/fieldcache/MamaFieldCache.cpp new file mode 100644 index 0000000..24ebdbd --- /dev/null +++ b/mama/c_cpp/src/cpp/fieldcache/MamaFieldCache.cpp @@ -0,0 +1,310 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/cpp/fieldcache/MamaFieldCache.cpp#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <mama/fieldcache/MamaFieldCache.h> +#include <mama/fieldcache/MamaFieldCacheRecord.h> +#include <mama/fieldcache/MamaFieldCacheField.h> +#include <mama/MamaMsg.h> +#include <mama/MamaDictionary.h> +#include <mama/fieldcache/fieldcacheiterator.h> + +namespace Wombat +{ + +struct MamaFieldCache::MamaFieldCacheImpl +{ + MamaFieldCacheImpl() + : mCache(NULL) + { + } + ~MamaFieldCacheImpl() + { + clear(); + } + + void clear(); + + mamaFieldCache mCache; + mutable MamaFieldCacheField mField; +}; + +void MamaFieldCache::MamaFieldCacheImpl::clear() +{ + // clear reusable container members + mField.getCValue() = NULL; + mField.clear(); +} + + +MamaFieldCache::MamaFieldCache() + : mPimpl(new MamaFieldCacheImpl) +{ +} + +MamaFieldCache::~MamaFieldCache() +{ + mamaFieldCache_destroy(mPimpl->mCache); + delete mPimpl; +} + +void MamaFieldCache::create() +{ + if (mPimpl->mCache) + return; // Already created + mamaFieldCache_create(&mPimpl->mCache); +} + +void MamaFieldCache::clear() +{ + mamaFieldCache_clear(mPimpl->mCache); + mPimpl->clear(); +} + +mama_size_t MamaFieldCache::getSize() const +{ + mama_size_t size = 0; + mamaFieldCache_getSize(mPimpl->mCache, &size); + return size; +} + +void MamaFieldCache::setTrackModified(bool value) +{ + mamaFieldCache_setTrackModified(mPimpl->mCache, (mama_bool_t)value); +} + +bool MamaFieldCache::getTrackModified() const +{ + mama_bool_t value = 0; + mamaFieldCache_getTrackModified(mPimpl->mCache, &value); + return value; +} + +void MamaFieldCache::setUseFieldNames(bool value) +{ + mamaFieldCache_setUseFieldNames(mPimpl->mCache, (mama_bool_t)value); +} + +bool MamaFieldCache::getUseFieldNames() const +{ + mama_bool_t value = 0; + mamaFieldCache_getUseFieldNames(mPimpl->mCache, &value); + return value; +} + +void MamaFieldCache::setUseLock(bool value) +{ + mamaFieldCache_setUseLock(mPimpl->mCache, (mama_bool_t)value); +} + +bool MamaFieldCache::getUseLock() const +{ + mama_bool_t value = 0; + mamaFieldCache_getUseLock(mPimpl->mCache, &value); + return value; +} + +void MamaFieldCache::lock() +{ + mamaFieldCache_lock(mPimpl->mCache); +} + +void MamaFieldCache::unlock() +{ + mamaFieldCache_unlock(mPimpl->mCache); +} + +const MamaFieldCacheField* MamaFieldCache::find(mama_fid_t fid, + const char* name) const +{ + mamaFieldCacheField field = NULL; + mamaFieldCache_find(mPimpl->mCache, fid, name, &field); + if (!field) + { + return NULL; + } + mPimpl->mField.getCValue() = field; + return &mPimpl->mField; +} + +MamaFieldCacheField* MamaFieldCache::find(mama_fid_t fid, + const char* name) +{ + mamaFieldCacheField field = NULL; + mamaFieldCache_find(mPimpl->mCache, fid, name, &field); + if (!field) + { + return NULL; + } + mPimpl->mField.getCValue() = field; + return &mPimpl->mField; +} + +void MamaFieldCache::setModified(MamaFieldCacheField& field) +{ + mamaFieldCache_setModified(mPimpl->mCache, field.getCValue()); +} + +void MamaFieldCache::apply(const MamaFieldCacheField& field) +{ + mamaFieldCache_applyField(mPimpl->mCache, field.getCValue()); +} + +void MamaFieldCache::apply(const MamaMsg& msg, const MamaDictionary* dict) +{ + mamaFieldCache_applyMessage(mPimpl->mCache, + msg.getUnderlyingMsg(), + dict ? dict->getDictC() : NULL); +} + +void MamaFieldCache::apply(const MamaFieldCacheRecord& record) +{ + mamaFieldCache_applyRecord(mPimpl->mCache, record.getCValue()); +} + +void MamaFieldCache::getFullMessage(MamaMsg& msg) +{ + mamaFieldCache_getFullMessage(mPimpl->mCache, msg.getUnderlyingMsg()); +} + +void MamaFieldCache::getDeltaMessage(MamaMsg& msg) +{ + mamaFieldCache_getDeltaMessage(mPimpl->mCache, msg.getUnderlyingMsg()); +} + +void MamaFieldCache::clearModifiedFields() +{ + mamaFieldCache_clearModifiedFields(mPimpl->mCache); +} + +MamaFieldCache::iterator MamaFieldCache::begin() +{ + return iterator(mPimpl->mCache); +} + +MamaFieldCache::const_iterator MamaFieldCache::begin() const +{ + return const_iterator(mPimpl->mCache); +} + +MamaFieldCache::iterator MamaFieldCache::end() +{ + return iterator(NULL); +} + +MamaFieldCache::const_iterator MamaFieldCache::end() const +{ + return const_iterator(NULL); +} + + +MamaFieldCache::MamaFieldCacheIterator::MamaFieldCacheIterator(mamaFieldCache fieldCache) + : mIterator(NULL) +{ + mamaFieldCacheIterator_create(&mIterator, fieldCache); + if (mamaFieldCacheIterator_hasNext(mIterator)) + { + ++(*this); // Set to the begin value + } +} + +MamaFieldCache::MamaFieldCacheIterator::MamaFieldCacheIterator(const MamaFieldCacheIterator& rhs) + : mIterator(rhs.mIterator) +{ + const_cast<MamaFieldCacheIterator&>(rhs).mIterator = NULL; + mField.getCValue() = rhs.mField.getCValue(); +} + +MamaFieldCache::MamaFieldCacheIterator::~MamaFieldCacheIterator () +{ + mamaFieldCacheIterator_destroy(mIterator); + // This is only a container - it is not responsible for destroying the real C field + mField.getCValue() = NULL; +} + +MamaFieldCache::MamaFieldCacheIterator& +MamaFieldCache::MamaFieldCacheIterator::operator=(const MamaFieldCacheIterator& rhs) +{ + if (this != &rhs) + { + if (mIterator) + { + mamaFieldCacheIterator_destroy(mIterator); + } + mIterator = rhs.mIterator; + const_cast<MamaFieldCacheIterator&>(rhs).mIterator = NULL; + mField.getCValue() = rhs.mField.getCValue(); + } + return *this; +} + +bool MamaFieldCache::MamaFieldCacheIterator::operator==(const MamaFieldCacheIterator& rhs) const +{ + return mField == rhs.mField; +} +bool MamaFieldCache::MamaFieldCacheIterator::operator!=(const MamaFieldCacheIterator& rhs) const +{ + return mField != rhs.mField; +} + +MamaFieldCache::MamaFieldCacheIterator& +MamaFieldCache::MamaFieldCacheIterator::operator++() +{ + const_cast<MamaFieldCacheField&>(mField).getCValue() = mamaFieldCacheIterator_next(mIterator); + return *this; +} + + +MamaFieldCache::iterator::iterator(mamaFieldCache fieldCache) + : MamaFieldCacheIterator (fieldCache) +{ +} + +MamaFieldCache::iterator::reference MamaFieldCache::iterator::operator*() +{ + return mField; +} + +MamaFieldCache::iterator::pointer MamaFieldCache::iterator::operator->() +{ + return &mField; +} + +MamaFieldCache::const_iterator::const_iterator(mamaFieldCache fieldCache) + : MamaFieldCacheIterator (fieldCache) +{ +} + +MamaFieldCache::const_iterator::const_iterator(const MamaFieldCache::iterator& it) + : MamaFieldCacheIterator(it) +{ +} + +MamaFieldCache::const_iterator::reference MamaFieldCache::const_iterator::operator*() +{ + return mField; +} + +MamaFieldCache::const_iterator::pointer MamaFieldCache::const_iterator::operator->() +{ + return &mField; +} + +} // namespace Wombat diff --git a/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheField.cpp b/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheField.cpp new file mode 100644 index 0000000..a34dbc3 --- /dev/null +++ b/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheField.cpp @@ -0,0 +1,229 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheField.cpp#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <mama/fieldcache/MamaFieldCacheField.h> +#include <mama/fieldcache/fieldcachefield.h> +#include <FieldDescriptorImpl.h> + +namespace Wombat +{ + +struct MamaFieldCacheField::MamaFieldCacheFieldImpl +{ + MamaFieldCacheFieldImpl(); + ~MamaFieldCacheFieldImpl(); + + void clear(); + + const mamaFieldDescriptor* getFieldDescriptorC() const; + + mamaFieldCacheField mField; + MamaFieldDescriptor mDescriptor; +}; + +MamaFieldCacheField::MamaFieldCacheFieldImpl::MamaFieldCacheFieldImpl() + : mField(NULL) + , mDescriptor(NULL) +{ +} + +MamaFieldCacheField::MamaFieldCacheFieldImpl::~MamaFieldCacheFieldImpl() +{ + clear(); +} + +void MamaFieldCacheField::MamaFieldCacheFieldImpl::clear() +{ + // clear reusable container members + mDescriptor.mPimpl->mField = NULL; +} + +const mamaFieldDescriptor* +MamaFieldCacheField::MamaFieldCacheFieldImpl::getFieldDescriptorC() const +{ + return &mDescriptor.mPimpl->mField; +} + + +MamaFieldCacheField::MamaFieldCacheField() + : mPimpl(new MamaFieldCacheFieldImpl) +{ +} + +MamaFieldCacheField::~MamaFieldCacheField() +{ + mamaFieldCacheField_destroy(mPimpl->mField); + delete mPimpl; +} + +MamaFieldCacheField::MamaFieldCacheField(const MamaFieldCacheField& rhs) + : mPimpl(new MamaFieldCacheFieldImpl) +{ + create(rhs.getFid(), rhs.getType(), rhs.getName()); + mamaFieldCacheField_copy(rhs.mPimpl->mField, mPimpl->mField); +} + +MamaFieldCacheField& MamaFieldCacheField::operator=(const MamaFieldCacheField& rhs) +{ + if (this != &rhs) + { + mamaFieldCacheField_copy(rhs.mPimpl->mField, mPimpl->mField); + } + return *this; +} + +bool MamaFieldCacheField::operator==(const MamaFieldCacheField& rhs) const +{ + return mPimpl->mField == rhs.mPimpl->mField; +} + +bool MamaFieldCacheField::operator!=(const MamaFieldCacheField& rhs) const +{ + return mPimpl->mField != rhs.mPimpl->mField; +} + +void MamaFieldCacheField::create(const MamaFieldDescriptor& descriptor) +{ + if (mPimpl->mField) + return; // Already created + + mamaFieldCacheField_create(&mPimpl->mField, + descriptor.getFid(), + descriptor.getType(), + descriptor.getName()); +} + +void MamaFieldCacheField::create( + mama_fid_t fid, + mamaFieldType type, + const char* name) +{ + if (mPimpl->mField) + return; // Already created + + mamaFieldCacheField_create(&mPimpl->mField, fid, type, name); +} + +void MamaFieldCacheField::clear() +{ + mPimpl->clear(); +} + +mama_fid_t MamaFieldCacheField::getFid() const +{ + mama_fid_t value = 0; + mamaFieldCacheField_getFid(mPimpl->mField, &value); + return value; +} + +mamaFieldType MamaFieldCacheField::getType() const +{ + mamaFieldType value = MAMA_FIELD_TYPE_UNKNOWN; + mamaFieldCacheField_getType(mPimpl->mField, &value); + return value; +} + +const char* MamaFieldCacheField::getName() const +{ + const char* cname = NULL; + mamaFieldCacheField_getName(mPimpl->mField, &cname); + return cname; +} + +void MamaFieldCacheField::setDescriptor(const MamaFieldDescriptor* descriptor) +{ + mamaFieldCacheField_setDescriptor( + mPimpl->mField, + descriptor ? descriptor->mPimpl->mField : NULL); +} + +const MamaFieldDescriptor* MamaFieldCacheField::getDescriptor() const +{ + const mamaFieldDescriptor descriptor = NULL; + mamaFieldCacheField_getDescriptor(mPimpl->mField, &descriptor); + mPimpl->mDescriptor.mPimpl->mField = descriptor; + return descriptor ? &mPimpl->mDescriptor : NULL; +} + +bool MamaFieldCacheField::isModified() const +{ + mama_bool_t value = 0; + mamaFieldCacheField_isModified(mPimpl->mField, &value); + return value; +} + +void MamaFieldCacheField::setPublish(bool value) +{ + mamaFieldCacheField_setPublish(mPimpl->mField, value); +} + +bool MamaFieldCacheField::getPublish() const +{ + mama_bool_t value = 0; + mamaFieldCacheField_getPublish(mPimpl->mField, &value); + return value; +} + +void MamaFieldCacheField::setCheckModified(bool value) +{ + mamaFieldCacheField_setCheckModified(mPimpl->mField, value); +} + +bool MamaFieldCacheField::getCheckModified() const +{ + mama_bool_t value = 0; + mamaFieldCacheField_getCheckModified(mPimpl->mField, &value); + return value; +} + +bool MamaFieldCacheField::isVector() const +{ + switch (getType()) + { + case MAMA_FIELD_TYPE_VECTOR_I8: + case MAMA_FIELD_TYPE_VECTOR_U8: + case MAMA_FIELD_TYPE_VECTOR_I16: + case MAMA_FIELD_TYPE_VECTOR_U16: + case MAMA_FIELD_TYPE_VECTOR_I32: + case MAMA_FIELD_TYPE_VECTOR_U32: + case MAMA_FIELD_TYPE_VECTOR_I64: + case MAMA_FIELD_TYPE_VECTOR_U64: + case MAMA_FIELD_TYPE_VECTOR_STRING: + case MAMA_FIELD_TYPE_VECTOR_PRICE: + case MAMA_FIELD_TYPE_VECTOR_TIME: + return true; + default: + break; + } + return false; +} + +mamaFieldCacheField& MamaFieldCacheField::getCValue() +{ + return mPimpl->mField; +} + +const mamaFieldCacheField& MamaFieldCacheField::getCValue() const +{ + return mPimpl->mField; +} + +} // namespace Wombat diff --git a/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheFieldTypes.cpp b/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheFieldTypes.cpp new file mode 100644 index 0000000..ede1a7b --- /dev/null +++ b/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheFieldTypes.cpp @@ -0,0 +1,873 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheFieldTypes.cpp#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <mama/fieldcache/MamaFieldCacheFieldTypes.h> +#include <mama/fieldcache/fieldcachefield.h> +#include <mama/price.h> +#include <string> +#include <sstream> + +namespace Wombat +{ + +// MAMA_FIELD_TYPE_CHAR +template <> +char MamaFieldCacheFieldChar::get(const MamaFieldCacheField& field) const +{ + checkType(field); + char res; + mamaFieldCacheField_getChar(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldChar::set(MamaFieldCacheField& field, const char& value) +{ + checkType(field); + mamaFieldCacheField_setChar(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_BOOL +template <> +mama_bool_t MamaFieldCacheFieldBool::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_bool_t res; + mamaFieldCacheField_getBool(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldBool::set(MamaFieldCacheField& field, const mama_bool_t& value) +{ + checkType(field); + mamaFieldCacheField_setBool(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_I8 +template <> +mama_i8_t MamaFieldCacheFieldI8::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_i8_t res; + mamaFieldCacheField_getI8(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldI8::set(MamaFieldCacheField& field, const mama_i8_t& value) +{ + checkType(field); + mamaFieldCacheField_setI8(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_U8 +template <> +mama_u8_t MamaFieldCacheFieldU8::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_u8_t res; + mamaFieldCacheField_getU8(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldU8::set(MamaFieldCacheField& field, const mama_u8_t& value) +{ + checkType(field); + mamaFieldCacheField_setU8(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_I16 +template <> +mama_i16_t MamaFieldCacheFieldI16::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_i16_t res; + mamaFieldCacheField_getI16(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldI16::set(MamaFieldCacheField& field, const mama_i16_t& value) +{ + checkType(field); + mamaFieldCacheField_setI16(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_U16 +template <> +mama_u16_t MamaFieldCacheFieldU16::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_u16_t res; + mamaFieldCacheField_getU16(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldU16::set(MamaFieldCacheField& field, const mama_u16_t& value) +{ + checkType(field); + mamaFieldCacheField_setU16(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_I32 +template <> +mama_i32_t MamaFieldCacheFieldI32::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_i32_t res; + mamaFieldCacheField_getI32(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldI32::set(MamaFieldCacheField& field, const mama_i32_t& value) +{ + checkType(field); + mamaFieldCacheField_setI32(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_U32 +template <> +mama_u32_t MamaFieldCacheFieldU32::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_u32_t res; + mamaFieldCacheField_getU32(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldU32::set(MamaFieldCacheField& field, const mama_u32_t& value) +{ + checkType(field); + mamaFieldCacheField_setU32(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_I64 +template <> +mama_i64_t MamaFieldCacheFieldI64::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_i64_t res; + mamaFieldCacheField_getI64(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldI64::set(MamaFieldCacheField& field, const mama_i64_t& value) +{ + checkType(field); + mamaFieldCacheField_setI64(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_U64 +template <> +mama_u64_t MamaFieldCacheFieldU64::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_u64_t res; + mamaFieldCacheField_getU64(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldU64::set(MamaFieldCacheField& field, const mama_u64_t& value) +{ + checkType(field); + mamaFieldCacheField_setU64(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_F32 +template <> +mama_f32_t MamaFieldCacheFieldF32::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_f32_t res; + mamaFieldCacheField_getF32(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldF32::set(MamaFieldCacheField& field, const mama_f32_t& value) +{ + checkType(field); + mamaFieldCacheField_setF32(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_F64 +template <> +mama_f64_t MamaFieldCacheFieldF64::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mama_f64_t res; + mamaFieldCacheField_getF64(field.getCValue(), &res); + return res; +} +template <> +void MamaFieldCacheFieldF64::set(MamaFieldCacheField& field, const mama_f64_t& value) +{ + checkType(field); + mamaFieldCacheField_setF64(field.getCValue(), value); +} + +// MAMA_FIELD_TYPE_STRING +void MamaFieldCacheFieldString::set(MamaFieldCacheField& field, + const char* value, + mama_size_t len) +{ + checkType(field); + mamaFieldCacheField_setString(field.getCValue(), value, len); +} +const char* MamaFieldCacheFieldString::get(const MamaFieldCacheField& field) const +{ + checkType(field); + const char* res = NULL; + mama_size_t len = 0; + mamaFieldCacheField_getString(field.getCValue(), &res, &len); + return res; +} + +// MAMA_FIELD_TYPE_PRICE +void MamaFieldCacheFieldPrice::set(MamaFieldCacheField& field, const MamaPrice& value) +{ + checkType(field); + mamaFieldCacheField_setPrice(field.getCValue(), value.getCValue()); +} +const MamaPrice& MamaFieldCacheFieldPrice::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mamaPrice res = NULL; + mamaFieldCacheField_getPrice(field.getCValue(), &res); + // res is pointer to the field in the cache - need to make a copy here + // otherwise the object containing MamaPrice returned would destroy the C + // field present in cache. + mamaPrice_copy(mPrice.getCValue(), res); + return mPrice; +} + +// MAMA_FIELD_TYPE_TIME +void MamaFieldCacheFieldDateTime::set(MamaFieldCacheField& field, const MamaDateTime& value) +{ + checkType(field); + mamaFieldCacheField_setDateTime(field.getCValue(), value.getCValue()); +} +const MamaDateTime& MamaFieldCacheFieldDateTime::get(const MamaFieldCacheField& field) const +{ + checkType(field); + mamaDateTime res = NULL; + mamaFieldCacheField_getDateTime(field.getCValue(), &res); + // res is pointer to the field in the cache - need to make a copy here + // otherwise the object containing MamaDateTime returned would destroy the C + // field present in cache. + mamaDateTime_copy(mDateTime.getCValue(), res); + return mDateTime; +} + +// MAMA_FIELD_TYPE_VECTOR_I8 +template <> +void MamaFieldCacheFieldI8Vector::set(MamaFieldCacheField& field, + const mama_i8_t* values, + mama_size_t size) +{ + checkType(field); + mamaFieldCacheField_setI8Vector(field.getCValue(), values, size); +} +template <> +void MamaFieldCacheFieldI8Vector::get(const MamaFieldCacheField& field, + const mama_i8_t*& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getI8Vector(field.getCValue(), &values, &size); +} +template <> +const mama_i8_t& MamaFieldCacheFieldI8Vector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mama_i8_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getI8Vector(field.getCValue(), &values, &size); + if (index < size) + return values[index]; + throw std::out_of_range("MamaFieldCacheFieldI8Vector::get"); +} + +// MAMA_FIELD_TYPE_VECTOR_U8 +template <> +void MamaFieldCacheFieldU8Vector::set(MamaFieldCacheField& field, + const mama_u8_t* values, + mama_size_t size) +{ + checkType(field); + mamaFieldCacheField_setU8Vector(field.getCValue(), values, size); +} +template <> +void MamaFieldCacheFieldU8Vector::get(const MamaFieldCacheField& field, + const mama_u8_t*& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getU8Vector(field.getCValue(), &values, &size); +} +template <> +const mama_u8_t& MamaFieldCacheFieldU8Vector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + const mama_u8_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getU8Vector(field.getCValue(), &values, &size); + if (index < size) + return values[index]; + throw std::out_of_range("MamaFieldCacheFieldU8Vector::get"); +} + +// MAMA_FIELD_TYPE_VECTOR_I16 +template <> +void MamaFieldCacheFieldI16Vector::set(MamaFieldCacheField& field, + const mama_i16_t* values, + mama_size_t size) +{ + checkType(field); + mamaFieldCacheField_setI16Vector(field.getCValue(), values, size); +} +template <> +void MamaFieldCacheFieldI16Vector::get(const MamaFieldCacheField& field, + const mama_i16_t*& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getI16Vector(field.getCValue(), &values, &size); +} +template <> +const mama_i16_t& MamaFieldCacheFieldI16Vector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mama_i16_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getI16Vector(field.getCValue(), &values, &size); + if (index < size) + return values[index]; + throw std::out_of_range("MamaFieldCacheFieldI16Vector::get"); +} + +// MAMA_FIELD_TYPE_VECTOR_U16 +template <> +void MamaFieldCacheFieldU16Vector::set(MamaFieldCacheField& field, + const mama_u16_t* values, + mama_size_t size) +{ + checkType(field); + mamaFieldCacheField_setU16Vector(field.getCValue(), values, size); +} +template <> +void MamaFieldCacheFieldU16Vector::get(const MamaFieldCacheField& field, + const mama_u16_t*& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getU16Vector(field.getCValue(), &values, &size); +} +template <> +const mama_u16_t& MamaFieldCacheFieldU16Vector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mama_u16_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getU16Vector(field.getCValue(), &values, &size); + if (index < size) + return values[index]; + throw std::out_of_range("MamaFieldCacheFieldU16Vector::get"); +} + +// MAMA_FIELD_TYPE_VECTOR_I32 +template <> +void MamaFieldCacheFieldI32Vector::set(MamaFieldCacheField& field, + const mama_i32_t* values, + mama_size_t size) +{ + checkType(field); + mamaFieldCacheField_setI32Vector(field.getCValue(), values, size); +} +template <> +void MamaFieldCacheFieldI32Vector::get(const MamaFieldCacheField& field, + const mama_i32_t*& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getI32Vector(field.getCValue(), &values, &size); +} +template <> +const mama_i32_t& MamaFieldCacheFieldI32Vector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mama_i32_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getI32Vector(field.getCValue(), &values, &size); + if (index < size) + return values[index]; + throw std::out_of_range("MamaFieldCacheFieldI32Vector::get"); +} + +// MAMA_FIELD_TYPE_VECTOR_U32 +template <> +void MamaFieldCacheFieldU32Vector::set(MamaFieldCacheField& field, + const mama_u32_t* values, + mama_size_t size) +{ + checkType(field); + mamaFieldCacheField_setU32Vector(field.getCValue(), values, size); +} +template <> +void MamaFieldCacheFieldU32Vector::get(const MamaFieldCacheField& field, + const mama_u32_t*& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getU32Vector(field.getCValue(), &values, &size); +} +template <> +const mama_u32_t& MamaFieldCacheFieldU32Vector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mama_u32_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getU32Vector(field.getCValue(), &values, &size); + if (index < size) + return values[index]; + throw std::out_of_range("MamaFieldCacheFieldU32Vector::get"); +} + +// MAMA_FIELD_TYPE_VECTOR_I64 +template <> +void MamaFieldCacheFieldI64Vector::set(MamaFieldCacheField& field, + const mama_i64_t* values, + mama_size_t size) +{ + mamaFieldCacheField_setI64Vector(field.getCValue(), values, size); +} +template <> +void MamaFieldCacheFieldI64Vector::get(const MamaFieldCacheField& field, + const mama_i64_t*& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getI64Vector(field.getCValue(), &values, &size); +} +template <> +const mama_i64_t& MamaFieldCacheFieldI64Vector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mama_i64_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getI64Vector(field.getCValue(), &values, &size); + if (index < size) + return values[index]; + throw std::out_of_range("MamaFieldCacheFieldI64Vector::get"); +} + +// MAMA_FIELD_TYPE_VECTOR_U64 +template <> +void MamaFieldCacheFieldU64Vector::set(MamaFieldCacheField& field, + const mama_u64_t* values, + mama_size_t size) +{ + checkType(field); + mamaFieldCacheField_setU64Vector(field.getCValue(), values, size); +} +template <> +void MamaFieldCacheFieldU64Vector::get(const MamaFieldCacheField& field, + const mama_u64_t*& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getU64Vector(field.getCValue(), &values, &size); +} +template <> +const mama_u64_t& MamaFieldCacheFieldU64Vector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mama_u64_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getU64Vector(field.getCValue(), &values, &size); + if (index < size) + return values[index]; + throw std::out_of_range("MamaFieldCacheFieldU64Vector::get"); +} + +// MAMA_FIELD_TYPE_VECTOR_F32 +template <> +void MamaFieldCacheFieldF32Vector::set(MamaFieldCacheField& field, + const mama_f32_t* values, + mama_size_t size) +{ + checkType(field); + mamaFieldCacheField_setF32Vector(field.getCValue(), values, size); +} +template <> +void MamaFieldCacheFieldF32Vector::get(const MamaFieldCacheField& field, + const mama_f32_t*& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getF32Vector(field.getCValue(), &values, &size); +} +template <> +const mama_f32_t& MamaFieldCacheFieldF32Vector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mama_f32_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getF32Vector(field.getCValue(), &values, &size); + if (index < size) + return values[index]; + throw std::out_of_range("MamaFieldCacheFieldF32Vector::get"); +} + +// MAMA_FIELD_TYPE_VECTOR_F64 +template <> +void MamaFieldCacheFieldF64Vector::set(MamaFieldCacheField& field, + const mama_f64_t* values, + mama_size_t size) +{ + checkType(field); + mamaFieldCacheField_setF64Vector(field.getCValue(), values, size); +} +template <> +void MamaFieldCacheFieldF64Vector::get(const MamaFieldCacheField& field, + const mama_f64_t*& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getF64Vector(field.getCValue(), &values, &size); +} +template <> +const mama_f64_t& MamaFieldCacheFieldF64Vector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mama_f64_t* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getF64Vector(field.getCValue(), &values, &size); + if (index < size) + return values[index]; + throw std::out_of_range("MamaFieldCacheFieldF64Vector::get"); +} + +// MAMA_FIELD_TYPE_VECTOR_STRING +void MamaFieldCacheFieldStringVector::set(MamaFieldCacheField& field, + const char** values, + mama_size_t size) +{ + checkType(field); + mamaFieldCacheField_setStringVector(field.getCValue(), values, size); +} +void MamaFieldCacheFieldStringVector::get(const MamaFieldCacheField& field, + const char**& values, + mama_size_t& size) const +{ + checkType(field); + mamaFieldCacheField_getStringVector(field.getCValue(), &values, &size); +} +const char* MamaFieldCacheFieldStringVector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const char** values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getStringVector(field.getCValue(), &values, &size); + if (index < size) + { + return values[index]; + } + return NULL; +} + +// MAMA_FIELD_TYPE_VECTOR_PRICE +void MamaFieldCacheFieldPriceVector::set(MamaFieldCacheField& field, + const MamaPrice* values, + mama_size_t size) +{ + checkType(field); + mamaPrice* cvalues = new mamaPrice[size]; + for (mama_size_t i = 0; i < size; ++i) + { + cvalues[i] = values[i].getCValue(); + } + mamaFieldCacheField_setPriceVector(field.getCValue(), cvalues, size); + delete[] cvalues; +} +void MamaFieldCacheFieldPriceVector::get(const MamaFieldCacheField& field, + const MamaPrice*& values, + mama_size_t& size) const +{ + checkType(field); + const mamaPrice* cvalues = NULL; + mamaFieldCacheField_getPriceVector(field.getCValue(), &cvalues, &size); + grow(size); + for (mama_size_t i = 0; i < size; ++i) + { + // We should avoid the copy (if we could assign the CValue) + mamaPrice_copy(mValues[i].getCValue(), cvalues[i]); + } + values = mValues; +} +const MamaPrice* MamaFieldCacheFieldPriceVector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mamaPrice* values = NULL; + mama_size_t size = 0; + mamaFieldCacheField_getPriceVector(field.getCValue(), &values, &size); + if (index < size) + { + // We should avoid the copy (if we could assign the CValue) + mamaPrice_copy(mValue.getCValue(), values[index]); + return &mValue; + } + return NULL; +} + +// MAMA_FIELD_TYPE_VECTOR_TIME +void MamaFieldCacheFieldDateTimeVector::set(MamaFieldCacheField& field, + const MamaDateTime* values, + mama_size_t size) +{ + checkType(field); + mamaDateTime* cvalues = new mamaDateTime[size]; + for (mama_size_t i = 0; i < size; ++i) + { + cvalues[i] = values[i].getCValue(); + } + mamaFieldCacheField_setDateTimeVector(field.getCValue(), cvalues, size); + delete[] cvalues; +} +void MamaFieldCacheFieldDateTimeVector::get(const MamaFieldCacheField& field, + const MamaDateTime*& values, + mama_size_t& size) const +{ + checkType(field); + const mamaDateTime* cvalues = NULL; + mamaFieldCacheField_getDateTimeVector(field.getCValue(), &cvalues, &size); + grow(size); + for (mama_size_t i = 0; i < size; ++i) + { + // We should avoid the copy (if we could assign the CValue) + mamaDateTime_copy(mValues[i].getCValue(), cvalues[i]); + } + values = mValues; +} +const MamaDateTime* MamaFieldCacheFieldDateTimeVector::get(const MamaFieldCacheField& field, + mama_size_t index) const +{ + checkType(field); + const mamaDateTime* values; + mama_size_t size; + mamaFieldCacheField_getDateTimeVector(field.getCValue(), &values, &size); + if (index < size) + { + // We should avoid the copy (if we could assign the CValue) + mamaDateTime_copy(mValue.getCValue(), values[index]); + return &mValue; + } + return NULL; +} + + +void setFieldValue(MamaFieldCacheField& field, const char* value) +{ + MamaFieldCacheFieldString setField; + setField.set(field, value); +} + +void setFieldValue(MamaFieldCacheField& field, const MamaPrice& value) +{ + MamaFieldCacheFieldPrice setField; + setField.set(field, value); +} + +void setFieldValue(MamaFieldCacheField& field, const MamaDateTime& value) +{ + MamaFieldCacheFieldDateTime setField; + setField.set(field, value); +} + +void getFieldValue(const MamaFieldCacheField& field, const char*& value) +{ + MamaFieldCacheFieldString getField; + value = getField.get(field); +} + +void getFieldValue(const MamaFieldCacheField& field, MamaPrice& value) +{ + MamaFieldCacheFieldPrice getField; + value = getField.get(field); +} + +void getFieldValue(const MamaFieldCacheField& field, MamaDateTime& value) +{ + MamaFieldCacheFieldDateTime getField; + value = getField.get(field); +} + +void getFieldValue(const MamaFieldCacheField& field, + const char**& values, + mama_size_t& size) +{ + MamaFieldCacheFieldStringVector getField; + getField.get(field, values, size); +} + +void getFieldValue(const MamaFieldCacheField& field, + const MamaPrice*& values, + mama_size_t& size) +{ +// MamaFieldCacheFieldPriceVector getField; +// getField.get(field, values, size); + throw "getFieldValue for MamaPrice vector not implemented"; +} + +void getFieldValue(const MamaFieldCacheField& field, + const MamaDateTime*& values, + mama_size_t& size) +{ +// MamaFieldCacheFieldDateTimeVector getField; +// getField.get(field, values, size); + throw "getFieldValue for MamaDateTime vector not implemented"; +} + + +void mamaFieldCacheFieldFromString(MamaFieldCacheField& field, const std::string& value) +{ + std::istringstream is(value); + if (field.getType() == MAMA_FIELD_TYPE_STRING) + { + MamaFieldCacheFieldString f; + f.set(field, value.c_str(), value.size()); + return; + } + if (field.getType() == MAMA_FIELD_TYPE_PRICE) + { + MamaPrice val; + val.setFromString(value.c_str()); + MamaFieldCacheFieldPrice f; + f.set(field, val); + return; + } + if (field.getType() == MAMA_FIELD_TYPE_TIME) + { + MamaDateTime val; + val.setFromString(value.c_str()); + MamaFieldCacheFieldDateTime f; + f.set(field, val); + return; + } + switch (field.getType()) + { + case MAMA_FIELD_TYPE_CHAR: + { + char val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_CHAR>(), field, val); + break; + } + case MAMA_FIELD_TYPE_BOOL: + { + mama_bool_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_BOOL>(), field, val); + break; + } + case MAMA_FIELD_TYPE_I8: + { + mama_i8_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_I8>(), field, val); + break; + } + case MAMA_FIELD_TYPE_U8: + { + mama_u8_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_U8>(), field, val); + break; + } + case MAMA_FIELD_TYPE_I16: + { + mama_i16_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_I16>(), field, val); + break; + } + case MAMA_FIELD_TYPE_U16: + { + mama_u16_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_U16>(), field, val); + break; + } + case MAMA_FIELD_TYPE_I32: + { + mama_i32_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_I32>(), field, val); + break; + } + case MAMA_FIELD_TYPE_U32: + { + mama_u32_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_U32>(), field, val); + break; + } + case MAMA_FIELD_TYPE_I64: + { + mama_i64_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_I64>(), field, val); + break; + } + case MAMA_FIELD_TYPE_U64: + { + mama_u64_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_U64>(), field, val); + break; + } + case MAMA_FIELD_TYPE_F32: + { + mama_f32_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_F32>(), field, val); + break; + } + case MAMA_FIELD_TYPE_F64: + { + mama_f64_t val; + is >> val; + setV(Type<MAMA_FIELD_TYPE_F64>(), field, val); + break; + } + default: + break; + } +} + +} // namespace Wombat diff --git a/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheRecord.cpp b/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheRecord.cpp new file mode 100644 index 0000000..bfff3db --- /dev/null +++ b/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheRecord.cpp @@ -0,0 +1,152 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/cpp/fieldcache/MamaFieldCacheRecord.cpp#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include <mama/fieldcache/MamaFieldCacheRecord.h> +#include <mama/fieldcache/MamaFieldCacheField.h> +#include <mama/fieldcache/fieldcacherecord.h> + +namespace Wombat +{ + +struct MamaFieldCacheRecord::MamaFieldCacheRecordImpl +{ + MamaFieldCacheRecordImpl() + : mRecord(NULL) + { + } + ~MamaFieldCacheRecordImpl() + { + clear(); + } + + void clear(); + + mamaFieldCacheRecord mRecord; + mutable MamaFieldCacheField mField; +}; + +void MamaFieldCacheRecord::MamaFieldCacheRecordImpl::clear() +{ + // clear reusable container members + mField.getCValue() = NULL; + mField.clear(); +} + + +MamaFieldCacheRecord::MamaFieldCacheRecord() + : mPimpl(new MamaFieldCacheRecordImpl) +{ +} + +MamaFieldCacheRecord::~MamaFieldCacheRecord() +{ + mamaFieldCacheRecord_destroy(mPimpl->mRecord); + delete mPimpl; +} + +void MamaFieldCacheRecord::create() +{ + if (mPimpl->mRecord) + return; // Already created + + mamaFieldCacheRecord_create(&mPimpl->mRecord); +} + +MamaFieldCacheField& MamaFieldCacheRecord::add(mama_fid_t fid, + mamaFieldType type, + const char* name) +{ + mamaFieldCacheField cfield = NULL; + mamaFieldCacheRecord_add(mPimpl->mRecord, fid, type, name, &cfield); + mPimpl->mField.getCValue() = cfield; + return mPimpl->mField; +} + +MamaFieldCacheField& MamaFieldCacheRecord::add(const MamaFieldDescriptor& descriptor) +{ + mamaFieldCacheField cfield = NULL; + mamaFieldCacheRecord_add(mPimpl->mRecord, + descriptor.getFid(), + descriptor.getType(), + descriptor.getName(), + &cfield); + mPimpl->mField.getCValue() = cfield; + return mPimpl->mField; +} + +const MamaFieldCacheField& MamaFieldCacheRecord::operator[](mama_size_t index) const +{ + mamaFieldCacheField cfield = NULL; + mamaFieldCacheRecord_getField(mPimpl->mRecord, index, &cfield); + mPimpl->mField.getCValue() = cfield; + return mPimpl->mField; +} + +MamaFieldCacheField& MamaFieldCacheRecord::operator[](mama_size_t index) +{ + mamaFieldCacheField cfield = NULL; + mamaFieldCacheRecord_getField(mPimpl->mRecord, index, &cfield); + mPimpl->mField.getCValue() = cfield; + return mPimpl->mField; +} + +const MamaFieldCacheField& MamaFieldCacheRecord::find(mama_fid_t fid, + const char* name) const +{ + mamaFieldCacheField cfield = NULL; + mamaFieldCacheRecord_find(mPimpl->mRecord, fid, name, &cfield); + mPimpl->mField.getCValue() = cfield; + return mPimpl->mField; +} + +MamaFieldCacheField& MamaFieldCacheRecord::find(mama_fid_t fid, + const char* name) +{ + mamaFieldCacheField cfield = NULL; + mamaFieldCacheRecord_find(mPimpl->mRecord, fid, name, &cfield); + mPimpl->mField.getCValue() = cfield; + return mPimpl->mField; +} + +mama_size_t MamaFieldCacheRecord::getSize() const +{ + mama_size_t size = 0; + mamaFieldCacheRecord_getSize(mPimpl->mRecord, &size); + return size; +} + +void MamaFieldCacheRecord::clear() +{ + mamaFieldCacheRecord_clear(mPimpl->mRecord); + mPimpl->clear(); +} + +mamaFieldCacheRecord MamaFieldCacheRecord::getCValue() +{ + return mPimpl->mRecord; +} + +const mamaFieldCacheRecord MamaFieldCacheRecord::getCValue() const +{ + return mPimpl->mRecord; +} + +} // namespace Wombat diff --git a/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCache.h b/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCache.h new file mode 100644 index 0000000..e956889 --- /dev/null +++ b/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCache.h @@ -0,0 +1,332 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCache.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MAMA_FIELD_CACHE_CPP_H__ +#define MAMA_FIELD_CACHE_CPP_H__ + +#include <mama/mamacpp.h> +#include <mama/fieldcache/MamaFieldCacheField.h> +#include <mama/fieldcache/fieldcache.h> + +namespace Wombat +{ + class MamaMsg; + class MamaDictionary; + class MamaFieldCacheRecord; + +/** + * The <code>MamaFieldCache</code> class is a collection of unordered + * <code>MamaFieldCacheField</code> elements. This class provides methods for creating + * and finding fields, applying changes to the fields in the cache and populating + * a MamaMsg with the fields in cache. + */ +class MAMACPPExpDLL MamaFieldCache +{ +public: + /** + * The <code>MamaFieldCacheIterator</code> class provides a way to iterate over + * the fields contained in the cache. + * Two iterators are provided: one const and one non-const. + * To use it use the standard C++ notation <code>MamaFieldCache::iterator</code>. + */ + class MAMACPPExpDLL MamaFieldCacheIterator + { + protected: + MamaFieldCacheIterator(mamaFieldCache fieldCache); + public: + MamaFieldCacheIterator(const MamaFieldCacheIterator&); + ~MamaFieldCacheIterator(); + + MamaFieldCacheIterator& operator=(const MamaFieldCacheIterator& rhs); + + bool operator==(const MamaFieldCacheIterator& rhs) const; + bool operator!=(const MamaFieldCacheIterator& rhs) const; + + MamaFieldCacheIterator& operator++(); + + protected: + mamaFieldCacheIterator mIterator; + MamaFieldCacheField mField; + + private: + friend class MamaFieldCache; + }; + + /** + * Iterator type used to iterate over the fields contained in the cache. + * This iterator allows modification of fields in the cache. + */ + class MAMACPPExpDLL iterator : public MamaFieldCacheIterator + { + protected: + iterator(mamaFieldCache fieldCache); + + public: + typedef std::input_iterator_tag iterator_category; + typedef MamaFieldCacheField value_type; + typedef std::iterator_traits<MamaFieldCacheField> difference_type; + typedef MamaFieldCacheField* pointer; + typedef MamaFieldCacheField& reference; + + reference operator*(); + pointer operator->(); + + private: + friend class MamaFieldCache; + }; + /** + * Iterator type used to iterate over the fields contained in the cache. + * This iterator does not allow modification of fields in the cache. + */ + class MAMACPPExpDLL const_iterator : public MamaFieldCacheIterator + { + protected: + const_iterator(mamaFieldCache fieldCache); + + public: + const_iterator(const iterator& it); + + typedef std::input_iterator_tag iterator_category; + typedef MamaFieldCacheField value_type; + typedef std::iterator_traits<MamaFieldCacheField> difference_type; + typedef const MamaFieldCacheField* pointer; + typedef const MamaFieldCacheField& reference; + + reference operator*(); + pointer operator->(); + + private: + friend class MamaFieldCache; + }; + +public: + /** + * Constructor. + * Use <code>create</code> to create the actual cache. + */ + MamaFieldCache(); + + /** + * Destructor. + * This is called automatically when an object is destroyed. This method will + * clean all the memory allocated. + */ + virtual ~MamaFieldCache(); + + /** + * Create a MamaFieldCache. + */ + virtual void create(); + + /** + * Clear the <code>MamaFieldCache</code>. + * No fields will be present in the cache after this operation. The cache is + * ready to be used, as long as create has been called once. + */ + virtual void clear(); + + /** + * Return the number of fields in cache. + * + * @return The number of fields in cache. + */ + virtual mama_size_t getSize() const; + + /** + * Set if field modifications are tracked when creating a delta message. + * See method <code>getDeltaMessage</code>. + * When modifications are not tracked, then calling <code>getDeltaMessage</code> + * is the same as calling <code>getFullMessage</code>. + * + * @param value Specify whether field modifications will be tracked. + */ + virtual void setTrackModified(bool value); + + /** + * Return the value of the track modifications flag. + * + * @return Whether tracking modifications is enabled or not. + */ + virtual bool getTrackModified() const; + + /** + * Set if field names are used when adding fields to MamaMsg. + * See methods <code>getDeltaMessage</code> and <code>getFullMessage</code>. + * + * @param value Specify whether field names will be used. + */ + virtual void setUseFieldNames(bool value); + + /** + * Return the value of the use field names flag. + * + * @return Whether field names are enabled or not. + */ + virtual bool getUseFieldNames() const; + + /** + * Set if the cache uses a lock when some methods are called for thread safety. + * + * @param value Specify whether locking will be used. + */ + virtual void setUseLock(bool value); + + /** + * Return the value of the locking flag. + * + * @return Whether the cache is using a lock or not. + */ + virtual bool getUseLock() const; + + /** + * Lock the cache. + */ + virtual void lock(); + + /** + * Unlock the cache. + */ + virtual void unlock(); + + /** + * Retrieve a field from the cache. + * If the field is not found then NULL is returned. + * + * @param fid Field id of the field to look up. + * @param name Field name of the field to look up. + * @return The field in the cache (if present) + */ + virtual const MamaFieldCacheField* find(mama_fid_t fid, + const char* name = NULL) const; + + /** + * Retrieve a field from the cache. + * If the field is not found then NULL is returned. + * + * @param fid Field id of the field to look up. + * @param name Field name of the field to look up. + * @return The field in the cache (if present) + */ + virtual MamaFieldCacheField* find(mama_fid_t fid, + const char* name = NULL); + + /** + * Set the specified field as modified even if the value has not changed. + * @param field The field to set the modified flag to. + */ + virtual void setModified(MamaFieldCacheField& field); + + /** + * Update the cache content with the field given. + * If the field is already present, it will be updated, otherwise it will be + * added to the cache. + * + * @param field The field to use for updating the cache. + */ + virtual void apply(const MamaFieldCacheField& field); + + /** + * Update the cache content with the data contained in the message. + * + * @param msg Reference to a <code>MamaMsg</code> containing the fields to + * update in the cache. + * @param dict Reference to a <code>MamaDictionary</code> representing a data + * dictionary. + */ + virtual void apply(const MamaMsg& msg, const MamaDictionary* dict = NULL); + + /** + * Update the cache content with the data contained in the record. + * + * @param record Reference to a <code>MamaFieldCacheRecord</code> containing + * the fields to update in the cache. + */ + virtual void apply(const MamaFieldCacheRecord& record); + + /** + * Populate a MamaMsg with all the fields present in the cache. + * + * @param msg MamaMsg which will be populated with the fields from the cache. + */ + virtual void getFullMessage(MamaMsg& msg); + + /** + * Populate a MamaMsg with all the fields currently modified in the cache. + * Note that this method also resets the modification state of the modified fields. + * If trackModifications flag is set to false, then this method is the same as + * <code>getFullMessage</code>. + * + * @param msg MamaMsg which will be populated with the modified fields from the cache. + */ + virtual void getDeltaMessage(MamaMsg& msg); + + /** + * Clear the list of all the modified fields and reset the modified flags + * for all the modified fields in the cache. + */ + virtual void clearModifiedFields(); + + /** + * Return a constant iterator to the first field in the cache and allows to + * iterate over the fields in the cache. + * + * @return An iterator to the first element in the cache. + */ + virtual const_iterator begin() const; + + /** + * Return an iterator to the first field in the cache and allows to iterate + * over the fields in the cache. + * + * @return An iterator to the first element in the cache. + */ + virtual iterator begin(); + + /** + * Return a const iterator to an invalid element and allows to check if an + * iterator has arrived to the end (no more elements to iterate). + * The content of this iterator must not be accessed. + * + * @return An iterator to the first element in the cache. + */ + virtual const_iterator end() const; + + /** + * Return an iterator to an invalid element and allows to check if an iterator + * has arrived to the end (no more elements to iterate). + * The content of this iterator must not be accessed. + * + * @return An iterator to the first element in the cache. + */ + virtual iterator end(); + +private: + MamaFieldCache(const MamaFieldCache&); + MamaFieldCache& operator=(const MamaFieldCache&); + +private: + struct MamaFieldCacheImpl; + MamaFieldCacheImpl* mPimpl; +}; + +} // namespace Wombat + +#endif // MAMA_FIELD_CACHE_CPP_H__ diff --git a/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheField.h b/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheField.h new file mode 100644 index 0000000..1e1a6f0 --- /dev/null +++ b/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheField.h @@ -0,0 +1,216 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheField.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MAMA_FIELD_CACHE_FIELD_CPP_H__ +#define MAMA_FIELD_CACHE_FIELD_CPP_H__ + +#include <mama/mamacpp.h> +#include <mama/fieldcache/fieldcachetypes.h> +#include <mama/fieldcache/fieldcachefield.h> +#include <cstring> + +namespace Wombat +{ + + class MamaFieldDescriptor; + +/** + * The <code>MamaFieldCacheField</code> class is used to store the information on + * the type of a field and its value(s). This class does not provide methods to set + * and get the value (check the specific types of fields such as + * <code>MamaFieldCacheFieldBool<code/>). + */ +class MAMACPPExpDLL MamaFieldCacheField +{ +public: + /** + * Constructor. + * Use <code>create</code> to create the actual field. + */ + MamaFieldCacheField(); + /** + * Destructor. + * This is called automatically when an object is destroyed. This method will + * clean all the memory allocated. + */ + virtual ~MamaFieldCacheField(); + + /** + * Copy constructor. + * + * @param + */ + MamaFieldCacheField(const MamaFieldCacheField& rhs); + + /** + * Copy rhs into the current object. + * + * @param rhs The source MamaFielCacheField. + * @return The MamaFieldCacheField itself. + */ + MamaFieldCacheField& operator=(const MamaFieldCacheField& rhs); + + /** + * Return if the current field is equal to the specified field. + * + * @param rhs The other field to check equality. + * @return Whether the two fields are equal. + */ + bool operator==(const MamaFieldCacheField& rhs) const; + /** + * Return if the current field is different from the specified field. + * + * @param rhs The other field to check difference. + * @return Whether the two fields are different. + */ + bool operator!=(const MamaFieldCacheField& rhs) const; + + /** + * Create a MamaFieldCacheField. + * + * @param descriptor Descriptor of the field to create. + */ + virtual void create(const MamaFieldDescriptor& descriptor); + /** + * Create a MamaFieldCacheField. + * + * @param fid Field id of the field to create. + * @param type Field type of the field to create. + * @param name Name of the field to create. + */ + virtual void create(mama_fid_t fid, mamaFieldType type, const char* name = NULL); + + /** + * Clear the <code>MamaFieldCacheField</code>. + * The field is ready to be used, as long as create has been called once. + */ + virtual void clear(); + + /** + * Return the field id. + * If the field is not valid, then 0 is returned. + * + * @return The field id of the field. + */ + virtual mama_fid_t getFid() const; + + /** + * Return the field type. + * If the field is not valid, then MAMA_FIELD_TYPE_UNKNOWN is returned. + * + * @return The field type of the field. + */ + virtual mamaFieldType getType() const; + + /** + * Return the name of the field. + * If the name is not set, then NULL is returned. + * @return + */ + const char* getName() const; + + /** + * Set the descriptor of the field. + * + * @param descriptor Pointer to the descriptor of the field. + */ + void setDescriptor(const MamaFieldDescriptor* descriptor); + + /** + * Return the descriptor of the field. + * If the descriptor is not set, NULL is returned. + * + * @return Pointer to the descriptor of the field. + */ + const MamaFieldDescriptor* getDescriptor() const; + + /** + * Return whether the field has been modified or not. + * + * @return Whether the field is modified. + */ + virtual bool isModified() const; + + /** + * Set the publish flag of the field. + * If set to false, the field is never published. + * + * @param value The publish flag. + */ + virtual void setPublish(bool value = true); + + /** + * Return the always publish flag of the field. + * + * @return The publish flag. + */ + virtual bool getPublish() const; + + /** + * Set the checkModifed flag of a field. + * If set to true, the field will be checked for modification before publishing. + * + * @param value The checkModified flag. + */ + virtual void setCheckModified(bool value = true); + + /** + * Return the checkModified flag of the field. + * + * @return The check modified flag. + */ + virtual bool getCheckModified() const; + + /** + * Return if the field is a vector (otherwise is a single-value field). + * + * @return If the field is a vector field. + */ + virtual bool isVector() const; + + mamaFieldCacheField& getCValue(); + const mamaFieldCacheField& getCValue() const; + +private: + struct MamaFieldCacheFieldImpl; + MamaFieldCacheFieldImpl* mPimpl; +}; + + +/** + * Base type for fields + */ +class MAMACPPExpDLL MamaFieldCacheFieldBase +{ +protected: + MamaFieldCacheFieldBase() {} + +public: + virtual ~MamaFieldCacheFieldBase() {} + +private: // Cannot copy MamaFieldCacheField objects + MamaFieldCacheFieldBase(const MamaFieldCacheFieldBase& field); + MamaFieldCacheFieldBase& operator=(const MamaFieldCacheFieldBase& field); +}; + +} // namespace Wombat + +#endif // MAMA_FIELD_CACHE_FIELD_CPP_H__ diff --git a/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheFieldTypes.h b/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheFieldTypes.h new file mode 100644 index 0000000..7da6586 --- /dev/null +++ b/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheFieldTypes.h @@ -0,0 +1,1079 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheFieldTypes.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MAMA_FIELD_CACHE_FIELD_TYPES_CPP_H__ +#define MAMA_FIELD_CACHE_FIELD_TYPES_CPP_H__ + +#include <mama/mamacpp.h> +#include <mama/fieldcache/MamaFieldCacheField.h> +#include <mama/MamaPrice.h> +#include <mama/MamaDateTime.h> +#include <stdexcept> + +namespace Wombat +{ + +/** + * MamaFieldCacheFieldBasic. + * Base class for basic single-value types. Allows to set and get the value of the field. + */ +template <typename T, mamaFieldType fieldType> +class MAMACPPExpDLL MamaFieldCacheFieldBasic : public MamaFieldCacheFieldBase +{ +public: + virtual ~MamaFieldCacheFieldBasic() {} + + /** + * Set the field value. + * + * @param field The field to set the value to. + * @param value The new value of the field. + */ + void set(MamaFieldCacheField& field, const T& value); + /** + * Return the value of the field. + * + * @param field The field to get the value from. + * @return The value of the field. + */ + T get(const MamaFieldCacheField& field) const; + +protected: + void checkType(const MamaFieldCacheField& field) const + { + if (field.getType() != fieldType) + throw std::invalid_argument("MamaFieldCacheFieldBasic"); + } +}; + +// Basic single-value types +/** + * MamaFieldCacheFieldChar. + * Class used to set and get the value of a char single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<char, MAMA_FIELD_TYPE_CHAR> + MamaFieldCacheFieldChar; +/** + * MamaFieldCacheFieldBool. + * Class used to set and get the value of a bool single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_bool_t, MAMA_FIELD_TYPE_BOOL> + MamaFieldCacheFieldBool; +/** + * MamaFieldCacheFieldI8. + * Class used to set and get the value of a mama_i8_t single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_i8_t, MAMA_FIELD_TYPE_I8> + MamaFieldCacheFieldI8; +/** + * MamaFieldCacheFieldU8. + * Class used to set and get the value of a mama_u8_t single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_u8_t, MAMA_FIELD_TYPE_U8> + MamaFieldCacheFieldU8; +/** + * MamaFieldCacheFieldI16. + * Class used to set and get the value of a mama_i16_t single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_i16_t, MAMA_FIELD_TYPE_I16> + MamaFieldCacheFieldI16; +/** + * MamaFieldCacheFieldU16. + * Class used to set and get the value of a mama_u16_t single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_u16_t, MAMA_FIELD_TYPE_U16> + MamaFieldCacheFieldU16; +/** + * MamaFieldCacheFieldI32. + * Class used to set and get the value of a mama_i32_t single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_i32_t, MAMA_FIELD_TYPE_I32> + MamaFieldCacheFieldI32; +/** + * MamaFieldCacheFieldU32. + * Class used to set and get the value of a mama_u32_t single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_u32_t, MAMA_FIELD_TYPE_U32> + MamaFieldCacheFieldU32; +/** + * MamaFieldCacheFieldI64. + * Class used to set and get the value of a mama_i64_t single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_i64_t, MAMA_FIELD_TYPE_I64> + MamaFieldCacheFieldI64; +/** + * MamaFieldCacheFieldU64. + * Class used to set and get the value of a mama_u64_t single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_u64_t, MAMA_FIELD_TYPE_U64> + MamaFieldCacheFieldU64; +/** + * MamaFieldCacheFieldF32. + * Class used to set and get the value of a mama_f32_t single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_f32_t, MAMA_FIELD_TYPE_F32> + MamaFieldCacheFieldF32; +/** + * MamaFieldCacheFieldF64. + * Class used to set and get the value of a mama_f64_t single-value <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldBasic<mama_f64_t, MAMA_FIELD_TYPE_F64> + MamaFieldCacheFieldF64; + +// Special single-value types +/** + * MamaFieldCacheFieldString. + * Class used to set and get the value of a char* single-value <code>MamaFieldCacheField</code>. + */ +class MAMACPPExpDLL MamaFieldCacheFieldString : public MamaFieldCacheFieldBase +{ +public: + /** + * Set the field value. + * + * @param field The field to set the value to. + * @param value The new value of the field. + */ + void set(MamaFieldCacheField& field, const char* value, mama_size_t len = 0); + /** + * Return the value of the field. + * + * @param field The field to get the value from. + * @return The value of the field. + */ + const char* get(const MamaFieldCacheField& field) const; + +protected: + void checkType(const MamaFieldCacheField& field) const + { + if (field.getType() != MAMA_FIELD_TYPE_STRING) + throw std::invalid_argument("MamaFieldCacheFieldString"); + } +}; + +/** + * MamaFieldCacheFieldPrice. + * Class used to set and get the value of a MamaPrice single-value <code>MamaFieldCacheField</code>. + */ +class MAMACPPExpDLL MamaFieldCacheFieldPrice : public MamaFieldCacheFieldBase +{ +public: + /** + * Set the field value. + * + * @param field The field to set the value to. + * @param value The new value of the field. + */ + void set(MamaFieldCacheField& field, const MamaPrice& value); + /** + * Return the value of the field. + * + * @param field The field to get the value from. + * @return The value of the field. + */ + const MamaPrice& get(const MamaFieldCacheField& field) const; + +protected: + void checkType(const MamaFieldCacheField& field) const + { + if (field.getType() != MAMA_FIELD_TYPE_PRICE) + throw std::invalid_argument("MamaFieldCacheFieldPrice"); + } + +private: + mutable MamaPrice mPrice; +}; + +/** + * MamaFieldCacheFieldDateTime. + * Class used to set and get the value of a MamaDateTime single-value <code>MamaFieldCacheField</code>. + */ +class MAMACPPExpDLL MamaFieldCacheFieldDateTime : public MamaFieldCacheFieldBase +{ +public: + /** + * Set the field value. + * + * @param field The field to set the value to. + * @param value The new value of the field. + */ + void set(MamaFieldCacheField& field, const MamaDateTime& value); + /** + * Return the value of the field. + * + * @param field The field to get the value from. + * @return The value of the field. + */ + const MamaDateTime& get(const MamaFieldCacheField& field) const; + +protected: + void checkType(const MamaFieldCacheField& field) const + { + if (field.getType() != MAMA_FIELD_TYPE_TIME) + throw std::invalid_argument("MamaFieldCacheFieldDateTime"); + } + +private: + mutable MamaDateTime mDateTime; +}; + + +/** + * MamaFieldCacheFieldVectorBasic. + * Base class for basic vector types. Allows to set and get the value of the field. + */ +template <typename T, mamaFieldType fieldType> +class MAMACPPExpDLL MamaFieldCacheFieldVectorBasic : public MamaFieldCacheFieldBase +{ +public: + /** + * Set the field value. + * + * @param field The field to set the values to. + * @param values The new values of the field. + * @param size The number of fields in <code>values</code>. + */ + void set(MamaFieldCacheField& field, const T* values, mama_size_t size); + /** + * Return the field values. + * + * @param field The field to get the values from. + * @param values A reference to the values to be returned. + * @param size A reference to the size of the vector to be returned. + */ + void get(const MamaFieldCacheField& field, const T*& values, mama_size_t& size) const; + /** + * Return the value of a specific field of a vector field. + * + * @param field The field to get the value from. + * @param index The index of the element of the vector to get the value from. + * @return The value of the field. + */ + const T& get(const MamaFieldCacheField& field, mama_size_t index) const; + +protected: + void checkType(const MamaFieldCacheField& field) const + { + if (field.getType() != fieldType) + throw std::invalid_argument("MamaFieldCacheFieldVectorBasic"); + } +}; + +/** + * MamaFieldCacheFieldI8Vector. + * Class used to set and get the value of a mama_i8_t vector <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldVectorBasic<mama_i8_t, MAMA_FIELD_TYPE_VECTOR_I8> + MamaFieldCacheFieldI8Vector; +/** + * MamaFieldCacheFieldU8Vector. + * Class used to set and get the value of a mama_u8_t vector <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldVectorBasic<mama_u8_t, MAMA_FIELD_TYPE_VECTOR_U8> + MamaFieldCacheFieldU8Vector; +/** + * MamaFieldCacheFieldI16Vector. + * Class used to set and get the value of a mama_i16_t vector <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldVectorBasic<mama_i16_t, MAMA_FIELD_TYPE_VECTOR_I16> + MamaFieldCacheFieldI16Vector; +/** + * MamaFieldCacheFieldU16Vector. + * Class used to set and get the value of a mama_u16_t vector <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldVectorBasic<mama_u16_t, MAMA_FIELD_TYPE_VECTOR_U16> + MamaFieldCacheFieldU16Vector; +/** + * MamaFieldCacheFieldI32Vector. + * Class used to set and get the value of a mama_i32_t vector <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldVectorBasic<mama_i32_t, MAMA_FIELD_TYPE_VECTOR_I32> + MamaFieldCacheFieldI32Vector; +/** + * MamaFieldCacheFieldU32Vector. + * Class used to set and get the value of a mama_u32_t vector <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldVectorBasic<mama_u32_t, MAMA_FIELD_TYPE_VECTOR_U32> + MamaFieldCacheFieldU32Vector; +/** + * MamaFieldCacheFieldI64Vector. + * Class used to set and get the value of a mama_i64_t vector <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldVectorBasic<mama_i64_t, MAMA_FIELD_TYPE_VECTOR_I64> + MamaFieldCacheFieldI64Vector; +/** + * MamaFieldCacheFieldU64Vector. + * Class used to set and get the value of a mama_u64_t vector <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldVectorBasic<mama_u64_t, MAMA_FIELD_TYPE_VECTOR_U64> + MamaFieldCacheFieldU64Vector; +/** + * MamaFieldCacheFieldF32Vector. + * Class used to set and get the value of a mama_f32_t vector <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldVectorBasic<mama_f32_t, MAMA_FIELD_TYPE_VECTOR_F32> + MamaFieldCacheFieldF32Vector; +/** + * MamaFieldCacheFieldF64Vector. + * Class used to set and get the value of a mama_f64_t vector <code>MamaFieldCacheField</code>. + */ +typedef MamaFieldCacheFieldVectorBasic<mama_f64_t, MAMA_FIELD_TYPE_VECTOR_F64> + MamaFieldCacheFieldF64Vector; + + +// Special vector types +/** + * MamaFieldCacheField: String vector field + */ +class MAMACPPExpDLL MamaFieldCacheFieldStringVector + : public MamaFieldCacheFieldBase +{ +public: + /** + * Set the values of a string vector field. + * + * @param field The field to set the values to. + * @param values The new values of the field. + * @param size The number of fields in <code>values</code>. + */ + void set(MamaFieldCacheField& field, const char** values, mama_size_t size); + /** + * Return the values of a string vector. + * + * @param field The field to get the values from. + * @param values A reference to the values to be returned. + * @param size A reference to the size of the vector to be returned. + */ + void get(const MamaFieldCacheField& field, const char**& values, mama_size_t& size) const; + /** + * Return the value of a specific field of a string vector field. + * + * @param field The field to get the value from. + * @param index The index of the element of the vector to get the value from. + * @return The value of the field. + */ + const char* get(const MamaFieldCacheField& field, mama_size_t index) const; + +protected: + void checkType(const MamaFieldCacheField& field) const + { + if (field.getType() != MAMA_FIELD_TYPE_VECTOR_STRING) + throw std::invalid_argument("MamaFieldCacheFieldStringVector"); + } +}; + + +template <typename T> +class MamaFieldCacheFieldVector +{ +protected: + MamaFieldCacheFieldVector() + : mValues(NULL) + , mSize(0) + { + } + ~MamaFieldCacheFieldVector() + { + if (!mValues || !mSize) + { + return; + } + delete[] mValues; + } + + void grow(mama_size_t newSize) const + { + if (newSize <= mSize) + return; + + T* newVector = new T[newSize]; + for (mama_size_t i = 0; i < mSize; ++i) + { + newVector[i] = mValues[i]; + } + + if (mValues) + delete[] mValues; + + mValues = newVector; + mSize = newSize; + } + +protected: + mutable T* mValues; + mutable mama_size_t mSize; +}; + +/** + * MamaFieldCacheField: Price vector field + */ +class MAMACPPExpDLL MamaFieldCacheFieldPriceVector + : public MamaFieldCacheFieldBase + , public MamaFieldCacheFieldVector<MamaPrice> +{ +public: + /** + * Set the values of a MamaPrice vector field. + * + * @param field The field to set the values to. + * @param values The new values of the field. + * @param size The number of fields in <code>values</code>. + */ + void set(MamaFieldCacheField& field, const MamaPrice* values, mama_size_t size); + /** + * Return the values of a MamaPrice vector field. + * + * @param field The field to get the values from. + * @param values A reference to the values to be returned. + * @param size A reference to the size of the vector to be returned. + */ + void get(const MamaFieldCacheField& field, const MamaPrice*& values, mama_size_t& size) const; + /** + * Return the value of a specific field of a MamaPrice vector field. + * + * @param field The field to get the value from. + * @param index The index of the element of the vector to get the value from. + * @return The value of the field. + */ + const MamaPrice* get(const MamaFieldCacheField& field, mama_size_t index) const; + +protected: + void checkType(const MamaFieldCacheField& field) const + { + if (field.getType() != MAMA_FIELD_TYPE_VECTOR_PRICE) + throw std::invalid_argument("MamaFieldCacheFieldPriceVector"); + } + +private: + mutable MamaPrice mValue; +}; + +/** + * MamaFieldCacheField: DateTime vector field + */ +class MAMACPPExpDLL MamaFieldCacheFieldDateTimeVector + : public MamaFieldCacheFieldBase + , public MamaFieldCacheFieldVector<MamaDateTime> +{ +public: + /** + * Set the values of MamDateTime vector field. + * + * @param field The field to set the values to. + * @param values The new values of the field. + * @param size The number of fields in <code>values</code>. + */ + void set(MamaFieldCacheField& field, const MamaDateTime* values, mama_size_t size); + /** + * Return the values of a MamaDateTime vector field. + * + * @param field The field to get the values from. + * @param values A reference to the values to be returned. + * @param size A reference to the size of the vector to be returned. + */ + void get(const MamaFieldCacheField& field, const MamaDateTime*& values, mama_size_t& size) const; + /** + * Return the value of a specific field of a MamaDateTime vector field. + * + * @param field The field to get the value from. + * @param index The index of the element of the vector to get the value from. + * @return The value of the field. + */ + const MamaDateTime* get(const MamaFieldCacheField& field, mama_size_t index) const; + +protected: + void checkType(const MamaFieldCacheField& field) const + { + if (field.getType() != MAMA_FIELD_TYPE_VECTOR_TIME) + throw std::invalid_argument("MamaFieldCacheFieldTimeVector"); + } + +private: + mutable MamaDateTime mValue; +}; + + +/** + * Helper function to set the value of a String field. + * + * @param field The field to set the value to. + * @param value The value to set. + */ +void setFieldValue(MamaFieldCacheField& field, const char* value); + +/** + * Helper function to set the value of a MamaPrice field. + * + * @param field The field to set the value to. + * @param value The value to set. + */ +void setFieldValue(MamaFieldCacheField& field, const MamaPrice& value); + +/** + * Helper function to set the value of a MamaDateTime field. + * + * @param field The field to set the value to. + * @param value The value to set. + */ +void setFieldValue(MamaFieldCacheField& field, const MamaDateTime& value); + +/* +template <class Field, class Value> +void setFieldValue(MamaFieldCacheField& field, const Value& value) +{ + Field setField; + setField.set(field, value); +} +*/ + +template <mamaFieldType fieldType> +class Type +{ +}; + +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_CHAR> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldChar setField; + setField.set(field, value); +} + +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_BOOL> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldBool setField; + setField.set(field, value); +} + +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_I8> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldI8 setField; + setField.set(field, value); +} +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_U8> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldU8 setField; + setField.set(field, value); +} + +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_I16> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldI16 setField; + setField.set(field, value); +} +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_U16> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldU16 setField; + setField.set(field, value); +} + +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_I32> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldI32 setField; + setField.set(field, value); +} +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_U32> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldU32 setField; + setField.set(field, value); +} + +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_I64>, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldI64 setField; + setField.set(field, value); +} +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_U64> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldU64 setField; + setField.set(field, value); +} + +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_F32> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldF32 setField; + setField.set(field, value); +} +template <typename T> +void setV(Type<MAMA_FIELD_TYPE_F64> type, MamaFieldCacheField& field, const T& value) +{ + MamaFieldCacheFieldF64 setField; + setField.set(field, value); +} + +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_CHAR> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldChar getField; + value = getField.get(field); +} + +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_BOOL> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldBool getField; + value = getField.get(field); +} + +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_I8> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldI8 getField; + value = getField.get(field); +} +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_U8> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldU8 getField; + value = getField.get(field); +} + +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_I16> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldI16 getField; + value = getField.get(field); +} +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_U16> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldU16 getField; + value = getField.get(field); +} + +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_I32> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldI32 getField; + value = getField.get(field); +} +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_U32> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldU32 getField; + value = getField.get(field); +} + +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_I64> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldI64 getField; + value = getField.get(field); +} +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_U64> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldU64 getField; + value = getField.get(field); +} + +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_F32> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldF32 getField; + value = getField.get(field); +} +template <typename T> +void getV(Type<MAMA_FIELD_TYPE_F64> type, const MamaFieldCacheField& field, T& value) +{ + MamaFieldCacheFieldF64 getField; + value = getField.get(field); +} + +/** + * Helper function to set the value of a generic single-value field. + * + * @param field The field to set the value to. + * @param value The value to set. + */ +template <typename T> +void setFieldValue(MamaFieldCacheField& field, const T& value) +{ + switch(field.getType()) + { + case MAMA_FIELD_TYPE_CHAR: + { + setV(Type<MAMA_FIELD_TYPE_CHAR>(), field, value); + break; + } + case MAMA_FIELD_TYPE_BOOL: + { + setV(Type<MAMA_FIELD_TYPE_BOOL>(), field, value); + break; + } + case MAMA_FIELD_TYPE_I8: + { + setV(Type<MAMA_FIELD_TYPE_I8>(), field, value); + break; + } + case MAMA_FIELD_TYPE_U8: + { + setV(Type<MAMA_FIELD_TYPE_U8>(), field, value); + break; + } + case MAMA_FIELD_TYPE_I16: + { + setV(Type<MAMA_FIELD_TYPE_I16>(), field, value); + break; + } + case MAMA_FIELD_TYPE_U16: + { + setV(Type<MAMA_FIELD_TYPE_U16>(), field, value); + break; + } + case MAMA_FIELD_TYPE_I32: + { + setV(Type<MAMA_FIELD_TYPE_I32>(), field, value); + break; + } + case MAMA_FIELD_TYPE_U32: + { + setV(Type<MAMA_FIELD_TYPE_U32>(), field, value); + break; + } + case MAMA_FIELD_TYPE_I64: + { + setV(Type<MAMA_FIELD_TYPE_I64>(), field, value); + break; + } + case MAMA_FIELD_TYPE_U64: + { + setV(Type<MAMA_FIELD_TYPE_U64>(), field, value); + break; + } + case MAMA_FIELD_TYPE_F32: + { + setV(Type<MAMA_FIELD_TYPE_F32>(), field, value); + break; + } + case MAMA_FIELD_TYPE_F64: + { + setV(Type<MAMA_FIELD_TYPE_F64>(), field, value); + break; + } + default: + break; + } +} + +/** + * Helper function to get the value of a string field. + * + * @param field The field to get the value from. + * @param value The value to return. + */ +void getFieldValue(const MamaFieldCacheField& field, const char*& value); + +/** + * Helper function to get the value of a MamaPrice field. + * + * @param field The field to get the value from. + * @param value The value to return. + */ +void getFieldValue(const MamaFieldCacheField& field, MamaPrice& value); + +/** + * Helper function to get the value of a MamaDateTime field. + * + * @param field The field to get the value from. + * @param value The value to return. + */ +void getFieldValue(const MamaFieldCacheField& field, MamaDateTime& value); + +/** + * Helper function to get the value of a generic single-value field. + * + * @param field The field to get the value from. + * @param value The value to return. + */ +template <typename T> +void getFieldValue(const MamaFieldCacheField& field, T& value) +{ + switch(field.getType()) + { + case MAMA_FIELD_TYPE_CHAR: + { + getV(Type<MAMA_FIELD_TYPE_CHAR>(), field, value); + break; + } + case MAMA_FIELD_TYPE_BOOL: + { + getV(Type<MAMA_FIELD_TYPE_BOOL>(), field, value); + break; + } + case MAMA_FIELD_TYPE_I8: + { + getV(Type<MAMA_FIELD_TYPE_I8>(), field, value); + break; + } + case MAMA_FIELD_TYPE_U8: + { + getV(Type<MAMA_FIELD_TYPE_U8>(), field, value); + break; + } + case MAMA_FIELD_TYPE_I16: + { + getV(Type<MAMA_FIELD_TYPE_I16>(), field, value); + break; + } + case MAMA_FIELD_TYPE_U16: + { + getV(Type<MAMA_FIELD_TYPE_U16>(), field, value); + break; + } + case MAMA_FIELD_TYPE_I32: + { + getV(Type<MAMA_FIELD_TYPE_I32>(), field, value); + break; + } + case MAMA_FIELD_TYPE_U32: + { + getV(Type<MAMA_FIELD_TYPE_U32>(), field, value); + break; + } + case MAMA_FIELD_TYPE_I64: + { + getV(Type<MAMA_FIELD_TYPE_I64>(), field, value); + break; + } + case MAMA_FIELD_TYPE_U64: + { + getV(Type<MAMA_FIELD_TYPE_U64>(), field, value); + break; + } + case MAMA_FIELD_TYPE_F32: + { + getV(Type<MAMA_FIELD_TYPE_F32>(), field, value); + break; + } + case MAMA_FIELD_TYPE_F64: + { + getV(Type<MAMA_FIELD_TYPE_F64>(), field, value); + break; + } + default: + break; + } +} + +/** + * Helper function to set the values of a generic vector field. + * + * @param field The field to set the values to. + * @param values The values to set. + * @param size The number of values in the field. + */ +template <typename T> +void setFieldValue(MamaFieldCacheField& field, const T* values, mama_size_t size) +{ + switch(field.getType()) + { + case MAMA_FIELD_TYPE_VECTOR_I8: + { + MamaFieldCacheFieldI8Vector getField; + getField.set(field, (const mama_i8_t*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U8: + { + MamaFieldCacheFieldU8Vector getField; + getField.set(field, (const mama_u8_t*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I16: + { + MamaFieldCacheFieldI16Vector getField; + getField.set(field, (const mama_i16_t*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U16: + { + MamaFieldCacheFieldU16Vector getField; + getField.set(field, (const mama_u16_t*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I32: + { + MamaFieldCacheFieldI32Vector getField; + getField.set(field, (const mama_i32_t*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U32: + { + MamaFieldCacheFieldU32Vector getField; + getField.set(field, (const mama_u32_t*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I64: + { + MamaFieldCacheFieldI64Vector getField; + getField.set(field, (const mama_i64_t*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U64: + { + MamaFieldCacheFieldU64Vector getField; + getField.set(field, (const mama_u64_t*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_F32: + { + MamaFieldCacheFieldF32Vector getField; + getField.set(field, (const mama_f32_t*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_F64: + { + MamaFieldCacheFieldF64Vector getField; + getField.set(field, (const mama_f64_t*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_STRING: + { + MamaFieldCacheFieldStringVector getField; + getField.set(field, (const char**)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_PRICE: + { + MamaFieldCacheFieldPriceVector getField; + getField.set(field, (const MamaPrice*)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_TIME: + { + MamaFieldCacheFieldDateTimeVector getField; + getField.set(field, (const MamaDateTime*)values, size); + break; + } + default: + break; + } +} + +/** + * Helper function to set the values of a string vector field. + * + * @param field The field to set the values to. + * @param values The values to set. + * @param size The number of values in the field. + */ +void getFieldValue(const MamaFieldCacheField& field, const char**& values, mama_size_t& size); + +// TODO: NOT IMPLEMENTED YET +// Need to fix the C++ MamaPrice and MamaDateTime interface to allow replacing +// the inner C structure (otherwise a copy is needed causing either a memory leak +// or an early delete. +void getFieldValue(const MamaFieldCacheField& field, const MamaPrice*& values, mama_size_t& size); + +void getFieldValue(const MamaFieldCacheField& field, const mamaDateTime*& values, mama_size_t& size); + +/** + * Helper function to get the values of a generic vector field. + * + * @param field The field to get the values from. + * @param values The values to return. + * @param size The number of values in the field. + */ +template <typename T> +void getFieldValue(const MamaFieldCacheField& field, const T*& values, mama_size_t& size) +{ + switch(field.getType()) + { + case MAMA_FIELD_TYPE_VECTOR_I8: + { + MamaFieldCacheFieldI8Vector getField; + getField.get(field, (const mama_i8_t*&)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U8: + { + MamaFieldCacheFieldU8Vector getField; + getField.get(field, (const mama_u8_t*&)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I16: + { + MamaFieldCacheFieldI16Vector getField; + getField.get(field, (const mama_i16_t*&)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U16: + { + MamaFieldCacheFieldU16Vector getField; + getField.get(field, (const mama_u16_t*&)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I32: + { + MamaFieldCacheFieldI32Vector getField; + getField.get(field, (const mama_i32_t*&)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U32: + { + MamaFieldCacheFieldU32Vector getField; + getField.get(field, (const mama_u32_t*&)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I64: + { + MamaFieldCacheFieldI64Vector getField; + getField.get(field, (const mama_i64_t*&)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_U64: + { + MamaFieldCacheFieldU64Vector getField; + getField.get(field, (const mama_u64_t*&)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_F32: + { + MamaFieldCacheFieldF32Vector getField; + getField.get(field, (const mama_f32_t*&)values, size); + break; + } + case MAMA_FIELD_TYPE_VECTOR_F64: + { + MamaFieldCacheFieldF64Vector getField; + getField.get(field, (const mama_f64_t*&)values, size); + break; + } + default: + break; + } +} + +void mamaFieldCacheFieldFromString(MamaFieldCacheField& field, const std::string& value); + +} // namespace Wombat + +#endif // MAMA_FIELD_CACHE_FIELD_TYPES_CPP_H__ diff --git a/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheRecord.h b/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheRecord.h new file mode 100644 index 0000000..0ee6bd0 --- /dev/null +++ b/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheRecord.h @@ -0,0 +1,130 @@ +/* $Id: //commsof_depot/platform/products/6.0/trunk/mama/c_cpp/src/cpp/mama/fieldcache/MamaFieldCacheRecord.h#1 $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef MAMA_FIELD_CACHE_RECORD_CPP_H__ +#define MAMA_FIELD_CACHE_RECORD_CPP_H__ + +#include <mama/mamacpp.h> +#include <mama/fieldcache/fieldcachetypes.h> +#include <string> + +namespace Wombat +{ + + class MamaFieldCacheField; + +/** + * The <code>MamaFieldCacheRecord</code> class is a collection of unordered + * <code>MamaFieldCacheField</code> elements. + */ +class MAMACPPExpDLL MamaFieldCacheRecord +{ +public: + /** + * Constructor. + * Use <code>create</code> to create the actual cache. + */ + MamaFieldCacheRecord(); + /** + * Destructor. + * This is called automatically when an object is destroyed. This method will + * clean all the memory allocated. + */ + virtual ~MamaFieldCacheRecord(); + + /** + * Creates a <code>MamaFieldCacheRecord</code>. + */ + virtual void create(); + + /** + * Clear the <code>MamaFieldCacheRecord</code>. + * No fields will be present in the record after this operation. The record is + * ready to be used, as long as create has been called once. + */ + virtual void clear(); + + /** + * Add and creates a <code>MamaFieldCacheField</code> to the record. + * The new field is then returned. + * + * @param fid Field id of the field to create. + * @param type Field type of the field to create. + * @param name Name of the field to create. + * @return The new field created. + */ + virtual MamaFieldCacheField& add(mama_fid_t fid, + mamaFieldType type, + const char* name = NULL); + + /** + * Add and creates a <code>MamaFieldCacheField</code> to the record. + * The new field is then returned. + * + * @param descriptor Descriptor of the field to create. + * @return The new field created. + */ + virtual MamaFieldCacheField& add(const MamaFieldDescriptor& descriptor); + + + virtual const MamaFieldCacheField& operator[](mama_size_t index) const; + virtual MamaFieldCacheField& operator[](mama_size_t index); + + /** + * Find a <code>MamaFieldCacheField</code> in the record. + * + * @param fid Field id of the field to look up. + * @param name Field name of the field to look up. + * @return The field in the record. + */ + virtual const MamaFieldCacheField& find(mama_fid_t fid, + const char* name = NULL) const; + + /** + * Find a <code>MamaFieldCacheField</code> in the record. + * + * @param fid Field id of the field to look up. + * @param name Field name of the field to look up. + * @return The field in the record. + */ + virtual MamaFieldCacheField& find(mama_fid_t fid, const char* name = NULL); + /** + * Return the number of fields present in the record. + * + * @return Size of the record. + */ + virtual mama_size_t getSize() const; + + virtual mamaFieldCacheRecord getCValue(); + virtual const mamaFieldCacheRecord getCValue() const; + +private: + MamaFieldCacheRecord(const MamaFieldCacheRecord&); + MamaFieldCacheRecord& operator=(const MamaFieldCacheRecord&); + +private: + struct MamaFieldCacheRecordImpl; + MamaFieldCacheRecordImpl* mPimpl; +}; + +} // namespace Wombat + +#endif diff --git a/mama/c_cpp/src/cpp/mamacpp.vcproj b/mama/c_cpp/src/cpp/mamacpp.vcproj index 89dd2f5..7b6e5dd 100644 --- a/mama/c_cpp/src/cpp/mamacpp.vcproj +++ b/mama/c_cpp/src/cpp/mamacpp.vcproj @@ -518,6 +518,22 @@ > </File> <File + RelativePath=".\mama\fieldcache\MamaFieldCacheField.h" + > + </File> + <File + RelativePath=".\mama\fieldcache\MamaFieldCacheFieldTypes.h" + > + </File> + <File + RelativePath=".\mama\fieldcache\MamaFieldCache.h" + > + </File> + <File + RelativePath=".\mama\fieldcache\MamaFieldCacheRecord.h" + > + </File> + <File RelativePath=".\mama\MamaSource.h" > </File> @@ -654,6 +670,22 @@ > </File> <File + RelativePath=".\fieldcache\MamaFieldCache.cpp" + > + </File> + <File + RelativePath=".\fieldcache\MamaFieldCacheField.cpp" + > + </File> + <File + RelativePath=".\fieldcache\MamaFieldCacheFieldTypes.cpp" + > + </File> + <File + RelativePath=".\fieldcache\MamaFieldCacheRecord.cpp" + > + </File> + <File RelativePath=".\mamacpp.cpp" > </File> diff --git a/mama/c_cpp/src/examples/c/Makefile.am b/mama/c_cpp/src/examples/c/Makefile.am index e348415..ebaaae8 100644 --- a/mama/c_cpp/src/examples/c/Makefile.am +++ b/mama/c_cpp/src/examples/c/Makefile.am @@ -49,7 +49,8 @@ bin_PROGRAMS = mamalistenc \ mamaio \ mamamultisubscriberc \ mamaftmemberc \ - mamasymbollistsubscriberc + mamasymbollistsubscriberc \ + mamalistencachedc
dist_mamalistenc_SOURCES = mamalistenc.c dist_mamaproxyc_SOURCES = mamaproxyc.c @@ -60,6 +61,7 @@ dist_mamaio_SOURCES = mamaio.c dist_mamasymbollistsubscriberc_SOURCES = mamasymbollistsubscriberc.c dist_mamamultisubscriberc_SOURCES = mamamultisubscriberc.c dist_mamaftmemberc_SOURCES = mamaftmemberc.c +dist_mamalistencachedc_SOURCES = mamalistencachedc.c
# Additional installation directory for sample source code exampledir = ${prefix}/examples/mama/c @@ -76,4 +78,5 @@ example_DATA = \ $(dist_mamainboxc_SOURCES) \ $(dist_mamaio_SOURCES) \ $(dist_mamasymbollistsubscriberc_SOURCES) \ + $(dist_mamalistencachedc_SOURCES) \ Makefile.sample diff --git a/mama/c_cpp/src/examples/c/Makefile.sample b/mama/c_cpp/src/examples/c/Makefile.sample index 6f2507d..092efae 100644 --- a/mama/c_cpp/src/examples/c/Makefile.sample +++ b/mama/c_cpp/src/examples/c/Makefile.sample @@ -47,7 +47,8 @@ all: mamalistenc mamainboxc \ mamapublisherc mamasubscriberc \ mamasymbollistsubscriberc \ mamaproxyc mamaio \ - mamamultisubscriberc mamaftmemberc + mamamultisubscriberc mamaftmemberc \ + mamalistencachedc
mamalistenc: mamalistenc.o $(LINK.C) -o $@ $^ $(MAMA_LIBS) $(SYS_LIBS) @@ -75,3 +76,7 @@ mamasymbollistsubscriberc: mamasymbollistsubscriberc.o
mamaftmemberc: mamaftmemberc.o $(LINK.C) -o $@ $^ $(MAMA_LIBS) $(SYS_LIBS) + +mamalistencachedc: mamalistencachedc.o + $(LINK.C) -o $@ $^ $(MAMA_LIBS) $(SYS_LIBS) + diff --git a/mama/c_cpp/src/examples/c/SConscript b/mama/c_cpp/src/examples/c/SConscript index 154c801..694a5e5 100644 --- a/mama/c_cpp/src/examples/c/SConscript +++ b/mama/c_cpp/src/examples/c/SConscript @@ -18,7 +18,8 @@ env.Append( LIBPATH = libPath ) env.Append( CPPPATH = [ includePath ] ) env.Append( LIBS = [ 'mama','pthread','m','wombatcommon','rt' ] )
-bins = [ 'mamalistenc','mamaproxyc','mamapublisherc','mamasubscriberc','mamainboxc','mamaio','mamasymbollistsubscriberc','mamamultisubscriberc','mamaftmemberc','mamasymbollistsubscriberc' ] +bins = [ 'mamalistenc','mamaproxyc','mamapublisherc','mamasubscriberc','mamainboxc','mamaio','mamasymbollistsubscriberc','mamamultisubscriberc','mamaftmemberc','mamasymbollistsubscriberc', +'mamalistencachedc' ]
binary = []
diff --git a/mama/c_cpp/src/examples/c/SConscript.win b/mama/c_cpp/src/examples/c/SConscript.win index 156c624..77ac387 100644 --- a/mama/c_cpp/src/examples/c/SConscript.win +++ b/mama/c_cpp/src/examples/c/SConscript.win @@ -14,6 +14,7 @@ binaries = Split(""" mamaproxyc mamasubscriberc mamasymbollistsubscriberc + mamalistencachedc """)
libs = [] diff --git a/mama/c_cpp/src/examples/c/mamalistencachedc.c b/mama/c_cpp/src/examples/c/mamalistencachedc.c new file mode 100644 index 0000000..abf0efb --- /dev/null +++ b/mama/c_cpp/src/examples/c/mamalistencachedc.c @@ -0,0 +1,2839 @@ +/* $Id: mamalistencachedc.c,v 1.1.2.19 2012/04/16 10:56:24 gmolloy Exp $ + * + * OpenMAMA: The open middleware agnostic messaging API + * Copyright (C) 2011 NYSE Technologies, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + * + * + * mamalistencachedc - Example Mama API market data subscriber. + * + * <pre> + * Illustrates the following MAMA API features: + * 1. Data dictionary initialization. + * 2. Creating a transport. + * 3. Creating different types of subscriptions (Snapshot, group etc) + * 4. Walking all received fields in messages. + * 5 Displaying only specific fields in a message. + * + * Examples: + * + * 1. Display data dictionary with dictionary requested from source + * "ORDER" (default dictionary symbol name space is "WOMBAT" and + * used in subsequent examples, below). + * + * mamalistencahedc -S ORDER -D -d ORDER -s MSFT.ISLD -tport tport_name + * + * 2. Subscribing to top-of-book MSFT quote from Island ITCH feed (all + * fields) where the feed handler source is SOURCE: + * + * mamalistencachedc -S ORDER -s MSFT.ISLD -tport tport_name + * + * 3. Subscribing to top-of-book MSFT & ORCL from Island ITCH feed + * (specific fields): + * + * mamalistencachedc -S ORDER -s MSFT.ISLD -s MSFT.ISLD wBidPrice wBidSize wAskPrice + * + * 4. Subscribing to a list of symbols from a file (all fields) and + * report updates quietly (an additional -q would eliminate printing + * of all normal updates): + * + * mamalistencachedc -q -f file -tport tport_name + * + * <pre> + * + */ + +#include "wombat/port.h" + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <signal.h> + +#include <mama/mama.h> +#include <mama/marketdata.h> +#include <mama/transport.h> +#include <mama/msgstatus.h> +#include <mama/status.h> +#include <mama/timer.h> +#include <mama/symbolmapfile.h> +#include <mama/fieldcache/fieldcache.h> +#include <mama/fieldcache/fieldcachefield.h> +#include <mama/fieldcache/fieldcacheiterator.h> + +#define MAX_FIELDS 1000 +#define MAX_SUBSCRIPTIONS 250000 + +static char *gUsageString[] = +{ +"Example Mama API market data subscriber, which stores fields using a MamaFieldCache.", +"", +"Usage: mamalistenachedc -S symbolNameSpace [-s symbol | -f symbolFile]", +" [-tport transportName] [-dict_tport transportName]", +" [-d dictSymbolNameSpace] [-vDgE?IL1qWB] [-DF fileName]", +" [-hw highWaterMark] [-lw lowWaterMark]", +" [-threads numThreads] [-r throttleRate]", +" [-t subscriptionTimeout] [-version (requires -m)] [-m middleware]", +"", +"Options:", +"All the standard mamalistenc options are available, plus the following:", +" -verifyCache verifies the content of the cache against the message received.", +" -verifyInterval changes the interval used for verification, (default 5s).", +" -no_display will not print out any field data.", +" -printCache Print content of the cache after printing the generated message.", +"", +NULL +}; + + +/* This structure is used when verifying data held in the field cache + * against a snapshot image of a subscription. + */ +typedef struct VerificationData +{ + /* The queue the subscription was created on. */ + mamaQueue m_queue; + + /* The symbol name. */ + const char *m_symbol; + + /* The timer being used to verify the data. */ + mamaTimer m_timer; + + /* The index of the subscription/cache */ + int mIndex; + +} VerificationData, * PVerificationData; + +/* These members represent command line parameters detailed in the gUsageString above. */ +static int gVerifyCache = 0; +static double gVerifyInterval = 5.0; +static int gNoDisplay = 0; +static int gPrintCache = 0; + +/* There must be 1 field cache per symbol. */ +static mamaFieldCache *gFieldCaches = NULL; +static int *gFieldCacheIndexes = NULL; + +static mamaTransport gTransport = 0 ; +static long gThrottle = -1; +static long gRecapThrottle = -1; +static int gMsgCount = 0; +static long gNumMsg = 0; +static long gNumMsgLast = 0; + long gTotalMsg = 0; +static int gInterval = 2; +static int gThreads = 0; +static int gHasCreatedThreads = 0; +static int gQualityForAll = 1; +static mamaQueue* gQueues = NULL; +static mamaDispatcher* gDispatchers = NULL; + +static const char* gTport = NULL; + +static const char* gDictTport = NULL; +static mamaTransport gDictTransport = NULL; + +static mamaDictionary gDictionary; +static const char* gDictSymbolNamespace = "WOMBAT"; +static int gDumpDataDict = 0; +static int gDictToFile = 0; +static int gDictFromFile = 0; +static const char* gDictFile = NULL; +static int gBuildDataDict = 1; +static int gExtractData = 1; + +static const char** gFieldList = NULL; +static int gNumFields = 0; + +static int gDictionaryComplete = 0; + +static int gGroupSubscription = 0; +static int gRequireInitial = 1; +static int gSnapshot = 0; +static double gTimeout = 10.0; +static int gQuietness = 0; +static int gPrintVersionAndExit= 0; + +static mamaSubscription* gSubscriptionList = NULL; + +static int gNumSubscriptions = 0; +static const char** gSymbolList = NULL; +static int gNumSymbols = 0; +static MamaLogLevel gSubscLogLevel = MAMA_LOG_LEVEL_NORMAL; +static const char* gFilename = NULL; +static const char* gMapFilename = NULL; +static mamaSymbolMapFile gSymbolMapFromFile = NULL; + +static int gNewIterators = 0; +static const char* gSymbolNamespace = NULL; +static mamaSource gSubscriptionSource = NULL; +static mamaSource gDictSource = NULL; +static const char* gMiddleware = "wmw"; +static mamaBridge gMamaBridge = NULL; +static mamaQueue gMamaDefaultQueue = NULL; +static const char* gAppName = NULL; +static size_t gHighWaterMark = 0; +static size_t gLowWaterMark = 0; + + +/* Contains the amount of time that the example program will run for, if set to 0 then it + * will run indefinitely. + */ +static int gShutdownTime = 0; + + +static void parseCommandLine (int argc, const char* argv[]); +static void initializeMama (void); + +static void buildDataDictionary (void); +static void dumpDataDictionary (void); +static void loadSymbolMap (void); +static void readSymbolsFromFile (void); +static void subscribeToSymbols (void); +static void mamashutdown (void); +static void setQueueMonitors (mamaQueue queue, int queueIndex); +static FILE* gLogFile = NULL; + +static void MAMACALLTYPE +subscriptionOnMsg (mamaSubscription subscription, + mamaMsg msg, + void* closure, + void* itemClosure); +static void MAMACALLTYPE +subscriptionOnQuality (mamaSubscription subsc, + mamaQuality quality, + const char* symbol, + short cause, + const void* platformInfo, + void* closure); + +static void MAMACALLTYPE +subscriptionOnError (mamaSubscription subscription, + mama_status status, + void* platformError, + const char* subject, + void* closure); +static void MAMACALLTYPE +subscriptionOnCreate (mamaSubscription subscription, + void* closure); + +static void displayFields (mamaMsg msg, + mamaSubscription subscription); +static void displaySpecificField(mamaFieldDescriptor field, + mamaMsg msg); +static void displayField (mamaMsgField field, + const mamaMsg msg, + int indentLevel); +static void displayAllFields (mamaMsg msg, + mamaSubscription subscription, + int indentLevel); + +static void MAMACALLTYPE +rateReporterCallback (mamaTimer timer, + void * closure); + +static void MAMACALLTYPE +timeoutCb (mamaDictionary dict, + void * closure); +static void MAMACALLTYPE +errorCb (mamaDictionary dict, + const char * errMsg, + void * closure); +static void MAMACALLTYPE +completeCb (mamaDictionary dict, + void * closure); + +static void MAMACALLTYPE +displayCb (const mamaMsg msg, + const mamaMsgField field, + void * closure); + +/*Callback for event queue high watermark monitoring.*/ +static void MAMACALLTYPE +highWaterMarkCallback (mamaQueue queue, + size_t size, + void* closure); + +/*Callback for event queue low watermark monitoring.*/ +static void MAMACALLTYPE +lowWaterMarkCallback (mamaQueue queue, + size_t size, + void* closure); + +static void MAMACALLTYPE +shutdownTimerCallback(mamaTimer timer, void *closure) +{ + /* Stop dispatching messages. */ + mama_stop(gMamaBridge); +} + + +void usage (int exitStatus); + + +static void MAMACALLTYPE +verifyTimerCallback(mamaTimer timer, void *closure); + +/* Function Prototypes. */ +mama_status checkFieldIntegrityIds(mamaMsgField field, mamaFieldCache fieldCache, int *test); +mama_status checkSnapshotIntegrity(mamaFieldCache fieldCache, mamaMsg message); +mama_status createFieldCaches(void); +mama_status createVerificationTimer(mamaQueue queue, const char *symbol, int index); +mama_status destroyFieldCaches(void); +void destroyVerificationTimer(PVerificationData data); +mama_status displayHeader(mamaMsg message, mamaSubscription subscription); +/* +mama_status getFieldAsString(char *buffer, long bufferLength, mamaMsgField field, mamaFieldType type); +*/ +mama_status printAllCacheFields(mamaFieldCache fieldCache); +/* +mama_status printAllMessageFields(mamaFieldCache fieldCache, mamaMsg message); +*/ +void printField(mamaFieldCacheField field); +/* +mama_status printFieldUsingId(mamaMsgField field, mamaFieldCache fieldCache); +*/ +/* +mama_status displayFields(mamaFieldCache fieldCache); +*/ + +int main (int argc, const char **argv) +{ + mamaTimer mamatimer; + mamaTimer shutdownTimer = NULL; + + gSymbolList = (const char**)calloc (MAX_SUBSCRIPTIONS, sizeof (char*)); + gFieldList = (const char**)calloc (MAX_FIELDS, sizeof (char*)); + + gSubscriptionList = (mamaSubscription*)calloc (MAX_SUBSCRIPTIONS, + sizeof (mamaSubscription)); + + parseCommandLine (argc, argv); + + if (gNumSymbols == 0 && !gPrintVersionAndExit) + { + readSymbolsFromFile (); + } + + initializeMama (); + + buildDataDictionary (); + dumpDataDictionary (); + loadSymbolMap (); + + /* Create all of the field caches, note that there is 1 per symbol. */ + createFieldCaches(); + + subscribeToSymbols (); + + printf ("Type CTRL-C to exit.\n"); + + if (gMsgCount) + { + printf ("Timestamp , Interval , Total\n"); + mamaTimer_create (&mamatimer, + gMamaDefaultQueue, + rateReporterCallback, + gInterval, + NULL); + } + + /* Create the shutdown timer. */ + if(gShutdownTime > 0) + { + mamaTimer_create(&shutdownTimer, gMamaDefaultQueue, shutdownTimerCallback, gShutdownTime, NULL); + } + + /* Start dispatching on the default event queue, this will block until Ctrl+C is pressed or the shutdown + * timer fires. + */ + mama_start (gMamaBridge); + + /* Destroy the shutdown timer if it was created. */ + if(shutdownTimer != NULL) + { + mamaTimer_destroy(shutdownTimer); + } + + /* Destroy all of the field caches. */ + destroyFieldCaches(); + + mamashutdown (); + + if (gMsgCount) + { + mamaTimer_destroy (mamatimer); + } + + return 0; +} + +/* +* Create subscriptions for all specified symbols. +*/ +static void subscribeToSymbols (void) +{ + int howMany = 0; + mama_status status = MAMA_STATUS_OK; + size_t i; + mamaMsgCallbacks callbacks; + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.onCreate = subscriptionOnCreate; + callbacks.onError = subscriptionOnError; + callbacks.onMsg = subscriptionOnMsg; + callbacks.onQuality = subscriptionOnQuality; + callbacks.onGap = NULL; + callbacks.onRecapRequest = NULL; + /* + * If use of multiple threads/queue was specified create a new mamaQueue + * and mamaDispatcher for each one + */ + if ((gThreads > 0) && (gHasCreatedThreads == 0)) + { + gQueues = (mamaQueue*)calloc + (gThreads, sizeof (mamaQueue)); + gDispatchers = (mamaDispatcher*)calloc + (gThreads, sizeof (mamaDispatcher)); + + for (i = 0; i < gThreads; i++) + { + if (MAMA_STATUS_OK != (status = mamaQueue_create (&gQueues[i], + gMamaBridge))) + { + fprintf (stderr, "Error creating queue %s\n", + mamaStatus_stringForStatus( status ) ); + exit(1); + } + + /*Set up queue monitors if specified.*/ + setQueueMonitors (gQueues[i], i); + + status = mamaDispatcher_create (&gDispatchers[i] , gQueues[i]); + + if (status != MAMA_STATUS_OK) + { + fprintf (stderr, "Error creating dispatcher %s\n", + mamaStatus_stringForStatus( status ) ); + exit(1); + } + } + gHasCreatedThreads = 1; + } + + for (i = 0; i < gNumSymbols; i++) + { + /*If there is more than one queue round robin accross them*/ + mamaQueue queue = gQueues == + NULL ? gMamaDefaultQueue : gQueues[i % gThreads]; + + { + + mamaSubscription_allocate (&gSubscriptionList[howMany]); + + mamaSubscription_setTimeout (gSubscriptionList[howMany], + gTimeout); + + if (gSnapshot) + { + /* Create a snapshot subscription */ + mamaSubscription_setServiceLevel (gSubscriptionList[howMany], + MAMA_SERVICE_LEVEL_SNAPSHOT, + 0); + } + else if (gGroupSubscription) + { + /* Create a group subscription */ + mamaSubscription_setSubscriptionType + (gSubscriptionList[howMany], + MAMA_SUBSC_TYPE_GROUP); + mamaSubscription_setRequiresInitial (gSubscriptionList[howMany], + gRequireInitial); + } + else + { + /* Create a regular market data subscription. */ + mamaSubscription_setRequiresInitial (gSubscriptionList[howMany], + gRequireInitial); + } + + /* + Logging at the individual subscription level can be controlled + independantly from the global logging level. + */ + mamaSubscription_setDebugLevel (gSubscriptionList[howMany], + gSubscLogLevel); + + /* Create a verification timer for this subscription and queue. */ + createVerificationTimer(queue, gSymbolList[i], i); + + /* + The subscription is not created immediately here. Rather an action + to create the subscription is placed on the throttle queue. + Creation of subscriptions starts once mama_start() is called + */ + status = mamaSubscription_create (gSubscriptionList[howMany], + queue, + &callbacks, + gSubscriptionSource, + gSymbolList[i], + (void*)&gFieldCacheIndexes[i]); + + } + + if (status != MAMA_STATUS_OK) + { + fprintf (stdout, + "Error creating subscription for %s. STATUS: %s\n", + gSymbolList[i], mamaStatus_stringForStatus(status)); + /* + fprintf (stderr, + "Error creating subscription for %s. STATUS: %s\n", + gSymbolList[i], mamaStatus_stringForStatus(status)); + */ + continue; + } + + if (++howMany % 1000 == 0) + { + printf ("Subscribed to %d subjects.\n", howMany); + } + } +} + +/* +* Write the contents of the data dictionary to screen. +*/ +static void dumpDataDictionary (void) +{ + mama_fid_t i = 0; + + /* + Write the data dictionary to the file system. + A data dictionary can be recreated from this file at a later stage. + */ + if (gDictToFile) + { + printf ("Writing dict to %s\n", gDictFile); + mamaDictionary_writeToFile (gDictionary, gDictFile); + } + + if (gDumpDataDict) + { + size_t size = 0; + + mamaDictionary_getSize (gDictionary, &size); + + printf ("Number of fields in dictionary: %d\n", (unsigned int)size ); + + for (i = 0; i < size; i++) + { + mamaFieldDescriptor field = NULL; + mamaDictionary_getFieldDescriptorByIndex (gDictionary, + &field, + i); + if (field) + { + const char* typeName = "unknown"; + char tmp[100]; + + switch (mamaFieldDescriptor_getType (field)) + { + case MAMA_FIELD_TYPE_STRING: + typeName = "string"; + break; + case MAMA_FIELD_TYPE_BOOL: + typeName = "boolean"; + break; + case MAMA_FIELD_TYPE_CHAR: + case MAMA_FIELD_TYPE_I8: + typeName = "char"; + break; + case MAMA_FIELD_TYPE_U8: + case MAMA_FIELD_TYPE_I16: + case MAMA_FIELD_TYPE_U16: + case MAMA_FIELD_TYPE_I32: + case MAMA_FIELD_TYPE_U32: + case MAMA_FIELD_TYPE_I64: + case MAMA_FIELD_TYPE_U64: + typeName = "integer"; + break; + case MAMA_FIELD_TYPE_F64: + typeName = "double"; + break; + case MAMA_FIELD_TYPE_PRICE: + typeName = "price"; + break; + default: + snprintf (tmp, 100, "unknown(%d)", + mamaFieldDescriptor_getType (field)); + typeName = tmp; + break; + } + printf (" %3d : %-7s : %s\n", + mamaFieldDescriptor_getFid(field), typeName, + mamaFieldDescriptor_getName(field)); + fflush(stdout); + } + } + } +} + +void MAMACALLTYPE +timeoutCb (mamaDictionary dict, void *closure) +{ + printf ("Timed out waiting for dictionary\n" ); + mama_stop(gMamaBridge); +} + +void MAMACALLTYPE +errorCb (mamaDictionary dict, const char *errMsg, void *closure) +{ + fprintf (stderr, "Error getting dictionary: %s\n", errMsg ); + mama_stop(gMamaBridge); +} + +void MAMACALLTYPE +completeCb (mamaDictionary dict, void *closure) +{ + gDictionaryComplete = 1; + /* + Stop processing events until all subscriptions have been created. + */ + mama_stop (gMamaBridge); +} + +static void buildDataDictionary (void) +{ + mamaDictionaryCallbackSet dictionaryCallback; + mama_status result = MAMA_STATUS_OK; + if (gBuildDataDict) + { + memset(&dictionaryCallback, 0, sizeof(dictionaryCallback)); + dictionaryCallback.onComplete = completeCb; + dictionaryCallback.onTimeout = timeoutCb; + dictionaryCallback.onError = errorCb; + + /* + The dictionary is created asychronously. The dictionary has been + successfully retreived once the onComplete callback has been + invoked. + */ + result = mama_createDictionary (&gDictionary, + gMamaDefaultQueue,/*Use the default event queue*/ + dictionaryCallback, + gDictSource, + 10.0, + 3, + NULL);/*Don't specify a closure*/ + + if (result != MAMA_STATUS_OK) + { + fprintf (stderr, "Exception creating " + "dictionary: MamaStatus: %s\n", + mamaStatus_stringForStatus (result)); + exit (1); + } + + /* + Start dispatching on the default event queue. Dispatching on the + queue is unblocked once one of the dictionary callbacks is invoked. + */ + mama_start (gMamaBridge); + + /* + True only if onComplete resulted in the unblocking of the queue + dispatching + */ + if (!gDictionaryComplete) + { + fprintf (stderr, "Could not create dictionary.\n" ); + exit(1); + } + + + } + else if (gDictFromFile) + { + mamaDictionary_create (&gDictionary); + mamaDictionary_populateFromFile( + gDictionary, + gDictFile); + } +} +static void mamashutdown (void) +{ + int i; + + /* Stop all the queues. */ + if (gQueues != NULL) + { + fprintf(stderr, "mamashutdown: destroying dispatch queues\n"); + for (i = 0; i < gThreads; i++) + { + mamaDispatcher_destroy (gDispatchers[i]); + } + free (gDispatchers); + } + + fprintf(stderr, "mamashutdown: free-ing symbol and field lists\n"); + for (i = 0; i < gNumSymbols; i++) + { + free ((char *)gSymbolList[i]); + } + free ((void*)gSymbolList); + + for (i = 0; i < gNumFields; i++) + { + free ((char *)gFieldList[i]); + } + free ((void *)gFieldList); + + + fprintf(stderr, "mamashutdown: destroying subscriptions\n"); + + { + + for (i = 0; i < gNumSymbols; i++) + { + if (gSubscriptionList[i]) + { + mamaSubscription_destroy (gSubscriptionList[i]); + mamaSubscription_deallocate (gSubscriptionList[i]); + } + } + free (gSubscriptionList); + } + + /* Destroy the source. */ + if(NULL != gSubscriptionSource) + { + mamaSource_destroy(gSubscriptionSource); + } + + if (gQueues != NULL) + { + fprintf(stderr, "mamashutdown: destroying queues\n"); + for (i = 0; i < gThreads; i++) + { + mamaQueue_destroyWait (gQueues[i]); + } + free (gQueues); + } + + /* Destroy the dictionary. */ + if (gDictionary != NULL) + { + fprintf(stderr, "mamashutdown: destroying dictionary\n"); + mamaDictionary_destroy(gDictionary); + } + + /* Destroy the dictionary source. */ + if(NULL != gDictSource) + { + mamaSource_destroy(gDictSource); + } + + if (gTransport != NULL) + { + fprintf(stderr, "mamashutdown: destroying transport\n"); + mamaTransport_destroy (gTransport); + } + + mama_close (); +} + +static void MAMACALLTYPE +transportCb (mamaTransport tport, + mamaTransportEvent ev, + short cause, + const void* platformInfo, + void* closure) +{ + printf ("Transport callback: %s\n", mamaTransportEvent_toString (ev)); +} + +/*Steps required for initializing the API*/ +void initializeMama (void) +{ + mama_status status = MAMA_STATUS_OK; + + /* + mama_setApplicationName should be called before mama_open(). + */ + if (gAppName) + { + mama_setApplicationName (gAppName); + } + + status = mama_loadBridge (&gMamaBridge, gMiddleware); + + if (gPrintVersionAndExit) + { + if (gMamaBridge != NULL) + { + printf ("%s\n",mama_getVersion(gMamaBridge)); + } + exit (0); + } + + if (MAMA_STATUS_OK!=status) + { + fprintf (stderr,"Could not open MAMA %s bridge.\n", + gMiddleware); + exit (1); + } + + /* + mama_open() should be the first MAMA API call made in an + application, with the exception of mama_loadBridge, + mama_setApplicationName(), mama_setApplicationClassName() + and mama_setProperty(). + It is reference counted. mama_close() must be called a + corresponding number of times. + */ + if (MAMA_STATUS_OK!=(status=mama_open ())) + { + fprintf (stderr, + "Failed to initialize MAMA STATUS: %d (%s)\n", status, + mamaStatus_stringForStatus (status)); + exit(1); + } + + /*Get the default event queue*/ + mama_getDefaultEventQueue (gMamaBridge, &gMamaDefaultQueue); + + /*Check if we are monitoring queue activity*/ + setQueueMonitors (gMamaDefaultQueue, -1); + + /*Using a single transport for all subscriptions*/ + status = mamaTransport_allocate (&gTransport); + + if (status != MAMA_STATUS_OK) + { + fprintf (stderr, + "Failed to allocate transport STATUS: %d %s\n", status, + mamaStatus_stringForStatus (status)); + exit(1); + } + + /*Register interest in transport related events*/ + status = mamaTransport_setTransportCallback(gTransport, transportCb, NULL); + + /*The default throttle rate is 500 msg/sec*/ + if (gThrottle != -1) + { + if (MAMA_STATUS_OK!=(status=mamaTransport_setOutboundThrottle (gTransport, + MAMA_THROTTLE_DEFAULT, + gThrottle))) + { + fprintf (stderr, "Could not set default throttle" + "rate [%s]\n", mamaStatus_stringForStatus (status)); + } + } + + /*The default recap throttle rate is 250 msg/sec*/ + if (gRecapThrottle != -1) + { + if (MAMA_STATUS_OK!=(status=mamaTransport_setOutboundThrottle (gTransport, + MAMA_THROTTLE_RECAP, + gRecapThrottle))) + { + fprintf (stderr, "Could not set recap throttle" + "rate [%s]\n", mamaStatus_stringForStatus (status)); + } + } + + /* Create the transport after any properties have been set. */ + if (MAMA_STATUS_OK!= + (status=mamaTransport_create (gTransport, gTport, gMamaBridge))) + { + fprintf (stderr, + "Failed to create transport STATUS: %d %s\n", status, + mamaStatus_stringForStatus (status)); + exit(1); + } + + if (!gQualityForAll) + { + mamaTransport_setInvokeQualityForAllSubscs (gTransport, 0); + } + + /* + The mamaSource replaces the individual specifying of the + symbolNameSpace and the transport. The mamaSource acts as a unique + identifier for a source of data. Multiple subscriptions will typically + be created using a single mamaSource instance. + */ + + /*The mamaSource used for all subscription creation*/ + if (MAMA_STATUS_OK!=(status=mamaSource_create (&gSubscriptionSource))) + { + fprintf (stderr, + "Failed to create subscription mamaSource STATUS: %d %s\n", + status, mamaStatus_stringForStatus (status)); + exit(1); + } + + mamaSource_setId (gSubscriptionSource, "Subscription_Source"); + mamaSource_setTransport (gSubscriptionSource, gTransport); + mamaSource_setSymbolNamespace (gSubscriptionSource, gSymbolNamespace); + + /*Specify a separate transport on which to retreive the dictioanry*/ + if (gDictTport != NULL) + { + fprintf (stderr, + "Creating data dictionary transport using name: %s\n", + gDictTport); + if (strlen(gDictTport)==0) gDictTport = NULL; + + status = mamaTransport_allocate (&gDictTransport); + status = mamaTransport_create (gDictTransport, gDictTport, gMamaBridge); + if (status != MAMA_STATUS_OK) + { + fprintf (stderr, + "Failed to create data dictionary transport STATUS: %d %s\n", + status, mamaStatus_stringForStatus (status)); + exit(1); + } + } + else + { + gDictTransport = gTransport; + } + + /*The mamaSource used for creating the dictionary*/ + if (MAMA_STATUS_OK!=(status=mamaSource_create (&gDictSource))) + { + fprintf (stderr, + "Failed to create dictionary mamaSource STATUS: %d %s\n", + status, mamaStatus_stringForStatus (status)); + exit(1); + } + + mamaSource_setId (gDictSource, "Dictionary_Source"); + mamaSource_setTransport (gDictSource, gDictTransport); + mamaSource_setSymbolNamespace (gDictSource, gDictSymbolNamespace); +} + +static void readSymbolsFromFile (void) +{ + /* get subjects from file or interactively */ + FILE* fp = NULL; + char charbuf[1024]; + + if (gFilename) + { + if ((fp = fopen (gFilename, "r")) == (FILE *)NULL) + { + perror (gFilename); + exit (1); + } + } + else + { + fp = stdin; + } + if (isatty(fileno (fp))) + { + printf ("Enter one symbol per line and terminate with a .\n"); + printf ("Symbol> "); + } + while (fgets (charbuf, 1023, fp)) + { + char *c = charbuf; + + /* Input terminate case */ + if (*c == '.') + break; + + /* replace newlines with NULLs */ + while ((*c != '\0') && (*c != '\n')) + c++; + *c = '\0'; + + gSymbolList[gNumSymbols++] = strdup (charbuf); + if (isatty(fileno (fp))) + printf ("Symbol> "); + } +} + +static void loadSymbolMap (void) +{ + if (gMapFilename) + { + mama_status status = mamaSymbolMapFile_create (&gSymbolMapFromFile); + if (status == MAMA_STATUS_OK) + { + status = mamaSymbolMapFile_load (gSymbolMapFromFile, + gMapFilename); + } + + if (status != MAMA_STATUS_OK) + { + fprintf (stderr, + "Failed to initialize symbol map file: %s\n", + gMapFilename); + exit (1); + } + + mamaTransport_setSymbolMapFunc ( + gTransport, + (mamaSymbolMapFunc)mamaSymbolMapFile_map, + gSymbolMapFromFile); + } +} + +static void parseCommandLine (int argc, const char** argv) +{ + int i = 1; + + for (i = 1; i < argc; ) + { + if ((strcmp (argv[i], "-S") == 0) || + (strcmp (argv[i], "-source") == 0)|| + (strcmp (argv[i], "-SN") == 0)|| + (strcmp (argv[i], "-symbolnamespace") == 0)) + { + gSymbolNamespace = argv[i + 1]; + i += 2; + } + else if (strcmp (argv[i], "-d") == 0) + { + gDictSymbolNamespace = argv[i + 1]; + i += 2; + } + else if (strcmp (argv[i], "-D") == 0) + { + gDumpDataDict = 1; + i++; + } + else if (strcmp (argv[i], "-DF") == 0) + { + gDictToFile = 1; + gDictFile = argv[i+1]; + i+=2; + } + else if (strcmp (argv[i], "-B") == 0) + { + gBuildDataDict = 0; + i++; + } + else if (strcmp (argv[i], "-I") == 0) + { + gRequireInitial = 0; + i++; + } + else if (strcmp (argv[i], "-g") == 0) + { + gGroupSubscription = 1; + i++; + } + else if (strcmp (argv[i], "-s") == 0) + { + if (argv[i + 1] != NULL) + { + gSymbolList[gNumSymbols++]=strdup (argv[i + 1]); + i += 2; + } + else + { + gSymbolList[gNumSymbols++]=""; + i += 2; + } + } + else if (strcmp (argv[i], "-f") == 0) + { + gFilename = argv[i + 1]; + i += 2; + } + else if (strcmp (argv[i], "-1") == 0) + { + gSnapshot = 1; + i++; + } + else if (strcmp ("-m", argv[i]) == 0) + { + gMiddleware = argv[i+1]; + i += 2; + } + else if (strcmp (argv[i], "-r") == 0) + { + gThrottle = strtol (argv[i+1], NULL, 10); + i += 2; + } + else if (strcmp (argv[i], "-rr") == 0) + { + gRecapThrottle = strtol (argv[i+1], NULL, 10); + i += 2; + } + else if (strcmp (argv[i], "-t") == 0) + { + gTimeout = strtod (argv[i+1], NULL); + i += 2; + } + else if (strcmp (argv[i], "-q") == 0) + { + gQuietness++; + i++; + } + else if (strcmp (argv[i], "-E") == 0) + { + gExtractData=0; + i++; + } + else if (strcmp (argv[i], "-c") == 0) + { + gMsgCount=1; + gInterval = strtol (argv[i+1], NULL,10); + if (gInterval < 1) + { + gInterval=2; + } + i+=2; + } + else if (strcmp (argv[i], "-mp") == 0) + { + gMapFilename = argv[i + 1]; + i += 2; + } + else if (strcmp (argv[i], "-threads") == 0) + { + gThreads = atoi (argv[i + 1]); + i += 2; + } + else if (strcmp (argv[i], "-A") == 0) + { + gQualityForAll = 0; + i++; + } + else if (strcmp (argv[i], "-tport") == 0) + { + gTport = argv[i+1]; + i += 2; + } + else if (strcmp (argv[i], "-dict_tport") == 0) + { + gDictTport = argv[i+1]; + i += 2; + } + else if (strcmp (argv[i], "-v") == 0) + { + if (mama_getLogLevel () == MAMA_LOG_LEVEL_WARN) + { + mama_enableLogging (stderr, MAMA_LOG_LEVEL_NORMAL); + } + else if (mama_getLogLevel () == MAMA_LOG_LEVEL_NORMAL) + { + mama_enableLogging (stderr, MAMA_LOG_LEVEL_FINE); + } + else if (mama_getLogLevel () == MAMA_LOG_LEVEL_FINE) + { + mama_enableLogging (stderr, MAMA_LOG_LEVEL_FINER); + } + else + { + mama_enableLogging (stderr, MAMA_LOG_LEVEL_FINEST); + } + i++; + } + else if ( strcmp( argv[i], "-log_file" ) == 0 ) + { + gLogFile = fopen( argv[i+1],"w+" ); + if( gLogFile == NULL) + { + fprintf (stderr, "Failed open log file %s\n",argv[i+1] ); + exit(1); + } + else + { + mama_enableLogging (gLogFile, mama_getLogLevel ()); + } + i += 2; + } + else if ( strcmp( argv[i], "-app" ) == 0 ) + { + gAppName = argv[i+1]; + i += 2; + } + else if ( strcmp( argv[i], "-ni" ) == 0 ) + { + gNewIterators = 1; + i++; + } + else if (strcmp( argv[i], "-hw" ) == 0) + { + gHighWaterMark = atoi (argv [i+1]); + i += 2; + } + else if (strcmp( argv[i], "-lw" ) == 0) + { + gLowWaterMark = atoi (argv [i+1]); + i += 2; + } + else if ( strcmp( argv[i], "-V" ) == 0 ) + { + if (gSubscLogLevel == MAMA_LOG_LEVEL_NORMAL) + { + gSubscLogLevel = MAMA_LOG_LEVEL_FINE; + } + else if (gSubscLogLevel == MAMA_LOG_LEVEL_FINE) + { + gSubscLogLevel = MAMA_LOG_LEVEL_FINER; + } + else + { + gSubscLogLevel = MAMA_LOG_LEVEL_FINEST; + } + + i++; + } + else if (strcmp (argv[i], "-version") == 0) + { + gPrintVersionAndExit = 1; + i+=1; + } + else if ((strcmp (argv[i], "-?") == 0)|| + ((strcmp (argv[i], "--help") == 0))) + { + usage (0); + } + else if (strcmp (argv[i], "-use_dict_file") == 0) + { + gDictFromFile = 1; + gBuildDataDict =0; + gDictFile = strdup (argv[i+1]); + i+=2; + } + + else if (strcmp ("-shutdown", argv[i]) == 0) + { + gShutdownTime = atoi (argv[i + 1]); + i += 2; + } + else if (strcmp (argv[i], "-verifyCache") == 0) + { + gVerifyCache = 1; + i++; + } + else if (strcmp (argv[i], "-verifyInterval") == 0) + { + gVerifyInterval = strtod (argv[i+1], NULL); + i += 2; + } + else if (strcmp (argv[i], "-no_display") == 0) + { + gNoDisplay = 1; + i++; + } + else if (strcmp (argv[i],"-printCache") == 0) + { + gPrintCache = 1; + i++; + } + else + { + gFieldList[gNumFields++] = strdup (argv[i]); + i++; + } + } +} + +/* + This callback function, passed to the mamaSubscription upon creation, is + where most of the processing within a MAMA based application will occur. + This callback is invoked for each message received by the API. +*/ +void MAMACALLTYPE +subscriptionOnMsg (mamaSubscription subscription, + mamaMsg msg, + void *closure, + void *itemClosure) +{ + mamaMsg message; + /* The closure is the index of the subscription within the list. */ + + mamaFieldCache fieldCache = NULL; + + int subscriptionIndex = 0; + + if (closure) + { + subscriptionIndex = *(int*)closure; + + /* Get the field cache for this symbol. */ + fieldCache = gFieldCaches[subscriptionIndex]; + } + + gNumMsg++; + + /* + The type and status of a mamaMsg can indicate how the message should + be interpretated. + */ + switch (mamaMsgType_typeForMsg (msg)) + { + case MAMA_MSG_TYPE_SNAPSHOT: + { + checkSnapshotIntegrity(fieldCache, msg); + return; + } + case MAMA_MSG_TYPE_DELETE: + case MAMA_MSG_TYPE_EXPIRE: + mamaSubscription_destroy (subscription); + mamaSubscription_deallocate (subscription); + gSubscriptionList[subscriptionIndex] = 0; + + if (--gNumSubscriptions == 0) + { + fprintf (stderr, + "Symbol deleted or expired. No more subscriptions\n"); + exit(1); + } + return; + default: + break; + } + + switch (mamaMsgStatus_statusForMsg (msg)) + { + case MAMA_MSG_STATUS_BAD_SYMBOL: + case MAMA_MSG_STATUS_EXPIRED: + case MAMA_MSG_STATUS_TIMEOUT: + mamaSubscription_destroy (subscription); + mamaSubscription_deallocate (subscription); + gSubscriptionList[subscriptionIndex] = 0; + + if (--gNumSubscriptions == 0) + { + fprintf (stderr, "Bad or expired symbol.\n" ); + exit(1); + } + return; + default: + break; + } + + /* Apply the message to the field cache. */ + mamaFieldCache_applyMessage(fieldCache, msg, gDictionary); + + mamaMsg_create(&message); + mamaFieldCache_getFullMessage(fieldCache, message); + + if (!gNoDisplay) + { + if (gNumFields == 0) + { + displayAllFields(message, subscription, 0); + } + else + { + displayFields(message, subscription); + } + + if (gPrintCache) + { + displayHeader(msg, subscription); + printAllCacheFields(fieldCache); + } + } + + mamaMsg_clear(message); + mamaFieldCache_getDeltaMessage(fieldCache, message); + mamaMsg_destroy(message); + + fflush(stdout); +} + +/* + The onQuality callback is invoked when the quality of a subscription + changes state. E.g. From OK to STALE and vise versa. +*/ +void MAMACALLTYPE +subscriptionOnQuality (mamaSubscription subsc, + mamaQuality quality, + const char* symbol, + short cause, + const void* platformInfo, + void* closure) +{ + printf ("Quality changed to %s for %s, cause %d, platformInfo: %s\n", + mamaQuality_convertToString (quality), symbol, cause, + platformInfo ? (char*)platformInfo: ""); +} + + +void displayFields(mamaMsg msg, mamaSubscription subscription ) +{ + const char* source = NULL; + const char* symbol = NULL; + int i = 0; + + mamaSubscription_getSource (subscription, &source); + mamaSubscription_getSymbol (subscription, &symbol); + + if (gQuietness < 2) + { + const char* issueSymbol = NULL; + mamaMsg_getString (msg, NULL, 305, &issueSymbol); + printf ("%s.%s.%s Type: %s Status %s \n", + issueSymbol, + source, + symbol, + mamaMsgType_stringForMsg (msg), + mamaMsgStatus_stringForMsg (msg)); + } + + for (i = 0; i < gNumFields; i++) + { + mamaFieldDescriptor field = NULL; + + /* + Get the field descriptor for the specified field from the data + dictionary. This will be used to extract data for that field from + the message. + */ + mamaDictionary_getFieldDescriptorByName ( + gDictionary, + &field, + gFieldList[i]); + + displaySpecificField (field, msg); + } + +} +/* +void displayFields(mamaFieldCache fieldCache) +{ + mama_status ret = MAMA_STATUS_OK; + mamaFieldCacheField cacheField = NULL; + int fieldIndex = 0; + mamaFieldDescriptor descriptor = NULL; + + while((ret == MAMA_STATUS_OK) && (fieldIndex < gNumFields)) + { + ret = mamaDictionary_getFieldDescriptorByName(gDictionary, + &descriptor, + gFieldList[fieldIndex]); + if(ret == MAMA_STATUS_OK) + { + ret = mamaFieldCache_find(fieldCache, + mamaFieldDescriptor_getFid(descriptor), + NULL, + &cacheField); + if(ret == MAMA_STATUS_OK) + { + printField(cacheField); + } + } + fieldIndex++; + } + return ret; +} +*/ + +void displaySpecificField (mamaFieldDescriptor field, + mamaMsg msg) +{ + const char* fieldName = NULL; + short fid = 0; + char value[256]; + + if (field == NULL) return; + + /* + The mamaFieldDescriptor contains meta data describing a fields + attributes. The name and the fid for a field can be obtained from the + descriptor. + */ + fieldName = mamaFieldDescriptor_getName (field); + fid = mamaFieldDescriptor_getFid (field); + + if (fieldName == NULL || strlen (fieldName) == 0) + { + mamaFieldDescriptor dictEntry; + mamaDictionary_getFieldDescriptorByFid (gDictionary, &dictEntry, fid); + + fieldName = mamaFieldDescriptor_getName (dictEntry); + } + + if (gQuietness < 3) + { + /* + If performance is an issue do not use getFieldAsString. Rather, use + the strongly typed accessors on the message or field objects. + For absolute performance use field iteration rather than direct + message access. + */ + mama_status status = mamaMsg_getFieldAsString (msg, + fieldName, + fid, + value, + 256); + if (gQuietness < 1) + { + if (MAMA_STATUS_NOT_FOUND == status) + { + sprintf (value,"%s","Field Not Found"); + } + + printf ("%-20s | %3d | %20s | %s\n", + fieldName, + fid, + mamaFieldDescriptor_getTypeName (field), + value); + } + } +} + +#define printData(value, format) \ +do \ +{ \ + if (gQuietness==0) \ + { \ + printf (format, value); \ + } \ +} while (0) \ + +void displayField (mamaMsgField field, const mamaMsg msg, int indentLevel) +{ + mamaFieldType fieldType = 0; + const char* fieldName = NULL; + const char* fieldTypeName = NULL; + uint16_t fid = 0; + const char* indentOffset = NULL; + const char* indentOffsetAll = "%-20s | %4d | %13s | "; + + if (!gExtractData)return; + + /*For formatting of output only*/ + switch (indentLevel) + { + case 0: + indentOffset = "%2s"; + break; + case 1: + indentOffset = "%4s"; + break; + case 2: + indentOffset = "%6s"; + break; + case 3: + indentOffset = "%8s"; + break; + default: + indentOffset = "%10s"; + } + + if (gQuietness<1) + { + printData ("",indentOffset); + /* + Attributes for a field can be obtained directly from the field + rather than from the field descriptor describing that field. + */ + mamaMsgField_getName (field, &fieldName); + mamaMsgField_getFid (field, &fid); + mamaMsgField_getTypeName (field, &fieldTypeName); + printf (indentOffsetAll, + fieldName ? fieldName : "", + fid, + fieldTypeName); + } + + /* + The most efficient way of extracting data while iterating fields is to + obtain the field type and then call the associated strongly typed + accessor. + + mamaMsgField_getAsString() will return a stringified version of the + data but is considerably less efficient and is not recommended for + production use. + */ + mamaMsgField_getType (field, &fieldType); + + switch (fieldType) + { + case MAMA_FIELD_TYPE_BOOL: + { + mama_bool_t result; + mamaMsgField_getBool (field, &result); + printData (result, "%d\n"); + break; + } + case MAMA_FIELD_TYPE_CHAR: + { + char result; + mamaMsgField_getChar (field, &result); + printData (result, "%c\n"); + break; + } + case MAMA_FIELD_TYPE_I8: + { + int8_t result; + mamaMsgField_getI8 (field, &result); + printData (result, "%d\n"); + break; + } + case MAMA_FIELD_TYPE_U8: + { + uint8_t result; + mamaMsgField_getU8 (field, &result); + printData (result, "%u\n"); + break; + } + case MAMA_FIELD_TYPE_I16: + { + int16_t result; + mamaMsgField_getI16 (field, &result); + printData (result, "%d\n"); + break; + } + case MAMA_FIELD_TYPE_U16: + { + uint16_t result; + mamaMsgField_getU16 (field, &result); + printData (result, "%u\n"); + break; + } + case MAMA_FIELD_TYPE_I32: + { + int32_t result; + mamaMsgField_getI32 (field, &result); + printData (result, "%d\n"); + break; + } + case MAMA_FIELD_TYPE_U32: + { + uint32_t result; + mamaMsgField_getU32 (field, &result); + printData (result, "%u\n"); + break; + } + case MAMA_FIELD_TYPE_I64: + { + int64_t result; + mamaMsgField_getI64 (field, &result); + printData (result, "%"PRId64"\n"); + break; + } + case MAMA_FIELD_TYPE_U64: + { + uint64_t result; + mamaMsgField_getU64 (field, &result); + printData (result, "%"PRId64"\n"); + break; + } + case MAMA_FIELD_TYPE_F32: + { + mama_f32_t result; + mamaMsgField_getF32 (field, &result); + printData (result, "%f\n"); + break; + } + case MAMA_FIELD_TYPE_F64: + { + mama_f64_t result; + mamaMsgField_getF64 (field, &result); + printData (result, "%f\n"); + break; + } + case MAMA_FIELD_TYPE_TIME: + { + mamaDateTime result = NULL; + char dateTimeString[56]; + mamaDateTime_create (&result); + mamaMsgField_getDateTime (field, result); + mamaDateTime_getAsString (result,dateTimeString, 56); + printData (dateTimeString, "%s\n"); + mamaDateTime_destroy (result); + break; + } + case MAMA_FIELD_TYPE_PRICE: + { + mamaPrice result; + char priceString[56]; + mamaPrice_create (&result); + mamaMsgField_getPrice (field, result); + mamaPrice_getAsString (result, priceString, 56); + printData (priceString, "%s\n"); + mamaPrice_destroy (result); + break; + } + case MAMA_FIELD_TYPE_STRING: + { + const char* result = NULL; + mamaMsgField_getString (field, &result); + printData (result, "%s\n"); + break; + } + case MAMA_FIELD_TYPE_VECTOR_STRING: + { + const char** result = NULL; + mama_size_t size = 0; + mama_size_t i; + mamaMsgField_getVectorString ( + field, + &result, + &size); + printData("","%s\n"); + for (i=0;i<size;i++) + { + printData("",indentOffset); + printData(result[i], " %s\n"); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_I32: + { + const mama_i32_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaMsgField_getVectorI32 (field,&result,&size); + printData("","%s\n"); + for (i=0;i<size;i++) + { + printData("", indentOffset); + printData(result[i], " %d\n"); + } + break; + } + + case MAMA_FIELD_TYPE_VECTOR_F64: + { + const mama_f64_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaMsgField_getVectorF64 (field,&result,&size); + printData("","%s\n"); + for (i=0;i<size;i++) + { + printData("", indentOffset); + printData(result[i], " %f\n"); + } + break; + } + case MAMA_FIELD_TYPE_MSG: + { + mamaMsg result; + mamaMsgField_getMsg (field, &result); + printData ("", "%s\n"); + displayAllFields (result, NULL, indentLevel+1); + break; + } + case MAMA_FIELD_TYPE_VECTOR_MSG: + { + /* + Vectors of messages are only supported using WomabtMsg as + the wire encoding data format. The example here + recursively prints all data in all messages. + */ + const mamaMsg* result; + mama_size_t resultLen; + int i; + mamaMsgField_getVectorMsg (field, &result, &resultLen); + printData ("", "%s\n"); + printData ("",indentOffset); + printData ("{", "%s\n"); + for (i=0;i<resultLen;i++) + { + displayAllFields (result[i], NULL, indentLevel+1); + } + printData ("",indentOffset); + printData ("}", "%s\n"); + break; + } + default: + { + printData ("Unknown", "%s\n"); + } + break; + }/*End switch*/ +} + +void MAMACALLTYPE +displayCb (const mamaMsg msg, + const mamaMsgField field, + void* closure) +{ + displayField (field, msg, (int)closure); +} + +void displayAllFields (mamaMsg msg, mamaSubscription subscription, int + indentLevel) +{ + mamaMsgField field = NULL; + mama_status status = MAMA_STATUS_OK; + + if (gQuietness < 2 && subscription) + { + const char* source = NULL; + const char* symbol = NULL; + const char* issueSymbol = NULL; + + mamaSubscription_getSource (subscription, &source); + mamaSubscription_getSymbol (subscription, &symbol); + mamaMsg_getString (msg, NULL, 305, &issueSymbol); + printf ("%s.%s.%s Type: %s Status %s \n", + issueSymbol == NULL ? "" : issueSymbol, + source == NULL ? "" : source, + symbol == NULL ? "" : symbol, + mamaMsgType_stringForMsg (msg), + mamaMsgStatus_stringForMsg (msg)); + } + + /* + Iterating over all the fields in a message is more efficient than + accessing data directly on the message object itself. When accessing + the message directly the message must first find the field before + returning the data. For messages which do not contain the requested + field this requires traversal of the whole message before returning. + Using the iteration approach requires that each field within the + message is only visited once. + */ + if (gNewIterators == 0) + { + mamaMsg_iterateFields (msg, displayCb, gDictionary, (void*)indentLevel); + } + else + { + if (gNewIterators != 0) + { + mamaMsgIterator iterator = NULL; + /*An iterator can be reused for efficiency - however, it cannot + be shared across all queues*/ + mamaMsgIterator_create(&iterator, gDictionary); + + if (MAMA_STATUS_OK!=(status=mamaMsgIterator_associate(iterator, msg))) + { + fprintf (stderr, "Could not associate iterator " + "with message. [%s]\n", mamaStatus_stringForStatus (status)); + } + else + { + while ((field = mamaMsgIterator_next(iterator)) != NULL) + { + displayField (field, msg, 0); + } + } + + mamaMsgIterator_destroy(iterator); + } + } +} + +/* + Creation of subscriptions is throttled by the API. The onCreate callback + is invoked whenther the subscription request is sent from the throttle + queue. +*/ + +void MAMACALLTYPE +subscriptionOnCreate (mamaSubscription subscription, void* closure) +{ + const char* source = NULL; + const char* symbol = NULL; + mamaQueue queue; + + gNumSubscriptions++; + mamaSubscription_getSource (subscription, &source); + mamaSubscription_getSymbol (subscription, &symbol); + + mamaSubscription_getQueue(subscription, &queue); + + if (gQuietness < 3) + { + fprintf(stdout, + "Created subscription: source=[%s], symbol=[%s]\n", + source, symbol); + } +} + +static void MAMACALLTYPE +subscriptionOnError (mamaSubscription subscription, + mama_status status, + void* platformError, + const char* subject, + void* closure) +{ + fprintf (stdout, + "An error occurred creating subscription for %s: %s\n", + subject ? subject : "(null)", + mamaStatus_stringForStatus (status)); +} + +static void MAMACALLTYPE +rateReporterCallback (mamaTimer timer, void* closure) +{ + int msgInterval = gNumMsg - gNumMsgLast; + char timeStr[20]; + mamaDateTime now; + + mamaDateTime_create (&now); + mamaDateTime_setToNow (now); + mamaDateTime_getAsFormattedString (now, timeStr, 20, "%F %T"); + mamaDateTime_destroy (now); + printf ("%s, %-10d, %-12ld\n", timeStr, msgInterval, gNumMsg); + gNumMsgLast = gNumMsg; +} + +void usage (int exitStatus) +{ + int i = 0; + while (gUsageString[i]!=NULL) + { + printf ("%s\n", gUsageString[i++]); + } + exit (exitStatus); +} + +static void MAMACALLTYPE +highWaterMarkCallback (mamaQueue queue, + size_t size, + void* closure) +{ + mama_status status = MAMA_STATUS_OK; + const char* queueName = NULL; + + if (queue) + { + if (MAMA_STATUS_OK!=(status=mamaQueue_getQueueName (queue, &queueName))) + { + fprintf (stderr, "Could not get queue name [%s]", + mamaStatus_stringForStatus (status)); + } + } + else /*Default queue*/ + { + queueName = "DEFAULT_QUEUE"; + } + + printf ("%s high water mark exceeded. Num events " + "on queue: %u\n", + queueName == NULL ? "" : queueName, size); +} + +static void MAMACALLTYPE +lowWaterMarkCallback (mamaQueue queue, + size_t size, + void* closure) +{ + mama_status status = MAMA_STATUS_OK; + const char* queueName = NULL; + + if (queue) + { + if (MAMA_STATUS_OK!=(status=mamaQueue_getQueueName (queue, &queueName))) + { + fprintf (stderr, "Could not get queue name [%s]", + mamaStatus_stringForStatus (status)); + } + } + else /*Default queue*/ + { + queueName = "DEFAULT_QUEUE"; + } + + printf ("%s low water mark exceeded. Num events on queue: %u\n", + queueName == NULL ? "" : queueName, size); +} + +void setQueueMonitors (mamaQueue queue, int queueIndex) +{ + if (gHighWaterMark>0 || gLowWaterMark>0) + { + mamaQueueMonitorCallbacks queueCallbacks; + char queueNameBuf[10]; + mama_status status = MAMA_STATUS_OK; + + snprintf (queueNameBuf, 10, "QUEUE %d", queueIndex); + + mamaQueue_setQueueName (queue, queueNameBuf); + + queueCallbacks.onQueueHighWatermarkExceeded = + highWaterMarkCallback; + queueCallbacks.onQueueLowWatermark = lowWaterMarkCallback; + + mamaQueue_setQueueMonitorCallbacks (queue, + &queueCallbacks, + NULL); + + if (gHighWaterMark>0) + { + if (MAMA_STATUS_OK!=(status=mamaQueue_setHighWatermark + (queue, gHighWaterMark))) + { + fprintf (stderr, + "Could not set high water mark for queue %s. [%s]", + queueNameBuf, + mamaStatus_stringForStatus (status)); + } + } + + if (gLowWaterMark>0) + { + if (MAMA_STATUS_OK!=(status=mamaQueue_setLowWatermark + (queue, gLowWaterMark))) + { + fprintf (stderr, + "Could not set low water mark for queue %s. [%s]", + queueNameBuf, + mamaStatus_stringForStatus (status)); + } + } + } + return; +} + +/* mamalistencachedc specific methods */ +mama_status checkFieldIntegrityIds(mamaMsgField field, mamaFieldCache fieldCache, int *test) +{ + mama_status ret = MAMA_STATUS_OK; + mamaFieldType type = 0; + mamaFieldCacheField fieldCacheField = NULL; + const char* fieldName = NULL; + int localTest = 1; + + mama_fid_t fieldId = 0; + ret = mamaMsgField_getFid(field, &fieldId); + if(ret == MAMA_STATUS_OK) + { + if(fieldId > WOMBAT_MAX_RESERVED_FID) + { + ret = mamaMsgField_getType(field, &type); + if(ret == MAMA_STATUS_OK) + { + mamaMsgField_getName(field, &fieldName); + ret = mamaFieldCache_find(fieldCache, fieldId, NULL, &fieldCacheField); + if(ret == MAMA_STATUS_OK) + { + switch (type) + { + case MAMA_FIELD_TYPE_BOOL: + { + mama_bool_t cacheVal = -1, msgVal; + mamaMsgField_getBool(field, &msgVal); + mamaFieldCacheField_getBool(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %d, %d", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_CHAR: + { + char cacheVal = '\0', msgVal; + mamaMsgField_getChar(field, &msgVal); + mamaFieldCacheField_getChar(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %d, %d", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_I8: + { + mama_i8_t cacheVal = -1, msgVal; + mamaMsgField_getI8(field, &msgVal); + mamaFieldCacheField_getI8(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %d, %d", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_U8: + { + mama_u8_t cacheVal = 1, msgVal; + mamaMsgField_getU8(field, &msgVal); + mamaFieldCacheField_getU8(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %d, %d", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_I16: + { + mama_i16_t cacheVal = -987, msgVal; + mamaMsgField_getI16(field, &msgVal); + mamaFieldCacheField_getI16(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %d, %d", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_U16: + { + mama_u16_t cacheVal = 987, msgVal; + mamaMsgField_getU16(field, &msgVal); + mamaFieldCacheField_getU16(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %d, %d", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_I32: + { + mama_i32_t cacheVal = -987, msgVal; + mamaMsgField_getI32(field, &msgVal); + mamaFieldCacheField_getI32(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %d, %d", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_U32: + { + mama_u32_t cacheVal = 987, msgVal; + mamaMsgField_getU32(field, &msgVal); + mamaFieldCacheField_getU32(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %d, %d", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_I64: + { + mama_i64_t cacheVal = -987, msgVal; + mamaMsgField_getI64(field, &msgVal); + mamaFieldCacheField_getI64(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %"PRId64", %"PRId64, + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_U64: + { + mama_u64_t cacheVal = 987, msgVal; + mamaMsgField_getU64(field, &msgVal); + mamaFieldCacheField_getU64(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %"PRId64", %"PRId64, + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_F32: + { + mama_f32_t cacheVal = -1, msgVal; + mamaMsgField_getF32(field, &msgVal); + mamaFieldCacheField_getF32(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %f, %f", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_F64: + { + mama_f64_t cacheVal = -1, msgVal; + mamaMsgField_getF64(field, &msgVal); + ret = mamaFieldCacheField_getF64(fieldCacheField, &cacheVal); + if (cacheVal != msgVal) + { + printf ("\nThe Failed Field is %s and the values are %g, %g", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_STRING: + { + const char *cacheVal = NULL, *msgVal = NULL; + mama_size_t len = 0; + mamaMsgField_getString(field, &msgVal); + mamaFieldCacheField_getString(fieldCacheField, &cacheVal, &len); + if (strcmp(cacheVal, msgVal) != 0) + { + printf ("\nThe Failed Field is %s and the values are %s, %s", + fieldName,msgVal,cacheVal); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_TIME: + { + mamaDateTime cacheVal = NULL, msgVal = NULL; + mama_u64_t msgValNumber, cacheValNumber; + mamaMsgField_getDateTime(field, msgVal); + mamaFieldCacheField_getDateTime(fieldCacheField, &cacheVal); + if (mamaDateTime_equal(msgVal, cacheVal) != 0) + { + mamaDateTime_getEpochTimeMicroseconds(msgVal, &msgValNumber); + mamaDateTime_getEpochTimeMicroseconds(cacheVal, &cacheValNumber); + printf ("\nThe Failed Field is %s and the values are %"PRId64", %"PRId64, + fieldName,msgValNumber,cacheValNumber); + localTest = 0; + } + break; + } + case MAMA_FIELD_TYPE_PRICE: + { + mamaPrice cacheVal = NULL, msgVal = NULL; + double msgValNumber, cacheValNumber; + mamaMsgField_getPrice(field, &msgVal); + mamaFieldCacheField_getPrice(fieldCacheField, &cacheVal); + if (mamaPrice_equal(msgVal, cacheVal) != 0) + { + mamaPrice_getValue(msgVal, &msgValNumber); + mamaPrice_getValue(cacheVal, &cacheValNumber); + printf ("\nThe Failed Field is %s and the values are %f, %f", + fieldName,msgValNumber,cacheValNumber); + localTest = 0; + } + break; + } + default: + printf("\nFailed: default"); + break; + } + } + else + { + printf("\nFailed: cannot find field in cache"); + } + } + else + { + printf("\nFailed: cannot get field type for field"); + } + } + } + else + { + printf("\nFailed: cannot get field if for field"); + } + + if(ret != MAMA_STATUS_OK) + { + localTest = 0; + } + + *test = localTest; + + return ret; +} + +mama_status checkSnapshotIntegrity(mamaFieldCache fieldCache, mamaMsg message) +{ + /* Create a new iterator. */ + mamaMsgIterator iterator = NULL; + mama_status ret = mamaMsgIterator_create(&iterator, gDictionary); + if(ret == MAMA_STATUS_OK) + { + /* Associate the iterator with the message. */ + ret = mamaMsgIterator_associate(iterator, message); + if(ret == MAMA_STATUS_OK) + { + /* This flag will be set to 1 for each field that has passed the test. */ + int test = 1; + + /* Create an enumerator. */ + mamaMsgField nextField = mamaMsgIterator_next(iterator); + + printf("Field cache integrity check start.\n"); + + /* Enumerate all the fields. */ + while((nextField != NULL) && (ret == MAMA_STATUS_OK) && (test == 1)) + { + /* Check the integrity of this field, if there is a dictionary then + * this will be done using field names. + */ + ret = checkFieldIntegrityIds(nextField, fieldCache, &test); + + /* Get the next field. */ + nextField = mamaMsgIterator_next(iterator); + } + + /* Print a message if all the tests passed. */ + if(test == 0) + { + printf ("\ncheckSnapshotIntegrity: FAILED"); + } + else + { + printf ("\ncheckSnapshotIntegrity: SUCCESSFUL"); + } + printf("\nField cache integrity check end.\n"); + } + + /* Destroy the iterator. */ + { + mama_status error = mamaMsgIterator_destroy(iterator); + if(ret == MAMA_STATUS_OK) + { + ret = error; + } + } + } + + return ret; +} + +mama_status createFieldCaches(void) +{ + mama_status ret = MAMA_STATUS_NOMEM; + int cacheIndex = 0; + + /* Allocate the array of field caches. */ + gFieldCaches = (mamaFieldCache *)calloc(gNumSymbols, sizeof(mamaFieldCache)); + if(gFieldCaches != NULL) + { + gFieldCacheIndexes = (int*)calloc(gNumSymbols, sizeof(int)); + /* Enumerate the array and create each one in turn. */ + cacheIndex = 0; + ret = MAMA_STATUS_OK; + while((ret == MAMA_STATUS_OK) && (cacheIndex<gNumSymbols)) + { + /* Create the cache with typical values and ensure that auto string format is on. */ + ret = mamaFieldCache_create(&gFieldCaches[cacheIndex]); + mamaFieldCache_setUseLock(gFieldCaches[cacheIndex], 0); + gFieldCacheIndexes[cacheIndex] = cacheIndex; + + /* Increment the loop counter. */ + cacheIndex++; + } + + /* If something went wrong then destroy the caches. */ + if(ret != MAMA_STATUS_OK) + { + destroyFieldCaches(); + } + } + + return ret; +} + +mama_status createVerificationTimer(mamaQueue queue, const char *symbol, int index) +{ + /* Returns. */ + mama_status ret = MAMA_STATUS_OK; + + /* If field cache data must be verified then create a timer that will obtain + * snapshot subscriptions at a regular interval. + */ + if((gVerifyCache == 1) && (gVerifyInterval > 0)) + { + /* Allocate a structure. */ + PVerificationData data = calloc(1, sizeof(VerificationData)); + ret = MAMA_STATUS_NOMEM; + if(data != NULL) + { + /* Save arguments in member variables. */ + data->m_queue = queue; + data->m_symbol = strdup(symbol); + data->mIndex = index; + { + /* Create the timer. */ + ret = mamaTimer_create(&data->m_timer, queue, verifyTimerCallback, gVerifyInterval, data); + + /* If it didn't work then delete the data object. */ + if(ret != MAMA_STATUS_OK) + { + destroyVerificationTimer(data); + } + } + } + } + + return ret; +} + +mama_status destroyFieldCaches(void) +{ + mama_status ret = MAMA_STATUS_OK; + int cacheIndex = 0; + + if(gFieldCaches != NULL) + { + return ret; + } + + /* Enumerate the array and destroy each one in turn. */ + for(cacheIndex=0; cacheIndex<gNumSymbols; cacheIndex++) + { + /* Destroy the cache and preserve the function return code. */ + mamaFieldCache_destroy(gFieldCaches[cacheIndex]); + } + + /* Free the array itself. */ + free(gFieldCaches); + gFieldCaches = NULL; + + free(gFieldCacheIndexes); + gFieldCacheIndexes = NULL; + + return ret; +} + +void destroyVerificationTimer(PVerificationData data) +{ + /* Only continue if the data is valid. */ + if(data != NULL) + { + /* Free the symbol. */ + if(data->m_symbol != NULL) + { + free((void *)data->m_symbol); + } + + /* Destroy the timer. */ + if(data->m_timer != NULL) + { + mamaTimer_destroy(data->m_timer); + } + + /* Delete the structure. */ + free(data); + } +} + +mama_status displayHeader(mamaMsg message, mamaSubscription subscription) +{ + mama_status ret = MAMA_STATUS_OK; + + if(gQuietness < 2) + { + const char* source = NULL; + ret = mamaSubscription_getSource(subscription, &source); + if(ret == MAMA_STATUS_OK) + { + const char* symbol = NULL; + ret = mamaSubscription_getSymbol(subscription, &symbol); + if(ret == MAMA_STATUS_OK) + { + const char* issueSymbol = NULL; + ret = mamaMsg_getString(message, NULL, 305, &issueSymbol); + if(ret == MAMA_STATUS_OK) + { + printf ("%s.%s.%s Type: %s Status %s \n", + issueSymbol, + source, + symbol, + mamaMsgType_stringForMsg(message), + mamaMsgStatus_stringForMsg(message)); + } + } + } + } + + return ret; +} + + +mama_status printAllCacheFields(mamaFieldCache fieldCache) +{ + mama_status ret = MAMA_STATUS_OK; + mamaFieldCacheIterator cacheIterator = NULL; + mamaFieldCacheField field = NULL; + mama_size_t size = 0; + + mamaFieldCache_getSize(fieldCache, &size); + printf("Cache size: %u\n", size); + + ret = mamaFieldCacheIterator_create(&cacheIterator, fieldCache); + while (mamaFieldCacheIterator_hasNext(cacheIterator)) + { + field = mamaFieldCacheIterator_next(cacheIterator); + printField(field); + } + + mamaFieldCacheIterator_destroy(cacheIterator); + return ret; +} +/* +mama_status printAllMessageFields(mamaFieldCache fieldCache, mamaMsg message) +{ + mama_status ret = MAMA_STATUS_OK; + mamaMsgIterator iterator = NULL; + mamaMsgField field = NULL; + + if (gPrintUsingName) + { + return MAMA_STATUS_INVALID_ARG; + } + + ret = mamaMsgIterator_create(&iterator, gDictionary); + ret = mamaMsgIterator_associate(iterator, message); + field = mamaMsgIterator_next(iterator); + while((field != NULL) && (ret == MAMA_STATUS_OK)) + { + ret = printFieldUsingId(field, fieldCache); + field = mamaMsgIterator_next(iterator); + } + + mamaMsgIterator_destroy(iterator); + return ret; +} +*/ +void printField(mamaFieldCacheField field) +{ + mama_fid_t fid; + mamaFieldType type; + const char *typeName; + char valueChar; + const char* valueStr; + mama_bool_t valueBool; + mama_i8_t valueI8; + mama_u8_t valueU8; + mama_i16_t valueI16; + mama_u16_t valueU16; + mama_i32_t valueI32; + mama_u32_t valueU32; + mama_i64_t valueI64; + mama_u64_t valueU64; + mama_f32_t valueFloat; + mama_f64_t valueDouble; + mama_size_t strLen; + const char *fieldName = ""; + mamaFieldDescriptor fieldDesc; + mama_bool_t modified = 0; + + if(gQuietness < 1) + { + char fieldBuffer[256] = ""; + + mamaFieldCacheField_getType(field, &type); + typeName = mamaFieldTypeToString(type); + + mamaFieldCacheField_getFid(field, &fid); + + mamaFieldCacheField_isModified(field, &modified); + + if(gDictionary != NULL) + { + mamaDictionary_getFieldDescriptorByFid(gDictionary, &fieldDesc, fid); + fieldName = mamaFieldDescriptor_getName(fieldDesc); + } + + sprintf( + fieldBuffer, + " %-30s | %4d | %10s | %c | ", + fieldName, + fid, + typeName, + modified ? '*': ' '); + printf("%s", (const char*)fieldBuffer); + + switch (type) + { + case MAMA_FIELD_TYPE_CHAR: + mamaFieldCacheField_getChar(field, &valueChar); + printf("%c\n", valueChar); + break; + case MAMA_FIELD_TYPE_BOOL: + mamaFieldCacheField_getBool(field, &valueBool); + printf("%d\n", valueBool); + break; + case MAMA_FIELD_TYPE_I8: + mamaFieldCacheField_getI8(field, &valueI8); + printf("%d\n", valueI8); + break; + case MAMA_FIELD_TYPE_U8: + mamaFieldCacheField_getU8(field, &valueU8); + printf("%d\n", valueU8); + break; + case MAMA_FIELD_TYPE_I16: + mamaFieldCacheField_getI16(field, &valueI16); + printf("%d\n", valueI16); + break; + case MAMA_FIELD_TYPE_U16: + mamaFieldCacheField_getU16(field, &valueU16); + printf("%d\n", valueU16); + break; + case MAMA_FIELD_TYPE_I32: + mamaFieldCacheField_getI32(field, &valueI32); + printf("%d\n", valueI32); + break; + case MAMA_FIELD_TYPE_U32: + mamaFieldCacheField_getU32(field, &valueU32); + printf("%d\n", valueU32); + break; + case MAMA_FIELD_TYPE_I64: + mamaFieldCacheField_getI64(field, &valueI64); + printf("%"PRId64"\n", valueI64); + break; + case MAMA_FIELD_TYPE_U64: + mamaFieldCacheField_getU64(field, &valueU64); + printf("%"PRId64"\n", valueU64); + break; + case MAMA_FIELD_TYPE_F32: + mamaFieldCacheField_getF32(field, &valueFloat); + printf("%f\n", valueFloat); + break; + case MAMA_FIELD_TYPE_F64: + mamaFieldCacheField_getF64(field, &valueDouble); + printf("%f\n", valueDouble); + break; + case MAMA_FIELD_TYPE_STRING: + mamaFieldCacheField_getString(field, &valueStr, &strLen); + printf("%s\n", valueStr); + break; + case MAMA_FIELD_TYPE_TIME: + { + const mamaDateTime result = NULL; + char dateTimeString[56]; + mamaFieldCacheField_getDateTime (field, &result); + mamaDateTime_getAsString (result,dateTimeString, 56); + printf ("%s\n", dateTimeString); + break; + } + case MAMA_FIELD_TYPE_PRICE: + { + const mamaPrice result = NULL; + char priceString[56]; + mamaFieldCacheField_getPrice (field, &result); + mamaPrice_getAsString (result, priceString, 56); + printf ("%s\n", priceString); + break; + } + case MAMA_FIELD_TYPE_VECTOR_I8: + { + const mama_i8_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaFieldCacheField_getI8Vector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %d\n", (int)result[i]); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_U8: + { + const mama_u8_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaFieldCacheField_getU8Vector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %d\n", (unsigned int)result[i]); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_I16: + { + const mama_i16_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaFieldCacheField_getI16Vector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %d\n", result[i]); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_U16: + { + const mama_u16_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaFieldCacheField_getU16Vector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %d\n", result[i]); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_I32: + { + const mama_i32_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaFieldCacheField_getI32Vector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %d\n", result[i]); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_U32: + { + const mama_u32_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaFieldCacheField_getU32Vector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %d\n", result[i]); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_I64: + { + const mama_i64_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaFieldCacheField_getI64Vector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %"PRId64"\n", result[i]); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_U64: + { + const mama_u64_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaFieldCacheField_getU64Vector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %"PRId64"\n", result[i]); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_F32: + { + const mama_f32_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaFieldCacheField_getF32Vector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %f\n", result[i]); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_F64: + { + const mama_f64_t* result = NULL; + mama_size_t size = 0; + mama_size_t i =0; + mamaFieldCacheField_getF64Vector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %f\n", result[i]); + } + break; + } + case MAMA_FIELD_TYPE_VECTOR_STRING: + { + const char** result = NULL; + mama_size_t size = 0; + mama_size_t i; + mamaFieldCacheField_getStringVector(field,&result,&size); + printf("\n"); + for (i=0;i<size;i++) + { + printf(" %s\n", result[i]); + } + break; + } + default: + break; + } + } +} + +/* +mama_status printFieldUsingId(mamaMsgField field, mamaFieldCache fieldCache) +{ + mama_status ret = MAMA_STATUS_OK; + + mama_fid_t id = 0; + ret = mamaMsgField_getFid(field, &id); + if(ret == MAMA_STATUS_OK) + { + mamaFieldType type = 0; + ret = mamaMsgField_getType(field, &type); + if(ret == MAMA_STATUS_OK) + { + mamaFieldCacheField cacheField = NULL; + ret = mamaFieldCache_find(fieldCache, id, NULL, &cacheField); + if(ret == MAMA_STATUS_OK) + { + printField(cacheField); + } + } + } + + return ret; +} +*/ + +static void MAMACALLTYPE +verifyTimerCallback(mamaTimer timer, void *closure) +{ + /* Cast the closure to a data structure. */ + PVerificationData verificationData = (PVerificationData)closure; + + /* We verify the cache by creating a snapshot subscription, when the callback + * is received the contents of the snapshot will be compared against the cache. + */ + mamaSubscription snapShotSubscription = NULL; + mama_status error = mamaSubscription_allocate(&snapShotSubscription); + if(error == MAMA_STATUS_OK) + { + /* Re-use all the existing callback functions. */ + mamaMsgCallbacks callbacks; + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.onCreate = subscriptionOnCreate; + callbacks.onError = subscriptionOnError; + callbacks.onMsg = subscriptionOnMsg; + callbacks.onQuality = subscriptionOnQuality; + callbacks.onGap = NULL; + callbacks.onRecapRequest = NULL; + + /* Set properties. */ + mamaSubscription_setTimeout(snapShotSubscription, 10.0); + mamaSubscription_setRetries(snapShotSubscription, 3); + mamaSubscription_setRequiresInitial(snapShotSubscription, 1); + + /* Create the subscription, note that it will be deleted whenever it expires. */ + mamaSubscription_createSnapshot(snapShotSubscription, verificationData->m_queue, &callbacks, + gSubscriptionSource, verificationData->m_symbol, &verificationData->mIndex); + } +} diff --git a/mama/c_cpp/src/examples/c/mamalistencachedc.vcproj b/mama/c_cpp/src/examples/c/mamalistencachedc.vcproj new file mode 100644 index 0000000..f068779 --- /dev/null +++ b/mama/c_cpp/src/examples/c/mamalistencachedc.vcproj @@ -0,0 +1,373 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="mamalistencachedc" + ProjectGUID="{14EEBB9E-9A32-47DC-9371-8E450F4AA587}" + RootNamespace="mamalistencachedc_vc7" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Dynamic-Debug|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="0" + BuildLogFile="$(IntDir)\$(TargetName).htm" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="$(API_HOME)\include" + PreprocessorDefinitions="WIN32;" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="libmamacmdd.lib ws2_32.lib" + OutputFile="$(OutDir)/mamalistencachedc_vc7.exe" + LinkIncremental="2" + AdditionalLibraryDirectories="$(API_HOME)\lib\dynamic-debug" + GenerateDebugInformation="true" + ProgramDatabaseFile="$(OutDir)/mamalistencachedc_vc7.pdb" + SubSystem="0" + TargetMachine="0" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Dynamic|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="0" + BuildLogFile="$(IntDir)\$(TargetName).htm" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="$(API_HOME)\include" + PreprocessorDefinitions="WIN32" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + CompileAs="1" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="libmamacmd.lib ws2_32.lib" + OutputFile="$(OutDir)/mamalistencachedc_vc7.exe" + LinkIncremental="1" + AdditionalLibraryDirectories="$(API_HOME)\lib\dynamic" + GenerateDebugInformation="true" + SubSystem="0" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Static|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="0" + BuildLogFile="$(IntDir)\$(TargetName).htm" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="$(API_HOME)\include" + PreprocessorDefinitions="WIN32; MAMA_STATIC" + RuntimeLibrary="0" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="shlwapi.lib libwombatcommonmt.lib libwcachemt.lib libmamacmt.lib libwombatmsgmt.lib $(PLATFORM_LIB) ws2_32.lib" + OutputFile="$(OutDir)/mamalistencachedc_vc7.exe" + LinkIncremental="1" + AdditionalLibraryDirectories="$(API_HOME)\lib\static" + GenerateDebugInformation="true" + SubSystem="0" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="0" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Static-Debug|Win32" + OutputDirectory="$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" + CharacterSet="0" + BuildLogFile="$(IntDir)\$(TargetName).htm" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="$(API_HOME)\include" + PreprocessorDefinitions="WIN32; MAMA_STATIC" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + AdditionalDependencies="shlwapi.lib libwombatcommonmtd.lib libwcachemtd.lib libmamacmtd.lib libwombatmsgmtd.lib $(PLATFORM_LIB_DEBUG) ws2_32.lib" + OutputFile="$(OutDir)/mamalistencachedc_vc7.exe" + LinkIncremental="2" + AdditionalLibraryDirectories="$(API_HOME)\lib\static-debug" + IgnoreDefaultLibraryNames="LIBCMT" + GenerateDebugInformation="true" + ProgramDatabaseFile="$(OutDir)/mamalistencachedc_vc7.pdb" + SubSystem="0" + TargetMachine="0" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\mamalistencachedc.c" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" + > + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/mama/c_cpp/src/examples/c/openmamalistencachedc.vcproj b/mama/c_cpp/src/examples/c/openmamalistencachedc.vcproj new file mode 100644 index 0000000..4851f64 --- /dev/null +++ b/mama/c_cpp/src/examples/c/openmamalistencachedc.vcproj @@ -0,0 +1,365 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="mamalistencachedc" + ProjectGUID="{77CDA662-CA86-4713-A549-4F1422BD44DA}" + RootNamespace="mamalistencachedc" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + <Platform + Name="x64" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories=""$(SOLUTIONDIR)\common\c_cpp\src\c\windows";"$(SOLUTIONDIR)\common\c_cpp\src\c";"$(SOLUTIONDIR)\mama\c_cpp\src\c"" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + ForcedIncludeFiles="wombat/targetsxs.h" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + OutputFile="$(OutDir)\mamalistencachedc.exe" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories=""$(SOLUTIONDIR)\common\c_cpp\src\c\windows";"$(SOLUTIONDIR)\common\c_cpp\src\c";"$(SOLUTIONDIR)\mama\c_cpp\src\c"" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + ForcedIncludeFiles="wombat/targetsxs.h" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="true" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Debug|x64" + OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)" + IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + TargetEnvironment="3" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories=""$(SOLUTIONDIR)\common\c_cpp\src\c\windows";"$(SOLUTIONDIR)\common\c_cpp\src\c";"$(SOLUTIONDIR)\mama\c_cpp\src\c"" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + ForcedIncludeFiles="wombat/targetsxs.h" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="17" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> |