6c92951047
Move the common_time service developed in the ics-aah branch back into master. The common_time service is a small service build to synchronize an arbitrary timeline amongst peers on a local sub-net. While running and configured, the service will elect a master from the set of available devices within the subnet, define a relationship between the common_time timeline the local time timeline (provided by the local time HAL), and then attempt to maintain synchronization between common and local time by controlling the frequency of the local time clock via the HAL, or by disciplining local time in the digital domain if the local time HAL implementation does not support HW slewing. On its own, the native common time service will do nothing until it is configured. The CommonTimeManagementService (running out of the system server process) is responsible for implementing policy regarding configuration and operation of the common_time service and will be added in a subsequent CL. Change-Id: I71292f9b9b1797665865689c4572c9d3a0552f64 Signed-off-by: John Grossman <johngro@google.com>
91 lines
3.7 KiB
C++
91 lines
3.7 KiB
C++
/*
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <common_time/ICommonClock.h>
|
|
|
|
#ifndef ANDROID_COMMON_CLOCK_SERVICE_H
|
|
#define ANDROID_COMMON_CLOCK_SERVICE_H
|
|
|
|
namespace android {
|
|
|
|
class CommonTimeServer;
|
|
|
|
class CommonClockService : public BnCommonClock,
|
|
public android::IBinder::DeathRecipient {
|
|
public:
|
|
static sp<CommonClockService> instantiate(CommonTimeServer& timeServer);
|
|
|
|
virtual status_t dump(int fd, const Vector<String16>& args);
|
|
|
|
virtual status_t isCommonTimeValid(bool* valid, uint32_t *timelineID);
|
|
virtual status_t commonTimeToLocalTime(int64_t common_time,
|
|
int64_t* local_time);
|
|
virtual status_t localTimeToCommonTime(int64_t local_time,
|
|
int64_t* common_time);
|
|
virtual status_t getCommonTime(int64_t* common_time);
|
|
virtual status_t getCommonFreq(uint64_t* freq);
|
|
virtual status_t getLocalTime(int64_t* local_time);
|
|
virtual status_t getLocalFreq(uint64_t* freq);
|
|
virtual status_t getEstimatedError(int32_t* estimate);
|
|
virtual status_t getTimelineID(uint64_t* id);
|
|
virtual status_t getState(ICommonClock::State* state);
|
|
virtual status_t getMasterAddr(struct sockaddr_storage* addr);
|
|
|
|
virtual status_t registerListener(
|
|
const sp<ICommonClockListener>& listener);
|
|
virtual status_t unregisterListener(
|
|
const sp<ICommonClockListener>& listener);
|
|
|
|
void notifyOnTimelineChanged(uint64_t timelineID);
|
|
|
|
private:
|
|
CommonClockService(CommonTimeServer& timeServer)
|
|
: mTimeServer(timeServer) { };
|
|
|
|
virtual void binderDied(const wp<IBinder>& who);
|
|
|
|
CommonTimeServer& mTimeServer;
|
|
|
|
// locks used to synchronize access to the list of registered listeners.
|
|
// The callback lock is held whenever the list is used to perform callbacks
|
|
// or while the list is being modified. The registration lock used to
|
|
// serialize access across registerListener, unregisterListener, and
|
|
// binderDied.
|
|
//
|
|
// The reason for two locks is that registerListener, unregisterListener,
|
|
// and binderDied each call into the core service and obtain the core
|
|
// service thread lock when they call reevaluateAutoDisableState. The core
|
|
// service thread obtains the main thread lock whenever its thread is
|
|
// running, and sometimes needs to call notifyOnTimelineChanged which then
|
|
// obtains the callback lock. If callers of registration functions were
|
|
// holding the callback lock when they called into the core service, we
|
|
// would have a classic A/B, B/A ordering deadlock. To avoid this, the
|
|
// registration functions hold the registration lock for the duration of
|
|
// their call, but hold the callback lock only while they mutate the list.
|
|
// This way, the list's size cannot change (because of the registration
|
|
// lock) during the call into reevaluateAutoDisableState, but the core work
|
|
// thread can still safely call notifyOnTimelineChanged while holding the
|
|
// main thread lock.
|
|
Mutex mCallbackLock;
|
|
Mutex mRegistrationLock;
|
|
|
|
Vector<sp<ICommonClockListener> > mListeners;
|
|
};
|
|
|
|
}; // namespace android
|
|
|
|
#endif // ANDROID_COMMON_CLOCK_SERVICE_H
|