1 /* 2 * Copyright 2009 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Author(s): 6 * Ma Jie, china.majie at gmail 7 */ 8 9 #include "PoorManLogger.h" 10 11 #include <time.h> 12 #include <netinet/in.h> 13 14 #include <Messenger.h> 15 #include <Message.h> 16 #include <TypeConstants.h> 17 18 #include "PoorManApplication.h" 19 #include "PoorManWindow.h" 20 21 void 22 poorman_log(const char* msg, bool needTimeHeader, 23 in_addr_t addr, rgb_color color) 24 { 25 time_t now = time(NULL); 26 27 PoorManWindow* window = static_cast<PoorManApplication*>(be_app)->GetPoorManWindow(); 28 29 if(!window->LogConsoleFlag() && !window->LogFileFlag()) 30 return; 31 32 BMessenger messenger(window); 33 BMessage message(MSG_LOG); 34 35 if(message.AddString("cstring", msg) != B_OK) 36 return; 37 if(needTimeHeader){ 38 if(message.AddData("time_t", B_TIME_TYPE, &now, sizeof(time_t)) != B_OK) 39 return; 40 } 41 if(addr != INADDR_NONE) 42 message.AddData("in_addr_t", B_ANY_TYPE, &addr, sizeof(in_addr_t)); 43 44 if(color != BLACK) 45 message.AddData("rgb_color", B_RGB_COLOR_TYPE, &color, sizeof(rgb_color)); 46 47 messenger.SendMessage(&message, (BHandler*)NULL, 1000000); 48 } 49