DF-0
DF-0: Data processing Framework with Zero-overhead
Loading...
Searching...
No Matches
content_type.h
1/**************************************************************************/
2/* */
3/* DF-0: Data processing Framework with Zero-overhead */
4/* */
5/* Copyright (c) DF-0 Team https://github.com/df0-io/df0 */
6/* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DF0-Commercial */
7/* */
8/**************************************************************************/
9
10#ifndef DF0_CONTENT_TYPE_H
11#define DF0_CONTENT_TYPE_H
12
13#include "pipeline/element_base.hpp"
14#include "content_type_by_signature.h"
15#include "ref_or_owned.h"
16
37namespace df0::content_type
38{
39
72DF0_CONTENT_TYPE_EXPORT void detect(data_source& data, const by_signature::database& signatures_db_to_use = by_signature::database{});
73
104class detector : public pipeline::transformer_element<detector>
105{
106public:
107
119 : m_signatures_db_to_use(signatures_db_to_use) {}
120
121 continuation operator()(message_ptr msg, const message_callbacks& emit_message)
122 {
123 try
124 {
125 if (msg->is<data_source>())
126 {
127 data_source& data = msg->get<data_source>();
128 content_type::detect(data, m_signatures_db_to_use.get());
129 }
130 else if (msg->is<document::image>())
131 {
132 data_source& data = msg->get<document::image>().source;
133 content_type::detect(data, m_signatures_db_to_use.get());
134 }
135 }
136 catch (const std::exception& e)
137 {
138 emit_message(make_nested_ptr(std::current_exception(), DF0_MAKE_ERROR("Content type detection failed")));
139 }
140 return emit_message(std::move(msg));
141 }
142
143private:
144 ref_or_owned<by_signature::database> m_signatures_db_to_use;
145};
146
147} // namespace df0::content_type
148
149#endif // DF0_CONTENT_TYPE
detector(ref_or_owned< by_signature::database > signatures_db_to_use=by_signature::database{})
Constructs a new detector with the given database of signatures.
A utility class that simplifies declaring function attributes that need to be stored without requirin...
Provides a multi-stage pipeline for content type detection.
DF0_CONTENT_TYPE_EXPORT void detect(data_source &data, const by_signature::database &signatures_db_to_use=by_signature::database{})
std::exception_ptr make_nested_ptr(Inner &&inner, Outer &&outer, Rest &&... rest)
Creates a pointer to a nested exception from an inner exception and an outer exception.
Callback bundle used by pipeline elements to emit messages.
Definition message.h:90