Extract libese C++ wrapper.

Test: built it
Change-Id: I645df50ed6f4d37c4d053aba2a24024512b27161
diff --git a/Android.bp b/Android.bp
index 7299dea..3d12556 100644
--- a/Android.bp
+++ b/Android.bp
@@ -20,6 +20,7 @@
     "examples",
     "libapdu",
     "libese",
+    "libese-cpp",
     "libese-hw",
     "libese-sysdeps",
     "libese-teq1",
diff --git a/esed/Android.bp b/esed/Android.bp
index 222316d..445efd3 100644
--- a/esed/Android.bp
+++ b/esed/Android.bp
@@ -14,10 +14,8 @@
 // limitations under the License.
 //
 
-subdirs = ["pn81a"]
-
 cc_defaults {
-    name: "esed_cflags_defaults",
+    name: "esed_defaults",
     proprietary: true,
     cflags: [
         "-pedantic",
@@ -33,19 +31,6 @@
     },
 }
 
-cc_defaults {
-    name: "esed_defaults",
-    defaults: ["esed_cflags_defaults"],
-    shared_libs: [
-        "libbase",
-        "libese",
-        "libhidlbase",
-        "libhidltransport",
-        "libhwbinder",
-        "libutils",
-    ],
-}
-
 cc_binary {
     name: "esed",
     srcs: [
@@ -54,8 +39,12 @@
     init_rc = ["esed.rc"],
     defaults: ["esed_defaults"],
     shared_libs: [
-        "liblog",
+        "libbase",
+        "libese_cpp_nxp_pn80t_nq_nci",
+        "libhidlbase",
         "libhidltransport",
-        "esed_pn81a"
+        "libhwbinder",
+        "liblog",
+        "libutils",
     ],
 }
diff --git a/esed/esed.cpp b/esed/esed.cpp
index 02dd3d3..2bfb890 100644
--- a/esed/esed.cpp
+++ b/esed/esed.cpp
@@ -22,11 +22,9 @@
 #include <hidl/HidlTransportSupport.h>
 #include <utils/StrongPointer.h>
 
-#include "libese.h"
-
 // Select the implementation
-#include "pn81a/pn81a.h"
-using EseInterfaceImpl = android::esed::pn81a::EseInterface;
+#include <esecpp/NxpPn80tNqNci.h>
+using EseInterfaceImpl = android::NxpPn80tNqNci;
 
 using android::OK;
 using android::sp;
diff --git a/esed/pn81a/Android.bp b/esed/pn81a/Android.bp
deleted file mode 100644
index d7a5421..0000000
--- a/esed/pn81a/Android.bp
+++ /dev/null
@@ -1,32 +0,0 @@
-//
-// Copyright (C) 2017 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-cc_library_shared {
-    name: "esed_pn81a",
-    srcs: [
-        "pn81a.cpp",
-    ],
-    defaults: ["esed_defaults"],
-    shared_libs: [
-        "liblog",
-        "libese-hw-nxp-pn80t-nq-nci",
-        "libese-teq1",
-        "libhidltransport",
-    ],
-    static_libs: [
-        "libapdu",
-    ],
-}
diff --git a/esed/pn81a/utils.h b/esed/utils.h
similarity index 100%
rename from esed/pn81a/utils.h
rename to esed/utils.h
diff --git a/libese-cpp/Android.bp b/libese-cpp/Android.bp
new file mode 100644
index 0000000..7339e10
--- /dev/null
+++ b/libese-cpp/Android.bp
@@ -0,0 +1,56 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_defaults {
+    name: "libese_cpp_defaults",
+    proprietary: true,
+    cflags: [
+        "-pedantic",
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+    ],
+}
+
+cc_library_headers {
+    name: "libese_cpp",
+    defaults: ["libese_cpp_defaults"],
+    export_include_dirs: ["include"],
+}
+
+cc_library_shared {
+    name: "libese_cpp_nxp_pn80t_nq_nci",
+    defaults: ["libese_cpp_defaults"],
+    srcs: [
+        "NxpPn80tNqNci.cpp",
+    ],
+    export_include_dirs: ["include"],
+    header_libs: ["libese_cpp"],
+    shared_libs: [
+        "libese",
+	"libese-hw-nxp-pn80t-nq-nci",
+    ],
+    export_shared_lib_headers: [
+        "libese",
+    ],
+    host_supported: false,
+}
+
+cc_test_library {
+    name: "libese_cpp_mock",
+    defaults: ["libese_cpp_defaults"],
+    export_include_dirs: ["tests/include"],
+}
diff --git a/esed/pn81a/pn81a.cpp b/libese-cpp/NxpPn80tNqNci.cpp
similarity index 78%
rename from esed/pn81a/pn81a.cpp
rename to libese-cpp/NxpPn80tNqNci.cpp
index 6575dec..316440d 100644
--- a/esed/pn81a/pn81a.cpp
+++ b/libese-cpp/NxpPn80tNqNci.cpp
@@ -14,33 +14,27 @@
  * limitations under the License.
  */
 
