1 /******************************************************************************
2  *
3  *  Copyright 2020 NXP
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #include <NfccI2cTransport.h>
20 #include <NfccTransportFactory.h>
21 #include <phNxpLog.h>
22 
23 /*******************************************************************************
24  **
25  ** Function         NfccTransportFactory
26  **
27  ** Description      Constructor for transportFactory. This will be private to
28  **                  support singleton
29  **
30  ** Parameters       none
31  **
32  ** Returns          none
33  ******************************************************************************/
NfccTransportFactory()34 NfccTransportFactory::NfccTransportFactory() {}
35 
36 /*******************************************************************************
37 **
38 ** Function         getTransport
39 **
40 ** Description      selects and returns transport channel based on the input
41 **                  parameter
42 **
43 ** Parameters       Required transport Type
44 **
45 ** Returns          Selected transport channel
46 ******************************************************************************/
getInstance()47 NfccTransportFactory& NfccTransportFactory::getInstance() {
48   static NfccTransportFactory mTransprtFactoryInstance;
49   return mTransprtFactoryInstance;
50 }
51 
52 /*******************************************************************************
53 **
54 ** Function         getTransport
55 **
56 ** Description      selects and returns transport channel based on the input
57 **                  parameter
58 **
59 ** Parameters       Required transport Type
60 **
61 ** Returns          Selected transport channel
62 ******************************************************************************/
getTransport(transportIntf transportType)63 spTransport NfccTransportFactory::getTransport(transportIntf transportType) {
64   NXPLOG_TML_D("%s Requested transportType: %d\n", __func__, transportType);
65   spTransport mspTransportInterface;
66   switch (transportType) {
67     case I2C:
68     case UNKNOWN:
69       mspTransportInterface = std::make_shared<NfccI2cTransport>();
70       break;
71     default:
72       mspTransportInterface = std::make_shared<NfccI2cTransport>();
73       break;
74   }
75   return mspTransportInterface;
76 }
77