• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "image_io/base/message_handler.h"
2 
3 #include <memory>
4 #include <string>
5 #include <utility>
6 
7 #include "image_io/base/cout_message_writer.h"
8 
9 namespace photos_editing_formats {
10 namespace image_io {
11 
12 using std::string;
13 using std::unique_ptr;
14 
MessageHandler()15 MessageHandler::MessageHandler()
16     : message_writer_(new CoutMessageWriter),
17       message_store_(new VectorMessageStore),
18       message_stats_(new MessageStats) {}
19 
SetMessageWriter(std::unique_ptr<MessageWriter> message_writer)20 void MessageHandler::SetMessageWriter(
21     std::unique_ptr<MessageWriter> message_writer) {
22   message_writer_ = std::move(message_writer);
23 }
24 
SetMessageStore(std::unique_ptr<MessageStore> message_store)25 void MessageHandler::SetMessageStore(
26     std::unique_ptr<MessageStore> message_store) {
27   message_store_ = std::move(message_store);
28 }
29 
ReportMessage(Message::Type type,const string & text)30 void MessageHandler::ReportMessage(Message::Type type, const string& text) {
31   int system_errno = (type == Message::kStdLibError) ? errno : 0;
32   ReportMessage(Message(type, system_errno, text));
33 }
34 
ReportMessage(const Message & message)35 void MessageHandler::ReportMessage(const Message& message) {
36   if (message.IsError()) {
37     message_stats_->error_count++;
38   } else if (message.IsWarning()) {
39     message_stats_->warning_count++;
40   } else {
41     message_stats_->status_count++;
42   }
43   if (message_store_) {
44     message_store_->AddMessage(message);
45   }
46   if (message_writer_) {
47     message_writer_->WriteMessage(message);
48   }
49 }
50 
51 }  // namespace image_io
52 }  // namespace photos_editing_formats
53