bin/pc: Mark non-returning function as void
[haiku.git] / src / servers / notification / NotificationReceived.cpp
blobf5d9b01fdbd777ffdfde2c2b2e59b6110ceb12d4
1 /*
2 * Copyright 2010, Haiku, Inc. All Rights Reserved.
3 * Copyright 2008-2009, Pier Luigi Fiorini. All Rights Reserved.
4 * Copyright 2004-2008, Michael Davidson. All Rights Reserved.
5 * Copyright 2004-2007, Mikael Eiman. All Rights Reserved.
6 * Distributed under the terms of the MIT License.
8 * Authors:
9 * Michael Davidson, slaad@bong.com.au
10 * Mikael Eiman, mikael@eiman.tv
11 * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
14 #include <Message.h>
15 #include <Notification.h>
16 #include <NotificationReceived.h>
18 const type_code kTypeCode = 'ipnt';
21 NotificationReceived::NotificationReceived()
23 fTitle(""),
24 fType(B_INFORMATION_NOTIFICATION),
25 fEnabled(false),
26 fLastReceived(time(NULL))
31 NotificationReceived::NotificationReceived(const char* title,
32 notification_type type, bool enabled)
34 fTitle(title),
35 fType(type),
36 fEnabled(enabled),
37 fLastReceived(time(NULL))
42 NotificationReceived::~NotificationReceived()
47 bool
48 NotificationReceived::AllowsTypeCode(type_code code) const
50 return code == kTypeCode;
54 status_t
55 NotificationReceived::Flatten(void* buffer, ssize_t numBytes) const
57 BMessage msg;
58 msg.AddString("notify_title", fTitle);
59 msg.AddInt32("notify_type", (int32)fType);
60 msg.AddInt32("notify_lastreceived", (int32)fLastReceived);
61 msg.AddBool("notify_enabled", fEnabled);
63 if (numBytes < msg.FlattenedSize())
64 return B_ERROR;
66 return msg.Flatten((char*)buffer, numBytes);
70 ssize_t
71 NotificationReceived::FlattenedSize() const
73 BMessage msg;
74 msg.AddString("notify_title", fTitle);
75 msg.AddInt32("notify_type", (int32)fType);
76 msg.AddInt32("notify_lastreceived", (int32)fLastReceived);
77 msg.AddBool("notify_enabled", fEnabled);
79 return msg.FlattenedSize();
83 bool
84 NotificationReceived::IsFixedSize() const
86 return false;
90 type_code
91 NotificationReceived::TypeCode() const
93 return kTypeCode;
97 status_t
98 NotificationReceived::Unflatten(type_code code, const void* buffer,
99 ssize_t numBytes)
101 if (code != kTypeCode)
102 return B_ERROR;
104 BMessage msg;
105 status_t error = msg.Unflatten((const char*)buffer);
107 if (error == B_OK) {
108 msg.FindString("notify_title", &fTitle);
109 msg.FindInt32("notify_type", (int32 *)&fType);
110 msg.FindInt32("notify_lastreceived", (int32 *)&fLastReceived);
111 msg.FindBool("notify_enabled", &fEnabled);
114 return error;
118 const char*
119 NotificationReceived::Title()
121 return fTitle.String();
125 notification_type
126 NotificationReceived::Type()
128 return fType;
132 void
133 NotificationReceived::SetType(notification_type type)
135 fType = type;
139 time_t
140 NotificationReceived::LastReceived()
142 return fLastReceived;
146 bool
147 NotificationReceived::Allowed()
149 return fEnabled;
153 void
154 NotificationReceived::UpdateTimeStamp()
156 fLastReceived = time(NULL);
160 void
161 NotificationReceived::SetTimeStamp(time_t time)
163 fLastReceived = time;