CCard * CardConnect(const std::string &csReader, CContext *poContext, CPinpad *poPinpad, CDynamicLib &oCardPluginLib) { CCard *poCard = NULL; long lErrCode = EIDMW_ERR_CHECK; // should never be returned const char *strReader = NULL; if (poContext->m_ulConnectionDelay != 0) CThread::SleepMillisecs(poContext->m_ulConnectionDelay); // Try if we can connect to the card via a normal SCardConnect() SCARDHANDLE hCard = 0; try { hCard = poContext->m_oPCSC.Connect(csReader); if (hCard == 0) goto done; } catch(CMWException &e) { if (e.GetError() == (long)EIDMW_ERR_NO_CARD) goto done; if (e.GetError() != (long)EIDMW_ERR_CANT_CONNECT && e.GetError() != (long)EIDMW_ERR_CARD_COMM) throw; lErrCode = e.GetError(); hCard = 0; } // So a card is present, get the names of the available plugin libs if (!m_bPluginNamesOK) GetPluginNames(); strReader = csReader.c_str(); if (hCard != 0) { // 1. A card is present and we could connect to it via a normal SCardConnect() for (size_t i = 0; poCard == NULL && i < m_Plugins.size(); i++) { tPluginInfo &plugin = m_Plugins.at(i); if (plugin.csReader.size() != 0 && plugin.csReader.compare(0, string::npos, strReader, plugin.csReader.length())) continue; poCard = GetCardInstance(strReader, hCard, poContext, poPinpad, plugin.csPath, oCardPluginLib); } #ifdef CAL_BEID if (poCard == NULL) poCard = BeidCardGetInstance(PLUGIN_VERSION, strReader, hCard, poContext, poPinpad); //if (poCard == NULL) // poCard = SISPluginReadData(strReader, hCard, poContext, poPinpad, oCardPluginLib); /* SIS support no longer in the CardLayer�, only via the plugins */ #if SIS_IN_CAL if (poCard == NULL && StartsWith(csReader.c_str(), "ACS ACR38")) { #ifdef __APPLE__ poContext->m_oPCSC.Disconnect(hCard, DISCONNECT_RESET_CARD); poCard = SISCardConnectGetInstance(PLUGIN_VERSION, strReader, poContext, poPinpad); #else poCard = SISCardGetInstance(PLUGIN_VERSION, strReader, hCard, poContext, poPinpad); #endif } #ifdef CAL_EMULATION // Emulated reader doesn't start with "ACS ACR38" if (poCard == NULL) poCard = SISCardGetInstance(PLUGIN_VERSION, strReader, hCard, poContext, poPinpad); #endif #endif // SIS_IN_CAL #endif // CAL_BEID #ifndef __APPLE__ // If no other CCard subclass could be found if (poCard == NULL) poCard = new CUnknownCard(hCard, poContext, poPinpad, CByteArray()); #else // On Mac OS X, SCardConnect() always works when reading a SIS card on an ACR38U, // but not the following SCardTransmit() to read out the data. So we set hCard // to 0 which will cause SISCardConnectGetInstance() below to first switch to // the correct mode to read out the SIS card. hCard = 0; #endif } if (hCard == 0) { // 2. A card is present, but connecting to it is reader-specific (e.g. synchron. cards) strReader = csReader.c_str(); for (size_t i = 0; poCard == NULL && i < m_Plugins.size(); i++) { tPluginInfo &plugin = m_Plugins.at(i); if (!plugin.bFull || (plugin.csReader.size() != 0 && plugin.csReader.compare(0, string::npos, strReader, plugin.csReader.length()))) continue; poCard = ConnectGetCardInstance(strReader, poContext, poPinpad, plugin.csPath, oCardPluginLib); } #ifdef CAL_BEID // if (poCard == NULL) // poCard = SISPluginReadData(strReader, hCard, poContext, poPinpad, oCardPluginLib); if (poCard == NULL) poCard = new CUnknownCard(hCard, poContext, poPinpad, CByteArray()); /* SIS support no longer in the CardLayer�, only via the plugins */ #if SIS_IN_CAL if (poCard == NULL && StartsWith(csReader.c_str(), "ACS ACR38")) poCard = SISCardConnectGetInstance(PLUGIN_VERSION, strReader, poContext, poPinpad); #endif // SIS_IN_CAL #endif // CAL_BEID // If the card is still not recognized here, then it may as well // be an badly inserted card, so we'll throw the exception that we // caught in the beginnin of this function if (poCard == NULL) throw CMWEXCEPTION(lErrCode); } done: return poCard; }
int main (int argc, char** argv) { // Creates runtime and base app pI::Application app; pI::Runtime runtime(app.GetRuntime()); std::cerr << "Plugin dir: " << app.FindPIPluginDir() << std::endl; app.LoadPluginLibraries (app.FindPIPluginDir().c_str()); std::vector<std::string> names(GetPluginNames (runtime)); const pI_int count(names.size()); std::cout << "{" << std::endl; appendValue(std::cout, API_VERSION, runtime.GetRuntimeVersion()); appendValue(std::cout, PLUGIN_COUNT, count); std::cout << "\"" << PLUGINS << "\":" << std::endl << "[" << std::endl; for (pI_int lv = 0; lv < count; ++lv) { std::cout << "{" << std::endl; appendValue(std::cout, NAME, names[lv]); if (names[lv] == "CImg/Functions") { // special treatment for CImg META plugin try { pI::pInPtr p(runtime.SpawnPlugin ((const pI_str) names[lv].c_str())); pI::Arguments params(p->GetParameterSignature()); appendValue(std::cout, DESCRIPTION, p->GetDescription()); appendValue(std::cout, PLUGIN_VERSION, p->GetpInVersion()); appendValue(std::cout, API_VERSION, p->GetAPIVersion()); appendValue(std::cout, AUTHOR, p->GetAuthor()); appendValue(std::cout, COPYRIGHT, p->GetCopyright()); appendValue(std::cout, OPTIONAL_INIT, "false"); appendValue(std::cout, DEFAULT_INIT, "true"); std::cout << "\"parameters\":" << std::endl << "[" << std::endl; for (pI_size lv2 = 0; lv2 < params.size(); ++lv2) { std::cout << runtime.SerializeArgument (params[lv2]); if (lv2 < params.size() - 1) { std::cout << ","; } std::cout << std::endl; } std::cout << "]," << std::endl; pI::StringSelection sts(params[0]); std::cout << "\"CImg functions\":" << std::endl << "[" << std::endl; for (pI_size lv2 = 0; lv2 < sts.GetCount(); ++lv2) { sts.SetIndex (lv2); p->Initialize (params); std::cout << "{" << std::endl; appendValue(std::cout, NAME, sts.GetSymbols (lv2)); std::cout << "\"inputSignature\":" << std::endl << "[" << std::endl; pI::Arguments is(p->GetInputSignature()); for (pI_size lv3 = 0; lv3 < is.size(); ++lv3) { std::cout << runtime.SerializeArgument (is[lv3]); if (lv3 < is.size() - 1) std::cout << ","; } std::cout << std::endl << "]," << std::endl; std::cout << "\"outputSignature\":" << std::endl << "[" << std::endl; pI::Arguments os(p->GetOutputSignature()); for (pI_size lv3 = 0; lv3 < os.size(); ++lv3) { std::cout << runtime.SerializeArgument (os[lv3]); if (lv3 < os.size() - 1) std::cout << ","; } std::cout << std::endl << "]" << std::endl; std::cout << "}"; if (lv2 < sts.GetCount() - 1) std::cout << ","; std::cout << std::endl; } std::cout << "]" << std::endl; } catch (...) {} } else { try { pI::pInPtr p(runtime.SpawnPlugin ((const pI_str) names[lv].c_str())); appendValue(std::cout, DESCRIPTION, p->GetDescription()); appendValue(std::cout, PLUGIN_VERSION, p->GetpInVersion()); appendValue(std::cout, API_VERSION, p->GetAPIVersion()); appendValue(std::cout, AUTHOR, p->GetAuthor()); appendValue(std::cout, COPYRIGHT, p->GetCopyright()); bool optional_init((p->GetInputSignature().size() > 0) || (p->GetOutputSignature().size() > 0)); appendValue(std::cout, OPTIONAL_INIT, (optional_init ? "true" : "false")); std::cout << "\"" << PARAMETERS << "\":" << std::endl << "[" << std::endl; pI::Arguments params(p->GetParameterSignature()); for (pI_size lv2 = 0; lv2 < params.size(); ++lv2) { std::cout << runtime.SerializeArgument (params[lv2]); if (lv2 < params.size() - 1) { std::cout << ","; } std::cout << std::endl; } std::cout << "]," << std::endl; bool default_init; try { p->Initialize (params); default_init = true; } catch (...) { default_init = false; } appendValue(std::cout, DEFAULT_INIT, (default_init ? "true" : "false"), optional_init || default_init); if (optional_init || default_init) { std::cout << "\"" << INPUT_SIGNATURE << "\":" << std::endl << "[" << std::endl; pI::Arguments is(p->GetInputSignature()); for (pI_size lv2 = 0; lv2 < is.size(); ++lv2) { std::cout << runtime.SerializeArgument (is[lv2]); if (lv2 < is.size() - 1) std::cout << ","; } std::cout << std::endl << "]," << std::endl; std::cout << "\"" << OUTPUT_SIGNATURE << "\":" << std::endl << "[" << std::endl; pI::Arguments os(p->GetOutputSignature()); for (pI_size lv2 = 0; lv2 < os.size(); ++lv2) { std::cout << runtime.SerializeArgument (os[lv2]); if (lv2 < os.size() - 1) std::cout << ","; } std::cout << std::endl << "]" << std::endl; } else std::cout << std::endl; } catch (...) {} } std::cout << "}"; if (lv < count - 1) std::cout << ","; std::cout << std::endl; } std::cout << "]" << std::endl << "}" << std::endl; return 0; }