1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef ANDROID_ESED_SCOPED_ESE_CONNECTION_H
17#define ANDROID_ESED_SCOPED_ESE_CONNECTION_H
18
19#include <android-base/logging.h>
20#include <esecpp/EseInterface.h>
21
22namespace android {
23namespace esed {
24
25using ::android::EseInterface;
26
27class ScopedEseConnection {
28 public:
29  ScopedEseConnection(EseInterface& ese) : mEse_(ese) {}
30  ~ScopedEseConnection() { mEse_.close(); }
31
32  bool init() {
33    mEse_.init();
34    int res = mEse_.open();
35    if (res != 0) {
36      LOG(ERROR) << "Failed to open eSE connection: " << res;
37      return false;
38    }
39    return true;
40  }
41
42 private:
43  EseInterface& mEse_;
44};
45
46}  // namespace esed
47}  // namespace android
48
49#endif  // ANDROID_ESED_SCOPED_ESE_CONNECTION_H
50