1 /*
2 * Copyright (c) 2014, 2016, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted
5 * provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright notice, this list of
7 * conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright notice, this list of
9 * conditions and the following disclaimer in the documentation and/or other materials provided
10 * with the distribution.
11 * * Neither the name of The Linux Foundation nor the names of its contributors may be used to
12 * endorse or promote products derived from this software without specific prior written
13 * permission.
14 *
15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <utils/constants.h>
29
30 #include "dump_impl.h"
31
32 namespace sdm {
33
34 DumpImpl* DumpImpl::dump_list_[] = { 0 };
35 uint32_t DumpImpl::dump_count_ = 0;
36
GetDump(char * buffer,uint32_t length)37 DisplayError DumpInterface::GetDump(char *buffer, uint32_t length) {
38 if (!buffer || !length) {
39 return kErrorParameters;
40 }
41
42 buffer[0] = '\0';
43 DumpImpl::AppendString(buffer, length, "\n-------- Snapdragon Display Manager --------");
44 for (uint32_t i = 0; i < DumpImpl::dump_count_; i++) {
45 DumpImpl::dump_list_[i]->AppendDump(buffer, length);
46 }
47 DumpImpl::AppendString(buffer, length, "\n\n");
48
49 return kErrorNone;
50 }
51
DumpImpl()52 DumpImpl::DumpImpl() {
53 Register(this);
54 }
55
~DumpImpl()56 DumpImpl::~DumpImpl() {
57 Unregister(this);
58 }
59
AppendString(char * buffer,uint32_t length,const char * format,...)60 void DumpImpl::AppendString(char *buffer, uint32_t length, const char *format, ...) {
61 uint32_t filled = UINT32(strlen(buffer));
62 // Reserve one byte for null terminating character
63 if ((filled + 1) >= length) {
64 return;
65 }
66 buffer += filled;
67
68 va_list list;
69 va_start(list, format);
70 vsnprintf(buffer, length - filled -1, format, list);
71 }
72
73 // Every object is created or destroyed through display core only, which itself protects the
74 // the access, so no need to protect registration or de-registration.
Register(DumpImpl * dump_impl)75 void DumpImpl::Register(DumpImpl *dump_impl) {
76 if (dump_count_ < kMaxDumpObjects) {
77 dump_list_[dump_count_] = dump_impl;
78 dump_count_++;
79 }
80 }
81
Unregister(DumpImpl * dump_impl)82 void DumpImpl::Unregister(DumpImpl *dump_impl) {
83 for (uint32_t i = 0; i < dump_count_; i++) {
84 if (dump_list_[i] == dump_impl) {
85 dump_count_--;
86 for (; i < dump_count_; i++) {
87 dump_list_[i] = dump_list_[i + 1];
88 }
89 }
90 }
91 }
92
93 } // namespace sdm
94
95