Service Applications

서비스 어플리케이션은 그래픽 유저 인터페이스를 갖지 않고 백그라운드에서 동작하는 Tizen Native application 이다. 서비스 어플리케이션은 센서 데이터를 얻는 것과 같이 사용자의 개입없이 백그라운드에서 지속적 혹은 주기적으로 수행되는 작업들에 배우 유용하다. 


서비스 어플리케이션은 UI 어플리케이션에 의해 실행될 수 있다.  또한 서비스 어플리케이션은 주건에 따라 실행될 수 있다. 


사용자는 task switcher에서 실행되고 있는 서비스 어플리케이션을 체크할 수 있다. 하지만, 사용자가 task switcher를 통해 서비스 어플리케이션을 선택할 경우 어떠한 이벤트도 발생하지 않는다. 메인 메뉴는 서비스 어플리케이션을 위한 아이콘을 포함하지 않는다. 다중 서비스 어플리케이션(Multiple Service Application)은 다른 서비스 혹은 UI 어플리케이션과 동시에 실행된다. 



Service Application Fundamentals

모든 서비스 어플리케이션에 필요한 기본적인 기능을 수행하기 위해서, Tizen::App네임스페이스는 여러 기능을 제공한다. 

Tizen IDE의 Project Wizard를 사용하여 어플리케이션을 생성하면 Tizen IDE는 자동적으로 다음과 같은 기본적인 코드를 생성해준다.

  1. Inheriting the ServiceApp clasee (ServiceApp 클래스를 상속받은 클래스)

  2. Creating the Application Entry Point (어플리케이션 entry point 생성)

  3. 어플리케이션 Life-cycle(생명주기) 관리

  4. 어플리케이션 정보 ( GetAppName(), GetAppId() 메소드를 통해 어플리케이션의 정보를 얻을 수 있다)  

  5. 시스템 이벤트 처리

또한, 어플리케이션은 어플리케이션을 나타내는 속성, ID, 이름들이 정해져야만 한다. 이러한 몇몇의 속성들은 자동적으로 어플리케이션이 생성될때 설정된다. 


Inheriting the ServiceApp Class

Tizen::App::ServiceApp클래스는 Tizen 서비스 어플리케이션 프로그램을 정의하는데 필요한 기본적인 기능을 제공한다. 그러므로 모든 타이젠 서비스 어플리케이션은 ServiceApp class를 상속받아야만 한다.

 class MyApp
   : public Tizen::App::ServiceApp


Creating the Application Entry Point

어플리케이션이 실행될때, Tizen IDE는 자동적으로 OspMain() 메소드를 <어플리케이션 이름>Entry.cpp에 생성한다.

int
OspMain(int argc, char* pArgv[])
{
   r = Tizen::App::ServiceApp::Execute(MyApp::CreateInstance, pArgs);
}


ServiceApp 클래스에서 파생된 클래스를 선언하고 해당 인스턴스를 생성하는 정적 메서드를 정의해야 한다.

// Declare the method
static Tizen::App::ServiceApp* MyApp::CreateInstance(void);

// Define the method
ServiceApp*
MyApp::CreateInstance(void)
{
   return new MyApp;
}


Managing the Service Application Life-cycle

어플리케이션의 Life-Cycle(생명주기)는 어플리케이션의 상태변화에 따라 호출되는 이벤트 핸들러의 집합으로 관리된다. 

  • The OnAppInitializing() event handler is called when an application state changes to 'Initializing'. If the OnAppInitializing() event handler returns false, the application is directly terminated.

  • The OnAppInitialized() event handler is called when the application state changes to 'Running'.

  • The OnAppTerminating() event handler is called when the application state changes to 'Terminated'.


bool
MyApp::OnAppInitializing(AppRegistry& appRegistry)
{
   // Initialize application specific data
   // The application's permanent data and context can be obtained from the application registry
   // If this method is successful, return true; otherwise, return false
   // If this method returns false, the application is terminated
   // Uncomment the following statement to listen to the screen on/off events

   // React when the application is in the 'initializing' state

   return true;
}

bool
MyApp::OnAppInitialized(void)
{
   // React to application initialization

   return true;
}
bool
MyApp::OnAppWillTerminate(void)
{
   // React to the application termination status

   return true;
}

bool
MyApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
{
   // Deallocate resources allocated by this application for termination
   // The application's permanent data and context can be saved in the application registry

   // React when the application is in the 'terminating' state

   return true;
}


Posted by No names
,