tizen 2.4 release
[adaptation/xorg/driver/xserver-xorg-module-lazyload.git] / src / module_lazyload.c
1 /**************************************************************************
2
3 xserver-xorg-module-lazyload
4
5 Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
6
7 Contact: Sung-Jin Park <sj76.park@samsung.com>
8          Sangjin LEE <lsj119@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <sys/types.h>
37 #include <unistd.h>
38 #include <sys/stat.h>
39 #include <fcntl.h>
40
41 #include <xf86.h>
42
43 #include "module_lazyload_main.h"
44 #include "module_lazyload_options.h"
45
46 MODULESETUPPROTO (moduleSetup);
47 MODULETEARDOWNPROTO (moduleTearDown);
48
49 static XF86ModuleVersionInfo ModuleVersRec =
50 {
51     MODULE_NAME,
52     MODULEVENDORSTRING,
53     MODINFOSTRING1,
54     MODINFOSTRING2,
55     XORG_VERSION_CURRENT,
56     PACKAGE_VERSION_MAJOR,
57     PACKAGE_VERSION_MINOR,
58     PACKAGE_VERSION_PATCHLEVEL,
59     ABI_CLASS_NONE,
60     SET_ABI_VERSION (0,1),
61     NULL,
62     {0,0,0,0}
63 };
64
65 _X_EXPORT XF86ModuleData lazyloadModuleData =
66 {
67     &ModuleVersRec,
68     moduleSetup,
69     moduleTearDown
70 };
71
72 static ModuleLazyload module_lazyload;
73
74 static void
75 _moduleLazyloadBlockHandler (pointer data, OSTimePtr pTimeout, pointer pRead)
76 {
77     /* _moduleLazyloadBlockHandler called only at the first. */
78     RemoveBlockAndWakeupHandlers(_moduleLazyloadBlockHandler,
79                                  (WakeupHandlerProcPtr)NoopDDA,
80                                  data);
81
82     /* main */
83     moduleLazyloadMain (&module_lazyload, data);
84 }
85
86 pointer
87 moduleSetup (pointer module, pointer opts, int *errmaj, int *errmin)
88 {
89     XF86OptionPtr pOpt = (XF86OptionPtr)opts;
90     static Bool setupDone = FALSE;
91
92     if (!setupDone)
93     {
94         setupDone = TRUE;
95
96         //XDBG_KLOG (MX11, "Setup:Xorg server pid : %d \n", p);
97
98         /* Parse Options */
99         moduleLazyloadParseOptions (&module_lazyload, pOpt);
100
101         /* Register block handler */
102         RegisterBlockAndWakeupHandlers (_moduleLazyloadBlockHandler,
103                                         (WakeupHandlerProcPtr)NoopDDA,
104                                         opts);
105
106         return (pointer) 1;
107     }
108     else
109     {
110         if (errmaj)
111             *errmaj = LDR_ONCEONLY;
112
113         return NULL;
114     }
115 }
116
117 void
118 moduleTearDown (pointer module)
119 {
120     //XDBG_KLOG (MX11, "TearDown:Xorg server pid : %d \n", p);
121
122     moduleLazyloadMainExit (&module_lazyload);
123
124     RemoveBlockAndWakeupHandlers (_moduleLazyloadBlockHandler,
125                                   (WakeupHandlerProcPtr)NoopDDA,
126                                   NULL);
127 }
128