Remove common_time code

This code is unused.

Bug: 80462439
Test: Build / boot
Change-Id: I1cfac4bdd59f1b8a9231abc49d3311637f71ce88
gugelfrei
Neil Fuller 6 years ago
parent 20bd30baf9
commit 2fb2096857

@ -1,108 +0,0 @@
/*
* 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.
*/
#ifndef ANDROID_ICOMMONCLOCK_H
#define ANDROID_ICOMMONCLOCK_H
#include <stdint.h>
#include <linux/socket.h>
#include <binder/IInterface.h>
#include <binder/IServiceManager.h>
namespace android {
class ICommonClockListener : public IInterface {
public:
DECLARE_META_INTERFACE(CommonClockListener);
virtual void onTimelineChanged(uint64_t timelineID) = 0;
};
class BnCommonClockListener : public BnInterface<ICommonClockListener> {
public:
virtual status_t onTransact(uint32_t code, const Parcel& data,
Parcel* reply, uint32_t flags = 0);
};
class ICommonClock : public IInterface {
public:
DECLARE_META_INTERFACE(CommonClock);
// Name of the ICommonClock service registered with the service manager.
static const String16 kServiceName;
// a reserved invalid timeline ID
static const uint64_t kInvalidTimelineID;
// a reserved invalid error estimate
static const int32_t kErrorEstimateUnknown;
enum State {
// the device just came up and is trying to discover the master
STATE_INITIAL,
// the device is a client of a master
STATE_CLIENT,
// the device is acting as master
STATE_MASTER,
// the device has lost contact with its master and needs to participate
// in the election of a new master
STATE_RONIN,
// the device is waiting for announcement of the newly elected master
STATE_WAIT_FOR_ELECTION,
};
virtual status_t isCommonTimeValid(bool* valid, uint32_t* timelineID) = 0;
virtual status_t commonTimeToLocalTime(int64_t commonTime,
int64_t* localTime) = 0;
virtual status_t localTimeToCommonTime(int64_t localTime,
int64_t* commonTime) = 0;
virtual status_t getCommonTime(int64_t* commonTime) = 0;
virtual status_t getCommonFreq(uint64_t* freq) = 0;
virtual status_t getLocalTime(int64_t* localTime) = 0;
virtual status_t getLocalFreq(uint64_t* freq) = 0;
virtual status_t getEstimatedError(int32_t* estimate) = 0;
virtual status_t getTimelineID(uint64_t* id) = 0;
virtual status_t getState(State* state) = 0;
virtual status_t getMasterAddr(struct sockaddr_storage* addr) = 0;
virtual status_t registerListener(
const sp<ICommonClockListener>& listener) = 0;
virtual status_t unregisterListener(
const sp<ICommonClockListener>& listener) = 0;
// Simple helper to make it easier to connect to the CommonClock service.
static inline sp<ICommonClock> getInstance() {
sp<IBinder> binder = defaultServiceManager()->checkService(
ICommonClock::kServiceName);
sp<ICommonClock> clk = interface_cast<ICommonClock>(binder);
return clk;
}
};
class BnCommonClock : public BnInterface<ICommonClock> {
public:
virtual status_t onTransact(uint32_t code, const Parcel& data,
Parcel* reply, uint32_t flags = 0);
};
}; // namespace android
#endif // ANDROID_ICOMMONCLOCK_H

@ -1,73 +0,0 @@
/*
* Copyright (C) 2012 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.
*/
#ifndef ANDROID_ICOMMONTIMECONFIG_H
#define ANDROID_ICOMMONTIMECONFIG_H
#include <stdint.h>
#include <linux/socket.h>
#include <binder/IInterface.h>
#include <binder/IServiceManager.h>
namespace android {
class String16;
class ICommonTimeConfig : public IInterface {
public:
DECLARE_META_INTERFACE(CommonTimeConfig);
// Name of the ICommonTimeConfig service registered with the service
// manager.
static const String16 kServiceName;
virtual status_t getMasterElectionPriority(uint8_t *priority) = 0;
virtual status_t setMasterElectionPriority(uint8_t priority) = 0;
virtual status_t getMasterElectionEndpoint(struct sockaddr_storage *addr) = 0;
virtual status_t setMasterElectionEndpoint(const struct sockaddr_storage *addr) = 0;
virtual status_t getMasterElectionGroupId(uint64_t *id) = 0;
virtual status_t setMasterElectionGroupId(uint64_t id) = 0;
virtual status_t getInterfaceBinding(String16& ifaceName) = 0;
virtual status_t setInterfaceBinding(const String16& ifaceName) = 0;
virtual status_t getMasterAnnounceInterval(int *interval) = 0;
virtual status_t setMasterAnnounceInterval(int interval) = 0;
virtual status_t getClientSyncInterval(int *interval) = 0;
virtual status_t setClientSyncInterval(int interval) = 0;
virtual status_t getPanicThreshold(int *threshold) = 0;
virtual status_t setPanicThreshold(int threshold) = 0;
virtual status_t getAutoDisable(bool *autoDisable) = 0;
virtual status_t setAutoDisable(bool autoDisable) = 0;
virtual status_t forceNetworklessMasterMode() = 0;
// Simple helper to make it easier to connect to the CommonTimeConfig service.
static inline sp<ICommonTimeConfig> getInstance() {
sp<IBinder> binder = defaultServiceManager()->checkService(
ICommonTimeConfig::kServiceName);
sp<ICommonTimeConfig> clk = interface_cast<ICommonTimeConfig>(binder);
return clk;
}
};
class BnCommonTimeConfig : public BnInterface<ICommonTimeConfig> {
public:
virtual status_t onTransact(uint32_t code, const Parcel& data,
Parcel* reply, uint32_t flags = 0);
};
}; // namespace android
#endif // ANDROID_ICOMMONTIMECONFIG_H

