Home | History | Annotate | Download | only in vibrator
      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 #define LOG_TAG "android.hardware.vibrator (at) 1.0-service.marlin"
     17 
     18 #include <android/hardware/vibrator/1.0/IVibrator.h>
     19 #include <hidl/HidlSupport.h>
     20 #include <hidl/HidlTransportSupport.h>
     21 #include <utils/Errors.h>
     22 #include <utils/StrongPointer.h>
     23 
     24 #include "Vibrator.h"
     25 
     26 using android::hardware::configureRpcThreadpool;
     27 using android::hardware::joinRpcThreadpool;
     28 using android::hardware::vibrator::V1_0::IVibrator;
     29 using android::hardware::vibrator::V1_0::implementation::Vibrator;
     30 using namespace android;
     31 
     32 static const char *ENABLE_PATH = "/sys/class/timed_output/vibrator/enable";
     33 static const char *AMPLITUDE_PATH = "/sys/class/timed_output/vibrator/voltage_level";
     34 
     35 status_t registerVibratorService() {
     36     std::ofstream enable{ENABLE_PATH};
     37     if (!enable) {
     38         int error = errno;
     39         ALOGE("Failed to open %s (%d): %s", ENABLE_PATH, error, strerror(error));
     40         return -error;
     41     }
     42 
     43     std::ofstream amplitude{AMPLITUDE_PATH};
     44     if (!amplitude) {
     45         int error = errno;
     46         ALOGE("Failed to open %s (%d): %s", AMPLITUDE_PATH, error, strerror(error));
     47         return -error;
     48     }
     49 
     50     sp<IVibrator> vibrator = new Vibrator(std::move(enable), std::move(amplitude));
     51     (void) vibrator->registerAsService(); // suppress unused-result warning
     52     return OK;
     53 }
     54 
     55 int main() {
     56     configureRpcThreadpool(1, true);
     57     status_t status = registerVibratorService();
     58 
     59     if (status != OK) {
     60         return status;
     61     }
     62 
     63     joinRpcThreadpool();
     64 }
     65