-#include "pn81a.h"
-
-#include <ese/ese.h>
+#include <esecpp/NxpPn80tNqNci.h>
 ESE_INCLUDE_HW(ESE_HW_NXP_PN80T_NQ_NCI);
 
 namespace android {
-namespace esed {
-namespace pn81a {
 
-void EseInterface::init() {
+void NxpPn80tNqNci::init() {
     mEse = new ::EseInterface;
     ese_init(mEse, ESE_HW_NXP_PN80T_NQ_NCI);
 }
 
-int EseInterface::open() {
-    const int ret = ese_open(mEse, NULL);
+int NxpPn80tNqNci::open() {
+    const int ret = ese_open(mEse, nullptr);
     mOpen = !(ret < 0);
     return ret;
 }
 
-void EseInterface::close() {
+void NxpPn80tNqNci::close() {
     if (mOpen) {
         ese_close(mEse);
     }
     delete mEse;
 }
 
-} // namespace pn81a
-} // namespace esed
 } // namespace android
diff --git a/esed/libese.h b/libese-cpp/include/esecpp/EseInterface.h
similarity index 84%
rename from esed/libese.h
rename to libese-cpp/include/esecpp/EseInterface.h
index fc5c777..8b1cccf 100644
--- a/esed/libese.h
+++ b/libese-cpp/include/esecpp/EseInterface.h
@@ -14,17 +14,14 @@
  * limitations under the License.
  */
 
-#ifndef ESED_LIBESE_H_
-#define ESED_LIBESE_H_
+#ifndef CPP_ESE_H_
+#define CPP_ESE_H_
 
 #include <vector>
 
-#include <android-base/logging.h>
-
 #include <ese/ese.h>
 
 namespace android {
-namespace esed {
 
 /**
  * Mockable wrapper for libese's C API.
@@ -52,15 +49,22 @@
                               rx.data(), static_cast<uint32_t>(rx.size()));
     }
 
+    // TODO: overload transceive for ese_transceive_sg
+
     virtual bool error() { return ese_error(mEse); }
     virtual const char* error_message() { return ese_error_message(mEse); }
     virtual int error_code() { return ese_error_code(mEse); }
 
+    /**
+     * This is needed in order to call the applet libraries written in C. We
+     * should work out a better way to do this.
+     */
+    ::EseInterface* ese_interface() { return mEse; }
+
 protected:
     ::EseInterface* mEse;
 };
 
-} // namespace esed
 } // namespace android
 
-#endif // ESED_LIBESE_H_
+#endif // CPP_ESE_H_
diff --git a/esed/pn81a/pn81a.h b/libese-cpp/include/esecpp/NxpPn80tNqNci.h
similarity index 74%
rename from esed/pn81a/pn81a.h
rename to libese-cpp/include/esecpp/NxpPn80tNqNci.h
index 7913425..c49027c 100644
--- a/esed/pn81a/pn81a.h
+++ b/libese-cpp/include/esecpp/NxpPn80tNqNci.h
@@ -14,17 +14,15 @@
  * limitations under the License.
  */
 
-#ifndef ESED_PN81A_H_
-#define ESED_PN81A_H_
+#ifndef ESECPP_NXP_PN80T_NQ_NCI_H_
+#define ESECPP_NXP_PN80T_NQ_NCI_H_
 
-#include "../libese.h"
+#include <esecpp/EseInterface.h>
 
 namespace android {
-namespace esed {
-namespace pn81a {
 
-struct EseInterface : public ::android::esed::EseInterface {
-    ~EseInterface() { close(); }
+struct NxpPn80tNqNci : public EseInterface {
+    ~NxpPn80tNqNci() { close(); }
 
     void init() override;
     int open() override;
@@ -34,8 +32,6 @@
     bool mOpen = false;
 };
 
-} // namespace pn81a
-} // namespace esed
 } // namespace android
 
-#endif // ESED_PROXY_H_
+#endif // ESECPP_NXP_PN80T_NQ_NCI_H_
diff --git a/esed/tests/libese.h b/libese-cpp/tests/include/esecpp/MockEseInterface.h
similarity index 96%
rename from esed/tests/libese.h
rename to libese-cpp/tests/include/esecpp/MockEseInterface.h
index 50c1a34..86cca3f 100644
--- a/esed/tests/libese.h
+++ b/libese-cpp/tests/include/esecpp/MockEseInterface.h
@@ -17,10 +17,9 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
-#include "../libese.h"
+#include <esecpp/EseInterface.h>
 
 namespace android {
-namespace esed {
 
 using ::testing::_;
 using ::testing::ContainerEq;
@@ -56,5 +55,4 @@
     return mockEse;
 }
 
-} // namespace esed
 } // namespace android