25#include <boost/date_time/posix_time/posix_time_types.hpp>
26#include <boost/date_time/posix_time/time_formatters.hpp>
27#include <boost/date_time/posix_time/time_parsers.hpp>
28#include <boost/interprocess/sync/file_lock.hpp>
51 "<!DOCTYPE oks-schema [\n"
53 " <!ELEMENT oks-schema (info, (include)?, (comments)?, (class)+)>\n"
55 " <!ELEMENT info EMPTY>\n"
57 " name CDATA #IMPLIED\n"
58 " type CDATA #IMPLIED\n"
59 " num-of-items CDATA #REQUIRED\n"
60 " oks-format CDATA #FIXED \"schema\"\n"
61 " oks-version CDATA #REQUIRED\n"
62 " created-by CDATA #IMPLIED\n"
63 " created-on CDATA #IMPLIED\n"
64 " creation-time CDATA #IMPLIED\n"
65 " last-modified-by CDATA #IMPLIED\n"
66 " last-modified-on CDATA #IMPLIED\n"
67 " last-modification-time CDATA #IMPLIED\n"
70 " <!ELEMENT include (file)+>\n"
71 " <!ELEMENT file EMPTY>\n"
73 " path CDATA #REQUIRED\n"
76 " <!ELEMENT comments (comment)+>\n"
77 " <!ELEMENT comment EMPTY>\n"
78 " <!ATTLIST comment\n"
79 " creation-time CDATA #REQUIRED\n"
80 " created-by CDATA #REQUIRED\n"
81 " created-on CDATA #REQUIRED\n"
82 " author CDATA #REQUIRED\n"
83 " text CDATA #REQUIRED\n"
86 " <!ELEMENT class (superclass | attribute | relationship | method)*>\n"
88 " name CDATA #REQUIRED\n"
89 " description CDATA \"\"\n"
90 " is-abstract (yes|no) \"no\"\n"
93 " <!ELEMENT superclass EMPTY>\n"
94 " <!ATTLIST superclass name CDATA #REQUIRED>\n"
96 " <!ELEMENT attribute EMPTY>\n"
97 " <!ATTLIST attribute\n"
98 " name CDATA #REQUIRED\n"
99 " description CDATA \"\"\n"
100 " type (bool|s8|u8|s16|u16|s32|u32|s64|u64|float|double|date|time|string|uid|enum|class) #REQUIRED\n"
101 " range CDATA \"\"\n"
102 " format (dec|hex|oct) \"dec\"\n"
103 " is-multi-value (yes|no) \"no\"\n"
104 " init-value CDATA \"\"\n"
105 " is-not-null (yes|no) \"no\"\n"
106 " ordered (yes|no) \"no\"\n"
109 " <!ELEMENT relationship EMPTY>\n"
110 " <!ATTLIST relationship\n"
111 " name CDATA #REQUIRED\n"
112 " description CDATA \"\"\n"
113 " class-type CDATA #REQUIRED\n"
114 " low-cc (zero|one) #REQUIRED\n"
115 " high-cc (one|many) #REQUIRED\n"
116 " is-composite (yes|no) #REQUIRED\n"
117 " is-exclusive (yes|no) #REQUIRED\n"
118 " is-dependent (yes|no) #REQUIRED\n"
119 " ordered (yes|no) \"no\"\n"
122 " <!ELEMENT method (method-implementation*)>\n"
123 " <!ATTLIST method\n"
124 " name CDATA #REQUIRED\n"
125 " description CDATA \"\"\n"
128 " <!ELEMENT method-implementation EMPTY>\n"
129 " <!ATTLIST method-implementation\n"
130 " language CDATA #REQUIRED\n"
131 " prototype CDATA #REQUIRED\n"
138 "<!DOCTYPE oks-data [\n"
140 " <!ELEMENT oks-data (info, (include)?, (comments)?, (obj)+)>\n"
142 " <!ELEMENT info EMPTY>\n"
144 " name CDATA #IMPLIED\n"
145 " type CDATA #IMPLIED\n"
146 " num-of-items CDATA #REQUIRED\n"
147 " oks-format CDATA #FIXED \"data\"\n"
148 " oks-version CDATA #REQUIRED\n"
149 " created-by CDATA #IMPLIED\n"
150 " created-on CDATA #IMPLIED\n"
151 " creation-time CDATA #IMPLIED\n"
152 " last-modified-by CDATA #IMPLIED\n"
153 " last-modified-on CDATA #IMPLIED\n"
154 " last-modification-time CDATA #IMPLIED\n"
157 " <!ELEMENT include (file)*>\n"
158 " <!ELEMENT file EMPTY>\n"
160 " path CDATA #REQUIRED\n"
163 " <!ELEMENT comments (comment)*>\n"
164 " <!ELEMENT comment EMPTY>\n"
165 " <!ATTLIST comment\n"
166 " creation-time CDATA #REQUIRED\n"
167 " created-by CDATA #REQUIRED\n"
168 " created-on CDATA #REQUIRED\n"
169 " author CDATA #REQUIRED\n"
170 " text CDATA #REQUIRED\n"
173 " <!ELEMENT obj (attr | rel)*>\n"
175 " class CDATA #REQUIRED\n"
176 " id CDATA #REQUIRED\n"
178 " <!ELEMENT attr (data)*>\n"
180 " name CDATA #REQUIRED\n"
181 " type (bool|s8|u8|s16|u16|s32|u32|s64|u64|float|double|date|time|string|uid|enum|class|-) \"-\"\n"
184 " <!ELEMENT data EMPTY>\n"
186 " val CDATA #REQUIRED\n"
188 " <!ELEMENT rel (ref)*>\n"
190 " name CDATA #REQUIRED\n"
191 " class CDATA \"\"\n"
194 " <!ELEMENT ref EMPTY>\n"
196 " class CDATA #REQUIRED\n"
197 " id CDATA #REQUIRED\n"
204 return (std::string(
"Failed to add include \'") + include_name +
"\' to file \'" + file.get_full_file_name() +
205 "\' because:\n" + reason);
211 return (std::string(
"Failed to remove include \'") + include_name +
"\' from file \'" + file.get_full_file_name() +
212 "\' because:\n" + reason);
217 const std::string& from,
218 const std::string&
to,
219 const std::string& reason)
noexcept
221 return (std::string(
"Failed to rename include of \'") + file.get_full_file_name() +
"\' from \'" + from +
"\' to \'" +
222 to +
"\' because:\n" + reason);
228 return (std::string(
"Failed to add new comment to file \'") + file.get_full_file_name() +
"\' because:\n" + reason);
234 return (std::string(
"Failed to remove comment created at \'") + creation_time +
"\' from file \'" +
235 file.get_full_file_name() +
"\' because:\n" + reason);
241 return (std::string(
"Failed to change comment created at \'") + creation_time +
"\' from file \'" +
242 file.get_full_file_name() +
"\' because:\n" + reason);
248 return (std::string(
"Failed to ") + (lock_action ?
"" :
"un") +
"lock file \'" + file.get_full_file_name() +
249 "\' because:\n" + reason);
255 return (std::string(
"Failed to ") + action +
" of file \'" + file.get_full_file_name() +
"\' because:\n" + reason);
261 return (std::string(
"Failed to compare file \'") + src +
"\' with \'" + dest +
"\' because:\n" + reason);
265 const std::string& ln,
266 const std::string& ft,
267 const std::string& ff,
298 for (std::map<std::string, oks::Comment*>::iterator i =
p_comments.begin(); i !=
p_comments.end(); ++i) {
344 for (
const auto& i : f.p_comments) {
371 const char* fname =
"OksFile::OksFile()";
383 const char* tag_start = xmls->get_tag_start();
386 xmls->throw_unexpected_tag(tag_start,
"?xml");
406 <<
"\' in the xml file header. Either \'version\' or \'encoding\' is expected.\n";
413 }
catch (std::exception& e) {
422 const char* dtd = xmls->get_tag();
423 const char dtd_start[] =
"<!DOCTYPE ";
424 if (!strncmp(dtd_start, dtd,
sizeof(dtd_start) - 1)) {
429 }
catch (std::exception& e) {
438 xmls->store_position();
440 const char* a_tag = xmls->get_tag();
442 const char xml_stylesheet_start[] =
"<?xml-stylesheet";
443 if (strncmp(xml_stylesheet_start, a_tag,
sizeof(xml_stylesheet_start) - 1)) {
444 xmls->restore_position();
448 }
catch (std::exception& e) {
455 xmls->get_tag_start();
458 }
catch (std::exception& e) {
465 const char* tag_start = xmls->get_tag_start();
472 }
catch (std::exception& e) {
476 std::string oks_version;
514 else if (!strcmp(attr.
name(),
"last-modification-time"))
518 xmls->throw_unexpected_tag(attr.
name(),
"info\'s tags");
523 }
catch (std::exception& e) {
529 xmls->store_position();
531 bool read_include =
false;
534 const char* tag_start = xmls->get_tag_start();
538 read_include =
false;
540 xmls->restore_position();
545 }
catch (std::exception& e) {
554 const char* tag_start = xmls->get_tag_start();
557 xmls->throw_unexpected_tag(tag_start + 1,
xml_file_tag);
576 xmls->throw_unexpected_tag(attr.
name(),
"path");
582 }
catch (std::exception& e) {
591 const char* tag_start = xmls->get_tag_start();
600 std::unique_ptr<oks::Comment> comment(
new oks::Comment());
601 std::string creation_time;
624 xmls->throw_unexpected_tag(attr.
name(),
"comment\'s tags");
628 comment->validate(creation_time);
631 std::ostringstream text;
632 text <<
"The comment created at \'" << creation_time <<
"\' was already defined in this file";
633 throw std::runtime_error(text.str().c_str());
636 p_comments[creation_time] = comment.release();
640 }
catch (std::exception& e) {
652 if (creation_time.size() != 15 || creation_time[8] !=
'T') {
653 std::ostringstream msg;
654 msg <<
"the creation time \'" << creation_time <<
"\' is not an ISO-8601 date-time";
655 throw std::runtime_error(msg.str().c_str());
665 throw std::runtime_error(
"text is empty");
695 boost::posix_time::ptime now = boost::posix_time::second_clock::universal_time();
696 std::string creation_time = boost::posix_time::to_iso_string(now);
699 std::unique_ptr<oks::Comment> comment(
new oks::Comment(text, author));
705 x = comment.release();
710 }
catch (std::exception& ex) {
720 std::map<std::string, oks::Comment*>::const_iterator i =
p_comments.find(creation_time);
721 return (i ==
p_comments.end()) ? 0 : i->second;
734 std::string saved_author(comment->p_author);
735 std::string saved_text(comment->p_text);
737 comment->p_author = author;
738 comment->p_text = text;
742 }
catch (std::exception& ex) {
743 comment->p_author = saved_author;
744 comment->p_text = saved_text;
775 const static std::string __data(
"data");
776 const static std::string __schema(
"schema");
779 const char __oks_data[] =
"oks-data";
780 const char __oks_schema[] =
"oks-schema";
782 const char* id(__oks_data);
783 long id_len(
sizeof(__oks_data) - 1);
790 id_len =
sizeof(__oks_schema) - 1;
794 throw std::runtime_error(
"bad oks format");
799 const char __hdr_start[] =
"\n\n<!-- ";
800 const char __hdr_end[] =
" version 2.2 -->\n\n\n";
803 header.append(__hdr_start,
sizeof(__hdr_start) - 1);
804 header.append(
id, id_len);
805 header.append(__hdr_end,
sizeof(__hdr_end) - 1);
806 header.append(dtd, dtd_len);
808 xmls.
put_raw(header.c_str(), header.size());
821 std::string created_c_str;
844 if (!created_c_str.empty())
845 xmls.
put_attribute(
"creation-time",
sizeof(
"creation-time") - 1, created_c_str.c_str());
849 xmls.
put_attribute(
"last-modification-time",
sizeof(
"last-modification-time") - 1, last_modified_c_str.c_str());
880 xmls.
put_attribute(
"creation-time",
sizeof(
"creation-time") - 1, i.first.c_str());
881 xmls.
put_attribute(
"created-by",
sizeof(
"created-by") - 1, i.second->p_created_by.c_str());
882 xmls.
put_attribute(
"created-on",
sizeof(
"created-on") - 1, i.second->p_created_on.c_str());
883 xmls.
put_attribute(
"author",
sizeof(
"author") - 1, i.second->p_author.c_str());
884 xmls.
put_attribute(
"text",
sizeof(
"text") - 1, i.second->p_text.c_str());
893 }
catch (std::exception& ex) {
919 if (
size_t len = s.size()) {
952 if (idx == std::string::npos)
957 const char _prefix_str[] =
".oks-lock-";
962 if (idx == std::string::npos) {
981 lock_file_contents.clear();
986 if (stat(lock_name, &buf) == 0) {
987 std::ifstream f(lock_name);
990 std::getline(f, lock_file_contents);
993 lock_file_contents =
"unknown [cannot read lock file \'";
995 lock_file_contents +=
"\']";
1033 std::string lock_file_contents;
1039 if (
lock.try_lock() ==
false) {
1040 std::ostringstream text;
1041 text <<
"file is already locked by \"" << lock_file_contents <<
'\"';
1046 }
catch (
const boost::interprocess::interprocess_exception& ex) {
1047 std::ostringstream text;
1048 text <<
"boost::interprocess::unlock() failed: \"" << ex.what() <<
'\"';
1054 <<
"\' created by \n\"" << lock_file_contents <<
"\"\n";
1058 std::ostringstream text;
1063 }
catch (
const boost::interprocess::interprocess_exception& ex) {
1064 std::ostringstream text;
1065 text <<
"boost::interprocess::try_lock() failed: \"" << ex.what() <<
'\"';
1077 std::ostringstream text;
1083 boost::posix_time::ptime now(boost::posix_time::second_clock::universal_time());
1088 }
catch (std::exception& ex) {
1089 std::ostringstream text;
1090 text <<
"failed to write lock file \'" <<
p_lock_file_name <<
"\': " << ex.what();
1098 if (
p_lock->try_lock() ==
false) {
1099 throw std::runtime_error(
"file is locked by another process");
1101 }
catch (
const std::exception& ex) {
1102 std::ostringstream text;
1103 text <<
"boost::interprocess::try_lock() failed: \"" << ex.what() <<
'\"';
1117 }
catch (
const boost::interprocess::interprocess_exception& ex) {
1118 std::ostringstream text;
1119 text <<
"boost::interprocess::unlock() failed: \"" << ex.what() <<
'\"';
1127 std::ostringstream text;
1133std::list<std::string>::iterator
1175 }
catch (std::exception& ex) {
1272 s <<
"user \"" << c.get_created_by() <<
"\" (" << c.get_author() <<
")"
1273 <<
" on \"" << c.get_created_on() <<
"\" wrote: \"" << c.get_text() <<
"\"";
1282 " short file name: \'"
1283 << f.get_short_file_name()
1285 " full file name: \'"
1286 << f.get_full_file_name()
1288 " lock file name: \'"
1289 << f.get_lock_file()
1292 << f.get_logical_name()
1298 << f.get_oks_format()
1300 " number of items: "
1301 << f.get_number_of_items()
1304 << f.get_created_by()
1307 << boost::posix_time::to_simple_string(f.get_creation_time())
1310 << f.get_created_on()
1312 " last modified by: \'"
1313 << f.get_last_modified_by()
1315 " last modification time: "
1316 << boost::posix_time::to_simple_string(f.get_last_modification_time())
1318 " last modified on: "
1319 << f.get_last_modified_on()
1322 << (f.is_read_only() ?
"read-only" :
"read-write")
1325 << (f.is_locked() ?
"" :
"not ")
1328 << (f.is_updated() ?
"" :
"not ") <<
"updated\n";
1331 size_t num_of_includes = f.get_include_files().size();
1333 if (num_of_includes) {
1334 s <<
" contains " << num_of_includes <<
" include file(s)";
1335 for (
const auto& i : f.get_include_files())
1336 s <<
" - \'" << i <<
"\'\n";
1338 s <<
" contains no include files\n";
1343 size_t num_of_comments = f.get_comments().size();
1345 if (num_of_comments) {
1346 s <<
" contains " << num_of_comments <<
" comment(s)";
1347 for (
const auto& i : f.get_comments())
1348 s <<
" - " << boost::posix_time::to_simple_string(boost::posix_time::from_iso_string(i.first)) <<
": \'"
1349 << *i.second <<
"\'\n";
1351 s <<
" contains no comments\n";
1355 s <<
"END of oks file\n";
1384 if (update_repository ==
true ) {
1387 if (!full_repository_name.empty() && stat(full_repository_name.c_str(), &buf) == 0) {
1453 OksFile::Map::const_iterator j = data_files.find(&s);
1454 if (j != data_files.end()) {
1455 if (
out.find(j->second) !=
out.end()) {
1458 out.insert(j->second);
1460 j = schema_files.find(&s);
1461 if (j != schema_files.end()) {
1462 if (
out.find(j->second) !=
out.end()) {
1465 out.insert(j->second);
1471 j->second->get_all_include_files(kernel,
out);
1482 static const char start_tag[] =
"<info ";
1483 static const char last_tag[] =
1484 "last-modification-time=\"yyyymmddThhmmss\"/>";
1486 const std::string::size_type len = line.length();
1488 return ((len < (
sizeof(start_tag) +
sizeof(last_tag))) ||
1489 (line.compare(0,
sizeof(start_tag) - 1, start_tag,
sizeof(start_tag) - 1) != 0) ||
1490 (line.compare(len -
sizeof(last_tag) + 1, 24, last_tag, 24) != 0));
1496 std::ifstream f1(file1_name);
1497 std::ifstream f2(file2_name);
1511 if (f1.eof() && f2.eof()) {
1515 std::getline(f1, line1);
1516 std::getline(f2, line2);
Cannot add include file. Such exception is thrown when OKS cannot add include file.
static std::string fill(const OksFile &file, const std::string &include_name, const std::string &reason) noexcept
Cannot remove include file. Such exception is thrown when OKS cannot remove include file.
static std::string fill(const OksFile &file, const std::string &include_name, const std::string &reason) noexcept
Cannot rename include file. Such exception is thrown when OKS cannot rename include file.
static std::string fill(const OksFile &file, const std::string &from, const std::string &to, const std::string &reason) noexcept
static std::string fill(const OksFile &file, const std::string &action, const std::string &reason) noexcept
static std::string fill(const std::string &src, const std::string &dest, const std::string &reason) noexcept
Cannot add include file. Such exception is thrown when OKS cannot add include file.
static std::string fill(const OksFile &file, bool lock_action, const std::string &reason) noexcept
Provides interface to the OKS XML schema and data files.
static bool compare(const char *file1_name, const char *file2_name)
Compare two files.
static const char xml_schema_file_dtd[]
std::shared_ptr< boost::interprocess::file_lock > p_lock
std::string p_lock_file_name
std::list< std::string >::iterator find_include_file(const std::string &)
static const char xml_comments_tag[]
std::map< std::string, oks::Comment * > p_comments
void unlock()
Unlock OKS file.
void add_include_file(const std::string &name)
Add include file.
time_t p_repository_last_modified
OksFile(const std::string &, const std::string &, const std::string &, const std::string &, OksKernel *)
oks::Comment * get_comment(const std::string &creation_time) noexcept
void get_all_include_files(const OksKernel *kernel, std::set< OksFile * > &out)
Get all include files.
void lock()
Lock OKS file.
void write(OksXmlOutputStream &)
void set_type(const std::string &type)
Set file type.
void init_lock_name() const
bool get_lock_string(std::string &info) const
Return lock status of OKS file and if the file is locked, get information string about process which ...
static const char xml_data_file_dtd[]
std::string make_repository_name() const
static bool p_nolock_mode
boost::posix_time::ptime p_last_modification_time
std::list< std::string > p_list_of_include_files
boost::posix_time::ptime p_creation_time
std::string p_logical_name
const std::string & get_repository_name() const
Get name of file inside repository.
void remove_comment(const std::string &creation_time)
Modify existing comment.
void set_logical_name(const std::string &name)
Set logical name of file.
std::string p_repository_name
std::string p_last_modified_by
void add_comment(const std::string &text, const std::string &author)
Add new comment to file.
std::map< const std::string *, OksFile *, SortByName > Map
void update_status_of_file(bool update_local=true, bool update_repository=true)
Update status of file.
bool is_repository_file() const
Get information about repository, the file belongs to.
void clear_comments() noexcept
static const char xml_file_tag[]
OksFile * check_parent(const OksFile *parent_h)
Set given parent, if this file is not yet included.
const OksFile * p_included_by
static const char xml_comment_tag[]
std::string p_last_modified_on
OksFile & operator=(const OksFile &)
void modify_comment(const std::string &creation_time, const std::string &text, const std::string &author)
void rename_include_file(const std::string &from, const std::string &to)
Rename include file.
static const char xml_file_header[]
FileStatus get_status_of_file() const
Return update status of file.
static const char xml_include_tag[]
void rename(const std::string &short_name, const std::string &full_name)
void remove_include_file(const std::string &name)
Remove include file.
static const char xml_info_tag[]
Provides interface to the OKS kernel.
const std::string & get_user_repository_root() const
Get user OKS repository root.
static std::string & get_host_name()
Get hostname of given process.
static std::string & get_user_name()
Get username of given process.
static bool check_read_only(OksFile *f)
Check if the OKS file is read-only.
const OksFile::Map & data_files() const
Get all data files.
void k_close_dangling_includes()
Close files which lost their parent.
OksFile * k_load_file(const std::string &name, bool bind, const OksFile *parent, OksPipeline *pipeline)
std::string get_file_path(const std::string &path, const OksFile *parent_file=0, bool strict_paths=true) const
Calculates full path to file.
static const std::string & get_repository_root()
Get OKS repository root.
static const char * GetVersion()
Get OKS version. The method returns string containing CVS tag and date of OKS build.
bool get_silence_mode() const
Get status of silence mode. The method returns true, if the silence mode is switched 'On'....
const OksFile::Map & schema_files() const
Get all schema files.
void put_last_tag(const char *, size_t len)
void put_attribute(const char *, size_t len, const char *)
void put_start_tag(const char *, size_t len)
static std::ostream & warning_msg(const char *)
virtual const char * what() const noexcept
#define TLOG_DEBUG(lvl,...)
bool cmp_str8(const char *s1, const char s2[9])
const std::string strerror(int error)
Convert C error number to string.
bool cmp_str1(const char *s1, const char s2[2])
bool cmp_str4(const char *s1, const char s2[5])
bool cmp_str6(const char *s1, const char s2[7])
bool cmp_str10(const char *s1, const char s2[11])
static bool is_not_info(const std::string &line)
bool cmp_str9(const char *s1, const char s2[10])
boost::posix_time::ptime str2time(const char *value, size_t len, const char *file_name=nullptr)
std::ostream & operator<<(std::ostream &s, const oks::exception &ex)
bool cmp_str13(const char *s1, const char s2[14])
bool cmp_str16(const char *s1, const char s2[17])
bool cmp_str15(const char *s1, const char s2[16])
bool cmp_str11(const char *s1, const char s2[12])
bool cmp_str12(const char *s1, const char s2[13])
bool cmp_str7(const char *s1, const char s2[8])
FELIX Initialization std::string initerror FELIX queue timed out
Both frame_count_limit and tp_count_limit were set to(disabled) in the TPCRawDataProcessor " "config. TPs will not send."