headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / debugger / settings / TeamSignalSettings.cpp
blobd9d83044ab509338372f3e10131b0e21f9f99bd5
1 /*
2 * Copyright 2015, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5 #include "TeamSignalSettings.h"
8 static const char* skDefaultSignalFieldName = "signal:default_disposition";
9 static const char* skSignalNumberFieldName = "signal:number";
10 static const char* skSignalDispositionFieldName = "signal:disposition";
11 static const char* skSignalSettingName = "signal:setting";
14 TeamSignalSettings::TeamSignalSettings()
16 fValues()
21 TeamSignalSettings::~TeamSignalSettings()
26 TeamSignalSettings&
27 TeamSignalSettings::operator=(const TeamSignalSettings& other)
29 fValues = other.fValues;
31 return *this;
35 const char*
36 TeamSignalSettings::ID() const
38 return "Signals";
42 status_t
43 TeamSignalSettings::SetTo(const BMessage& archive)
45 try {
46 fValues = archive;
47 } catch (...) {
48 return B_NO_MEMORY;
51 return B_OK;
55 status_t
56 TeamSignalSettings::WriteTo(BMessage& archive) const
58 try {
59 archive = fValues;
60 } catch (...) {
61 return B_NO_MEMORY;
64 return B_OK;
68 void
69 TeamSignalSettings::Unset()
71 fValues.MakeEmpty();
75 void
76 TeamSignalSettings::SetDefaultSignalDisposition(int32 disposition)
78 fValues.SetInt32(skDefaultSignalFieldName, disposition);
82 int32
83 TeamSignalSettings::DefaultSignalDisposition() const
85 return fValues.GetInt32(skDefaultSignalFieldName,
86 SIGNAL_DISPOSITION_IGNORE);
90 int32
91 TeamSignalSettings::CountCustomSignalDispositions() const
93 type_code type;
94 int32 count = 0;
96 if (fValues.GetInfo(skSignalSettingName, &type, &count) == B_OK)
97 return count;
99 return 0;
103 status_t
104 TeamSignalSettings::AddCustomSignalDisposition(int32 signal, int32 disposition)
106 BMessage setting;
107 if (setting.AddInt32(skSignalNumberFieldName, signal) != B_OK
108 || setting.AddInt32(skSignalDispositionFieldName, disposition) != B_OK
109 || fValues.AddMessage(skSignalSettingName, &setting) != B_OK) {
110 return B_NO_MEMORY;
113 return B_OK;
117 status_t
118 TeamSignalSettings::RemoveCustomSignalDispositionAt(int32 index)
120 return fValues.RemoveData(skSignalSettingName, index);
124 status_t
125 TeamSignalSettings::GetCustomSignalDispositionAt(int32 index, int32& signal,
126 int32& disposition) const
128 BMessage setting;
129 status_t error = fValues.FindMessage(skSignalSettingName, index, &setting);
130 if (error != B_OK)
131 return error;
133 error = setting.FindInt32(skSignalNumberFieldName, &signal);
134 if (error != B_OK)
135 return error;
137 return setting.FindInt32(skSignalDispositionFieldName, &disposition);
141 TeamSignalSettings*
142 TeamSignalSettings::Clone() const
144 TeamSignalSettings* settings = new(std::nothrow)
145 TeamSignalSettings();
147 if (settings == NULL)
148 return NULL;
150 if (settings->SetTo(fValues) != B_OK) {
151 delete settings;
152 return NULL;
155 return settings;