@ -1,72 +0,0 @@
/*
* 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.
*/
#ifndef __CC_HELPER_H__
#define __CC_HELPER_H__
#include <stdint.h>
#include <common_time/ICommonClock.h>
#include <utils/threads.h>
namespace android {
// CCHelper is a simple wrapper class to help with centralizing access to the
// Common Clock service and implementing lifetime managment, as well as to
// implement a simple policy of making a basic attempt to reconnect to the
// common clock service when things go wrong.
//
// On platforms which run the native common_time service in auto-disable mode,
// the service will go into networkless mode whenever it has no active clients.
// It tracks active clients using registered CommonClockListeners (the callback
// interface for onTimelineChanged) since this provides a convienent death
// handler notification for when the service's clients die unexpectedly. This
// means that users of the common time service should really always have a
// CommonClockListener, unless they know that the time service is not running in
// auto disabled mode, or that there is at least one other registered listener
// active in the system. The CCHelper makes this a little easier by sharing a
// ref counted ICommonClock interface across all clients and automatically
// registering and unregistering a listener whenever there are CCHelper
// instances active in the process.
class CCHelper {
public:
CCHelper();
~CCHelper();
status_t isCommonTimeValid(bool* valid, uint32_t* timelineID);
status_t commonTimeToLocalTime(int64_t commonTime, int64_t* localTime);
status_t localTimeToCommonTime(int64_t localTime, int64_t* commonTime);
status_t getCommonTime(int64_t* commonTime);
status_t getCommonFreq(uint64_t* freq);
status_t getLocalTime(int64_t* localTime);
status_t getLocalFreq(uint64_t* freq);
private:
class CommonClockListener : public BnCommonClockListener {
public:
void onTimelineChanged(uint64_t timelineID);
};
static bool verifyClock_l();
static Mutex lock_;
static sp<ICommonClock> common_clock_;
static sp<ICommonClockListener> common_clock_listener_;
static uint32_t ref_count_;
};
} // namespace android
#endif // __CC_HELPER_H__

@ -1,47 +0,0 @@
/*
* 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.
*/
#ifndef __LOCAL_CLOCK_H__
#define __LOCAL_CLOCK_H__
#include <stdint.h>
#include <hardware/local_time_hal.h>
#include <utils/Errors.h>
#include <utils/threads.h>
namespace android {
class LocalClock {
public:
LocalClock();
bool initCheck();
int64_t getLocalTime();
uint64_t getLocalFreq();
status_t setLocalSlew(int16_t rate);
int32_t getDebugLog(struct local_time_debug_event* records,
int max_records);
private:
static Mutex dev_lock_;
static local_time_hw_device_t* dev_;
};
} // namespace android
#endif // __LOCAL_CLOCK_H__

@ -1,24 +0,0 @@
LOCAL_PATH:= $(call my-dir)
#
# libcommon_time_client
# (binder marshalers for ICommonClock as well as common clock and local clock
# helper code)
#
include $(CLEAR_VARS)
LOCAL_MODULE := libcommon_time_client
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := cc_helper.cpp \
local_clock.cpp \
ICommonClock.cpp \
ICommonTimeConfig.cpp \
utils.cpp
LOCAL_SHARED_LIBRARIES := libbinder \
libhardware \
libutils \
liblog
LOCAL_CFLAGS := -Wall -Werror
include $(BUILD_SHARED_LIBRARY)

