summaryrefslogtreecommitdiff
path: root/indra/llui/llnotificationslistener.cpp
blob: fe4fbe75105eeb2064d5b9a6d188cd0b3ef387ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
 * @file   llnotificationslistener.cpp
 * @author Brad Kittenbrink
 * @date   2009-07-08
 * @brief  Implementation for llnotificationslistener.
 * 
 * $LicenseInfo:firstyear=2009&license=viewergpl$
 * Copyright (c) 2009, Linden Research, Inc.
 * $/LicenseInfo$
 */

#include "linden_common.h"

#include "llnotificationslistener.h"

#include "llnotifications.h"

LLNotificationsListener::LLNotificationsListener(LLNotifications & notifications) :
    LLEventAPI("LLNotifications",
               "LLNotifications listener to (e.g.) pop up a notification"),
    mNotifications(notifications)
{
    add("requestAdd",
        "Add a notification with specified [\"name\"], [\"substitutions\"] and [\"payload\"].\n"
        "If optional [\"reply\"] specified, arrange to send user response on that LLEventPump.",
        &LLNotificationsListener::requestAdd);
}

void LLNotificationsListener::requestAdd(const LLSD& event_data) const
{
	if(event_data.has("reply"))
	{
		mNotifications.add(event_data["name"], 
						   event_data["substitutions"], 
						   event_data["payload"],
						   boost::bind(&LLNotificationsListener::NotificationResponder, 
									   this, 
									   event_data["reply"].asString(), 
									   _1, _2
									   )
						   );
	}
	else
	{
		mNotifications.add(event_data["name"], 
						   event_data["substitutions"], 
						   event_data["payload"]);
	}
}

void LLNotificationsListener::NotificationResponder(const std::string& reply_pump, 
										const LLSD& notification, 
										const LLSD& response) const
{
	LLSD reponse_event;
	reponse_event["notification"] = notification;
	reponse_event["response"] = response;
	LLEventPumps::getInstance()->obtain(reply_pump).post(reponse_event);
}