tizen 2.4 release
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / module / xdbg_module.c
1 /**************************************************************************
2
3 xdbg
4
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
6
7 Contact: Boram Park <boram1288.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 "xdbg_module_main.h"
44 #include "xdbg_module_options.h"
45
46 MODULESETUPPROTO (xDbgModuleSetup);
47 MODULETEARDOWNPROTO (xDbgModuleTearDown);
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 xdbgModuleData =
66 {
67     &ModuleVersRec,
68     xDbgModuleSetup,
69     xDbgModuleTearDown
70 };
71
72 static XDbgModule module_xdbg;
73
74 static void
75 _xDbgModuleBlockHandler (pointer data, OSTimePtr pTimeout, pointer pRead)
76 {
77     /* _xDbgModuleBlockHandler called only at the first. */
78     RemoveBlockAndWakeupHandlers(_xDbgModuleBlockHandler,
79                                  (WakeupHandlerProcPtr)NoopDDA,
80                                  NULL);
81
82     /* main */
83     xDbgModuleMain (&module_xdbg);
84 }
85
86 pointer
87 xDbgModuleSetup (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         /* Parse Options */
97         xDbgModuleParseOptions (&module_xdbg, pOpt);
98
99         xorg_list_init (&module_xdbg.trace_list);
100
101         /* Register block handler */
102         RegisterBlockAndWakeupHandlers (_xDbgModuleBlockHandler,
103                                        (WakeupHandlerProcPtr)NoopDDA,
104                                        NULL);
105         return (pointer) 1;
106     }
107     else
108     {
109         if (errmaj)
110             *errmaj = LDR_ONCEONLY;
111
112         return NULL;
113     }
114 }
115
116 void
117 xDbgModuleTearDown (pointer module)
118 {
119     xDbgModuleMainExit (module);
120 }