2014년 6월 28일 토요일

[Binder] Native Service Example 2

I'll try to finish off Client part



class BpLcdService : public BpInterface
{
public:
 BpLcdService(const sp& impl): BpInterface(impl) {}

 virtual void LcdOn()
 {
  Parcel data, reply;
  remote()->transact(LCD_ON, data, &reply);
 }

 virtual void LcdOff()
 {
  Parcel data, reply;
  remote()->transact(LCD_OFF, data, &reply);
 }
};
IMPLEMENT_META_INTERFACE(LcdService, "android.app.lcdcontrol")

sp<ILcdService> LcdService()
{
sp<IBinder> binder = defaultServiceManager()->getService(String16("LcdService"));
return interface_cast<ILcdService>(binder);
}


This client does not have main() as I intended to make this as shared library file (.so) so I can call LcdOn/Off methods from Java application with Java Native Interface.

댓글 없음:

댓글 쓰기