@ -1,433 +0,0 @@
/*
* Copyright (C) 2012 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 <sys/socket.h>
#include <common_time/ICommonClock.h>
#include <binder/Parcel.h>
#include "utils.h"
namespace android {
/***** ICommonClock *****/
enum {
IS_COMMON_TIME_VALID = IBinder::FIRST_CALL_TRANSACTION,
COMMON_TIME_TO_LOCAL_TIME,
LOCAL_TIME_TO_COMMON_TIME,
GET_COMMON_TIME,
GET_COMMON_FREQ,
GET_LOCAL_TIME,
GET_LOCAL_FREQ,
GET_ESTIMATED_ERROR,
GET_TIMELINE_ID,
GET_STATE,
GET_MASTER_ADDRESS,
REGISTER_LISTENER,
UNREGISTER_LISTENER,
};
const String16 ICommonClock::kServiceName("common_time.clock");
const uint64_t ICommonClock::kInvalidTimelineID = 0;
const int32_t ICommonClock::kErrorEstimateUnknown = 0x7FFFFFFF;
class BpCommonClock : public BpInterface<ICommonClock>
{
public:
explicit BpCommonClock(const sp<IBinder>& impl)
: BpInterface<ICommonClock>(impl) {}
virtual status_t isCommonTimeValid(bool* valid, uint32_t* timelineID) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
status_t status = remote()->transact(IS_COMMON_TIME_VALID,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*valid = reply.readInt32();
*timelineID = reply.readInt32();
}
}
return status;
}
virtual status_t commonTimeToLocalTime(int64_t commonTime,
int64_t* localTime) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
data.writeInt64(commonTime);
status_t status = remote()->transact(COMMON_TIME_TO_LOCAL_TIME,
data, &reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*localTime = reply.readInt64();
}
}
return status;
}
virtual status_t localTimeToCommonTime(int64_t localTime,
int64_t* commonTime) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
data.writeInt64(localTime);
status_t status = remote()->transact(LOCAL_TIME_TO_COMMON_TIME,
data, &reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*commonTime = reply.readInt64();
}
}
return status;
}
virtual status_t getCommonTime(int64_t* commonTime) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
status_t status = remote()->transact(GET_COMMON_TIME, data, &reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*commonTime = reply.readInt64();
}
}
return status;
}
virtual status_t getCommonFreq(uint64_t* freq) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
status_t status = remote()->transact(GET_COMMON_FREQ, data, &reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*freq = reply.readInt64();
}
}
return status;
}
virtual status_t getLocalTime(int64_t* localTime) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
status_t status = remote()->transact(GET_LOCAL_TIME, data, &reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*localTime = reply.readInt64();
}
}
return status;
}
virtual status_t getLocalFreq(uint64_t* freq) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
status_t status = remote()->transact(GET_LOCAL_FREQ, data, &reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*freq = reply.readInt64();
}
}
return status;
}
virtual status_t getEstimatedError(int32_t* estimate) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
status_t status = remote()->transact(GET_ESTIMATED_ERROR, data, &reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*estimate = reply.readInt32();
}
}
return status;
}
virtual status_t getTimelineID(uint64_t* id) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
status_t status = remote()->transact(GET_TIMELINE_ID, data, &reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*id = static_cast<uint64_t>(reply.readInt64());
}
}
return status;
}
virtual status_t getState(State* state) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
status_t status = remote()->transact(GET_STATE, data, &reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*state = static_cast<State>(reply.readInt32());
}
}
return status;
}
virtual status_t getMasterAddr(struct sockaddr_storage* addr) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
status_t status = remote()->transact(GET_MASTER_ADDRESS, data, &reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK)
deserializeSockaddr(&reply, addr);
}
return status;
}
virtual status_t registerListener(
const sp<ICommonClockListener>& listener) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
data.writeStrongBinder(IInterface::asBinder(listener));
status_t status = remote()->transact(REGISTER_LISTENER, data, &reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
virtual status_t unregisterListener(
const sp<ICommonClockListener>& listener) {
Parcel data, reply;
data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
data.writeStrongBinder(IInterface::asBinder(listener));
status_t status = remote()->transact(UNREGISTER_LISTENER, data, &reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
};
IMPLEMENT_META_INTERFACE(CommonClock, "android.os.ICommonClock");
status_t BnCommonClock::onTransact(uint32_t code,
const Parcel& data,
Parcel* reply,
uint32_t flags) {
switch(code) {
case IS_COMMON_TIME_VALID: {
CHECK_INTERFACE(ICommonClock, data, reply);
bool valid;
uint32_t timelineID;
status_t status = isCommonTimeValid(&valid, &timelineID);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt32(valid);
reply->writeInt32(timelineID);
}
return OK;
} break;
case COMMON_TIME_TO_LOCAL_TIME: {
CHECK_INTERFACE(ICommonClock, data, reply);
int64_t commonTime = data.readInt64();
int64_t localTime;
status_t status = commonTimeToLocalTime(commonTime, &localTime);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt64(localTime);
}
return OK;
} break;
case LOCAL_TIME_TO_COMMON_TIME: {
CHECK_INTERFACE(ICommonClock, data, reply);
int64_t localTime = data.readInt64();
int64_t commonTime;
status_t status = localTimeToCommonTime(localTime, &commonTime);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt64(commonTime);
}
return OK;
} break;
case GET_COMMON_TIME: {
CHECK_INTERFACE(ICommonClock, data, reply);
int64_t commonTime;
status_t status = getCommonTime(&commonTime);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt64(commonTime);
}
return OK;
} break;
case GET_COMMON_FREQ: {
CHECK_INTERFACE(ICommonClock, data, reply);
uint64_t freq;
status_t status = getCommonFreq(&freq);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt64(freq);
}
return OK;
} break;
case GET_LOCAL_TIME: {
CHECK_INTERFACE(ICommonClock, data, reply);
int64_t localTime;
status_t status = getLocalTime(&localTime);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt64(localTime);
}
return OK;
} break;
case GET_LOCAL_FREQ: {
CHECK_INTERFACE(ICommonClock, data, reply);
uint64_t freq;
status_t status = getLocalFreq(&freq);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt64(freq);
}
return OK;
} break;
case GET_ESTIMATED_ERROR: {
CHECK_INTERFACE(ICommonClock, data, reply);
int32_t error;
status_t status = getEstimatedError(&error);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt32(error);
}
return OK;
} break;
case GET_TIMELINE_ID: {
CHECK_INTERFACE(ICommonClock, data, reply);
uint64_t id;
status_t status = getTimelineID(&id);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt64(static_cast<int64_t>(id));
}
return OK;
} break;
case GET_STATE: {
CHECK_INTERFACE(ICommonClock, data, reply);
State state;
status_t status = getState(&state);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt32(static_cast<int32_t>(state));
}
return OK;
} break;
case GET_MASTER_ADDRESS: {
CHECK_INTERFACE(ICommonClock, data, reply);
struct sockaddr_storage addr;
status_t status = getMasterAddr(&addr);
if ((status == OK) && !canSerializeSockaddr(&addr)) {
status = UNKNOWN_ERROR;
}
reply->writeInt32(status);
if (status == OK) {
serializeSockaddr(reply, &addr);
}
return OK;
} break;
case REGISTER_LISTENER: {
CHECK_INTERFACE(ICommonClock, data, reply);
sp<ICommonClockListener> listener =
interface_cast<ICommonClockListener>(data.readStrongBinder());
status_t status = registerListener(listener);
reply->writeInt32(status);
return OK;
} break;
case UNREGISTER_LISTENER: {
CHECK_INTERFACE(ICommonClock, data, reply);
sp<ICommonClockListener> listener =
interface_cast<ICommonClockListener>(data.readStrongBinder());
status_t status = unregisterListener(listener);
reply->writeInt32(status);
return OK;
} break;
}
return BBinder::onTransact(code, data, reply, flags);
}
/***** ICommonClockListener *****/
enum {
ON_TIMELINE_CHANGED = IBinder::FIRST_CALL_TRANSACTION,
};
class BpCommonClockListener : public BpInterface<ICommonClockListener>
{
public:
explicit BpCommonClockListener(const sp<IBinder>& impl)
: BpInterface<ICommonClockListener>(impl) {}
virtual void onTimelineChanged(uint64_t timelineID) {
Parcel data, reply;
data.writeInterfaceToken(
ICommonClockListener::getInterfaceDescriptor());
data.writeInt64(timelineID);
remote()->transact(ON_TIMELINE_CHANGED, data, &reply);
}
};
IMPLEMENT_META_INTERFACE(CommonClockListener,
"android.os.ICommonClockListener");
status_t BnCommonClockListener::onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
switch(code) {
case ON_TIMELINE_CHANGED: {
CHECK_INTERFACE(ICommonClockListener, data, reply);
uint32_t timelineID = data.readInt64();
onTimelineChanged(timelineID);
return NO_ERROR;
} break;
}
return BBinder::onTransact(code, data, reply, flags);
}
}; // namespace android

