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();
}
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));
}
	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);
	}
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());
}
Exemplo n.º 5
0
// 중재자(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");
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
void PriorityNotificationQueue::dispatch(NotificationCenter& notificationCenter)
{
    FastMutex::ScopedLock lock(_mutex);
    Notification::Ptr pNf = dequeueOne();
    while (pNf)
    {
        notificationCenter.postNotification(pNf);
        pNf = dequeueOne();
    }
}
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;
}
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);
}
Exemplo n.º 10
0
	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();
	}
Exemplo n.º 11
0
	void NotificationView::Init(NotificationCenter & center)
	{
		auto model = std::make_shared<NotificationModel>(center.GetStore());
		SetModel(std::move(model));
	}
Exemplo n.º 12
0
void NotificationCenterTest::test1()
{
	NotificationCenter nc;
	nc.postNotification(new Notification);
}
Exemplo n.º 13
0
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));
}
Observer::~Observer() {
  NotificationCenter *nc = NotificationCenter::get();
  if (nc->is_registered(this))
    logError("Notifications: Observer %p was deleted while still listening for notifications.\n", this);
}