Squashed 'deps/ox/' changes from c63e0c1..bf5c4e2

bf5c4e2 Add missing optype.hpp file
fdcc303 Removed unused CMake file
4e1f304 Fix version mismatch when loading FileSystems
565c56e Increment FileStore version for inode ID size change
64543b7 Bump FileStore32's InodeId type to uint16_t
fe062cf Add methods for getting array and string length of Metal Claw fields
8deae14 Add general ioOp that will call ioOpRead or ioOpWrite
009cf99 Add OpType for Metal Claw operators
1cf6164 Remove array globals from OxStd, as they were causing section overlaps on GBA
3ffba29 Add op(const char*, (u)int8_t) methods to MetalClaw
489736d Add an optional sizeOut parameter to Metal Claw write
443a62c Fix ArrayLength type case in Metal Claw writer
a46fc8b Add MetalClaw to OxConfig.cmake

git-subtree-dir: deps/ox
git-subtree-split: bf5c4e2c4712b83befff7da25147902408146dd7
This commit is contained in:
Gary Talent 2017-12-22 00:31:12 -06:00
parent 8559ab53cc
commit 12371c21d2
13 changed files with 143 additions and 69 deletions

View File

@ -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 "")

View File

@ -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)

27
deps/ox/src/ox/mc/optype.hpp vendored Normal file
View File

@ -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<typename T, typename O>
ox::Error ioOp(T *io, O *obj) {
if (io->opType() == ox::OpType::Read) {
return ioOpRead(io, obj);
} else {
return ioOpWrite(io, obj);
}
}
}

View File

@ -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<Header>::format(uint8_t *buffer, typename Header::FsSize_t si
}
typedef FileStore<FileStoreHeader<uint16_t, uint16_t>> FileStore16;
typedef FileStore<FileStoreHeader<uint32_t, uint64_t>> FileStore32;
typedef FileStore<FileStoreHeader<uint32_t, uint16_t>> FileStore32;
typedef FileStore<FileStoreHeader<uint64_t, uint64_t>> FileStore64;
}

View File

@ -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);

View File

@ -719,7 +719,7 @@ uint64_t FileSystemTemplate<FileStore, FS_TYPE>::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) {

27
src/ox/mc/optype.hpp Normal file
View File

@ -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<typename T, typename O>
ox::Error ioOp(T *io, O *obj) {
if (io->opType() == ox::OpType::Read) {
return ioOpRead(io, obj);
} else {
return ioOpWrite(io, obj);
}
}
}

View File

@ -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);

View File

@ -11,6 +11,7 @@
#include <ox/std/byteswap.hpp>
#include <ox/std/string.hpp>
#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<size_t L>
int op(const char*, ox::bstring<L> *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<typename I>
int readInteger(I *val);
@ -71,7 +86,6 @@ int MetalClawReader::op(const char*, ox::bstring<L> *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;

View File

@ -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;
}
}

View File

@ -11,6 +11,7 @@
#include <ox/std/string.hpp>
#include <ox/std/types.hpp>
#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<typename I>
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<typename T>
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;
}
}

View File

@ -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();
}

View File

@ -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();
};