2014년 6월 28일 토요일

[Binder] Native Service Example 1

Here I'm going to make a native service for turning on/off LCD screen, and a client that make a request to the native service. At the end I will try to install a client application to my Android phone and see whether it actually work as intended.

Basically the flows looks like this:



Android uses some prefixes like Bp, Bn,
Bp stands for Binder Proxy (client side) whereas Bn stands for Binder Native, this one is for service server side. That's why we have BpLcdService, BnLcdService.

ok .. firstly in order to communicate between client and server, there should be some sort of protocol
so we define ILcdService that contains only two virtual methods. Whoever that use this protocol must provide LcdOn/Off methods.

class ILcdService : public IInterface
{
public:
       DECLARE_META_INTERFACE(LcdService)
       enum { LCD_ON = 1, LCD_OFF };

       virtual void LcdOn() = 0;
       virtual void LcdOff() = 0;
};

IInterface (in Android F/W) provides asBinder() method to convert the type of ILcdServce to IBinder. Why we need this conversion is that during IPC , IBinder type object will be stored in RPC data and sent to Binder driver. In other words say when registering LcdService to the System, Service Manager needs to send RPC data with service object (BBinder type) to Context Manager. In this process service will be converted to IBinder type and sent to Binder Driver.




댓글 없음:

댓글 쓰기