--- /dev/null
+/*
+ * SWAP Trace Parser
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * Alexander Aksenov <a.aksenov@samsung.com>
+ *
+ * Licensed 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.
+ *
+ * Contributors:
+ * - Samsung RnD Institute Russia
+ *
+ */
+
+
+
+#include <boost/algorithm/string.hpp>
+#include <data_writer.h>
+#include "writer_py.h"
+
+
+template<typename T>
+static void data_out(const std::string &name, const T val, std::ostream &ios_)
+{
+ ios_ << "'" << name << "': " << val << "," << std::endl;
+}
+
+template<typename T>
+static void data_hex_out(const std::string &name, const T val,
+ std::ostream &ios_)
+{
+ ios_ << "'" << name << "': 0x" << std::hex << val << std::dec << "," << std::endl;
+}
+
+template<typename T>
+static void args_out(const std::string &name, const T val, std::ostream &ios_)
+{
+ ios_ << "'" << name << "': " << val << "," << std::endl;
+}
+
+template<typename T>
+static void args_vector_out(const std::string &name, const std::vector<T> &val,
+ std::ostream &ios_)
+{
+ ios_ << "'" << name << "': [";
+
+ for (auto const &item : val)
+ ios_ << item << ", ";
+
+ ios_ << "]," << std::endl;
+}
+
+
+void DataWriterPython::output_val(const std::string &name, const uint8_t val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterPython::output_val(const std::string &name, const uint32_t val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterPython::output_val(const std::string &name, const uint64_t val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterPython::output_val(const std::string &name, const float val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterPython::output_val(const std::string &name, const double val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterPython::output_val(const std::string &name,
+ const std::string &val)
+{
+ ios_ << "'" << name << "': '";
+
+ if ((val.find("\n") == std::string::npos) && (val.find("\r") == std::string::npos)) {
+ ios_ << val;
+ } else {
+ std::string new_val(val);
+
+ boost::replace_all(new_val, "\n", "\\n");
+ boost::replace_all(new_val, "\r", "\\r");
+ ios_ << new_val;
+ }
+
+ ios_ << "'," << std::endl;
+}
+
+void DataWriterPython::output_val(const std::string &name, const char val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterPython::output_val(const std::string &name, const int val)
+{
+ data_out(name, val, ios_);
+}
+
+void DataWriterPython::output_hex(const std::string &name, const uint32_t val)
+{
+ data_hex_out(name, val, ios_);
+}
+
+void DataWriterPython::output_hex(const std::string &name, const uint64_t val)
+{
+ data_hex_out(name, val, ios_);
+}
+
+void DataWriterPython::output_args(const std::string &name, const bool val)
+{
+ args_out(name, val, ios_);
+}
+
+void DataWriterPython::output_args(const std::string &name, const uint8_t val)
+{
+ args_out(name, val, ios_);
+}
+
+void DataWriterPython::output_args(const std::string &name, const uint32_t val)
+{
+ args_out(name, val, ios_);
+}
+
+void DataWriterPython::output_args(const std::string &name, const uint64_t val)
+{
+ args_out(name, val, ios_);
+}
+
+void DataWriterPython::output_args(const std::string &name, const float val)
+{
+ args_out(name, val, ios_);
+}
+
+void DataWriterPython::output_args(const std::string &name, const double val)
+{
+ args_out(name, val, ios_);
+}
+
+void DataWriterPython::output_args(const std::string &name,
+ const std::string &val)
+{
+ ios_ << "'" << name << "': '";
+
+ if ((val.find("\n") == std::string::npos) && (val.find("\r") == std::string::npos)) {
+ ios_ << val;
+ } else {
+ std::string new_val(val);
+
+ boost::replace_all(new_val, "\n", "\\n");
+ boost::replace_all(new_val, "\r", "\\r");
+
+ ios_ << new_val;
+ }
+
+ ios_ << "'," << std::endl;
+}
+
+void DataWriterPython::output_args(const std::string &name,
+ const std::vector<float> &val, uint64_t p)
+{
+ args_vector_out(name, val, ios_);
+}
+
+void DataWriterPython::output_args(const std::string &name,
+ const std::vector<uint32_t> &val, uint64_t p)
+{
+ args_vector_out(name, val, ios_);
+}
+
+void DataWriterPython::output_args(const std::string &name)
+{
+ ios_ << "'" << name << "': None," << std::endl;
+}
+
+void DataWriterPython::output_args_hex(const std::string &name,
+ const uint64_t val)
+{
+ ios_ << "'" << name << "': 0x" << std::hex << val << std::dec << ","
+ << std::endl;
+}
+
+void DataWriterPython::output_time(const std::string &name, uint64_t val)
+{
+ ios_ << name << ": " << val << "," << std::endl;
+}
+
+void DataWriterPython::output_buf(const std::vector<char> &buf)
+{
+ // TODO No place with implemnetation
+}
+
+void DataWriterPython::start_array(const std::string &name)
+{
+ ios_ << "'" << name << "': {" ;
+}
+
+void DataWriterPython::finish_array()
+{
+ ios_ << "}," << std::endl;
+}
+
+void DataWriterPython::start_object(const std::string &name)
+{
+ ios_ << "'" << name << "':{";
+}
+
+void DataWriterPython::finish_object()
+{
+ ios_ << "}," << std::endl;
+}
+
+void DataWriterPython::start_msg()
+{
+ ios_ << "{";
+}
+
+void DataWriterPython::finish_msg()
+{
+ ios_ << "}," << std::endl;
+}
+
+void DataWriterPython::start_file(const uint32_t version)
+{
+ ios_ << "trace_info = {" << std::endl;
+ ios_ << "'protocol_version': " << version << std::endl;
+ ios_ << "}" << std::endl;
+
+ ios_ << "trace_obj = [" << std::endl;
+}
+
+void DataWriterPython::finish_file()
+{
+ ios_ << "]" << std::endl;
+}
--- /dev/null
+/*
+ * SWAP Trace Parser
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * Alexander Aksenov <a.aksenov@samsung.com>
+ *
+ * Licensed 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.
+ *
+ * Contributors:
+ * - Samsung RnD Institute Russia
+ *
+ */
+
+
+
+#ifndef __WRITER_PY_H__
+#define __WRITER_PY_H__
+
+
+#include <data_writer.h>
+
+
+class DataWriterPython: public DataWriter
+{
+public:
+ using DataWriter::DataWriter;
+
+ void start_file(const uint32_t version);
+ void finish_file();
+
+ void start_msg();
+ void finish_msg();
+
+ void output_val(const std::string &name, const uint8_t val);
+ void output_val(const std::string &name, const uint32_t val);
+ void output_val(const std::string &name, const uint64_t val);
+ void output_val(const std::string &name, const float val);
+ void output_val(const std::string &name, const double val);
+ void output_val(const std::string &name, const std::string &val);
+ void output_val(const std::string &name, const char val);
+ void output_val(const std::string &name, const int val);
+
+ void output_hex(const std::string &name, const uint32_t val);
+ void output_hex(const std::string &name, const uint64_t val);
+
+ void output_args(const std::string &name, const bool val);
+ void output_args(const std::string &name, const uint8_t val);
+ void output_args(const std::string &name, const uint32_t val);
+ void output_args(const std::string &name, const uint64_t val);
+ void output_args(const std::string &name, const float val);
+ void output_args(const std::string &name, const double val);
+ void output_args(const std::string &name, const std::string &val);
+ void output_args(const std::string &name);
+ void output_args(const std::string &name, const std::vector<float> &val,
+ uint64_t p);
+ void output_args(const std::string &name, const std::vector<uint32_t> &val,
+ uint64_t p);
+ void output_args_hex(const std::string &name, const uint64_t val);
+
+ void output_time(const std::string &name, const uint64_t val);
+ void output_buf(const std::vector<char> &buf);
+ void start_array(const std::string &name);
+ void finish_array();
+ void start_object(const std::string &name);
+ void finish_object();
+};
+
+#endif /* __WRITER_PY_H__ */