• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (C) 2009 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  
17  /** \file
18    This file consists of implementation of class AdbIOCompletion that
19    encapsulates a generic wrapper around OVERLAPPED Win32 structure
20    returned from asynchronous I/O requests.
21  */
22  
23  #include "stdafx.h"
24  #include "adb_io_completion.h"
25  
AdbIOCompletion(AdbEndpointObject * parent_io_obj,ULONG expected_trans_size,HANDLE event_hndl)26  AdbIOCompletion::AdbIOCompletion(AdbEndpointObject* parent_io_obj,
27                                   ULONG expected_trans_size,
28                                   HANDLE event_hndl)
29      : AdbObjectHandle(AdbObjectTypeIoCompletion),
30        expected_transfer_size_(expected_trans_size),
31        parent_io_object_(parent_io_obj) {
32    ATLASSERT(NULL != parent_io_obj);
33    parent_io_obj->AddRef();
34    ZeroMemory(&overlapped_, sizeof(overlapped_));
35    overlapped_.hEvent = event_hndl;
36  }
37  
~AdbIOCompletion()38  AdbIOCompletion::~AdbIOCompletion() {
39    parent_io_object_->Release();
40  }
41  
IsCompleted()42  bool AdbIOCompletion::IsCompleted() {
43    SetLastError(NO_ERROR);
44    if (!IsOpened()) {
45      SetLastError(ERROR_INVALID_HANDLE);
46      return true;
47    }
48  
49    return HasOverlappedIoCompleted(overlapped()) ? true : false;
50  }
51