Newer
Older
* Copyright (c) 2015-2016, Luca Fulchir<luca@fulchir.it>, All rights reserved.
*
* This file is part of "libRaptorQ".
*
* libRaptorQ 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 3
* of the License, or (at your option) any later version.
*
* libRaptorQ 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and a copy of the GNU Lesser General Public License
* along with libRaptorQ. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cRaptorQ.h"
#include "RaptorQ.hpp"
struct RAPTORQ_LOCAL RaptorQ_ptr
{
void *ptr;
const RaptorQ_type type;
RaptorQ_ptr (const RaptorQ_type _type) : ptr (nullptr), type (_type) {}
};
struct RAPTORQ_LOCAL RaptorQ_future
{
std::future<std::pair<RaptorQ__v1::Error, uint8_t>> f;
};
struct RaptorQ_ptr *RaptorQ_Enc (const RaptorQ_type type, void *data,
const uint64_t size,
const uint16_t min_subsymbol_size,
const uint16_t symbol_size,
const size_t max_memory)
{
reinterpret_cast<uint8_t*> (data),
reinterpret_cast<uint8_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
reinterpret_cast<uint16_t*> (data),
reinterpret_cast<uint16_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
reinterpret_cast<uint32_t*> (data),
reinterpret_cast<uint32_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
reinterpret_cast<uint64_t*> (data),
reinterpret_cast<uint64_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
return new RaptorQ_ptr (RaptorQ_type::RQ_NONE);
}
return ret.release();
}
struct RaptorQ_ptr *RaptorQ_Dec (const RaptorQ_type type,
const RaptorQ_OTI_Common_Data common,
const RaptorQ_OTI_Scheme_Specific_Data scheme)
{
std::unique_ptr<RaptorQ_ptr> ret (new RaptorQ_ptr (type));
switch (type) {
new RaptorQ__v1::Decoder<uint16_t*, uint16_t*> (common,scheme));
new RaptorQ__v1::Decoder<uint32_t*, uint32_t*> (common,scheme));
new RaptorQ__v1::Decoder<uint64_t*, uint64_t*> (common,scheme));
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
return new RaptorQ_ptr (RaptorQ_type::RQ_NONE);
///////////////////////////
// Precomputation caching
///////////////////////////
uint64_t RaptorQ_shared_cache_size (const uint64_t shared_cache)
{
RaptorQ_Error RaptorQ_local_cache_size (const uint64_t local_cache)
return static_cast<RaptorQ_Error> (RaptorQ__v1::local_cache_size (
local_cache));
/////////////////////
// Common functions
/////////////////////
bool RaptorQ_set_thread_pool (const size_t threads,
const uint16_t max_block_concurrency,
const RaptorQ_Work exit_type)
{
return RaptorQ__v1::set_thread_pool (threads, max_block_concurrency,
static_cast<RaptorQ__v1::Work_State> (exit_type));
}
RaptorQ_Error RaptorQ_future_valid (struct RaptorQ_future *future)
{
if (future == nullptr)
return RQ_ERR_WRONG_INPUT;
if (future->f.valid())
return RQ_ERR_WORKING;
}
RaptorQ_Error RaptorQ_future_wait_for (struct RaptorQ_future *future,
const uint64_t time,
const RaptorQ_Unit_Time unit)
{
if (future == nullptr)
return RQ_ERR_WRONG_INPUT;
switch (unit) {
case RQ_TIME_NANOSEC:
status = future->f.wait_for (std::chrono::nanoseconds (time));
break;
status = future->f.wait_for (std::chrono::microseconds (time));
break;
status = future->f.wait_for (std::chrono::milliseconds (time));
break;
status = future->f.wait_for (std::chrono::seconds (time));
break;
status = future->f.wait_for (std::chrono::minutes (time));
break;
status = future->f.wait_for (std::chrono::hours (time));
break;
Loading full blame...