xref: /haiku/src/apps/debugger/user_interface/gui/settings/DebuggerUiSettingsFactory.cpp (revision ec60909a20fb5d87db22583cd87e225e5c67e95e)
1 /*
2  * Copyright 2011-2016, Rene Gollent, rene@gollent.com.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "DebuggerUiSettingsFactory.h"
8 
9 #include <Message.h>
10 
11 #include "GuiTeamUiSettings.h"
12 
13 
14 DebuggerUiSettingsFactory* DebuggerUiSettingsFactory::sDefaultInstance = NULL;
15 
16 
DebuggerUiSettingsFactory()17 DebuggerUiSettingsFactory::DebuggerUiSettingsFactory()
18 {
19 }
20 
21 
~DebuggerUiSettingsFactory()22 DebuggerUiSettingsFactory::~DebuggerUiSettingsFactory()
23 {
24 }
25 
26 
27 DebuggerUiSettingsFactory*
Default()28 DebuggerUiSettingsFactory::Default()
29 {
30 	return sDefaultInstance;
31 }
32 
33 
34 status_t
CreateDefault()35 DebuggerUiSettingsFactory::CreateDefault()
36 {
37 	sDefaultInstance = new(std::nothrow) DebuggerUiSettingsFactory();
38 	if (sDefaultInstance == NULL)
39 		return B_NO_MEMORY;
40 
41 	return B_OK;
42 }
43 
44 
45 void
DeleteDefault()46 DebuggerUiSettingsFactory::DeleteDefault()
47 {
48 	delete sDefaultInstance;
49 	sDefaultInstance = NULL;
50 }
51 
52 
53 status_t
Create(const BMessage & archive,TeamUiSettings * & settings) const54 DebuggerUiSettingsFactory::Create(const BMessage& archive,
55 	TeamUiSettings*& settings) const
56 {
57 	int32 type;
58 	status_t error = archive.FindInt32("type", &type);
59 	if (error != B_OK)
60 		return error;
61 
62 	switch (type) {
63 		case TEAM_UI_SETTINGS_TYPE_GUI:
64 			settings = new(std::nothrow) GuiTeamUiSettings();
65 			if (settings == NULL)
66 				return B_NO_MEMORY;
67 
68 			error = settings->SetTo(archive);
69 			if (error != B_OK) {
70 				delete settings;
71 				settings = NULL;
72 				return error;
73 			}
74 			break;
75 
76 		case TEAM_UI_SETTINGS_TYPE_CLI:
77 			// TODO: implement once we have a CLI interface
78 			// (and corresponding settings)
79 			return B_UNSUPPORTED;
80 
81 		default:
82 			return B_BAD_DATA;
83 	}
84 
85 	return B_OK;
86 }
87