mirror of https://github.com/ARMmbed/mbed-os.git
Address @paul-szczepanek-arm's comments
parent
bfe4c748ce
commit
b5bfcc3fcb
|
@ -82,13 +82,14 @@ public:
|
|||
* @param[in] delegate the delegate instance to use
|
||||
*/
|
||||
void set_delegate(Delegate *delegate);
|
||||
protected:
|
||||
|
||||
protected:
|
||||
/**
|
||||
* An implementation must call this function (can be called from interrupt context)
|
||||
* when the controller asserts its interrupt line
|
||||
*/
|
||||
void hw_interrupt();
|
||||
|
||||
private:
|
||||
Delegate *_delegate;
|
||||
};
|
||||
|
|
|
@ -119,6 +119,9 @@ private:
|
|||
void continue_read();
|
||||
void continue_erase();
|
||||
|
||||
// NFCNDEFCapable implementation
|
||||
virtual NFCNDEFCapable::Delegate *ndef_capable_delegate();
|
||||
|
||||
enum nfc_eeprom_operation_t {
|
||||
nfc_eeprom_idle,
|
||||
|
||||
|
|
|
@ -81,13 +81,6 @@ public:
|
|||
~Delegate() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the delegate that will receive events generated by this class.
|
||||
*
|
||||
* @param[in] delegate the delegate instance to use
|
||||
*/
|
||||
void set_ndef_delegate(Delegate *delegate);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Parse a NDEF message.
|
||||
|
@ -111,13 +104,19 @@ protected:
|
|||
ndef_msg_t *ndef_message();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Get the delegate that will receive events generated by this class.
|
||||
*
|
||||
* @return the delegate instance to use
|
||||
*/
|
||||
virtual Delegate *ndef_capable_delegate();
|
||||
|
||||
// Callbacks from NDEF stack
|
||||
static nfc_err_t s_ndef_encode(ndef_msg_t *pTag, ac_buffer_builder_t *pBufferBldr, void *pUserData);
|
||||
static nfc_err_t s_ndef_decode(ndef_msg_t *pTag, ac_buffer_t *pBuffer, void *pUserData);
|
||||
nfc_err_t ndef_encode(ac_buffer_builder_t *pBufferBldr);
|
||||
nfc_err_t ndef_decode(ac_buffer_t *pBuffer);
|
||||
|
||||
Delegate *_delegate;
|
||||
ndef_msg_t _ndef_message;
|
||||
};
|
||||
|
||||
|
|
|
@ -92,6 +92,9 @@ protected:
|
|||
virtual void disconnected();
|
||||
|
||||
private:
|
||||
// NFCNDEFCapable implementation
|
||||
virtual NFCNDEFCapable::Delegate *ndef_capable_delegate();
|
||||
|
||||
Delegate *_delegate;
|
||||
};
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ nfc_err_t NFCEEPROM::initialize()
|
|||
void NFCEEPROM::set_delegate(NFCEEPROM::Delegate *delegate)
|
||||
{
|
||||
_delegate = delegate;
|
||||
set_ndef_delegate(delegate);
|
||||
}
|
||||
|
||||
void NFCEEPROM::write_ndef_message()
|
||||
|
@ -419,3 +418,8 @@ void NFCEEPROM::handle_error(nfc_err_t ret)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
NFCNDEFCapable::Delegate *NFCEEPROM::ndef_capable_delegate()
|
||||
{
|
||||
return _delegate;
|
||||
}
|
|
@ -25,29 +25,27 @@
|
|||
using namespace mbed;
|
||||
using namespace mbed::nfc;
|
||||
|
||||
NFCNDEFCapable::NFCNDEFCapable(const Span<uint8_t> &buffer) : _delegate(NULL)
|
||||
NFCNDEFCapable::NFCNDEFCapable(const Span<uint8_t> &buffer)
|
||||
{
|
||||
ndef_msg_init(&_ndef_message, s_ndef_encode, s_ndef_decode, buffer.data(), buffer.size(), this);
|
||||
}
|
||||
|
||||
void NFCNDEFCapable::set_ndef_delegate(NFCNDEFCapable::Delegate *delegate)
|
||||
{
|
||||
_delegate = delegate;
|
||||
}
|
||||
|
||||
void NFCNDEFCapable::parse_ndef_message(const ac_buffer_t &buffer)
|
||||
{
|
||||
ac_buffer_t reader;
|
||||
ac_buffer_dup(&reader, &buffer);
|
||||
if (_delegate != NULL) {
|
||||
_delegate->parse_ndef_message(make_const_Span(ac_buffer_reader_current_buffer_pointer(&reader), ac_buffer_reader_current_buffer_length(&reader)));
|
||||
|
||||
Delegate *delegate = ndef_capable_delegate();
|
||||
if (delegate != NULL) {
|
||||
delegate->parse_ndef_message(make_const_Span(ac_buffer_reader_current_buffer_pointer(&reader), ac_buffer_reader_current_buffer_length(&reader)));
|
||||
}
|
||||
}
|
||||
|
||||
void NFCNDEFCapable::build_ndef_message(ac_buffer_builder_t &buffer_builder)
|
||||
{
|
||||
if (_delegate != NULL) {
|
||||
size_t count = _delegate->build_ndef_message(make_Span(ac_buffer_builder_write_position(&buffer_builder), ac_buffer_builder_writable(&buffer_builder)));
|
||||
Delegate *delegate = ndef_capable_delegate();
|
||||
if (delegate != NULL) {
|
||||
size_t count = delegate->build_ndef_message(make_Span(ac_buffer_builder_write_position(&buffer_builder), ac_buffer_builder_writable(&buffer_builder)));
|
||||
ac_buffer_builder_write_n_skip(&buffer_builder, count);
|
||||
}
|
||||
}
|
||||
|
@ -80,3 +78,8 @@ ndef_msg_t *NFCNDEFCapable::ndef_message()
|
|||
{
|
||||
return &_ndef_message;
|
||||
}
|
||||
|
||||
NFCNDEFCapable::Delegate *NFCNDEFCapable::ndef_capable_delegate()
|
||||
{
|
||||
return NULL;
|
||||
}
|
|
@ -20,7 +20,7 @@ using namespace mbed;
|
|||
using namespace mbed::nfc;
|
||||
|
||||
NFCRemoteInitiator::NFCRemoteInitiator(NFCController *controller, const Span<uint8_t> &buffer) :
|
||||
NFCRemoteEndpoint(controller), NFCNDEFCapable(buffer)
|
||||
NFCRemoteEndpoint(controller), NFCNDEFCapable(buffer), _delegate(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ NFCRemoteInitiator::~NFCRemoteInitiator()
|
|||
void NFCRemoteInitiator::set_delegate(Delegate *delegate)
|
||||
{
|
||||
_delegate = delegate;
|
||||
set_ndef_delegate(delegate);
|
||||
}
|
||||
|
||||
void NFCRemoteInitiator::connected()
|
||||
|
@ -49,3 +48,8 @@ void NFCRemoteInitiator::disconnected()
|
|||
_delegate->on_disconnected();
|
||||
}
|
||||
}
|
||||
|
||||
NFCNDEFCapable::Delegate *NFCRemoteInitiator::ndef_capable_delegate()
|
||||
{
|
||||
return _delegate;
|
||||
}
|
Loading…
Reference in New Issue