@ -1,509 +0,0 @@
/*
* 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 <sys/socket.h>
#include <common_time/ICommonTimeConfig.h>
#include <binder/Parcel.h>
#include "utils.h"
namespace android {
/***** ICommonTimeConfig *****/
enum {
GET_MASTER_ELECTION_PRIORITY = IBinder::FIRST_CALL_TRANSACTION,
SET_MASTER_ELECTION_PRIORITY,
GET_MASTER_ELECTION_ENDPOINT,
SET_MASTER_ELECTION_ENDPOINT,
GET_MASTER_ELECTION_GROUP_ID,
SET_MASTER_ELECTION_GROUP_ID,
GET_INTERFACE_BINDING,
SET_INTERFACE_BINDING,
GET_MASTER_ANNOUNCE_INTERVAL,
SET_MASTER_ANNOUNCE_INTERVAL,
GET_CLIENT_SYNC_INTERVAL,
SET_CLIENT_SYNC_INTERVAL,
GET_PANIC_THRESHOLD,
SET_PANIC_THRESHOLD,
GET_AUTO_DISABLE,
SET_AUTO_DISABLE,
FORCE_NETWORKLESS_MASTER_MODE,
};
const String16 ICommonTimeConfig::kServiceName("common_time.config");
class BpCommonTimeConfig : public BpInterface<ICommonTimeConfig>
{
public:
explicit BpCommonTimeConfig(const sp<IBinder>& impl)
: BpInterface<ICommonTimeConfig>(impl) {}
virtual status_t getMasterElectionPriority(uint8_t *priority) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
status_t status = remote()->transact(GET_MASTER_ELECTION_PRIORITY,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*priority = static_cast<uint8_t>(reply.readInt32());
}
}
return status;
}
virtual status_t setMasterElectionPriority(uint8_t priority) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
data.writeInt32(static_cast<int32_t>(priority));
status_t status = remote()->transact(SET_MASTER_ELECTION_PRIORITY,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
virtual status_t getMasterElectionEndpoint(struct sockaddr_storage *addr) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
status_t status = remote()->transact(GET_MASTER_ELECTION_ENDPOINT,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
deserializeSockaddr(&reply, addr);
}
}
return status;
}
virtual status_t setMasterElectionEndpoint(
const struct sockaddr_storage *addr) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
if (!canSerializeSockaddr(addr))
return BAD_VALUE;
if (NULL == addr) {
data.writeInt32(0);
} else {
data.writeInt32(1);
serializeSockaddr(&data, addr);
}
status_t status = remote()->transact(SET_MASTER_ELECTION_ENDPOINT,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
virtual status_t getMasterElectionGroupId(uint64_t *id) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
status_t status = remote()->transact(GET_MASTER_ELECTION_GROUP_ID,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*id = static_cast<uint64_t>(reply.readInt64());
}
}
return status;
}
virtual status_t setMasterElectionGroupId(uint64_t id) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
data.writeInt64(id);
status_t status = remote()->transact(SET_MASTER_ELECTION_GROUP_ID,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
virtual status_t getInterfaceBinding(String16& ifaceName) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
status_t status = remote()->transact(GET_INTERFACE_BINDING,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
ifaceName = reply.readString16();
}
}
return status;
}
virtual status_t setInterfaceBinding(const String16& ifaceName) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
data.writeString16(ifaceName);
status_t status = remote()->transact(SET_INTERFACE_BINDING,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
virtual status_t getMasterAnnounceInterval(int *interval) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
status_t status = remote()->transact(GET_MASTER_ANNOUNCE_INTERVAL,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*interval = reply.readInt32();
}
}
return status;
}
virtual status_t setMasterAnnounceInterval(int interval) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
data.writeInt32(interval);
status_t status = remote()->transact(SET_MASTER_ANNOUNCE_INTERVAL,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
virtual status_t getClientSyncInterval(int *interval) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
status_t status = remote()->transact(GET_CLIENT_SYNC_INTERVAL,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*interval = reply.readInt32();
}
}
return status;
}
virtual status_t setClientSyncInterval(int interval) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
data.writeInt32(interval);
status_t status = remote()->transact(SET_CLIENT_SYNC_INTERVAL,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
virtual status_t getPanicThreshold(int *threshold) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
status_t status = remote()->transact(GET_PANIC_THRESHOLD,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*threshold = reply.readInt32();
}
}
return status;
}
virtual status_t setPanicThreshold(int threshold) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
data.writeInt32(threshold);
status_t status = remote()->transact(SET_PANIC_THRESHOLD,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
virtual status_t getAutoDisable(bool *autoDisable) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
status_t status = remote()->transact(GET_AUTO_DISABLE,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
if (status == OK) {
*autoDisable = (0 != reply.readInt32());
}
}
return status;
}
virtual status_t setAutoDisable(bool autoDisable) {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
data.writeInt32(autoDisable ? 1 : 0);
status_t status = remote()->transact(SET_AUTO_DISABLE,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
virtual status_t forceNetworklessMasterMode() {
Parcel data, reply;
data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
status_t status = remote()->transact(FORCE_NETWORKLESS_MASTER_MODE,
data,
&reply);
if (status == OK) {
status = reply.readInt32();
}
return status;
}
};
IMPLEMENT_META_INTERFACE(CommonTimeConfig, "android.os.ICommonTimeConfig");
status_t BnCommonTimeConfig::onTransact(uint32_t code,
const Parcel& data,
Parcel* reply,
uint32_t flags) {
switch(code) {
case GET_MASTER_ELECTION_PRIORITY: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
uint8_t priority;
status_t status = getMasterElectionPriority(&priority);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt32(static_cast<int32_t>(priority));
}
return OK;
} break;
case SET_MASTER_ELECTION_PRIORITY: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
uint8_t priority = static_cast<uint8_t>(data.readInt32());
status_t status = setMasterElectionPriority(priority);
reply->writeInt32(status);
return OK;
} break;
case GET_MASTER_ELECTION_ENDPOINT: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
struct sockaddr_storage addr;
status_t status = getMasterElectionEndpoint(&addr);
if ((status == OK) && !canSerializeSockaddr(&addr)) {
status = UNKNOWN_ERROR;
}
reply->writeInt32(status);
if (status == OK) {
serializeSockaddr(reply, &addr);
}
return OK;
} break;
case SET_MASTER_ELECTION_ENDPOINT: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
struct sockaddr_storage addr;
int hasAddr = data.readInt32();
status_t status;
if (hasAddr) {
deserializeSockaddr(&data, &addr);
status = setMasterElectionEndpoint(&addr);
} else {
status = setMasterElectionEndpoint(&addr);
}
reply->writeInt32(status);
return OK;
} break;
case GET_MASTER_ELECTION_GROUP_ID: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
uint64_t id;
status_t status = getMasterElectionGroupId(&id);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt64(id);
}
return OK;
} break;
case SET_MASTER_ELECTION_GROUP_ID: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
uint64_t id = static_cast<uint64_t>(data.readInt64());
status_t status = setMasterElectionGroupId(id);
reply->writeInt32(status);
return OK;
} break;
case GET_INTERFACE_BINDING: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
String16 ret;
status_t status = getInterfaceBinding(ret);
reply->writeInt32(status);
if (status == OK) {
reply->writeString16(ret);
}
return OK;
} break;
case SET_INTERFACE_BINDING: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
String16 ifaceName;
ifaceName = data.readString16();
status_t status = setInterfaceBinding(ifaceName);
reply->writeInt32(status);
return OK;
} break;
case GET_MASTER_ANNOUNCE_INTERVAL: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
int interval;
status_t status = getMasterAnnounceInterval(&interval);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt32(interval);
}
return OK;
} break;
case SET_MASTER_ANNOUNCE_INTERVAL: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
int interval = data.readInt32();
status_t status = setMasterAnnounceInterval(interval);
reply->writeInt32(status);
return OK;
} break;
case GET_CLIENT_SYNC_INTERVAL: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
int interval;
status_t status = getClientSyncInterval(&interval);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt32(interval);
}
return OK;
} break;
case SET_CLIENT_SYNC_INTERVAL: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
int interval = data.readInt32();
status_t status = setClientSyncInterval(interval);
reply->writeInt32(status);
return OK;
} break;
case GET_PANIC_THRESHOLD: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
int threshold;
status_t status = getPanicThreshold(&threshold);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt32(threshold);
}
return OK;
} break;
case SET_PANIC_THRESHOLD: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
int threshold = data.readInt32();
status_t status = setPanicThreshold(threshold);
reply->writeInt32(status);
return OK;
} break;
case GET_AUTO_DISABLE: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
bool autoDisable;
status_t status = getAutoDisable(&autoDisable);
reply->writeInt32(status);
if (status == OK) {
reply->writeInt32(autoDisable ? 1 : 0);
}
return OK;
} break;
case SET_AUTO_DISABLE: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
bool autoDisable = (0 != data.readInt32());
status_t status = setAutoDisable(autoDisable);
reply->writeInt32(status);
return OK;
} break;
case FORCE_NETWORKLESS_MASTER_MODE: {
CHECK_INTERFACE(ICommonTimeConfig, data, reply);
status_t status = forceNetworklessMasterMode();
reply->writeInt32(status);
return OK;
} break;
}
return BBinder::onTransact(code, data, reply, flags);
}
}; // namespace android

