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