wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / NFC / NFCTag.cpp
old mode 100755 (executable)
new mode 100644 (file)
index a05f153..8f60f34
 // limitations under the License.
 //
 
-
-
-
-#include <dpl/log/log.h>
-
 #include <Commons/Exception.h>
 #include <JSTizenException.h>
 
 #include "NFCTag.h"
 #include "NFCUtil.h"
+#include <Logger.h>
 
 namespace DeviceAPI {
 namespace NFC {
@@ -38,29 +34,29 @@ namespace
        * @param this_ User data pointer.
        */
        static bool TagInformationCallback(const char *key, const unsigned char *value, int value_size, void *user_data) {
-               LogDebug("Callback TagInformationCallback.");
+               LoggerD("Callback TagInformationCallback.");
                if (user_data) {
                        NFCUtil util;
                        std::vector<unsigned char> tagInfo = util.toVector(value, value_size);
                        (static_cast<NFCTag*>(user_data))->makeTagProperties(key, tagInfo);
                        return TRUE;
                }
-               LogDebug("Error! TagInformationCallback is Null.");
+               LoggerD("Error! TagInformationCallback is Null.");
                return false;
        }
 
        static void TagReadCallback(nfc_error_e result , nfc_ndef_message_h message , void * data) {
-               LogDebug("Callback TagReadCallback.");
+               LoggerD("Callback TagReadCallback.");
                if (data) {
                        NFCTag *tagPtr = (NFCTag *)((EventNFCPtrs<EventTagActionRead> *)data)->getThisPtr();
                        if (tagPtr) {
                                EventTagActionReadPtr event = ((EventNFCPtrs<EventTagActionRead> *)data)->getEventPtrs();
-                               LogDebug("message handler :" << message);
+                               LoggerD("message handler :" << message);
 
                                unsigned char *rawdata = NULL;
                                int size;
                                if (nfc_ndef_message_get_rawdata(message, &rawdata, &size) != NFC_ERROR_NONE) {
-                                       LogError("Can't get record's rawdata");
+                                       LoggerE("Can't get record's rawdata");
                                        if (rawdata)
                                                free(rawdata);
                                        return;
@@ -74,43 +70,43 @@ namespace
                        }
                
                } else {
-                       LogDebug("Error! TagReadCallback is Null.");
+                       LoggerD("Error! TagReadCallback is Null.");
                }
        }
 
        static void TagWriteCallback(nfc_error_e result, void *data) {
-               LogDebug("Callback TagWriteCallback.");
+               LoggerD("Callback TagWriteCallback.");
                if (data) {
                        ((NFCTag *)data)->writeNdefManualAnswer((int)result);
                } else {
-                       LogDebug("Error! TagWriteCallback is Null.");
+                       LoggerD("Error! TagWriteCallback is Null.");
                }               
        }
 
        static void TagTransceiveCallback(nfc_error_e result, unsigned char *buffer, int buffer_size,  void *data) {
-               LogDebug("Callback TagTransceiveCallback.");
+               LoggerD("Callback TagTransceiveCallback.");
                if (data) {
                        NFCUtil util;
                        std::vector<unsigned char> responseData = util.toVector(buffer, buffer_size)    ;
                        ((NFCTag *)data)->transceiveManualAnswer((int)result, responseData);
                } else {
-                       LogDebug("Error! TagTransceiveCallback is Null.");
+                       LoggerD("Error! TagTransceiveCallback is Null.");
                }               
        }
 
        static void TagFormatCallback(nfc_error_e result, void *data) {
-               LogDebug("Callback TagFormatCallback.");
+               LoggerD("Callback TagFormatCallback.");
                if (data) {
                        ((NFCTag *)data)->formatManualAnswer((int)result);              
                } else {
-                       LogDebug("Error! TagFormatCallback is Null.");
+                       LoggerD("Error! TagFormatCallback is Null.");
                }               
        }
 }//private namespace
 
 NFCTag::NFCTag(void *tagHandle)
 {
-       LogDebug("entered");
+       LoggerD("entered");
 
        handle = (nfc_tag_h)tagHandle;
 
@@ -121,7 +117,7 @@ NFCTag::NFCTag(void *tagHandle)
 
 NFCTag::~NFCTag()
 {
-       LogDebug("entered");
+       LoggerD("entered");
        handle = NULL;
 }
 
@@ -166,7 +162,7 @@ long NFCTag::getNdefSize(){
        return static_cast<long>(ndefSize);
 }
 std::vector<NFCTagProperties> NFCTag::getProperties() {
-       LogDebug("Enter");
+       LoggerD("Enter");
        props.clear();
        int result = nfc_tag_foreach_information(handle, TagInformationCallback, this);
 
@@ -185,7 +181,7 @@ void NFCTag::makeTagProperties(const char *key, std::vector<unsigned char> &valu
 }
 
 void NFCTag::readNdef(const EventTagActionReadPtr& event) {
-       LogDebug("Enter");
+       LoggerD("Enter");
        if (!isNDEFSupport())
                ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Not Support NDEF");
 
@@ -193,7 +189,7 @@ void NFCTag::readNdef(const EventTagActionReadPtr& event) {
 }
 
 void NFCTag::writeNdef(const EventTagActionWritePtr& event) {
-       LogDebug("Enter");
+       LoggerD("Enter");
        if (!isNDEFSupport())
                ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Not Support NDEF");
 
@@ -206,7 +202,7 @@ void NFCTag::writeNdef(const EventTagActionWritePtr& event) {
 }
 
 void NFCTag::transceive(const EventTagActionTransceivePtr& event) {
-       LogDebug("Enter");
+       LoggerD("Enter");
 
        if (m_EventTagActionTransceivePtr.Get() != NULL)
                EventTagActionTransceives.push_back(event);
@@ -215,13 +211,13 @@ void NFCTag::transceive(const EventTagActionTransceivePtr& event) {
 }
 
 void NFCTag::format(const EventTagActionFormatPtr& event) {
-       LogDebug("Enter");
+       LoggerD("Enter");
        EventRequestReceiver<EventTagActionFormat>::PostRequest(event);
 }
 
 void NFCTag::readNdefManualAnswer(int result, std::vector<unsigned char> &data, const EventTagActionReadPtr &event)
 {
-       LogDebug("Enter");
+       LoggerD("Enter");
        if ((nfc_error_e)result == NFC_ERROR_NONE) {
                event->setResult(TRUE);
                event->setReadNdefResult(data);
@@ -237,7 +233,7 @@ void NFCTag::readNdefManualAnswer(int result, std::vector<unsigned char> &data,
        for (it = EventTagActionsReads.begin(); it != EventTagActionsReads.end(); ++it) {
                if ((*it)->getEventPtrs() == event) {
                        EventTagActionsReads.erase(it);
-                       LogDebug("event is removed. (" << EventTagActionsReads.size() << ")");
+                       LoggerD("event is removed. (" << EventTagActionsReads.size() << ")");
                        break;
                }
        }
@@ -245,10 +241,10 @@ void NFCTag::readNdefManualAnswer(int result, std::vector<unsigned char> &data,
 
 void NFCTag::writeNdefManualAnswer(int result)
 {
-       LogDebug("Enter");
+       LoggerD("Enter");
        if (m_EventTagActionWritePtr.Get() != NULL) {
                if (nfc_ndef_message_destroy(static_cast<nfc_ndef_message_h>(m_EventTagActionWritePtr->getNdefForWriting())) != NFC_ERROR_NONE)
-                       LogError("Can't destroy NdefMessage");
+                       LoggerE("Can't destroy NdefMessage");
 
                if ((nfc_error_e)result == NFC_ERROR_NONE) {
                        m_EventTagActionWritePtr->setResult(TRUE);
@@ -264,7 +260,7 @@ void NFCTag::writeNdefManualAnswer(int result)
                if (EventTagActionWrites.size() > 0) {
                        EventTagActionWritePtr event = EventTagActionWrites.front();
                        EventTagActionWrites.erase(EventTagActionWrites.begin());
-                       LogDebug("EventTagActionWrites is removed. (" << EventTagActionWrites.size() << ")");
+                       LoggerD("EventTagActionWrites is removed. (" << EventTagActionWrites.size() << ")");
                        EventRequestReceiver<EventTagActionWrite>::PostRequest(event);
                }
        }
@@ -272,7 +268,7 @@ void NFCTag::writeNdefManualAnswer(int result)
 
 void NFCTag::transceiveManualAnswer(int result , std::vector<unsigned char> &data)
 {
-       LogDebug("Enter");
+       LoggerD("Enter");
        if (m_EventTagActionTransceivePtr.Get() != NULL) {
                if ((nfc_error_e)result == NFC_ERROR_NONE) {
                        m_EventTagActionTransceivePtr->setResult(TRUE);
@@ -289,7 +285,7 @@ void NFCTag::transceiveManualAnswer(int result , std::vector<unsigned char> &dat
                if (EventTagActionTransceives.size() > 0) {
                        EventTagActionTransceivePtr event = EventTagActionTransceives.front();
                        EventTagActionTransceives.erase(EventTagActionTransceives.begin());
-                       LogDebug("EventTagActionWrites is removed. (" << EventTagActionTransceives.size() << ")");
+                       LoggerD("EventTagActionWrites is removed. (" << EventTagActionTransceives.size() << ")");
                        EventRequestReceiver<EventTagActionTransceive>::PostRequest(event);
                }
        }
@@ -297,7 +293,7 @@ void NFCTag::transceiveManualAnswer(int result , std::vector<unsigned char> &dat
 
 void NFCTag::formatManualAnswer(int result)
 {
-       LogDebug("Enter");
+       LoggerD("Enter");
        if (m_EventTagActionFormatPtr.Get() != NULL) {
                if ((nfc_error_e)result == NFC_ERROR_NONE) {
                        m_EventTagActionFormatPtr->setResult(TRUE);
@@ -313,7 +309,7 @@ void NFCTag::formatManualAnswer(int result)
 }
 
 void NFCTag::OnRequestReceived(const EventTagActionReadPtr& event) {
-       LogDebug("Enter");
+       LoggerD("Enter");
        
        try {
                event->switchToManualAnswer();
@@ -334,14 +330,14 @@ void NFCTag::OnRequestReceived(const EventTagActionReadPtr& event) {
                        for (it = EventTagActionsReads.begin(); it != EventTagActionsReads.end(); ++it) {
                                if ((*it)->getEventPtrs() == event) {
                                        EventTagActionsReads.erase(it);
-                                       LogDebug("event is removed. (" << EventTagActionsReads.size() << ")");
+                                       LoggerD("event is removed. (" << EventTagActionsReads.size() << ")");
                                        break;
                                }
                        }
                }
        }
        catch (const WrtDeviceApis::Commons::Exception& ex) {
-               LogError("Exception: " << ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
                event->setResult(false);
        
                EventRequestReceiver<EventTagActionRead>::ManualAnswer(event);
@@ -364,7 +360,7 @@ void NFCTag::OnRequestReceived(const EventTagActionWritePtr& event) {
                }
        }
        catch (const WrtDeviceApis::Commons::Exception& ex) {
-               LogError("Exception: " << ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
 
                 if (event != m_EventTagActionWritePtr)
                        m_EventTagActionWritePtr = event;
@@ -392,7 +388,7 @@ void NFCTag::OnRequestReceived(const EventTagActionTransceivePtr& event) {
                }
        }
        catch (const WrtDeviceApis::Commons::Exception& ex) {
-               LogError("Exception: " << ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
 
                std::vector<unsigned char> emptyData;
                transceiveManualAnswer(NFC_ERROR_OPERATION_FAILED, emptyData);
@@ -415,7 +411,7 @@ void NFCTag::OnRequestReceived(const EventTagActionFormatPtr& event) {
                m_EventTagActionFormatPtr = event;
                
                NFCUtil util;
-               LogDebug("key size :" <<  event->getKeySize());
+               LoggerD("key size :" <<  event->getKeySize());
 
                unsigned char *key = util.toCharPtr(event->getKey());
                int result = nfc_tag_format_ndef(handle, key, event->getKeySize(), TagFormatCallback, this);
@@ -433,7 +429,7 @@ void NFCTag::OnRequestReceived(const EventTagActionFormatPtr& event) {
                }
        }
        catch (const WrtDeviceApis::Commons::Exception& ex) {
-               LogError("Exception: " << ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
                event->setResult(false);
                
                EventRequestReceiver<EventTagActionFormat>::ManualAnswer(event);