@ -1,190 +0,0 @@
Copyright (c) 2005-2008, 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.
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.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

@ -1,129 +0,0 @@
/*
* 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 <stdint.h>
#include <common_time/cc_helper.h>
#include <common_time/ICommonClock.h>
#include <utils/threads.h>
namespace android {
Mutex CCHelper::lock_;
sp<ICommonClock> CCHelper::common_clock_;
sp<ICommonClockListener> CCHelper::common_clock_listener_;
uint32_t CCHelper::ref_count_ = 0;
bool CCHelper::verifyClock_l() {
bool ret = false;
if (common_clock_ == NULL) {
common_clock_ = ICommonClock::getInstance();
if (common_clock_ == NULL)
goto bailout;
}
if (ref_count_ > 0) {
if (common_clock_listener_ == NULL) {
common_clock_listener_ = new CommonClockListener();
if (common_clock_listener_ == NULL)
goto bailout;
if (OK != common_clock_->registerListener(common_clock_listener_))
goto bailout;
}
}
ret = true;
bailout:
if (!ret) {
common_clock_listener_ = NULL;
common_clock_ = NULL;
}
return ret;
}
CCHelper::CCHelper() {
Mutex::Autolock lock(&lock_);
ref_count_++;
verifyClock_l();
}
CCHelper::~CCHelper() {
Mutex::Autolock lock(&lock_);
assert(ref_count_ > 0);
ref_count_--;
// If we were the last CCHelper instance in the system, and we had
// previously register a listener, unregister it now so that the common time
// service has the chance to go into auto-disabled mode.
if (!ref_count_ &&
(common_clock_ != NULL) &&
(common_clock_listener_ != NULL)) {
common_clock_->unregisterListener(common_clock_listener_);
common_clock_listener_ = NULL;
}
}
void CCHelper::CommonClockListener::onTimelineChanged(uint64_t /*timelineID*/) {
// do nothing; listener is only really used as a token so the server can
// find out when clients die.
}
// Helper methods which attempts to make calls to the common time binder
// service. If the first attempt fails with DEAD_OBJECT, the helpers will
// attempt to make a connection to the service again (assuming that the process
// hosting the service had crashed and the client proxy we are holding is dead)
// If the second attempt fails, or no connection can be made, the we let the
// error propagate up the stack and let the caller deal with the situation as
// best they can.
#define CCHELPER_METHOD(decl, call) \
status_t CCHelper::decl { \
Mutex::Autolock lock(&lock_); \
\
if (!verifyClock_l()) \
return DEAD_OBJECT; \
\
status_t status = common_clock_->call; \
if (DEAD_OBJECT == status) { \
if (!verifyClock_l()) \
return DEAD_OBJECT; \
status = common_clock_->call; \
} \
\
return status; \
}
#define VERIFY_CLOCK()
CCHELPER_METHOD(isCommonTimeValid(bool* valid, uint32_t* timelineID),
isCommonTimeValid(valid, timelineID))
CCHELPER_METHOD(commonTimeToLocalTime(int64_t commonTime, int64_t* localTime),
commonTimeToLocalTime(commonTime, localTime))
CCHELPER_METHOD(localTimeToCommonTime(int64_t localTime, int64_t* commonTime),
localTimeToCommonTime(localTime, commonTime))
CCHELPER_METHOD(getCommonTime(int64_t* commonTime),
getCommonTime(commonTime))
CCHELPER_METHOD(getCommonFreq(uint64_t* freq),
getCommonFreq(freq))
CCHELPER_METHOD(getLocalTime(int64_t* localTime),
getLocalTime(localTime))
CCHELPER_METHOD(getLocalFreq(uint64_t* freq),
getLocalFreq(freq))
} // namespace android

