|
| 1 | +/* IBM_PROLOG_BEGIN_TAG */ |
| 2 | +/* This is an automatically generated prolog. */ |
| 3 | +/* */ |
| 4 | +/* $Source: src/usr/console/console.C $ */ |
| 5 | +/* */ |
| 6 | +/* OpenPOWER HostBoot Project */ |
| 7 | +/* */ |
| 8 | +/* Contributors Listed Below - COPYRIGHT 2014 */ |
| 9 | +/* [+] International Business Machines Corp. */ |
| 10 | +/* [+] Google Inc. */ |
| 11 | +/* */ |
| 12 | +/* */ |
| 13 | +/* Licensed under the Apache License, Version 2.0 (the "License"); */ |
| 14 | +/* you may not use this file except in compliance with the License. */ |
| 15 | +/* You may obtain a copy of the License at */ |
| 16 | +/* */ |
| 17 | +/* http://www.apache.org/licenses/LICENSE-2.0 */ |
| 18 | +/* */ |
| 19 | +/* Unless required by applicable law or agreed to in writing, software */ |
| 20 | +/* distributed under the License is distributed on an "AS IS" BASIS, */ |
| 21 | +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ |
| 22 | +/* implied. See the License for the specific language governing */ |
| 23 | +/* permissions and limitations under the License. */ |
| 24 | +/* */ |
| 25 | +/* IBM_PROLOG_END_TAG */ |
| 26 | +#include <console/consoleif.H> |
| 27 | +#include <util/sprintf.H> |
| 28 | +#include <sys/msg.h> |
| 29 | +#include <stdio.h> |
| 30 | +#include <string.h> |
| 31 | +#include <time.h> |
| 32 | +#include <vector> |
| 33 | +#include "daemon.H" |
| 34 | + |
| 35 | +namespace CONSOLE |
| 36 | +{ |
| 37 | + msg_q_t g_msgq = msg_q_create(); |
| 38 | + |
| 39 | + void display(const char* str) |
| 40 | + { |
| 41 | + timespec_t time; |
| 42 | + clock_gettime(CLOCK_MONOTONIC, &time); |
| 43 | + |
| 44 | + msg_t* msg = msg_allocate(); |
| 45 | + msg->type = DISPLAY; |
| 46 | + msg->data[0] = time.tv_sec; |
| 47 | + msg->data[1] = time.tv_nsec; |
| 48 | + msg->extra_data = strdup(str); |
| 49 | + msg_send(g_msgq, msg); |
| 50 | + } |
| 51 | + |
| 52 | + void displayf(const char* header, const char* format, ...) |
| 53 | + { |
| 54 | + va_list args; |
| 55 | + va_start(args, format); |
| 56 | + |
| 57 | + vdisplayf(header, format, args); |
| 58 | + |
| 59 | + va_end(args); |
| 60 | + } |
| 61 | + |
| 62 | + void vdisplayf(const char* header, const char* format, va_list args) |
| 63 | + { |
| 64 | + using Util::vasprintf; |
| 65 | + |
| 66 | + class OutputBuffer : public Util::ConsoleBufferInterface |
| 67 | + { |
| 68 | + public: |
| 69 | + int putc(int c) |
| 70 | + { |
| 71 | + str.push_back(c); |
| 72 | + return c; |
| 73 | + } |
| 74 | + |
| 75 | + size_t operator()(int c) { return putc(c); } |
| 76 | + |
| 77 | + std::vector<char> str; |
| 78 | + }; |
| 79 | + |
| 80 | + OutputBuffer b; |
| 81 | + |
| 82 | + if (header) |
| 83 | + { |
| 84 | + while(*header) |
| 85 | + { |
| 86 | + b.putc(*header); |
| 87 | + header++; |
| 88 | + } |
| 89 | + b.putc('|'); |
| 90 | + } |
| 91 | + |
| 92 | + vasprintf(b, format, args); |
| 93 | + b.putc('\n'); |
| 94 | + b.putc('\0'); |
| 95 | + |
| 96 | + if (b.str.size()) |
| 97 | + { |
| 98 | + display(&b.str[0]); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + void flush() |
| 103 | + { |
| 104 | + msg_t* msg = msg_allocate(); |
| 105 | + msg->type = SYNC; |
| 106 | + msg_sendrecv(g_msgq, msg); |
| 107 | + } |
| 108 | + |
| 109 | +} |
0 commit comments