minor changes. bump version to reflect recent changes
[aros:aros.git] / AROS / workbench / devs / monitors / Compositor / startup.c
1 #include <dos/dosextens.h>
2 #include <exec/libraries.h>
3 #include <oop/ifmeta.h>
4 #include <oop/oop.h>
5
6 #include <proto/exec.h>
7 #include <proto/graphics.h>
8 #include <proto/oop.h>
9
10 #include "compositor_intern.h"
11
12 /* Libraries */
13 struct Library *OOPBase;
14 struct Library *UtilityBase;
15
16 /* Attr bases */
17 OOP_AttrBase HiddPixFmtAttrBase;
18 OOP_AttrBase HiddSyncAttrBase;
19 OOP_AttrBase HiddBitMapAttrBase;
20 OOP_AttrBase HiddGCAttrBase;
21 OOP_AttrBase HiddCompositorAttrBase;
22
23 const TEXT version[] = "$VER: Compositor 41.1 (8.10.2013)\n";
24
25 static const struct OOP_ABDescr attrbases[] = 
26 {
27     { IID_Hidd_PixFmt,          &HiddPixFmtAttrBase },
28     { IID_Hidd_Sync,            &HiddSyncAttrBase },
29     { IID_Hidd_BitMap,          &HiddBitMapAttrBase },
30     { IID_Hidd_GC,              &HiddGCAttrBase },
31     { IID_Hidd_Compositor,     &HiddCompositorAttrBase },
32     { NULL, NULL }
33 };
34
35 static OOP_Class *InitClass(void)
36 {
37     OOP_AttrBase MetaAttrBase = OOP_ObtainAttrBase(IID_Meta);
38     OOP_Class *cl = NULL;
39
40     struct TagItem Compositor_tags[] =
41     {
42         {aMeta_SuperID       , (IPTR)CLID_Root                   },
43         {aMeta_InterfaceDescr, (IPTR)Compositor_ifdescr  },
44         {aMeta_InstSize      , sizeof(struct HIDDCompositorData)},
45         {aMeta_ID            , (IPTR)CLID_Hidd_Compositor        },
46         {TAG_DONE            , 0                                 }
47     };
48
49     if (MetaAttrBase == 0)
50         return NULL;
51
52     cl = OOP_NewObject(NULL, CLID_HiddMeta, Compositor_tags);
53     if (cl)
54         OOP_AddClass(cl);
55
56     OOP_ReleaseAttrBase(IID_Meta);
57     return cl;
58 }
59
60 int __nocommandline = 1;
61
62 int main(void)
63 {
64     int ret = RETURN_FAIL;
65
66     /* 
67      * Open these libraries manually because we don't want them to be
68      * automatically closed when we stay resident.
69      */
70     UtilityBase = OpenLibrary("utility.library", 0);
71     if (UtilityBase)
72     {
73         OOPBase = OpenLibrary("oop.library", 42);
74         if (OOPBase)
75         {
76             if (OOP_ObtainAttrBases(attrbases))
77             {
78                 if (OOP_FindClass(CLID_Hidd_Compositor))
79                 {
80                     /* Double-starting is a valid operation. */
81                     ret = RETURN_OK;
82                 }
83                 else
84                 {
85                     OOP_Class *cl = InitClass();
86
87                     if (cl)
88                     {
89                         /*
90                          * Yes, composer is not a real display driver. It has totally different API.
91                          * AddDisplayDriverA() knows this.
92                          */
93                         ULONG err = AddDisplayDriverA(cl, NULL, NULL);
94
95                         if (!err)
96                         {
97                             /* Stay resident */
98                             struct Process *me = (struct Process *)FindTask(NULL);
99
100                             if (me->pr_CLI)
101                             {
102                                 struct CommandLineInterface *cli = BADDR(me->pr_CLI);
103
104                                 cli->cli_Module = BNULL;
105                             }
106                             else
107                                 me->pr_SegList = BNULL;
108
109                             /* Don't close our libraries and release attrbases. The HIDD needs them. */
110
111                             return RETURN_OK;
112                         }
113                     }
114                 }
115             }
116             OOP_ReleaseAttrBases(attrbases);
117             CloseLibrary(OOPBase);
118         }
119         CloseLibrary(UtilityBase);
120     }
121
122     return ret;
123 }