Example #1
0
Records Database::children(const RecordID& idParent) const
{
	Records result;
	
	Dbc* pCursor = nullptr;
	dbParentId_.cursor(NULL, &pCursor, 0);
	assert(pCursor);
    
    BOOST_SCOPE_EXIT(&pCursor) 
    {
        pCursor->close();
    } BOOST_SCOPE_EXIT_END
	
	Dbt keyParent(idParent.data(), idParent.size());
	Dbt keyChild;
	Dbt record;
	
	int res = pCursor->pget(&keyParent, &keyChild, &record, DB_SET);
	
	while (res == 0)
	{
		result.push_back(make_Record(RecordID(keyChild), RecordData(record)));
		res = pCursor->pget(&keyParent, &keyChild, &record, DB_NEXT_DUP);
	}
	
	return result;
}
CStdString MythProgramInfo::UID()
{
  // Creates unique IDs from ChannelID, StartTime and RecordID like "100_2011-12-10T12:00:00_247"
  char buf[50] = "";
  MythTimestamp time(RecordingStartTime());
  sprintf(buf, "%u_%s_%u", ChannelID(), time.String().c_str(), RecordID());
  return CStdString(buf);
}
CStdString MythProgramInfo::StrUID()
{
    // Creates unique IDs from ChannelID, RecordID and StartTime like "100_200_2011-12-10T12:00:00"
    char buf[40] = "";
    sprintf(buf, "%d_%ld_", ChannelID(), RecordID());
    time_t starttime = StartTime();
    strftime(buf + strlen(buf), 20, "%Y-%m-%dT%H:%M:%S", localtime(&starttime));
    return CStdString(buf);
}
Example #4
0
void Database::del(const RecordID& id)
{
	Dbt key(id.data(), id.size());
	// fetch children
	std::vector<RecordID> childrenIds;
	Dbc* pCursor = nullptr;
	dbParentId_.cursor(NULL, &pCursor, 0);
	assert(pCursor);
    
    BOOST_SCOPE_EXIT(&pCursor) 
    {
        if(pCursor) pCursor->close();
    } BOOST_SCOPE_EXIT_END
	
	Dbt keyChild;
	Dbt record;
	record.set_flags(DB_DBT_PARTIAL);
	record.set_doff(0);
	record.set_dlen(0);
	
	int res = pCursor->pget(&key, &keyChild, &record, DB_SET);
	
	while (res == 0)
	{
		childrenIds.push_back(RecordID(keyChild));
		res = pCursor->pget(&key, &keyChild, &record, DB_NEXT_DUP);
	}
	
	if (res != DB_NOTFOUND)
	{
		throw DbException("Failed to obtain children ids", res);
	}
	
	pCursor->close();
    pCursor = nullptr;
	
	// delete children
	for (const RecordID& childId : childrenIds)
	{
		del(childId);
	}
	
	// delete the record itself
	const int err = dbMain_.del(nullptr, &key, /*flags*/0);
	
	if (err && err != DB_NOTFOUND)
	{
		std::ostringstream ss;
		ss << "Failed to delete record id='" << id << '\'';
		throw DbException(ss.str().c_str(), err);
	}
}
Example #5
0
size_t URI::get_record_size() const
{
    if (!_uri) {
        return 0;
    }

    return MessageBuilder::compute_record_size(
               Record(
                   RecordType(
                       RecordType::well_known_type,
                       uri_record_type_value
                   ),
                   RecordPayload(_uri, _uri_size),
                   RecordID(),
                   /* chunk */ false,
                   /* last record */ false
               )
           );
}
Example #6
0
size_t Text::get_record_size() const
{
    if (!_text_record) {
        return 0;
    }

    return MessageBuilder::compute_record_size(
               Record(
                   RecordType(
                       RecordType::well_known_type,
                       text_record_type_value
                   ),
                   RecordPayload(_text_record, _text_record_size),
                   RecordID(),
                   /* chunk */ false,
                   /* last record */ false
               )
           );
}
Example #7
0
logger& logger::init()
{
    typedef sinks::debug_output_backend backend_t;
    auto pDebugBackend = boost::make_shared< backend_t >();

    auto pDebugSink = boost::make_shared< sinks::synchronous_sink< backend_t > >(pDebugBackend);
    pDebugSink->set_filter(expr::attr<severity_level>("Severity") >= trace);
    pDebugSink->set_formatter(
        expr::stream
        << "[" << expr::attr<UINT>("RecordID")
        << "][" << expr::format_date_time(_timestamp, "%Y-%m-%d %H:%M:%S.%f")
        << "][" << _severity
        << "]" << expr::message
        << std::endl);
    logging::core::get()->add_sink(pDebugSink);

    sink_ = logging::add_file_log(
                keywords::open_mode = std::ios::app, // append write
                keywords::file_name = file_name_ + "%Y-%m-%d.log",
                keywords::rotation_size = rotation_size_,
                keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
                keywords::min_free_space = min_free_space_,

                keywords::format = (
                                       expr::stream
                                       << "[" << expr::attr<UINT>("RecordID")
                                       << "][" << expr::format_date_time(_timestamp, "%Y-%m-%d %H:%M:%S.%f")
                                       << "][" << _severity
                                       << "]" << expr::message)
            );

    sink_->locked_backend()->auto_flush(auto_flush_);

    logging::add_common_attributes();

    attrs::counter<UINT> RecordID(1);
    logging::core::get()->add_global_attribute("RecordID", RecordID);

    this->set_filter_trace();

    return *this;
}
Example #8
0
Record Database::find(const std::string& fileName) const
{
	Dbt key;
	Dbt data;
	
	Dbt fileNameKey(const_cast<char*>(fileName.data()), fileName.size());
	const int err = dbFilename_.pget(nullptr, &fileNameKey, &key, &data, 0);
	
	if (err == DB_NOTFOUND)
	{
		return make_Record(NULL_RECORD_ID, RecordData());
	}
	
	if (err)
	{
		throw DbException("Failed to obtain record by filename key", err);
	}
	
	return make_Record(RecordID(key), RecordData(data));
}