Choco OS  V.0.16.9.0
Join to the chocolate world
oc_screenman.c
Go to the documentation of this file.
1 
27 #include <oc_screenman.h>
28 #include <oc_screens_cfg.c>
29 #include <oc_driverman.h>
30 #include <oc_module.h>
31 #include <oc_list.h>
32 #include <oc_string.h>
33 
39 #define _________________________________________LOCAL_TYPES________________________________________________________________________________
40 
41 
42 
43 #undef _________________________________________LOCAL_TYPES________________________________________________________________________________
44 
50 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________
51 
52 static oC_List(oC_Screen_t) Screens = NULL;
53 static const char * DefaultScreenName = NULL;
54 static oC_Allocator_t Allocator = {
55  .Name = "ScreenMan" ,
56 };
57 
58 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________
59 
60 
66 #define _________________________________________FUNCTIONS__________________________________________________________________________________
67 
68 //==========================================================================================================================================
79 //==========================================================================================================================================
80 oC_ErrorCode_t oC_ScreenMan_TurnOn( void )
81 {
82  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
83 
84  if(oC_Module_TurnOffVerification(&errorCode,oC_Module_ScreenMan))
85  {
86  Screens = oC_List_New(&Allocator,AllocationFlags_ZeroFill | AllocationFlags_CanWait1Second);
87 
88  if(ErrorCondition(Screens != NULL , oC_ErrorCode_AllocationError))
89  {
90  errorCode = oC_ErrorCode_None;
91 
92 #define CREATE_SCREEN( NAME , DRIVER_NAME , CONFIG_NAME ) \
93  oC_Screen_t NAME = oC_Screen_New( &DRIVER_NAME , &CONFIG_NAME , #NAME );
94  CFG_SCREENS_LIST(CREATE_SCREEN);
95 #undef CREATE_SCREEN
96 
97 #define ADD_SCREEN( NAME , DRIVER_NAME , CONFIG_NAME ) \
98  if(ErrorCondition( NAME != NULL , oC_ErrorCode_ObjectNotCorrect ))\
99  {\
100  bool success = oC_List_PushBack(Screens,NAME,&Allocator);\
101  ErrorCondition(success, oC_ErrorCode_CannotAddObjectToList);\
102  }
103  CFG_SCREENS_LIST(ADD_SCREEN)
104 #undef ADD_SCREEN
105 
106  DefaultScreenName = CFG_STRING_DEFAULT_SCREEN;
107  oC_Module_TurnOn(oC_Module_ScreenMan);
108  }
109  }
110 
111  return errorCode;
112 }
113 
114 //==========================================================================================================================================
124 //==========================================================================================================================================
125 oC_ErrorCode_t oC_ScreenMan_TurnOff( void )
126 {
127  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
128 
129  if(oC_Module_TurnOnVerification(&errorCode,oC_Module_ScreenMan))
130  {
131  errorCode = oC_ErrorCode_None;
132 
133 #define TAKE_SCREEN( NAME , DRIVER_NAME , CONFIG_NAME ) \
134  oC_Screen_t NAME = oC_ScreenMan_GetScreen( #NAME ); \
135  oC_List_RemoveAll(Screens,NAME);
136  CFG_SCREENS_LIST(TAKE_SCREEN);
137 #undef TAKE_SCREEN
138 
139 #define DELETE_SCREEN(NAME , DRIVER_NAME , CONFIG_NAME ) \
140  oC_Screen_Delete(&NAME);
141  CFG_SCREENS_LIST(DELETE_SCREEN);
142 #undef DELETE_SCREEN
143 
144  ErrorCondition( oC_List_Delete(Screens,AllocationFlags_CanWait1Second) , oC_ErrorCode_ReleaseError);
145 
146  oC_Module_TurnOff(oC_Module_ScreenMan);
147  }
148 
149  return errorCode;
150 }
151 
152 //==========================================================================================================================================
163 //==========================================================================================================================================
165 {
166  if(oC_Module_IsTurnedOn(oC_Module_ScreenMan))
167  {
168  oC_List_Foreach(Screens,screen)
169  {
170  if(oC_Screen_IsConfigured(screen) == false && oC_Driver_IsTurnedOn(oC_Screen_GetDriver(screen)) == true)
171  {
172  oC_SaveIfErrorOccur(oC_Screen_GetName(screen) , oC_Screen_Configure(screen));
173  }
174  }
175  }
176 }
177 
178 //==========================================================================================================================================
188 //==========================================================================================================================================
190 {
191  if(oC_Module_IsTurnedOn(oC_Module_ScreenMan))
192  {
193  oC_List_Foreach(Screens,screen)
194  {
195  if(oC_Screen_IsConfigured(screen) == true)
196  {
197  oC_SaveIfErrorOccur(oC_Screen_GetName(screen) , oC_Screen_Unconfigure(screen));
198  }
199  }
200  }
201 }
202 
203 //==========================================================================================================================================
214 //==========================================================================================================================================
216 {
217  oC_Screen_t screen = NULL;
218 
219  if(oC_Module_IsTurnedOn(oC_Module_ScreenMan))
220  {
221  screen = oC_ScreenMan_GetScreen(DefaultScreenName);
222  }
223 
224  return screen;
225 }
226 
227 //==========================================================================================================================================
241 //==========================================================================================================================================
242 oC_List(oC_Screen_t) oC_ScreenMan_GetList( void )
243 {
244  return Screens;
245 }
246 
247 //==========================================================================================================================================
259 //==========================================================================================================================================
261 {
262  oC_Screen_t defaultScreen = NULL;
263 
264  if(oC_Module_IsTurnedOn(oC_Module_ScreenMan))
265  {
266  oC_List_Foreach(Screens,screen)
267  {
268  if(strcmp(oC_Screen_GetName(screen),Name) == 0)
269  {
270  defaultScreen = screen;
271  }
272  }
273  }
274 
275  return defaultScreen;
276 }
277 
278 //==========================================================================================================================================
290 //==========================================================================================================================================
291 oC_ErrorCode_t oC_ScreenMan_AddScreen( oC_Screen_t Screen )
292 {
293  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
294 
295  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_ScreenMan))
296  {
297  if(ErrorCondition(oC_Screen_IsCorrect(Screen) , oC_ErrorCode_ObjectNotCorrect))
298  {
299  bool pushed = oC_List_PushBack(Screens,Screen,&Allocator);
300 
301  if(ErrorCondition(pushed,oC_ErrorCode_CannotAddObjectToList))
302  {
303  errorCode = oC_ErrorCode_None;
304  }
305  }
306  }
307 
308  return errorCode;
309 }
310 
311 //==========================================================================================================================================
323 //==========================================================================================================================================
324 oC_ErrorCode_t oC_ScreenMan_RemoveScreen( oC_Screen_t Screen )
325 {
326  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
327 
328  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_ScreenMan))
329  {
330  if(ErrorCondition(oC_Screen_IsCorrect(Screen) , oC_ErrorCode_ObjectNotCorrect))
331  {
332  bool removed = oC_List_RemoveAll(Screens,Screen);
333 
334  if(ErrorCondition(removed,oC_ErrorCode_CannotRemoveObjectFromList))
335  {
336  errorCode = oC_ErrorCode_None;
337  }
338  }
339  }
340 
341  return errorCode;
342 }
343 
344 #undef _________________________________________FUNCTIONS__________________________________________________________________________________
345 
346 
oC_ErrorCode_t oC_ScreenMan_RemoveScreen(oC_Screen_t Screen)
removes screen from the screens list
Definition: oc_screenman.c:324
void oC_ScreenMan_ConfigureAll(void)
configures all screens
Definition: oc_screenman.c:164
const char * oC_Screen_GetName(oC_Screen_t Screen)
returns name of the screen
Definition: oc_screen.c:386
const char * Name
Definition: oc_stdlib.h:161
identifier for allocations
Definition: oc_stdlib.h:159
oC_ErrorCode_t oC_ScreenMan_TurnOn(void)
turns on the screen manager module
Definition: oc_screenman.c:80
static oC_List(oC_Screen_t)
returns screens list
Definition: oc_screenman.c:52
The file with interface of the Screen Manager module.
oC_ErrorCode_t oC_ScreenMan_TurnOff(void)
turns off screen manager
Definition: oc_screenman.c:125
oC_Screen_t oC_ScreenMan_GetScreen(const char *Name)
returns selected screen
Definition: oc_screenman.c:260
The file with interface for the module library.
static bool oC_Module_IsTurnedOn(oC_Module_t Module)
checks if the module is turned on
Definition: oc_module.h:121
stores screen object data
Definition: oc_screen.c:43
The file with list library.
bool oC_Screen_IsConfigured(oC_Screen_t Screen)
checks if the screen is configured to work
Definition: oc_screen.c:234
oC_ErrorCode_t oC_Screen_Configure(oC_Screen_t Screen)
configures graphics driver to work
Definition: oc_screen.c:257
oC_Driver_t oC_Screen_GetDriver(oC_Screen_t Screen)
returns driver associated with the screen
Definition: oc_screen.c:415
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
Definition: oc_module.h:170
The file with drivers manager interface.
The file with interface for string library.
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
Definition: oc_module.h:155
void oC_ScreenMan_UnconfigureAll(void)
unconfigures all screens
Definition: oc_screenman.c:189
static const oC_Allocator_t Allocator
Definition: oc_eth.c:152
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
Definition: oc_module.h:138
bool oC_Screen_IsCorrect(oC_Screen_t Screen)
checks if the Screen object is correct
Definition: oc_screen.c:160
oC_ErrorCode_t oC_Screen_Unconfigure(oC_Screen_t Screen)
unconfigures graphics driver
Definition: oc_screen.c:292
oC_Screen_t oC_ScreenMan_GetDefaultScreen(void)
returns default screen
Definition: oc_screenman.c:215
#define NULL
pointer to a zero
Definition: oc_null.h:37
oC_ErrorCode_t oC_ScreenMan_AddScreen(oC_Screen_t Screen)
adds screen to the screens list
Definition: oc_screenman.c:291
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off
Definition: oc_module.h:185