本文整理汇总了C++中NotificationCenter类的典型用法代码示例。如果您正苦于以下问题:C++ NotificationCenter类的具体用法?C++ NotificationCenter怎么用?C++ NotificationCenter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NotificationCenter类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: INC_STATS
v8::Handle<v8::Value> V8NotificationCenter::requestPermissionCallback(const v8::Arguments& args)
{
INC_STATS(L"DOM.NotificationCenter.RequestPermission()");
NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder());
ScriptExecutionContext* context = notificationCenter->context();
// Make sure that script execution context is valid.
if (!context)
return throwError(INVALID_STATE_ERR);
// Requesting permission is only valid from a page context.
if (context->isWorkerContext())
return throwError(NOT_SUPPORTED_ERR);
RefPtr<V8CustomVoidCallback> callback;
if (args.Length() > 0) {
if (!args[0]->IsObject())
return throwError("Callback must be of valid type.", V8Proxy::TypeError);
callback = V8CustomVoidCallback::create(args[0], context);
}
notificationCenter->requestPermission(callback.release());
return v8::Undefined();
}
示例2: assert
void NotificationCenterTest::test2()
{
NotificationCenter nc;
nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
nc.postNotification(new Notification);
assert (_set.size() == 1);
assert (_set.find("handle1") != _set.end());
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
}
示例3: WindowProc
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ){
if( uMsg==WM_NOTIFICATION ){
NotificationCenter* nc = (NotificationCenter*) wParam;
Notification* notify = (Notification*) lParam;
if( nc )
nc->displayNotification(notify);
if( notify ) delete notify;
return 0;
}
return ::DefWindowProcA(hwnd, uMsg, wParam, lParam);
}
示例4: INC_STATS
v8::Handle<v8::Value> V8NotificationCenter::createNotificationCallback(const v8::Arguments& args)
{
INC_STATS(L"DOM.NotificationCenter.CreateNotification()");
NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder());
ExceptionCode ec = 0;
RefPtr<Notification> notification = notificationCenter->createNotification(toWebCoreString(args[0]), toWebCoreString(args[1]), toWebCoreString(args[2]), ec);
if (ec)
return throwError(ec);
return toV8(notification.get());
}
示例5: main
// 중재자(Mediator) 패턴
// - 복잡한 객체간의 관계를 단순화 시켜주는 클래스
int main()
{
NotificationCenter& globalCenter = NotificationCenter::defaultCenter();
NotificationCenter nc;
nc.addObserver("LOWBATTERY", &foo);
nc.addObserver("LOWBATTERY", bind(&goo, 5));
Dialog dialog;
nc.addObserver("LOWBATTERY", bind(&Dialog::warning, &dialog));
// 이제 배터리를 체크하는 모듈에서
nc.postNotificationWithName("LOWBATTERY");
}
示例6: main_1
int main_1(int argc, char** argv) {
NotificationCenter nc;
Target target;
// Observer works with plain pointers to Notification objects.
nc.addObserver(
Observer<Target, BaseNotification>(target, &Target::handleBase));
// NObserver works with AutoPtr<Notification>.
// handleBase and handleSub both got this
nc.addObserver(
NObserver<Target, SubNotification>(target, &Target::handleSub));
std::cout << "* postNotification: BaseNotification" << std::endl;
nc.postNotification(new BaseNotification("Base Class Notification"));
// Targets subscribed for a particular notification class also receive
// notifications that are subclasses of that class.
std::cout << "* postNotification: SubNotification" << std::endl;
nc.postNotification(new SubNotification("Sub Class Notification"));
nc.removeObserver(
Observer<Target, BaseNotification>(target, &Target::handleBase));
nc.removeObserver(
NObserver<Target, SubNotification>(target, &Target::handleSub));
return 0;
}
示例7: dispatch
void PriorityNotificationQueue::dispatch(NotificationCenter& notificationCenter)
{
FastMutex::ScopedLock lock(_mutex);
Notification::Ptr pNf = dequeueOne();
while (pNf)
{
notificationCenter.postNotification(pNf);
pNf = dequeueOne();
}
}
示例8: handleNotificationEvent
int LuaEngine::handleNotificationEvent(void* data)
{
if ( NULL == data)
return 0;
BasicScriptData* basicScriptData = (BasicScriptData*)(data);
if (NULL == basicScriptData->nativeObject ||NULL == basicScriptData->value)
return 0;
NotificationCenter* center = static_cast<NotificationCenter*>(basicScriptData->nativeObject);
int handler = center->getObserverHandlerByName((const char*)basicScriptData->value);
if (0 == handler)
return 0;
_stack->pushString((const char*)basicScriptData->value);
int ret = _stack->executeFunctionByHandler(handler, 1);
_stack->clean();
return ret;
}
示例9: assert
void NotificationCenterTest::test3()
{
NotificationCenter nc;
nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle2));
assert (nc.hasObservers());
assert (nc.countObservers() == 2);
nc.postNotification(new Notification);
assert (_set.size() == 2);
assert (_set.find("handle1") != _set.end());
assert (_set.find("handle2") != _set.end());
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle2));
assert (!nc.hasObservers());
assert (nc.countObservers() == 0);
}
示例10: dispatch
void MessageQueue::dispatch(NotificationCenter& center, unsigned int maxNumberToDispatch)
{
MessagesIterator iter;
unsigned int dispatchCount;
Poco::ScopedRWLock lock(dispatchQueueRWLock, true);
dispatchCount = 0;
// First copy the messages from the queuedMessages queue to the dispatchQueue
queuedMessagesRWLock.writeLock();
iter = queuedMessages.begin();
while ((iter != queuedMessages.end()) && ((maxNumberToDispatch == 0) || (dispatchCount < maxNumberToDispatch)))
{
// Insert message into dispatch queue
dispatchQueue.push_back(*iter);
// Remove message from queued messages queue
iter = queuedMessages.erase(iter);
dispatchCount++;
}
queuedMessages.clear();
queuedMessagesRWLock.unlock();
// Dispatch the messages
for (iter = dispatchQueue.begin(); iter != dispatchQueue.end(); )
{
// Call duplicate on the Message instance, since Poco doesn't expect the object to be shared
(*iter)->duplicate();
// Send the message
center.postNotification(*iter);
// Remove the message from the list
iter = dispatchQueue.erase(iter);
}
dispatchQueue.clear();
}
示例11: Init
void NotificationView::Init(NotificationCenter & center)
{
auto model = std::make_shared<NotificationModel>(center.GetStore());
SetModel(std::move(model));
}
示例12:
void NotificationCenterTest::test1()
{
NotificationCenter nc;
nc.postNotification(new Notification);
}
示例13: o1
void NotificationCenterTest::test4()
{
NotificationCenter nc;
Observer<NotificationCenterTest, Notification> o1(*this, &NotificationCenterTest::handle1);
Observer<NotificationCenterTest, Notification> o2(*this, &NotificationCenterTest::handle2);
nc.addObserver(o1);
assert (nc.hasObserver(o1));
nc.addObserver(o2);
assert (nc.hasObserver(o2));
nc.postNotification(new Notification);
assert (_set.size() == 2);
assert (_set.find("handle1") != _set.end());
assert (_set.find("handle2") != _set.end());
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
assert (!nc.hasObserver(o1));
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle2));
assert (!nc.hasObserver(o2));
_set.clear();
nc.postNotification(new Notification);
assert (_set.empty());
Observer<NotificationCenterTest, Notification> o3(*this, &NotificationCenterTest::handle3);
nc.addObserver(o3);
assert (nc.hasObserver(o3));
nc.postNotification(new Notification);
assert (_set.size() == 1);
assert (_set.find("handle3") != _set.end());
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle3));
assert (!nc.hasObserver(o3));
}
示例14: logError
Observer::~Observer() {
NotificationCenter *nc = NotificationCenter::get();
if (nc->is_registered(this))
logError("Notifications: Observer %p was deleted while still listening for notifications.\n", this);
}