@ -1,92 +0,0 @@
/*
* 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.
*/
#define LOG_TAG "common_time"
#include <utils/Log.h>
#include <assert.h>
#include <stdint.h>
#include <common_time/local_clock.h>
#include <hardware/hardware.h>
#include <hardware/local_time_hal.h>
#include <utils/Errors.h>
#include <utils/threads.h>
namespace android {
Mutex LocalClock::dev_lock_;
local_time_hw_device_t* LocalClock::dev_ = NULL;
LocalClock::LocalClock() {
int res;
const hw_module_t* mod;
AutoMutex lock(&dev_lock_);
if (dev_ != NULL)
return;
res = hw_get_module_by_class(LOCAL_TIME_HARDWARE_MODULE_ID, NULL, &mod);
if (res) {
ALOGE("Failed to open local time HAL module (res = %d)", res);
} else {
res = local_time_hw_device_open(mod, &dev_);
if (res) {
ALOGE("Failed to open local time HAL device (res = %d)", res);
dev_ = NULL;
}
}
}
bool LocalClock::initCheck() {
return (NULL != dev_);
}
int64_t LocalClock::getLocalTime() {
assert(NULL != dev_);
assert(NULL != dev_->get_local_time);
return dev_->get_local_time(dev_);
}
uint64_t LocalClock::getLocalFreq() {
assert(NULL != dev_);
assert(NULL != dev_->get_local_freq);
return dev_->get_local_freq(dev_);
}
status_t LocalClock::setLocalSlew(int16_t rate) {
assert(NULL != dev_);
if (!dev_->set_local_slew)
return INVALID_OPERATION;
return static_cast<status_t>(dev_->set_local_slew(dev_, rate));
}
int32_t LocalClock::getDebugLog(struct local_time_debug_event* records,
int max_records) {
assert(NULL != dev_);
if (!dev_->get_debug_log)
return INVALID_OPERATION;
return dev_->get_debug_log(dev_, records, max_records);
}
} // namespace android

