diff --git a/OxConfig.cmake b/OxConfig.cmake index 6312e31c..e908c543 100644 --- a/OxConfig.cmake +++ b/OxConfig.cmake @@ -3,9 +3,10 @@ if("${CMAKE_FIND_ROOT_PATH}" STREQUAL "") set(OxStd_LIBRARY /usr/local/lib/ox/libOxStd.a) set(OxFS_LIBRARY /usr/local/lib/ox/libOxFS.a) set(OxClArgs_LIBRARY /usr/local/lib/ox/libOxClArgs.a) + set(OxMetalClaw /usr/local/lib/ox/libOxMetalClaw.a) else("${CMAKE_FIND_ROOT_PATH}" STREQUAL "") set(Ox_INCLUDE_DIRS ${CMAKE_FIND_ROOT_PATH}/include/) set(OxStd_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxStd.a) set(OxFS_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxFS.a) - set(OxClArgs_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxClArgs.a) + set(OxMetalClaw ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxMetalClaw.a) endif("${CMAKE_FIND_ROOT_PATH}" STREQUAL "") diff --git a/cmake/Modules/FindJansson.cmake b/cmake/Modules/FindJansson.cmake deleted file mode 100644 index 19ee0774..00000000 --- a/cmake/Modules/FindJansson.cmake +++ /dev/null @@ -1,49 +0,0 @@ -# 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. - - -# - Try to find Jansson -# Once done this will define -# JANSSON_FOUND - System has Jansson -# JANSSON_INCLUDE_DIRS - The Jansson include directories -# JANSSON_LIBRARIES - The libraries needed to use Jansson -# JANSSON_DEFINITIONS - Compiler switches required for using Jansson - -find_path(JANSSON_INCLUDE_DIR jansson.h - PATHS - /usr/include - /usr/local/include -) - -find_library(JANSSON_LIBRARY - NAMES - jansson - PATHS - /usr/lib - /usr/local/lib -) - -set(JANSSON_LIBRARIES ${JANSSON_LIBRARY}) -set(JANSSON_INCLUDE_DIRS ${JANSSON_INCLUDE_DIR}) - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set JANSSON_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(Jansson DEFAULT_MSG - JANSSON_LIBRARY JANSSON_INCLUDE_DIR) - -mark_as_advanced(JANSSON_INCLUDE_DIR JANSSON_LIBRARY) diff --git a/deps/ox/src/ox/mc/optype.hpp b/deps/ox/src/ox/mc/optype.hpp new file mode 100644 index 00000000..7e3b96c6 --- /dev/null +++ b/deps/ox/src/ox/mc/optype.hpp @@ -0,0 +1,27 @@ +/* + * Copyright 2015 - 2017 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +namespace ox { + +enum class OpType { + Read = 0, + Write = 1 +}; + +template +ox::Error ioOp(T *io, O *obj) { + if (io->opType() == ox::OpType::Read) { + return ioOpRead(io, obj); + } else { + return ioOpWrite(io, obj); + } +} + +} diff --git a/src/ox/fs/filestore.hpp b/src/ox/fs/filestore.hpp index 99092bd9..5b418547 100644 --- a/src/ox/fs/filestore.hpp +++ b/src/ox/fs/filestore.hpp @@ -17,7 +17,7 @@ struct __attribute__((packed)) FileStoreHeader { public: typedef InodeId InodeId_t; typedef FsT FsSize_t; - const static auto VERSION = 6; + const static auto VERSION = 7; private: uint16_t m_version; @@ -917,7 +917,7 @@ uint8_t *FileStore
::format(uint8_t *buffer, typename Header::FsSize_t si } typedef FileStore> FileStore16; -typedef FileStore> FileStore32; +typedef FileStore> FileStore32; typedef FileStore> FileStore64; } diff --git a/src/ox/fs/filesystem.cpp b/src/ox/fs/filesystem.cpp index b6f9b94f..6a2535fb 100644 --- a/src/ox/fs/filesystem.cpp +++ b/src/ox/fs/filesystem.cpp @@ -16,7 +16,7 @@ FileSystem *createFileSystem(uint8_t *buff, size_t buffSize, bool ownsBuff) { FileSystem *fs = nullptr; switch (version) { - case 6: + case FileStore16::VERSION: switch (type) { case ox::OxFS_16: fs = new FileSystem16(buff, ownsBuff); diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index 1092195e..c63769d2 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -719,7 +719,7 @@ uint64_t FileSystemTemplate::generateInodeId() { // find an inode value for the given path while (!inode) { inode = rand.gen(); - inode >>= 64 - 8 * sizeof(typename FileStore::InodeId_t); + inode >>= 64 - 8 * sizeof(typename FileStore::InodeId_t); // make sure this does not already exist if (inode < INODE_RESERVED_END || stat(inode).inode) { diff --git a/src/ox/mc/optype.hpp b/src/ox/mc/optype.hpp new file mode 100644 index 00000000..7e3b96c6 --- /dev/null +++ b/src/ox/mc/optype.hpp @@ -0,0 +1,27 @@ +/* + * Copyright 2015 - 2017 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +namespace ox { + +enum class OpType { + Read = 0, + Write = 1 +}; + +template +ox::Error ioOp(T *io, O *obj) { + if (io->opType() == ox::OpType::Read) { + return ioOpRead(io, obj); + } else { + return ioOpWrite(io, obj); + } +} + +} diff --git a/src/ox/mc/read.cpp b/src/ox/mc/read.cpp index 3d4f5100..16b6bc4a 100644 --- a/src/ox/mc/read.cpp +++ b/src/ox/mc/read.cpp @@ -17,6 +17,10 @@ MetalClawReader::MetalClawReader(uint8_t *buff, size_t buffLen): m_fieldPresence m_buffLen = buffLen; } +int MetalClawReader::op(const char*, int8_t *val) { + return readInteger(val); +} + int MetalClawReader::op(const char*, int16_t *val) { return readInteger(val); } @@ -29,6 +33,11 @@ int MetalClawReader::op(const char*, int64_t *val) { return readInteger(val); } + +int MetalClawReader::op(const char*, uint8_t *val) { + return readInteger(val); +} + int MetalClawReader::op(const char*, uint16_t *val) { return readInteger(val); } @@ -46,6 +55,28 @@ int MetalClawReader::op(const char*, bool *val) { return 0; } +size_t MetalClawReader::arrayLength(const char*) { + size_t len = 0; + if (m_fieldPresence.get(m_field)) { + // read the length + if (m_buffIt + sizeof(ArrayLength) < m_buffLen) { + len = ox::bigEndianAdapt(*((ArrayLength*) &m_buff[m_buffIt])); + } + } + return len; +} + +size_t MetalClawReader::stringLength(const char*) { + size_t len = 0; + if (m_fieldPresence.get(m_field)) { + // read the length + if (m_buffIt + sizeof(StringLength) < m_buffLen) { + len = ox::bigEndianAdapt(*((StringLength*) &m_buff[m_buffIt])); + } + } + return len; +} + void MetalClawReader::setFields(int fields) { m_fields = fields; m_buffIt = (fields / 8 + 1) - (fields % 8 == 0); diff --git a/src/ox/mc/read.hpp b/src/ox/mc/read.hpp index 11b39287..3b8d27e4 100644 --- a/src/ox/mc/read.hpp +++ b/src/ox/mc/read.hpp @@ -11,6 +11,7 @@ #include #include #include "err.hpp" +#include "optype.hpp" #include "presencemask.hpp" namespace ox { @@ -18,6 +19,9 @@ namespace ox { class MetalClawReader { private: + typedef uint32_t ArrayLength; + typedef uint32_t StringLength; + FieldPresenseMask m_fieldPresence; int m_fields = 0; int m_field = 0; @@ -28,10 +32,12 @@ class MetalClawReader { public: MetalClawReader(uint8_t *buff, size_t buffLen); + int op(const char*, int8_t *val); int op(const char*, int16_t *val); int op(const char*, int32_t *val); int op(const char*, int64_t *val); + int op(const char*, uint8_t *val); int op(const char*, uint16_t *val); int op(const char*, uint32_t *val); int op(const char*, uint64_t *val); @@ -47,8 +53,17 @@ class MetalClawReader { template int op(const char*, ox::bstring *val); + size_t arrayLength(const char*); + + // stringLength returns the length of the string, including the null terminator. + size_t stringLength(const char*); + void setFields(int fields); + OpType opType() { + return OpType::Read; + } + private: template int readInteger(I *val); @@ -71,7 +86,6 @@ int MetalClawReader::op(const char*, ox::bstring *val) { int err = 0; if (m_fieldPresence.get(m_field)) { // read the length - typedef uint32_t StringLength; size_t size = 0; if (m_buffIt + sizeof(StringLength) < m_buffLen) { size = ox::bigEndianAdapt(*((StringLength*) &m_buff[m_buffIt])); @@ -120,10 +134,9 @@ int MetalClawReader::op(const char*, T *val, size_t valLen) { int err = 0; if (m_fieldPresence.get(m_field)) { // read the length - typedef uint32_t ArrayLength; size_t len = 0; if (m_buffIt + sizeof(ArrayLength) < m_buffLen) { - len = ox::bigEndianAdapt(*((T*) &m_buff[m_buffIt])); + len = ox::bigEndianAdapt(*((ArrayLength*) &m_buff[m_buffIt])); m_buffIt += sizeof(ArrayLength); } else { err = MC_BUFFENDED; diff --git a/src/ox/mc/write.cpp b/src/ox/mc/write.cpp index cf214d0e..65b0bd8f 100644 --- a/src/ox/mc/write.cpp +++ b/src/ox/mc/write.cpp @@ -17,6 +17,10 @@ MetalClawWriter::MetalClawWriter(uint8_t *buff, size_t buffLen): m_fieldPresence m_buffLen = buffLen; } +int MetalClawWriter::op(const char*, int8_t *val) { + return appendInteger(*val); +} + int MetalClawWriter::op(const char*, int16_t *val) { return appendInteger(*val); } @@ -29,6 +33,11 @@ int MetalClawWriter::op(const char*, int64_t *val) { return appendInteger(*val); } + +int MetalClawWriter::op(const char*, uint8_t *val) { + return appendInteger(*val); +} + int MetalClawWriter::op(const char*, uint16_t *val) { return appendInteger(*val); } @@ -51,4 +60,8 @@ void MetalClawWriter::setFields(int fields) { m_fieldPresence.setMaxLen(m_buffIt); } +size_t MetalClawWriter::size() { + return m_buffIt; +} + } diff --git a/src/ox/mc/write.hpp b/src/ox/mc/write.hpp index 8380b3c7..1cf497f7 100644 --- a/src/ox/mc/write.hpp +++ b/src/ox/mc/write.hpp @@ -11,6 +11,7 @@ #include #include #include "err.hpp" +#include "optype.hpp" #include "presencemask.hpp" namespace ox { @@ -28,10 +29,12 @@ class MetalClawWriter { public: MetalClawWriter(uint8_t *buff, size_t buffLen); + int op(const char*, int8_t *val); int op(const char*, int16_t *val); int op(const char*, int32_t *val); int op(const char*, int64_t *val); + int op(const char*, uint8_t *val); int op(const char*, uint16_t *val); int op(const char*, uint32_t *val); int op(const char*, uint64_t *val); @@ -49,6 +52,12 @@ class MetalClawWriter { void setFields(int fields); + size_t size(); + + OpType opType() { + return OpType::Write; + } + private: template int appendInteger(I val); @@ -120,7 +129,7 @@ int MetalClawWriter::op(const char*, T *val, size_t len) { // write the length typedef uint32_t ArrayLength; if (m_buffIt + sizeof(ArrayLength) < m_buffLen) { - *((T*) &m_buff[m_buffIt]) = ox::bigEndianAdapt((ArrayLength) len); + *((ArrayLength*) &m_buff[m_buffIt]) = ox::bigEndianAdapt((ArrayLength) len); m_buffIt += sizeof(ArrayLength); } else { err = MC_BUFFENDED; @@ -144,9 +153,13 @@ int MetalClawWriter::op(const char*, T *val, size_t len) { }; template -int write(uint8_t *buff, size_t buffLen, T *val) { +int write(uint8_t *buff, size_t buffLen, T *val, size_t *sizeOut = nullptr) { MetalClawWriter writer(buff, buffLen); - return ioOp(&writer, val); + auto err = ioOp(&writer, val); + if (sizeOut) { + *sizeOut = writer.size(); + } + return err; } } diff --git a/src/ox/std/random.cpp b/src/ox/std/random.cpp index 247cab5a..70ca85c3 100644 --- a/src/ox/std/random.cpp +++ b/src/ox/std/random.cpp @@ -11,7 +11,10 @@ namespace ox { -RandomSeed Random::DEFAULT_SEED = {540932923848, 540932540932}; +Random::Random() { + m_seed[0] = 540932923848; + m_seed[1] = 540932540932; +} Random::Random(RandomSeed seed) { m_seed[0] = seed[0]; @@ -32,9 +35,3 @@ uint64_t Random::gen() { } } - - -uint64_t ox_rand() { - static ox::Random rand; - return rand.gen(); -} diff --git a/src/ox/std/random.hpp b/src/ox/std/random.hpp index 43d4daaf..77ce64ad 100644 --- a/src/ox/std/random.hpp +++ b/src/ox/std/random.hpp @@ -16,13 +16,14 @@ typedef uint64_t RandomSeed[2]; class Random { public: - static RandomSeed DEFAULT_SEED; private: RandomSeed m_seed; public: - Random(RandomSeed seed = DEFAULT_SEED); + Random(); + + Random(RandomSeed seed); uint64_t gen(); };