android binder机制实现
2010-05-31 14:30:00 来源:WEB开发网virtual bool checkPermission(const String16& permission,int32_t pid, int32_t uid) = 0;
enum {
CHECK_PERMISSION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION
};
};
class BnPermissionController : public BnInterface
{
public:
virtual status_t onTransact( uint32_t code,
const Parcel& data,
Parcel* reply,
uint32_t flags = 0);
};
class IPermissionController : public IInterface { public: DECLARE_META_INTERFACE(PermissionController); virtual bool checkPermission(const String16& permission,int32_t pid, int32_t uid) = 0; enum { CHECK_PERMISSION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION }; }; class BnPermissionController : public BnInterface { public: virtual status_t onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0); };
IPermissionController是一个接口类,只有checkPermission()一个纯虚函数。
BnPermissionController继承了以BnPermissionController实例化模版类BnInterface。因
此,BnPermissionController,事实上BnPermissionController双继承了BBinder和
IPermissionController。
实现文件IPermissionController.cpp中,首先实现了一个BpPermissionController。
Java代码 < width="14" height="15" src="http://mintelong.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" pluginspage="http://www.macromedia.com/go/getflashplayer">
class BpPermissionController : public BpInterface
{
public:
BpPermissionController(const sp& impl)
: BpInterface(impl)
{
}
virtual bool checkPermission(const String16& permission, int32_t pid, int32_t uid)
{
Parcel data, reply;
data.writeInterfaceToken(IPermissionController::
getInterfaceDescriptor());
data.writeString16(permission);
赞助商链接