|
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 * This file contains the header file of the Plugin, FrontendPlugin, |
|
16 * CommChannelPlugin and CommChannelPluginObserver classes and implementation |
|
17 * of DummyCommObserver. |
|
18 */ |
|
19 |
|
20 // INCLUDES |
|
21 #include "IPCommPlugin.h" |
|
22 #include "plugin.h" |
|
23 #include "util.h" |
|
24 #include "serialcommplugin.h" |
|
25 |
|
26 |
|
27 extern DWORD g_ErrorCode; |
|
28 |
|
29 //********************************************************************************** |
|
30 // Class Plugin |
|
31 // |
|
32 //********************************************************************************** |
|
33 |
|
34 Plugin::Plugin() |
|
35 { |
|
36 Init(); |
|
37 } |
|
38 |
|
39 DWORD Plugin::Init() |
|
40 { |
|
41 m_Name = "NULL Plugin"; |
|
42 return NO_ERRORS; |
|
43 } |
|
44 |
|
45 const string& Plugin::GetName(string *name) |
|
46 { |
|
47 if (name != NULL) |
|
48 { |
|
49 *name = m_Name; |
|
50 } |
|
51 return m_Name; |
|
52 } |
|
53 |
|
54 //********************************************************************************** |
|
55 // Class CommChannelPlugin |
|
56 // |
|
57 // This class is the parent class of all communication channel plugins used |
|
58 // in DataGateway. |
|
59 //********************************************************************************** |
|
60 |
|
61 CommChannelPlugin* CommChannelPlugin::m_Self = NULL; |
|
62 |
|
63 /* |
|
64 * This method creates instance of specified plugin |
|
65 */ |
|
66 CommChannelPlugin* CommChannelPlugin::Instance(const string& pluginname, |
|
67 const CommChannelPluginObserver* observer) |
|
68 { |
|
69 if (m_Self == NULL) |
|
70 { |
|
71 if (pluginname.compare("SERIAL") == 0 ) |
|
72 { |
|
73 m_Self = new SerialCommPlugin(observer); |
|
74 } |
|
75 else if (pluginname.compare("IPCOMM") == 0 ) |
|
76 { |
|
77 m_Self = new IPCommPlugin(observer); |
|
78 } |
|
79 else |
|
80 { |
|
81 string err = "Error when creating communication channel plugin.\n"; |
|
82 err += "Unknown plugin '" + pluginname + "'"; |
|
83 Util::Error(err); |
|
84 m_Self = NULL; |
|
85 g_ErrorCode = ERR_DG_UNKNOWN_COMMCHANNEL; |
|
86 } |
|
87 } |
|
88 return m_Self; |
|
89 } |
|
90 |
|
91 /* |
|
92 * This method initializes and connects the instance of plugin |
|
93 */ |
|
94 DWORD CommChannelPlugin::Connect() |
|
95 { |
|
96 if (m_Self == NULL) return ERR_DG_UNINITIALISED_COMMCHANNEL; |
|
97 DWORD res; |
|
98 if ((res = m_Self->Init()) != NO_ERRORS) return res; |
|
99 return m_Self->Open(); |
|
100 } |
|
101 |
|
102 /* |
|
103 * This method closes and deletes the instance of plugin |
|
104 */ |
|
105 DWORD CommChannelPlugin::Disconnect() |
|
106 { |
|
107 if (m_Self == NULL) return ERR_DG_UNINITIALISED_COMMCHANNEL; |
|
108 Util::Info("[DataGateway] Waiting Communication Channel Plugin to shutdown"); |
|
109 m_Self->Close(); |
|
110 delete m_Self; |
|
111 m_Self = NULL; |
|
112 return NO_ERRORS; |
|
113 } |
|
114 |
|
115 CommChannelPlugin::CommChannelPlugin(const CommChannelPluginObserver* observer) |
|
116 : Plugin() |
|
117 { |
|
118 if (observer == NULL) |
|
119 { |
|
120 m_Observer = new DummyCommObserver; |
|
121 } |
|
122 else |
|
123 { |
|
124 m_Observer = observer; |
|
125 } |
|
126 } |
|
127 |
|
128 DWORD CommChannelPlugin::Init() |
|
129 { |
|
130 DWORD res; |
|
131 res = Plugin::Init(); |
|
132 m_Open = false; |
|
133 return res; |
|
134 } |
|
135 |
|
136 // End of the file |