@ -1,89 +0,0 @@
/*
* Copyright (C) 2012 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 <arpa/inet.h>
#include <linux/socket.h>
#include <binder/Parcel.h>
namespace android {
bool canSerializeSockaddr(const struct sockaddr_storage* addr) {
switch (addr->ss_family) {
case AF_INET:
case AF_INET6:
return true;
default:
return false;
}
}
void serializeSockaddr(Parcel* p, const struct sockaddr_storage* addr) {
switch (addr->ss_family) {
case AF_INET: {
const struct sockaddr_in* s =
reinterpret_cast<const struct sockaddr_in*>(addr);
p->writeInt32(AF_INET);
p->writeInt32(ntohl(s->sin_addr.s_addr));
p->writeInt32(static_cast<int32_t>(ntohs(s->sin_port)));
} break;
case AF_INET6: {
const struct sockaddr_in6* s =
reinterpret_cast<const struct sockaddr_in6*>(addr);
const int32_t* a =
reinterpret_cast<const int32_t*>(s->sin6_addr.s6_addr);
p->writeInt32(AF_INET6);
p->writeInt32(ntohl(a[0]));
p->writeInt32(ntohl(a[1]));
p->writeInt32(ntohl(a[2]));
p->writeInt32(ntohl(a[3]));
p->writeInt32(static_cast<int32_t>(ntohs(s->sin6_port)));
p->writeInt32(ntohl(s->sin6_flowinfo));
p->writeInt32(ntohl(s->sin6_scope_id));
} break;
}
}
void deserializeSockaddr(const Parcel* p, struct sockaddr_storage* addr) {
memset(addr, 0, sizeof(*addr));
addr->ss_family = p->readInt32();
switch(addr->ss_family) {
case AF_INET: {
struct sockaddr_in* s =
reinterpret_cast<struct sockaddr_in*>(addr);
s->sin_addr.s_addr = htonl(p->readInt32());
s->sin_port = htons(static_cast<uint16_t>(p->readInt32()));
} break;
case AF_INET6: {
struct sockaddr_in6* s =
reinterpret_cast<struct sockaddr_in6*>(addr);
int32_t* a = reinterpret_cast<int32_t*>(s->sin6_addr.s6_addr);
a[0] = htonl(p->readInt32());
a[1] = htonl(p->readInt32());
a[2] = htonl(p->readInt32());
a[3] = htonl(p->readInt32());
s->sin6_port = htons(static_cast<uint16_t>(p->readInt32()));
s->sin6_flowinfo = htonl(p->readInt32());
s->sin6_scope_id = htonl(p->readInt32());
} break;
}
}
} // namespace android

@ -1,34 +0,0 @@
/*
* Copyright (C) 2012 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.
*/
#ifndef ANDROID_LIBCOMMONCLOCK_UTILS_H
#define ANDROID_LIBCOMMONCLOCK_UTILS_H
#include <linux/socket.h>
#include <binder/Parcel.h>
#include <utils/Errors.h>
namespace android {
extern bool canSerializeSockaddr(const struct sockaddr_storage* addr);
extern void serializeSockaddr(Parcel* p, const struct sockaddr_storage* addr);
extern status_t deserializeSockaddr(const Parcel* p,
struct sockaddr_storage* addr);
}; // namespace android
#endif // ANDROID_LIBCOMMONCLOCK_UTILS_H
Loading…
Cancel
Save