You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by fi...@apache.org on 2012/08/02 16:56:39 UTC
svn commit: r1368502 - in /incubator/etch/trunk/binding-cpp/runtime:
include/util/EtchIdGenerator.h src/main/CMakeLists.txt
src/main/util/EtchIdGenerator.cpp
Author: fitzner
Date: Thu Aug 2 14:56:38 2012
New Revision: 1368502
URL: http://svn.apache.org/viewvc?rev=1368502&view=rev
Log:
ETCH-149: EtchIdGenerator Implementation
Change-Id: I4cb22b3e6d7e1e655d10323e505415d5c67d9a30
Added:
incubator/etch/trunk/binding-cpp/runtime/include/util/EtchIdGenerator.h
incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchIdGenerator.cpp
Modified:
incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
Added: incubator/etch/trunk/binding-cpp/runtime/include/util/EtchIdGenerator.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/util/EtchIdGenerator.h?rev=1368502&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/util/EtchIdGenerator.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/util/EtchIdGenerator.h Thu Aug 2 14:56:38 2012
@@ -0,0 +1,71 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ETCHIDGENERATOR_H__
+#define __ETCHIDGENERATOR_H__
+
+#include "capu/os/Mutex.h"
+#include "common/EtchConfig.h"
+
+/**
+ * Synchronously generates long id numbers.
+ */
+class EtchIdGenerator {
+public:
+
+ /**
+ * Constructs the IdGenerator with the default starting point of 1
+ * and the default stride of 1.
+ */
+ EtchIdGenerator();
+
+ /**
+ * Constructs the IdGenerator with the specified starting point
+ * and the default stride of 1.
+ *
+ * @param nextId
+ */
+ EtchIdGenerator(capu::int64_t nextId);
+
+ /**
+ * Constructs the IdGenerator with the specified starting point
+ * and the specified stride;
+ * @param nextId
+ * @param stride
+ */
+ EtchIdGenerator(capu::int64_t nextId, capu::uint32_t stride);
+
+ /**
+ * Destructor
+ */
+ virtual ~EtchIdGenerator();
+
+ /**
+ * @return the next id in sequence.
+ */
+ capu::int64_t next();
+
+private:
+
+ capu::int64_t mNextId;
+ const capu::uint32_t mStride;
+ capu::Mutex mMutex;
+};
+
+#endif /* ETCHIDGENERATOR_H */
+
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1368502&r1=1368501&r2=1368502&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Thu Aug 2 14:56:38 2012
@@ -121,6 +121,7 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/support/EtchTransportHelper.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
${PROJECT_SOURCE_DIR}/include/util/EtchCircularQueue.h
+ ${PROJECT_SOURCE_DIR}/include/util/EtchIdGenerator.h
)
#Add cpp files
@@ -194,6 +195,7 @@ SET(MAIN_SOURCES
support/EtchTransportHelper.cpp
util/EtchCircularQueue.cpp
util/EtchUtil.cpp
+ util/EtchIdGenerator.cpp
)
#Add source and header files to library so they are visible in the different IDEs (Visual Studio and Eclipse)
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchIdGenerator.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchIdGenerator.cpp?rev=1368502&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchIdGenerator.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchIdGenerator.cpp Thu Aug 2 14:56:38 2012
@@ -0,0 +1,44 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "util/EtchIdGenerator.h"
+#include "capu/os/Mutex.h"
+
+//TODO: Replace this via AtomicOperations
+
+EtchIdGenerator::~EtchIdGenerator() {
+}
+
+EtchIdGenerator::EtchIdGenerator()
+: mNextId(1), mStride(1) {
+}
+
+EtchIdGenerator::EtchIdGenerator(capu::int64_t nextId)
+: mNextId(nextId), mStride(1) {
+}
+
+EtchIdGenerator::EtchIdGenerator(capu::int64_t nextId, capu::uint32_t stride)
+: mNextId(nextId), mStride(stride) {
+}
+
+capu::int64_t EtchIdGenerator::next() {
+ mMutex.lock();
+ capu::int64_t id = mNextId;
+ mNextId += mStride;
+ mMutex.unlock();
+ return id;
+}