|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <logoutputfactory.h> |
|
18 #include <QHash> |
|
19 #include <QMetaObject> |
|
20 #include <QMetaProperty> |
|
21 #include "logoutput.h" |
|
22 #include "loglogger.h" |
|
23 |
|
24 typedef QHash<QString,LogOutputFactory::CREATE_ENTRY> CreateEntryContainer; |
|
25 |
|
26 Q_GLOBAL_STATIC(CreateEntryContainer, theCreateEntryList) |
|
27 |
|
28 static QString formalizeName(const QString &name) |
|
29 { |
|
30 QString formalName = name; |
|
31 formalName.toLower(); |
|
32 formalName = formalName.trimmed(); |
|
33 return formalName; |
|
34 } |
|
35 |
|
36 LogOutput *LogOutputFactory::createLogOutput(const QString &name) |
|
37 { |
|
38 return createLogOutput(name,QHash<QString,QVariant>()); |
|
39 } |
|
40 |
|
41 LogOutput *LogOutputFactory::createLogOutput(const QString &name, |
|
42 const QHash<QString,QVariant> &properties /*= QHash<QString,QVariant>()*/) |
|
43 { |
|
44 LogOutputFactory::CREATE_ENTRY entry = theCreateEntryList()->value(formalizeName(name)); |
|
45 |
|
46 LogOutput *output = entry ? (*entry)() : 0; |
|
47 |
|
48 if (output && !properties.isEmpty()) { |
|
49 const QMetaObject *metaObj = output->metaObject(); |
|
50 int count = metaObj->propertyCount(); |
|
51 for (int i = 0; i < count; i++) { |
|
52 QMetaProperty metaProperty = metaObj->property(i); |
|
53 if (metaProperty.isValid() && metaProperty.isWritable()) { |
|
54 QVariant var = properties.value(metaProperty.name()); |
|
55 if (var.isValid()) { |
|
56 metaProperty.write(output,var); |
|
57 } |
|
58 } |
|
59 } |
|
60 } |
|
61 |
|
62 return output; |
|
63 } |
|
64 |
|
65 void LogOutputFactory::addCreateLogOutputEntry(const QString &name,CREATE_ENTRY entry) |
|
66 { |
|
67 if (!entry) { |
|
68 return; |
|
69 } |
|
70 |
|
71 QString formalName = formalizeName(name); |
|
72 |
|
73 if (theCreateEntryList()->value(formalName)) { |
|
74 LOGGER_LOG(QString("LogOutputFactory::addCreateLogOutputEntry << ") |
|
75 + QString("create entry with the name:") + formalName + QString("already exists.")); |
|
76 return; |
|
77 } |
|
78 |
|
79 theCreateEntryList()->insert(formalName,entry); |
|
80 } |