Observer pattern and IStatusCallBack in VSIP
2004-06-18 15:57
453 查看
In the VSIP, it is common that some part needs to be notified when status of some other part changed. To do this, we need to define 2 interfaces, one for the observer, and the other for the subject, the event server.
This is a simple example for the VCM event handle. IVcmStatusCallback is the interface that the observer needs to implement. Fill each interface function with the the thing you want to do when event comes. IVcmStatusAdvisor is the interface the subject needs to implement. All the observer call these 2 functions to register or un-register themselves for the event alert.
//for VCM multi-thread
//// {B52A3189-56F6-4a02-BBD6-3E9069C18944}
[
uuid(B52A3189-56F6-4a02-BBD6-3E9069C18944),
version(1.0),
helpstring("IVcmStatusCallback Interface")
]
interface IVcmStatusCallback : IUnknown
{
HRESULT VcmBegin(
[in, out] BOOL* pfContinue);
HRESULT VcmEnd(
[in] BOOL fSuccess,
[in] BSTR OutPutFile,
[in] BSTR ErrFile);
HRESULT Tick(
[in, out] BOOL* pfContinue);
}
//{A17F59FA-098E-4e48-B301-8EF47208538B}
[
uuid(A17F59FA-098E-4e48-B301-8EF47208538B),
version(1.0),
helpstring("IVcmStatusAdvisor Interface")
]
interface IVcmStatusAdvisor : IUnknown
{
HRESULT AdviseVcmStatusCallback(
/* [in] */ IVcmStatusCallback *pIVcmStatusCallback,
/* [out] */ VSCOOKIE *pdwCookie);
HRESULT UnadviseVcmStatusCallback(
/* [in] */ VSCOOKIE dwCookie);
}
The general routine is: first, the observer gets the interface of the subject, then call Advise...StatusCallback with the observer interface pointer and get a VSCOOKIE as the identifier of itself. The VSCOOKIE can be used to un-register itself. The subject added the observer interface into its event alert array if possible. When the subject finished something and need to notify the observer, it go through the observers array and call their functions.
This is a simple example for the VCM event handle. IVcmStatusCallback is the interface that the observer needs to implement. Fill each interface function with the the thing you want to do when event comes. IVcmStatusAdvisor is the interface the subject needs to implement. All the observer call these 2 functions to register or un-register themselves for the event alert.
//for VCM multi-thread
//// {B52A3189-56F6-4a02-BBD6-3E9069C18944}
[
uuid(B52A3189-56F6-4a02-BBD6-3E9069C18944),
version(1.0),
helpstring("IVcmStatusCallback Interface")
]
interface IVcmStatusCallback : IUnknown
{
HRESULT VcmBegin(
[in, out] BOOL* pfContinue);
HRESULT VcmEnd(
[in] BOOL fSuccess,
[in] BSTR OutPutFile,
[in] BSTR ErrFile);
HRESULT Tick(
[in, out] BOOL* pfContinue);
}
//{A17F59FA-098E-4e48-B301-8EF47208538B}
[
uuid(A17F59FA-098E-4e48-B301-8EF47208538B),
version(1.0),
helpstring("IVcmStatusAdvisor Interface")
]
interface IVcmStatusAdvisor : IUnknown
{
HRESULT AdviseVcmStatusCallback(
/* [in] */ IVcmStatusCallback *pIVcmStatusCallback,
/* [out] */ VSCOOKIE *pdwCookie);
HRESULT UnadviseVcmStatusCallback(
/* [in] */ VSCOOKIE dwCookie);
}
The general routine is: first, the observer gets the interface of the subject, then call Advise...StatusCallback with the observer interface pointer and get a VSCOOKIE as the identifier of itself. The VSCOOKIE can be used to un-register itself. The subject added the observer interface into its event alert array if possible. When the subject finished something and need to notify the observer, it go through the observers array and call their functions.
相关文章推荐
- Understanding and Implementing Observer Pattern in C++
- Concurrent Programming in Java(TM): Design Principles and Pattern
- Android facing front camera and facing back camera setting in HAL
- How to Update to Metasploit 4 and use Autopwn in Backtrack 5
- Java里的生产者-消费者模型(Producer and Consumer Pattern in Java)
- Back/Forward and Refresh in browser
- backtracking in Date Structures and Algorithm Analysis in C
- observer pattern in javascript
- Open Baidu webpage and type in Chinese characters to start searching, press “Back” button to go to B
- shallow copy and deep copy in Prototype Pattern
- Observer pattern in Javascript
- Patterns in Objective-C: Observer Pattern
- Cross-Platform Development in C++: Building Mac OS X, Linux, and, Windows Applications (Paperback) Dec.2007.eBook-BBL
- Observer Pattern, Delegate and Event
- Observer Pattern in JavaScript II scope declared when subscribe()
- Observer Pattern in Android
- Convert IP addresses from a dots-and-number string to a struct in_addr and back
- CRUD Operations Using the Generic Repository Pattern and Dependency Injection in MVC
- Understanding and Implementing Factory Pattern in C++
- Observer Pattern, Delegate and Event