Keyple C++
0.9.0
Keyple, an Open Source SDK for Ticketing
|
#include <AbstractObservableLocalReader.h>
Inherits keyple::core::seproxy::plugin::AbstractLocalReader, and keyple::core::seproxy::plugin::ObservableReaderNotifier.
Inherited by keyple::plugin::pcsc::PcscReaderImpl [virtual]
, and keyple::plugin::stub::StubReaderImpl.
Public Member Functions | |
AbstractObservableLocalReader (const std::string &pluginName, const std::string &readerName) | |
virtual | ~AbstractObservableLocalReader ()=default |
bool | isSePresent () override |
void | startSeDetection (const ObservableReader::PollingMode pollingMode) final |
void | stopSeDetection () final |
void | setDefaultSelectionRequest (std::shared_ptr< AbstractDefaultSelectionsRequest > defaultSelectionsRequest, const ObservableReader::NotificationMode ¬ificationMode) final |
void | setDefaultSelectionRequest (std::shared_ptr< AbstractDefaultSelectionsRequest > defaultSelectionsRequest, const ObservableReader::NotificationMode ¬ificationMode, const ObservableReader::PollingMode pollingMode) final |
virtual std::shared_ptr< ReaderEvent > | processSeInserted () |
bool | isSePresentPing () |
void | processSeRemoved () |
const ObservableReader::PollingMode & | getPollingMode () const |
const MonitoringState & | getCurrentMonitoringState () const |
void | switchState (const MonitoringState stateId) |
void | addObserver (const std::shared_ptr< ObservableReader::ReaderObserver > observer) final |
void | removeObserver (const std::shared_ptr< ObservableReader::ReaderObserver > observer) final |
void | notifyObservers (const std::shared_ptr< ReaderEvent > event) final |
int | countObservers () const final |
void | clearObservers () final |
void | terminateSeCommunication () override |
void | finalizeSeProcessing () override |
void | onEvent (const InternalEvent event) |
![]() | |
AbstractLocalReader (const std::string &pluginName, const std::string &readerName) | |
virtual | ~AbstractLocalReader ()=default |
virtual bool | isLogicalChannelOpen () const final |
void | addSeProtocolSetting (std::shared_ptr< SeProtocol > seProtocol, const std::string &protocolRule) override |
virtual void | setSeProtocolSetting (const std::map< std::shared_ptr< SeProtocol >, std::string > &protocolSetting) override |
virtual std::shared_ptr< SelectionStatus > | openLogicalChannel (std::shared_ptr< SeSelector > seSelector) |
std::shared_ptr< SelectionStatus > | openLogicalChannelAndSelect (std::shared_ptr< SeSelector > seSelector) |
virtual std::vector< std::shared_ptr< SeResponse > > | processSeRequests (const std::vector< std::shared_ptr< SeRequest >> &seRequests, const MultiSeRequestProcessing &multiSeRequestProcessing, const ChannelControl &channelControl) override |
virtual std::shared_ptr< SeResponse > | processSeRequest (const std::shared_ptr< SeRequest > seRequest, const ChannelControl &channelControl) override |
![]() | |
std::vector< std::shared_ptr< SeResponse > > | transmitSeRequests (const std::vector< std::shared_ptr< SeRequest >> &seRequests, const MultiSeRequestProcessing &multiSeRequestProcessing, const ChannelControl &channelControl) override |
std::shared_ptr< SeResponse > | transmitSeRequest (std::shared_ptr< SeRequest > seRequest, const ChannelControl &channelControl) override |
const std::string & | getPluginName () const |
const std::string & | getName () const override |
![]() | |
AbstractSeProxyComponent (const std::string &name) | |
virtual | ~AbstractSeProxyComponent ()=default |
const std::string & | getName () const |
void | setParameters (const std::map< const std::string, const std::string > ¶meters) |
virtual void | setParameter (const std::string &key, const std::string &value)=0 |
![]() | |
virtual | ~SeReader () |
virtual const TransmissionMode & | getTransmissionMode () const =0 |
virtual bool | operator== (const SeReader &o) const |
![]() | |
virtual | ~ProxyElement ()=default |
virtual const std::map< const std::string, const std::string > & | getParameters () const =0 |
virtual void | setParameter (const std::string &key, const std::string &value)=0 |
virtual void | setParameters (const std::map< const std::string, const std::string > ¶meters) |
![]() | |
ObservableReaderNotifier () | |
virtual | ~ObservableReaderNotifier () |
![]() | |
virtual | ~ObservableReader ()=default |
virtual void | addObserver (const std::shared_ptr< ReaderObserver > observer)=0 |
virtual void | removeObserver (const std::shared_ptr< ReaderObserver > observer)=0 |
Protected Member Functions | |
virtual std::shared_ptr< ObservableReaderStateService > | initStateService ()=0 |
![]() | |
virtual bool | checkSePresence ()=0 |
void | closeLogicalAndPhysicalChannels () |
virtual const std::vector< uint8_t > & | getATR ()=0 |
virtual void | setForceGetDataFlag (bool forceGetDataFlag) |
virtual void | openPhysicalChannel ()=0 |
virtual void | closePhysicalChannel ()=0 |
virtual bool | isPhysicalChannelOpen ()=0 |
void | closeLogicalChannel () |
virtual bool | protocolFlagMatches (const std::shared_ptr< SeProtocol > protocolFlag)=0 |
std::shared_ptr< ApduResponse > | processApduRequest (std::shared_ptr< ApduRequest > apduRequest) |
virtual std::vector< uint8_t > | transmitApdu (const std::vector< uint8_t > &apduIn)=0 |
const std::map< std::shared_ptr< SeProtocol >, std::string > & | getProtocolsMap () const |
![]() | |
AbstractReader (const std::string &pluginName, const std::string &name) | |
virtual | ~AbstractReader ()=default |
Protected Attributes | |
std::shared_ptr< ObservableReaderStateService > | mStateService |
![]() | |
std::shared_ptr< DefaultSelectionsRequest > | mDefaultSelectionsRequest |
ObservableReader::NotificationMode | mNotificationMode |
Additional Inherited Members | |
![]() | |
enum | PollingMode { PollingMode::REPEATING, PollingMode::SINGLESHOT } |
![]() | |
std::atomic< bool > | mShuttingDown |
![]() | |
static bool | startsWith (const std::vector< uint8_t > &source, const std::vector< uint8_t > &match) |
This abstract class is used to manage the matter of observing SE events in the case of a local reader.
It provides the means to configure the plugin's behavior when a SE is detected.
The event management implements a ObservableReaderStateService state machine that is composed of four states.
WAIT_FOR_START_DETECTION
Infinitely waiting for a signal from the application to start SE detection by changing to WAIT_FOR_SE_INSERTION state. This signal is given by calling the setDefaultSelectionRequest method.
Note: The system always starts in the WAIT_FOR_START_DETECTION state.
WAIT_FOR_SE_INSERTION
Awaiting the SE insertion. After insertion, the processSeInserted method is called.
A number of cases arise:
There is no default selection: a SE_INSERTED event is then notified.
In the case where an event has been notified to the application, the state machine changes to the WAIT_FOR_SE_PROCESSING state otherwise it remains in the WAIT_FOR_SE_INSERTION state.
The notification consists in calling the "update" methods of the defined observers. In the case where several observers have been defined, it is up to the application developer to ensure that there is no long processing in these methods, by making their execution asynchronous for example.
WAIT_FOR_SE_PROCESSING
Waiting for the end of processing by the application. The end signal is triggered by a transmission made with a CLOSE_AFTER parameter.
If the instruction given when defining the default selection request is to stop (ObservableReader.PollingMode.SINGLESHOT) then the logical and physical channels are closed immediately and the machine state changes to WAIT_FOR_START_DETECTION state.
If the instruction given is continue (ObservableReader.PollingMode.REPEATING) then the state machine changes to WAIT_FOR_SE_REMOVAL.
WAIT_FOR_SE_REMOVAL:
Waiting for the SE to be removed. When the SE is removed, a SE_REMOVED event is notified to the application and the state machine changes to the WAIT_FOR_SE_INSERTION or WAIT_FOR_START_DETECTION state according the polling mode (ObservableReader.PollingMode).
keyple::core::seproxy::plugin::AbstractObservableLocalReader::AbstractObservableLocalReader | ( | const std::string & | pluginName, |
const std::string & | readerName | ||
) |
Reader constructor
Force the definition of a name through the use of super method.
pluginName | the name of the plugin that instantiated the reader |
readerName | the name of the reader |
|
virtualdefault |
|
final |
Add a keyple::core::seproxy::event::ObservableReader::ReaderObserver
The observer will receive all the events produced by this reader (se insertion, removal, etc.)
observer | the observer object |
|
finalvirtual |
Remove all observers at once
Implements keyple::core::seproxy::event::ObservableReader.
|
finalvirtual |
Implements keyple::core::seproxy::event::ObservableReader.
|
overridevirtual |
Terminates the processing of the SE, in particular after an interruption by exception
Do nothing if the channel is already closed.
Channel closing is nominally managed by using the CLOSE_AFTER flag during the last transmission with the SE. However, there are cases where exchanges with the SE are interrupted by an exception, in which case it is necessary to explicitly close the channel using this method.
Implements keyple::core::seproxy::event::ObservableReader.
const MonitoringState & keyple::core::seproxy::plugin::AbstractObservableLocalReader::getCurrentMonitoringState | ( | ) | const |
(package-private)
Get the current monitoring state
const ObservableReader::PollingMode & keyple::core::seproxy::plugin::AbstractObservableLocalReader::getPollingMode | ( | ) | const |
(package-private)
Get polling mode
|
protectedpure virtual |
Initialize the ObservableReaderStateService with the possible states and their implementation. ObservableReaderStateService define the initial state.
Make sure to initialize the stateService in your reader constructor with stateService = initStateService()
Implemented in keyple::plugin::stub::StubReaderImpl, and keyple::plugin::pcsc::PcscReaderImpl.
|
overridevirtual |
Check the presence of a SE
This method is recommended for non-observable readers.
When the SE is not present the logical and physical channels status may be refreshed through a call to the processSeRemoved method.
KeypleReaderIOException | if the communication with the reader or the SE has failed |
Reimplemented from keyple::core::seproxy::plugin::AbstractLocalReader.
bool keyple::core::seproxy::plugin::AbstractObservableLocalReader::isSePresentPing | ( | ) |
(package-private)
Sends a neutral APDU to the SE to check its presence. The status of the response is not verified as long as the mere fact that the SE responds is sufficient to indicate whether or not it is present.
This method has to be called regularly until the SE no longer respond.
Having this method not final allows a reader plugin to implement its own method.
|
finalvirtual |
Notify all registered observers with the provided keyple::core::seproxy::event::ReaderEvent
event | the reader event |
Implements keyple::core::seproxy::plugin::ObservableReaderNotifier.
void keyple::core::seproxy::plugin::AbstractObservableLocalReader::onEvent | ( | const InternalEvent | event | ) |
thread safe method to communicate an internal event to this reader Use this method to inform the reader of external event like a tag discovered or a Se inserted
C++ vs. Java: protected in Java
event | internal event |
|
virtual |
(package-private)
This method is invoked when a SE is inserted in the case of an observable reader.
e.g. from the monitoring thread in the case of a Pcsc plugin or from the NfcAdapter callback method onTagDiscovered in the case of a Android NFC plugin.
It will return a ReaderEvent in the following cases:
It returns null if a default selection is defined in MATCHED_ONLY mode but no SE matched the selection.
void keyple::core::seproxy::plugin::AbstractObservableLocalReader::processSeRemoved | ( | ) |
This method is invoked when a SE is removed in the case of an observable reader.
It will also be invoked if isSePresent is called and at least one of the physical or logical channels is still open (case of a non-observable reader)
The SE will be notified removed only if it has been previously notified present (observable reader only)
|
final |
Remove a keyple::core::seproxy::event::ObservableReader::ReaderObserver
The observer will do not receive any of the events produced by this reader.
observer | the observer object |
|
finalvirtual |
If defined, the prepared DefaultSelectionRequest will be processed as soon as a SE is inserted. The result of this request set will be added to the reader event notified to the application.
If it is not defined (set to null), a simple SE detection will be notified in the end.
Depending on the notification mode, the observer will be notified whenever an SE is inserted, regardless of the selection status, or only if the current SE matches the selection criteria.
defaultSelectionsRequest | the keyple::core::seproxy::event::AbstractDefaultSelectionsRequest to be executed when a SE is inserted |
notificationMode | the notification mode enum (ALWAYS or MATCHED_ONLY) |
Implements keyple::core::seproxy::event::ObservableReader.
|
finalvirtual |
A combination of defining the default selection request and starting the SE detection.
defaultSelectionsRequest | the selection request to be operated |
notificationMode | indicates whether a SE_INSERTED event should be notified even if the selection has failed (ALWAYS) or whether the SE insertion should be ignored in this case (MATCHED_ONLY). |
pollingMode | indicates the action to be followed after processing the SE: if CONTINUE, the SE detection is restarted, if STOP, the SE detection is stopped until a new call to startSeDetection is made. |
Implements keyple::core::seproxy::event::ObservableReader.
|
finalvirtual |
Starts the SE detection. Once activated, the application can be notified of the arrival of an SE.
This method must be overloaded by readers depending on the particularity of their management of the start of SE detection.
Note: they must call the super method with the argument PollingMode.
pollingMode | indicates the action to be followed after processing the SE: if REPEATING, the SE detection is restarted, if SINGLESHOT, the SE detection is stopped until a new call to startSeDetection is made. |
Implements keyple::core::seproxy::event::ObservableReader.
|
finalvirtual |
Stops the SE detection.
This method must be overloaded by readers depending on the particularity of their management of the start of SE detection.
Implements keyple::core::seproxy::event::ObservableReader.
void keyple::core::seproxy::plugin::AbstractObservableLocalReader::switchState | ( | const MonitoringState | stateId | ) |
(package-private)
Changes the state of the state machine
stateId | : new stateId |
|
overridevirtual |
package-private)
This method initiates the SE removal sequence.
The reader will remain in the WAIT_FOR_SE_REMOVAL state as long as the SE is present. It will change to the WAIT_FOR_START_DETECTION or WAIT_FOR_SE_INSERTION state depending on what was set when the detection was started.
Implements keyple::core::seproxy::plugin::AbstractLocalReader.
|
protected |
Service that handles Internal Events and their impact on the current state of the reader