ANDROID

[Service Framework] Service Interface & Service Class & Service Proxy

BLUE-NOTE 2011. 9. 7. 01:23
Service Interface
  • Service Interface
    - Service interface는 Binder 형변환 관련하여 주요 메소드를 가지고 있고, 서비스와 서비스 프록시에서 재정의 될 순수가상 함수를 제공한다.

  •  순수가상함수 asBinder() = 0  (IInterface class)
    • Service interface 를 IBinder형으로 변환하는 함수로, IInterface를 상속하는 BnInterface나 BpInterface class에서 재정의된 asBinder()가 호출된다. 
      • BnInterface의 asBinder() : BBinder를 상속하므로 자기 자신을 return한다.
      • BpInterface의 asBinder() : Sub class인 RefBpBase의 Remote함수를 통해 IBinder를 return 한다.
         
  • asInterface()
    • IBinder 형을 인자로 받아, Service Interface를 얻어온다.


       
 Service class
  • Service 
    - super class인 BnStub의, super class인 BnInterface의, super class인 Service Interface의 기능(후에 stub 함수)들을 재정의. (구현)
    - Instantiate() 
    • ServiceManager에게 addService()시켜 자신을 시스템에 등록한다.
       
  •  Service Stub
    • super class인 BnInterface의, super class인 BBinder의 onTransact()를 구현하여 Service interface의 RPC code를 분석하여, Service의 stub 함수 호출.


 
 Service Proxy
  • Service proxy
    - Binder RPC에 필요한 RPC코드, RPC 데이터를 BpBinder의 transact() 함수를 통해 전달하여 IPCThreadState::transact()를 호출한다. ( IPC Layer로 전송)
    - super class인 BpInterface의, super class인 RefBpBase의 Remote()를 통해 BpBinder형의 IBinder를 호출하고, BpBinder의 transact() 사용.