[Platinum UPnP] 101 :: (4) 간단한 Control-Point 만들기
[Platinum UPnP] 101 :: (1) 간단한 Device 만들기
[Platinum UPnP] 101 :: (2) Device에 Service 올리기 + StateVariable & Event
[Platinum UPnP] 101 :: (3) Service에 Action 추가하기
[Platinum UPnP] 101 :: (4) 간단한 Control-Point 만들기
파일: tutorial04.cpp
앞서 우리는 간단하지만 기본적인 기능을 모두 갖춘 하나의 Device를 만들어 보았습니다. 이번에는 UPnP의 또 다른 구성 요소인 Control-Point를 만들어 보겠습니다.
이에 앞서 Control-Point에 대해 간략히 설명하자면, Device를 검증하는데 사용했던 Device Spy가 대표적인 Control-Point라고 할 수 있습니다. 즉, Device를 찾고 Device의 정보를 보고 올바른 Action을 날리고 Event를 받는 등의 일을 하는 것이 Control-Point의 역할입니다.
이제 가장 간단한 Control-Point 프로그램을 구성해 보겠습니다. 코드는 아래와 같습니다.
#include <string> #include <iostream> #include "Platinum.h" int main() { PLT_UPnP upnp; PLT_CtrlPointReference ctrlpoint(new PLT_CtrlPoint); upnp.AddCtrlPoint(ctrlpoint); upnp.Start(); bool stop = false; do { std::string input; std::cin >> input; if (input == "q" || input == "Q") { stop = true; } else { // nothing } } while(!stop); upnp.Stop(); return 0; }
Control-Point의 기본적인 기능을 담당하는 PLT_CtrlPoint 클래스는 PLT_DeviceHost 클래스가 가상 클래스였던 것과는 다르게 독립적으로 객체를 생성할 수 있습니다. 다만, Device에 Service를 올리기 전까지 아무것도 할 수 없었던 것처럼 지금도 할 수 있는 것이 아무것도 없다는 것이 문제 입니다.
Device의 경우에는 PLT_DeviceHost 클래스를 상속 받아 객체 생성이 가능한 자식 클래스를 구성했습니다. 그러나 Control-Point는 Listener 객체를 등록받아 Listener 객체들에게 콜백을 호출합니다. 따라서 이번에는 PLT_CtrlPoint 클래스를 상속받는 것이 아니라 PLT_CtrlPointListener 클래스라는 순수 가상함수를 상속 받아 PLT_CtrlPoint 객체에게 등록해 줍니다.
PLT_CtrlPointListener 클래스를 상속 받은 TutorialListener 클래스의 기본 구현 코드는 아래와 같습니다.
class TutorialListener : public PLT_CtrlPointListener { public: virtual NPT_Result OnDeviceAdded(PLT_DeviceDataReference& device) { return NPT_SUCCESS; } virtual NPT_Result OnDeviceRemoved(PLT_DeviceDataReference& device) { return NPT_SUCCESS; } virtual NPT_Result OnActionResponse(NPT_Result res, PLT_ActionReference& action, void* userdata) { return NPT_SUCCESS; } virtual NPT_Result OnEventNotify(PLT_Service* service, NPT_List<PLT_StateVariable*>* vars) { return NPT_SUCCESS; } };
이제 PLT_CtrlPoint 객체에 TutorialListener 객체를 등록을 해줍니다. main() 함수의 코드가 아래와 같이 변경 됩니다.
TutorialListener listener; PLT_CtrlPointReference ctrlpoint(new PLT_CtrlPoint); ctrlpoint->AddListener(&listener); upnp.AddCtrlPoint(ctrlpoint);
이것으로 Control-Point의 기능을 만들기 위한 기본 코드가 완료되었습니다.
'오픈소스 > Network' 카테고리의 다른 글
[Platinum UPnP] 101 :: (6) Device에서 Event 받기 (0) | 2013.03.03 |
---|---|
[Platinum UPnP] 101 :: (5) Device 연결하고 Action 호출하기 (0) | 2013.03.02 |
[Platinum UPnP] 101 :: (3) Service에 Action 추가하기 (0) | 2013.03.01 |
[Platinum UPnP] 101 :: (2) Device에 Service 올리기 + StateVariable & Event (0) | 2013.03.01 |
[Platinum UPnP] 101 :: (1) 간단한 Device 만들기 (0) | 2013.03.01 |