source: Main/src/gfx_server/App.cpp @ 26

Revision 26, 4.7 KB checked in by duggan, 18 months ago (diff)

Getting ready to start on libraries.

Line 
1/*
2 * Copyright 2011 Dewey Taylor <james.dewey.taylor@gmail.com>
3 * All rights reserved. Distributed under the terms of the MIT license.
4 */
5
6#include "App.h"
7
8App::App()
9        :       BApplication("application/x-vnd.Drafter-gfx-server")
10{
11        // read display data from config files
12        SlotsUsed = 0;
13        if (LoadTopology("topology.txt") != B_OK)
14        {
15                status = B_ERROR;
16        }
17        // TODO: create framebuffers and windows to display them
18        uint32 headindex = 0;
19        for (int a = 0; a < SlotsUsed; a++)
20        {
21                for (int b = 0; b < Devices[a].HeadCount; b++)
22                {
23                        Devices[a].Heads[b].Index = headindex;
24                        headindex++;
25                }
26        }
27        HeadCount = headindex - 1;
28        HeadList = new Head*[HeadCount];
29        headindex = 0;
30}
31
32
33App::~App()
34{
35        for (int a = 0; a < SlotsUsed; a++)
36        {
37                for (int b = 0; b < Devices[a].HeadCount; b++)
38                {
39                        delete Devices[a].Heads[b].Resolutions;
40                }
41                delete Devices[a].Heads;
42        }
43}
44
45void
46App::ReadyToRun()
47{
48        // TODO: set up whatever other threads / systems
49
50        // Create console thread
51        BMessenger* msgr = new BMessenger(this);
52        ConsoleID = spawn_thread(Console, "Drafter Console", B_USER_INPUT_HANDLING, (void*) msgr);
53        resume_thread(ConsoleID);
54
55        // Create the windows for the heads
56        int headindex = 0;
57        for (int a = 0; a < SlotsUsed; a++)
58        {
59                for (int b = 0; b < Devices[a].HeadCount; b++)
60                {
61                        HeadList[headindex] = new Head(&(Devices[a].Heads[b]));
62                        HeadList[headindex]->Show();
63                        headindex++;
64                }
65        }
66}
67
68bool App::QuitRequested()
69{
70        be_app_messenger.SendMessage(B_QUIT_REQUESTED);
71        return BApplication::QuitRequested();
72}
73
74status_t
75App::LoadTopology(BString fname)
76{
77        BString line;
78        char rawline[1024];
79        ifstream file(fname.String());
80        if (file.is_open())
81        {
82                while (file.good())
83                {
84                        // Format:
85                        // # comment
86                        // Slot# : # of heads : ID (string)
87                        // connected(0/1) : number of resolutions : default / current resolution index : widthxheightxbpp@refresh : ... <-- one for each head
88                        file.getline(rawline, 1024);
89                        // TODO: implement a Trim function
90                        if (rawline[0] == '#' || rawline[0] == '\n')
91                        {
92                                continue;
93                        }
94                        SlotsUsed++;
95                        line = rawline;
96                        BString temp;
97                        uint32 slotnum;
98                        line.MoveInto(temp, 0, line.FindFirst(":"));
99                        line.RemoveFirst(":");
100                        slotnum = atoi(temp.String());
101                        cout<<"slotnum: "<<slotnum<<endl;
102                        line.MoveInto(temp, 0, line.FindFirst(":"));
103                        line.RemoveFirst(":");
104                        Devices[slotnum].HeadCount = atoi(temp.String());
105                        cout<<"headcount: "<<Devices[slotnum].HeadCount<<endl;
106                        Devices[slotnum].Heads = new HeadData[Devices[slotnum].HeadCount];
107                        Devices[slotnum].DeviceID = line;
108                        cout<<"deviceid: "<<Devices[slotnum].DeviceID<<endl;
109                        for(int a = 0 ; a < Devices[slotnum].HeadCount ; a++)
110                        {
111                                do
112                                {
113                                        file.getline(rawline, 1024);
114                                } while (rawline[0] == '#' || rawline[0] == '\n');
115                                line = rawline;
116                                line.MoveInto(temp, 0, line.FindFirst(":"));
117                                line.RemoveFirst(":");
118                                if (atoi(temp.String()) == 0)
119                                {
120                                        Devices[slotnum].Heads[a].Connected = false;
121                                }
122                                else
123                                {
124                                        Devices[slotnum].Heads[a].Connected = true;
125                                }
126                                cout<<"connected: "<<Devices[slotnum].Heads[a].Connected<<endl;
127                                line.MoveInto(temp, 0, line.FindFirst(":"));
128                                line.RemoveFirst(":");
129                                Devices[slotnum].Heads[a].ResolutionCount = atoi(temp.String());
130                                cout<<"rescount: "<<Devices[slotnum].Heads[a].ResolutionCount<<endl;
131                                Devices[slotnum].Heads[a].Resolutions = new ResolutionData[Devices[slotnum].Heads[a].ResolutionCount];
132                                line.MoveInto(temp, 0, line.FindFirst(":"));
133                                line.RemoveFirst(":");
134                                Devices[slotnum].Heads[a].CurrentResolution = atoi(temp.String());
135                                cout<<"current: "<<Devices[slotnum].Heads[a].CurrentResolution<<endl;
136                                for (int b = 0; b < Devices[slotnum].Heads[a].ResolutionCount; b++)
137                                {
138                                        if (line.FindFirst(":") != B_ERROR)
139                                        {
140                                                line.MoveInto(temp, 0, line.FindFirst(":"));
141                                                line.RemoveFirst(":");
142                                        }
143                                        else
144                                        {
145                                                temp = line;
146                                        }
147                                        BString temp2;
148                                        temp.MoveInto(temp2, 0, line.FindFirst("x"));
149                                        temp.RemoveFirst("x");
150                                        Devices[slotnum].Heads[a].Resolutions[b].Width = atoi(temp2.String());
151                                        temp.MoveInto(temp2, 0, line.FindFirst("x"));
152                                        temp.RemoveFirst("x");
153                                        Devices[slotnum].Heads[a].Resolutions[b].Height = atoi(temp2.String());
154                                        temp.MoveInto(temp2, 0, line.FindFirst("@"));
155                                        temp.RemoveFirst("@");
156                                        Devices[slotnum].Heads[a].Resolutions[b].BPP = atoi(temp2.String());
157                                        Devices[slotnum].Heads[a].Resolutions[b].Refresh = atoi(temp.String());
158                                }
159                        }
160                }
161        }
162        else
163        {
164                // File not found
165                return B_ERROR;
166        }
167        return B_OK;
168}
169
170void
171App::MessageReceived(BMessage* message)
172{
173        switch(message->what)
174        {
175                case CON_QUIT_MSG:
176                {
177                        QuitRequested();
178                }
179                case GFX_CREATE_CONTEXT:
180                {
181                        cout<<"Context creation request received"<<endl;
182                }
183        }
184}
185
186status_t
187App::Status()
188{
189        return status;
190}
Note: See TracBrowser for help on using the repository browser.