blob: d723d1bf4c00cf9f2bfd39de7717a54c6336b1d3 [file] [log] [blame]
Mike J. Chena94f7642011-08-15 11:14:35 -07001/*
2 * Copyright (C) 2011 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#ifndef ANDROID_ICOMMONCLOCK_H
18#define ANDROID_ICOMMONCLOCK_H
19
20#include <stdint.h>
21
22#include <binder/IInterface.h>
23#include <binder/IServiceManager.h>
24
25namespace android {
26
27class ICommonClockListener : public IInterface {
28 public:
29 DECLARE_META_INTERFACE(CommonClockListener);
30
31 virtual void onClockSync(uint32_t timelineID) = 0;
32 virtual void onClockSyncLoss() = 0;
33};
34
35class BnCommonClockListener : public BnInterface<ICommonClockListener> {
36 public:
37 virtual status_t onTransact(uint32_t code, const Parcel& data,
38 Parcel* reply, uint32_t flags = 0);
39};
40
41class ICommonClock : public IInterface {
42 public:
43 DECLARE_META_INTERFACE(CommonClock);
44
45 // Name of the ICommonClock service registered with the service manager.
46 static const String16 kServiceName;
47
48 // a reserved invalid timeline ID
49 static const uint32_t kInvalidTimelineID;
50
51 virtual status_t isCommonTimeValid(bool* valid, uint32_t* timelineID) = 0;
52 virtual status_t commonTimeToLocalTime(int64_t commonTime,
53 int64_t* localTime) = 0;
54 virtual status_t localTimeToCommonTime(int64_t localTime,
55 int64_t* commonTime) = 0;
56 virtual status_t getCommonTime(int64_t* commonTime) = 0;
57 virtual status_t getCommonFreq(uint64_t* freq) = 0;
58 virtual status_t getLocalTime(int64_t* localTime) = 0;
59 virtual status_t getLocalFreq(uint64_t* freq) = 0;
60
61 virtual status_t registerListener(
62 const sp<ICommonClockListener>& listener) = 0;
63 virtual status_t unregisterListener(
64 const sp<ICommonClockListener>& listener) = 0;
65
66 // Simple helper to make it easier to connect to the CommonClock service.
67 static inline sp<ICommonClock> getInstance() {
68 sp<IBinder> binder = defaultServiceManager()->checkService(
69 ICommonClock::kServiceName);
70 sp<ICommonClock> clk = interface_cast<ICommonClock>(binder);
71 return clk;
72 }
73};
74
75class BnCommonClock : public BnInterface<ICommonClock> {
76 public:
77 virtual status_t onTransact(uint32_t code, const Parcel& data,
78 Parcel* reply, uint32_t flags = 0);
79};
80
81}; // namespace android
82
83#endif // ANDROID_ICOMMONCLOCK_H