bin/pc: Mark non-returning function as void
[haiku.git] / src / servers / notification / AppUsage.cpp
blob6599c87c49575dd06a9a35c667c4503f453c3c08
1 /*
2 * Copyright 2010-2017, 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
12 * Brian Hill, supernova@tycho.email
15 #include <Message.h>
17 #include <AppUsage.h>
18 #include <NotificationReceived.h>
20 const type_code kTypeCode = 'ipau';
23 AppUsage::AppUsage()
25 fAppName(""),
26 fSignature(""),
27 fAllow(true)
32 AppUsage::AppUsage(const char* name, const char* signature, bool allow)
34 fAppName(name),
35 fSignature(signature),
36 fAllow(allow)
41 bool
42 AppUsage::AllowsTypeCode(type_code code) const
44 return code == kTypeCode;
48 status_t
49 AppUsage::Flatten(void* buffer, ssize_t numBytes) const
51 BMessage msg;
52 msg.AddString("name", fAppName);
53 msg.AddString("signature", fSignature);
54 msg.AddBool("allow", fAllow);
56 if (numBytes < msg.FlattenedSize())
57 return B_ERROR;
59 return msg.Flatten((char*)buffer, numBytes);
63 ssize_t
64 AppUsage::FlattenedSize() const
66 BMessage msg;
67 msg.AddString("name", fAppName);
68 msg.AddString("signature", fSignature);
69 msg.AddBool("allow", fAllow);
71 return msg.FlattenedSize();
75 bool
76 AppUsage::IsFixedSize() const
78 return false;
82 type_code
83 AppUsage::TypeCode() const
85 return kTypeCode;
89 status_t
90 AppUsage::Unflatten(type_code code, const void* buffer,
91 ssize_t numBytes)
93 if (code != kTypeCode)
94 return B_ERROR;
96 BMessage msg;
97 status_t status = B_ERROR;
99 status = msg.Unflatten((const char*)buffer);
101 if (status == B_OK) {
102 msg.FindString("name", &fAppName);
103 msg.FindString("signature", &fSignature);
104 msg.FindBool("allow", &fAllow);
107 return status;
111 const char*
112 AppUsage::AppName()
114 return fAppName.String();
118 const char*
119 AppUsage::Signature()
121 return fSignature.String();
125 bool
126 AppUsage::Allowed()
128 return fAllow;
132 void
133 AppUsage::SetAllowed(bool allow)
135 fAllow = allow;