Home | History | Annotate | Download | only in mock
      1 /*
      2  * Copyright (C) 2018 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 #include "mock/MockDispSync.h"
     18 #include <thread>
     19 
     20 namespace android {
     21 namespace mock {
     22 
     23 // Explicit default instantiation is recommended.
     24 DispSync::DispSync() = default;
     25 DispSync::~DispSync() = default;
     26 
     27 status_t DispSync::addEventListener(const char* /*name*/, nsecs_t phase, Callback* callback,
     28                                     nsecs_t /*lastCallbackTime*/) {
     29     if (mCallback.callback != nullptr) {
     30         return BAD_VALUE;
     31     }
     32 
     33     mCallback = {callback, phase};
     34     return NO_ERROR;
     35 }
     36 status_t DispSync::removeEventListener(Callback* callback, nsecs_t* /*outLastCallback*/) {
     37     if (mCallback.callback != callback) {
     38         return BAD_VALUE;
     39     }
     40 
     41     mCallback = {nullptr, 0};
     42     return NO_ERROR;
     43 }
     44 
     45 status_t DispSync::changePhaseOffset(Callback* callback, nsecs_t phase) {
     46     if (mCallback.callback != callback) {
     47         return BAD_VALUE;
     48     }
     49 
     50     mCallback.phase = phase;
     51     return NO_ERROR;
     52 }
     53 
     54 void DispSync::triggerCallback() {
     55     if (mCallback.callback == nullptr) return;
     56 
     57     mCallback.callback->onDispSyncEvent(
     58             std::chrono::steady_clock::now().time_since_epoch().count());
     59 }
     60 
     61 } // namespace mock
     62 } // namespace android
     63