sync with master
authorJinkun Jang <jinkun.jang@samsung.com>
Sat, 16 Mar 2013 12:56:46 +0000 (21:56 +0900)
committerJinkun Jang <jinkun.jang@samsung.com>
Sat, 16 Mar 2013 12:56:46 +0000 (21:56 +0900)
56 files changed:
AUTHORS [new file with mode: 0644]
COPYING [new file with mode: 0644]
ChangeLog [new file with mode: 0644]
INSTALL [new file with mode: 0644]
LICENSE.MIT [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
NEWS [new file with mode: 0644]
NOTICE [new file with mode: 0644]
README [new file with mode: 0644]
autogen.sh [new file with mode: 0755]
bin/Makefile.am [new file with mode: 0644]
bin/xdbg/Makefile.am [new file with mode: 0644]
bin/xdbg/xdbg.c [new file with mode: 0644]
configure.ac [new file with mode: 0644]
dbus/Makefile.am [new file with mode: 0644]
dbus/xdbg_dbus.h [new file with mode: 0644]
dbus/xdbg_dbus_client.c [new file with mode: 0644]
dbus/xdbg_dbus_client.h [new file with mode: 0644]
dbus/xdbg_dbus_server.c [new file with mode: 0644]
dbus/xdbg_dbus_server.h [new file with mode: 0644]
lib/Makefile.am [new file with mode: 0644]
lib/xdbg.h [new file with mode: 0644]
lib/xdbg.pc.in [new file with mode: 0644]
lib/xdbg_log.c [new file with mode: 0644]
lib/xdbg_log.h [new file with mode: 0644]
lib/xdbg_log_dlog.c [new file with mode: 0644]
lib/xdbg_log_klog.c [new file with mode: 0644]
module/Makefile.am [new file with mode: 0644]
module/ds/bintree.c [new file with mode: 0644]
module/ds/bintree.h [new file with mode: 0644]
module/ds/bool_exp_parser.c [new file with mode: 0644]
module/ds/bool_exp_parser.h [new file with mode: 0644]
module/ds/bool_exp_rule_checker.c [new file with mode: 0644]
module/ds/bool_exp_rule_checker.h [new file with mode: 0644]
module/ds/bool_exp_token.h [new file with mode: 0644]
module/ds/bool_exp_tokenizer.c [new file with mode: 0644]
module/ds/bool_exp_tokenizer.h [new file with mode: 0644]
module/xdbg_module.c [new file with mode: 0644]
module/xdbg_module_clist.c [new file with mode: 0644]
module/xdbg_module_clist.h [new file with mode: 0644]
module/xdbg_module_command.c [new file with mode: 0644]
module/xdbg_module_command.h [new file with mode: 0644]
module/xdbg_module_evlog.c [new file with mode: 0644]
module/xdbg_module_evlog.h [new file with mode: 0644]
module/xdbg_module_evlog_event.c [new file with mode: 0644]
module/xdbg_module_evlog_event.h [new file with mode: 0644]
module/xdbg_module_evlog_request.c [new file with mode: 0644]
module/xdbg_module_evlog_request.h [new file with mode: 0644]
module/xdbg_module_main.c [new file with mode: 0644]
module/xdbg_module_main.h [new file with mode: 0644]
module/xdbg_module_options.c [new file with mode: 0644]
module/xdbg_module_options.h [new file with mode: 0644]
module/xdbg_module_rlist.c [new file with mode: 0644]
module/xdbg_module_rlist.h [new file with mode: 0644]
module/xdbg_module_types.h [new file with mode: 0644]
packaging/xorg-x11-module-xdbg.spec [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..f6780ea
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+SangJin Lee <lsj119@samsung.com>
+Boram Park <boram1288.park@samsung.com>
diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..8635d57
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,23 @@
+Copyright 2013 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/LICENSE.MIT b/LICENSE.MIT
new file mode 100644 (file)
index 0000000..ca69760
--- /dev/null
@@ -0,0 +1,19 @@
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..a88c0fa
--- /dev/null
@@ -0,0 +1,25 @@
+# Copyright 2013 Samsung Electronics co., Ltd. All Rights Reserved.
+# 
+# Contact: Boram Park <boram1288.park@samsung.com>
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sub license, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+# 
+# The above copyright notice and this permission notice (including the
+# next paragraph) shall be included in all copies or substantial portions
+# of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+SUBDIRS = dbus lib module bin
diff --git a/NEWS b/NEWS
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/NOTICE b/NOTICE
new file mode 100644 (file)
index 0000000..ad43441
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,3 @@
+Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under MIT License.
+Please, see the LICENSE.MIT file for MIT License terms and conditions.
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/autogen.sh b/autogen.sh
new file mode 100755 (executable)
index 0000000..218197d
--- /dev/null
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+ORIGDIR=`pwd`
+cd $srcdir
+
+autoreconf -v --install || exit 1
+cd $ORIGDIR || exit $?
+
+#$srcdir/configure --enable-maintainer-mode "$@"
diff --git a/bin/Makefile.am b/bin/Makefile.am
new file mode 100644 (file)
index 0000000..016cafe
--- /dev/null
@@ -0,0 +1,25 @@
+# Copyright 2013 Samsung Electronics co., Ltd. All Rights Reserved.
+# 
+# Contact: Boram Park <boram1288.park@samsung.com>
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sub license, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+# 
+# The above copyright notice and this permission notice (including the
+# next paragraph) shall be included in all copies or substantial portions
+# of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+SUBDIRS = xdbg
diff --git a/bin/xdbg/Makefile.am b/bin/xdbg/Makefile.am
new file mode 100644 (file)
index 0000000..32b2bb2
--- /dev/null
@@ -0,0 +1,36 @@
+# Copyright 2013 Samsung Electronics co., Ltd. All Rights Reserved.
+# 
+# Contact: Boram Park <boram1288.park@samsung.com>
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sub license, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+# 
+# The above copyright notice and this permission notice (including the
+# next paragraph) shall be included in all copies or substantial portions
+# of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+bin_PROGRAMS = xdbg
+
+xdbg_LDADD = $(XDBG_LIBS) ../../dbus/libdbus.la ../../lib/libxdbg-log.la
+xdbg_LDFLAGS = ${LDFLAGS}
+xdbg_CFLAGS = \
+       ${CFLAGS} \
+       @XDBG_CFLAGS@ \
+       -I$(top_srcdir)/dbus \
+       -I$(top_srcdir)/lib
+
+xdbg_sc_SOURCES =      \
+        xdbg.c
diff --git a/bin/xdbg/xdbg.c b/bin/xdbg/xdbg.c
new file mode 100644 (file)
index 0000000..322f41b
--- /dev/null
@@ -0,0 +1,96 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <X11/Xlib.h>
+#include <xdbg.h>
+#include "xdbg_dbus_client.h"
+
+int main(int argc, char ** argv)
+{
+    XDbgDBusClientInfo* dbus_info;
+    Display *dpy;
+    char **new_argv;
+    int new_argc, i;
+    char temp[128];
+
+    dpy = XOpenDisplay (NULL);
+    if (!dpy)
+    {
+        fprintf (stderr, "failed: open display\n");
+        exit (-1);
+    }
+
+    dbus_info = xDbgDBusClientConnect ();
+    if (!dbus_info)
+    {
+        fprintf (stderr, "failed: connect dbus\n");
+        exit (-1);
+    }
+
+    new_argc = argc + 1;
+    new_argv = (char**)malloc (new_argc * sizeof (char*));
+    if (!new_argv)
+    {
+        fprintf (stderr, "failed: malloc new argv\n");
+        exit (-1);
+    }
+
+    snprintf (temp, sizeof(temp), "%d", getpid ());
+    new_argv[0] = temp;
+
+    for (i = 0; i < argc; i++)
+        new_argv[i+1] = argv[i];
+
+    xDbugDBusClientSendMessage (dbus_info, new_argc, new_argv);
+
+    xDbgDBusClientDisconnect (dbus_info);
+
+    free (new_argv);
+
+    XCloseDisplay (dpy);
+
+    return 0;
+}
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..04b51d0
--- /dev/null
@@ -0,0 +1,76 @@
+# Copyright 2013 Samsung Electronics co., Ltd. All Rights Reserved.
+# 
+# Contact: Boram Park <boram1288.park@samsung.com>
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sub license, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+# 
+# The above copyright notice and this permission notice (including the
+# next paragraph) shall be included in all copies or substantial portions
+# of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+AC_PREREQ(2.57)
+AC_INIT([xdbg], [0.1.0], [https://])
+AC_CONFIG_SRCDIR([Makefile.am])
+AC_CONFIG_AUX_DIR(.)
+AM_INIT_AUTOMAKE()
+
+AM_MAINTAINER_MODE
+
+# Require xorg-macros: XORG_DEFAULT_OPTIONS
+m4_ifndef([XORG_MACROS_VERSION], [AC_FATAL([must install xorg-macros 1.3 or later before running autoconf/autogen])])
+XORG_MACROS_VERSION(1.3)
+AM_CONFIG_HEADER([config.h])
+
+# Checks for programs.
+AC_PROG_LIBTOOL
+AC_PROG_CC
+XORG_DEFAULT_OPTIONS
+
+AH_TOP([#include "xorg-server.h"])
+
+AC_ARG_WITH(xorg-module-dir,
+            AC_HELP_STRING([--with-xorg-module-dir=DIR],
+                           [Default xorg module directory [[default=$libdir/xorg/modules]]]),
+                           [moduledir="$withval"],
+                           [moduledir="$libdir/xorg/modules"])
+
+# Checks for pkg-config packages
+PKG_CHECK_MODULES(XDBG, xorg-server x11 dbus-1 bigreqsproto compositeproto damageproto dmxproto dri2proto fixesproto fontsproto gestureproto inputproto kbproto randrproto recordproto renderproto resourceproto scrnsaverproto videoproto xcmiscproto xextproto xf86bigfontproto xf86dgaproto xf86driproto xf86vidmodeproto xineramaproto xproto)
+AC_SUBST([XDBG_CFLAGS])
+AC_SUBST([XDBG_LIBS])
+
+# Checks for header files.
+AC_HEADER_STDC
+
+MODULE_NAME=xdbg
+AC_SUBST([MODULE_NAME])
+AC_SUBST([moduledir])
+
+AC_DEFINE_UNQUOTED(MODULE_NAME, "$MODULE_NAME", [module name])
+
+AC_OUTPUT([Makefile
+           dbus/Makefile
+           bin/Makefile
+           bin/xdbg/Makefile
+           lib/Makefile
+           lib/xdbg.pc
+           module/Makefile])
+
+echo "CFLAGS     : $CFLAGS"
+echo "LDFLAGS    : $LDFLAGS"
+echo "XDBG_CFLAGS: $XDBG_CFLAGS"
+echo "XDBG_LIBS  : $XDBG_LIBS"
diff --git a/dbus/Makefile.am b/dbus/Makefile.am
new file mode 100644 (file)
index 0000000..bbe3b9f
--- /dev/null
@@ -0,0 +1,36 @@
+# Copyright 2013 Samsung Electronics co., Ltd. All Rights Reserved.
+# 
+# Contact: Boram Park <boram1288.park@samsung.com>
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sub license, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+# 
+# The above copyright notice and this permission notice (including the
+# next paragraph) shall be included in all copies or substantial portions
+# of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+noinst_LTLIBRARIES = libdbus.la
+
+libdbus_la_LIBADD = @XDBG_LIBS@
+libdbus_la_LDFLAGS = ${LDFLAGS}
+libdbus_la_CFLAGS = \
+    ${CFLAGS} \
+    @XDBG_CFLAGS@ \
+    -I$(top_srcdir)/lib
+
+libdbus_la_SOURCES = \
+    xdbg_dbus_server.c \
+    xdbg_dbus_client.c
diff --git a/dbus/xdbg_dbus.h b/dbus/xdbg_dbus.h
new file mode 100644 (file)
index 0000000..bc9c017
--- /dev/null
@@ -0,0 +1,43 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __X_DEBUG_DBUS_H__
+#define __X_DEBUG_DBUS_H__
+
+#define XDBG_DBUS_SERVER        "org.x.dbg.server"
+#define XDBG_DBUS_INTERFACE     "org.x.dbg.interface"
+#define XDBG_DBUS_PATH          "/org/x/dbg/path"
+#define XDBG_DBUS_CLIENT        "org.x.dbg.client"
+#define XDBG_DBUS_METHOD        "x_dbg_method"
+
+#define MDBUS   XDBG_M('D','B','U','S')
+
+#endif  /* __X_DEBUG_DBUS_H__ */
diff --git a/dbus/xdbg_dbus_client.c b/dbus/xdbg_dbus_client.c
new file mode 100644 (file)
index 0000000..5402be3
--- /dev/null
@@ -0,0 +1,268 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "xdbg.h"
+#include "xdbg_dbus_client.h"
+
+#define REPLY_TIME 1000
+#define STR_LEN  128
+
+#define WARNING_IF_FAIL(cond)         {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond);}}
+#define RETURN_IF_FAIL(cond)          {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); return; }}
+#define RETURN_VAL_IF_FAIL(cond, val) {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); return val; }}
+#define RETURN_VAL_IF_ERRNO(cond, val, errno)       {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); return val; }}
+#define GOTO_IF_FAIL(cond, dst)       {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); goto dst; }}
+#define GOTO_IF_ERRNO(cond, dst, errno)       {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); goto dst; }}
+
+struct _XDbgDBusClientInfo
+{
+    DBusConnection *conn;
+    char reqname[STR_LEN];
+    char client[STR_LEN];
+    int  pid;
+};
+
+static DBusHandlerResult
+_xDbgDBusClinetMsgFilter (DBusConnection *conn, DBusMessage *msg, void *data)
+{
+    XDbgDBusClientInfo *info = (XDbgDBusClientInfo*)data;
+
+    /* If we get disconnected, then take everything down, and attempt to
+     * reconnect immediately (assuming it's just a restart).  The
+     * connection isn't valid at this point, so throw it out immediately. */
+    if (dbus_message_is_signal (msg, DBUS_INTERFACE_LOCAL, "Disconnected"))
+    {
+        fprintf (stderr, "[CLIENT:%s] disconnected by signal\n", info->client);
+        info->conn = NULL;
+
+        return DBUS_HANDLER_RESULT_HANDLED;
+    }
+
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static Bool
+_xDbgDBusClinetInit (XDbgDBusClientInfo *info)
+{
+    DBusError err;
+    int ret;
+
+    dbus_error_init (&err);
+    RETURN_VAL_IF_FAIL (info->conn == NULL, FALSE);
+
+    info->conn = dbus_bus_get (DBUS_BUS_SYSTEM, &err);
+    if (dbus_error_is_set (&err))
+    {
+        fprintf (stderr, "[CLIENT:%s] failed: connection (%s)\n", info->client, err.message);
+        goto err_get;
+    }
+    if (!info->conn)
+    {
+        fprintf (stderr, "[CLIENT:%s] failed: connection NULL\n", info->client);
+        goto err_get;
+    }
+
+    dbus_connection_set_exit_on_disconnect (info->conn, FALSE);
+
+    if (!dbus_connection_add_filter (info->conn, _xDbgDBusClinetMsgFilter, info, NULL))
+    {
+        fprintf (stderr, "[CLIENT:%s] failed: add filter (%s)\n", info->client, err.message);
+        goto err_get;
+    }
+
+    ret = dbus_bus_request_name (info->conn, info->reqname,
+                                 DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
+    if (dbus_error_is_set (&err))
+    {
+        fprintf (stderr, "[CLIENT:%s] failed: request name (%s)\n", info->client, err.message);
+        goto err_request;
+    }
+    if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+    {
+        fprintf (stderr, "[CLIENT:%s] failed: Not Primary Owner (%d)\n", info->client, ret);
+        goto err_request;
+    }
+
+    dbus_error_free (&err);
+
+//    fprintf (stderr, "[CLIENT:%s] connected\n", info->client);
+
+    return TRUE;
+
+err_request:
+    dbus_connection_remove_filter (info->conn, _xDbgDBusClinetMsgFilter, info);
+
+err_get:
+    if (info->conn)
+    {
+        dbus_connection_unref (info->conn);
+        info->conn = NULL;
+    }
+
+    dbus_error_free (&err);
+
+    return FALSE;
+}
+
+
+static void
+_xDbgDBusClinetDeinit (XDbgDBusClientInfo *info)
+{
+    DBusError err;
+
+    if (!info->conn)
+        return;
+
+    dbus_error_init (&err);
+    dbus_bus_release_name (info->conn, info->reqname, &err);
+    if (dbus_error_is_set (&err))
+        fprintf (stderr, "[CLIENT:%s] failed: release name (%s)\n", info->client, err.message);
+    dbus_error_free (&err);
+
+    dbus_connection_remove_filter (info->conn, _xDbgDBusClinetMsgFilter, info);
+    dbus_connection_unref (info->conn);
+    info->conn = NULL;
+
+//    fprintf (stderr, "[CLIENT:%s] disconnected\n", info->client);
+}
+
+XDbgDBusClientInfo*
+xDbgDBusClientConnect (void)
+{
+    XDbgDBusClientInfo *info = NULL;
+
+    info = calloc (1, sizeof (XDbgDBusClientInfo));
+    GOTO_IF_FAIL (info != NULL, err_conn);
+
+    snprintf (info->client, STR_LEN, "%d", getpid());
+    snprintf (info->reqname, STR_LEN, "%s%d", XDBG_DBUS_CLIENT, getpid());
+
+    if (!_xDbgDBusClinetInit (info))
+        goto err_conn;
+
+    return info;
+
+err_conn:
+    if (info)
+        free (info);
+
+    return NULL;
+}
+
+void
+xDbgDBusClientDisconnect (XDbgDBusClientInfo* info)
+{
+    if (!info)
+        return;
+
+    _xDbgDBusClinetDeinit (info);
+
+    free (info);
+}
+
+void
+xDbugDBusClientSendMessage (XDbgDBusClientInfo *info, int argc, char **argv)
+{
+    DBusMessage *msg = NULL;
+    DBusMessage *reply_msg = NULL;
+    DBusMessageIter iter;
+    DBusError err;
+    char *arg = NULL;
+    int i;
+
+    RETURN_IF_FAIL (info != NULL);
+    RETURN_IF_FAIL (info->conn != NULL);
+    RETURN_IF_FAIL (argc > 0);
+    RETURN_IF_FAIL (argv[0] != '\0');
+
+    dbus_error_init (&err);
+
+    msg = dbus_message_new_method_call (XDBG_DBUS_SERVER, XDBG_DBUS_PATH,
+                                        XDBG_DBUS_INTERFACE, XDBG_DBUS_METHOD);
+    GOTO_IF_FAIL (msg != NULL, err_send);
+
+    dbus_message_iter_init_append (msg, &iter);
+    for (i = 0; i < argc; i++)
+        if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &argv[i]))
+        {
+            fprintf (stderr, "[CLIENT:%s] failed: append\n", info->client);
+            goto err_send;
+        }
+
+    reply_msg = dbus_connection_send_with_reply_and_block (info->conn, msg,
+                                                           REPLY_TIME, &err);
+    if (dbus_error_is_set (&err))
+    {
+        fprintf (stderr, "[CLIENT:%s] failed: send (%s)\n", info->client, err.message);
+        goto err_send;
+    }
+    GOTO_IF_FAIL (reply_msg != NULL, err_send);
+
+    if (!dbus_message_iter_init (reply_msg, &iter))
+    {
+        fprintf (stderr, "[CLIENT:%s] Message has no arguments\n", info->client);
+        goto err_send;
+    }
+
+    do
+    {
+        arg = NULL;
+
+        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING)
+        {
+            fprintf (stderr, "[CLIENT:%s] Argument is not string!\n", info->client);
+            goto err_send;
+        }
+
+        dbus_message_iter_get_basic (&iter, &arg);
+        if (!arg)
+        {
+            fprintf (stderr, "[CLIENT:%s] arg is NULL\n", info->client);
+            goto err_send;
+        }
+        else
+            fprintf (stderr, "%s\n", arg);
+    } while (dbus_message_iter_has_next (&iter) &&
+           dbus_message_iter_next (&iter));
+
+err_send:
+    if (msg)
+        dbus_message_unref(msg);
+    if (reply_msg)
+        dbus_message_unref(reply_msg);
+}
diff --git a/dbus/xdbg_dbus_client.h b/dbus/xdbg_dbus_client.h
new file mode 100644 (file)
index 0000000..0c37f1e
--- /dev/null
@@ -0,0 +1,46 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __X_DEBUG_DBUS_CLIENT_H__
+#define __X_DEBUG_DBUS_CLIENT_H__
+
+#include <dbus/dbus.h>
+
+#include "xdbg_dbus.h"
+
+typedef struct _XDbgDBusClientInfo XDbgDBusClientInfo;
+
+XDbgDBusClientInfo* xDbgDBusClientConnect (void);
+void xDbgDBusClientDisconnect   (XDbgDBusClientInfo *info);
+void xDbugDBusClientSendMessage (XDbgDBusClientInfo *info,
+                                 int argc, char **argv);
+
+#endif /* __X_DEBUG_DBUS_CLIENT_H__ */
diff --git a/dbus/xdbg_dbus_server.c b/dbus/xdbg_dbus_server.c
new file mode 100644 (file)
index 0000000..1a8e95a
--- /dev/null
@@ -0,0 +1,455 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <dbus/dbus.h>
+#include <os.h>
+#include <dix.h>
+
+#include "xdbg.h"
+#include "xdbg_dbus_server.h"
+
+#define ARGV_NUM        128
+#define REP_MSG_SIZE    8192
+#define STR_LEN         128
+
+#define RECONNECT_TIME  1000
+#define DISPATCH_TIME   50
+
+typedef struct _XDbgDBusServerInfo
+{
+    OsTimerPtr timer;
+    DBusConnection *conn;
+    XDbgDbusServerMethod *methods;
+    char rule[STR_LEN];
+    int fd;
+} XDbgDBusServerInfo;
+
+static XDbgDBusServerInfo server_info;
+
+static CARD32 _xDbgDBusServerTimeout (OsTimerPtr timer, CARD32 time, pointer arg);
+static Bool _xDbgDBusServerInit (XDbgDBusServerInfo *info);
+static void _xDbgDBusServerDeinit (XDbgDBusServerInfo *info);
+
+static Bool
+_xDbgDBusServerReplyMessage (XDbgDBusServerInfo *info, DBusMessage *msg, char *reply)
+{
+    DBusMessage *reply_msg = NULL;
+    DBusMessageIter iter;
+
+    XDBG_RETURN_VAL_IF_FAIL (info->conn != NULL, FALSE);
+
+    reply_msg = dbus_message_new_method_return (msg);
+    XDBG_RETURN_VAL_IF_FAIL (reply_msg != NULL, FALSE);
+
+    dbus_message_iter_init_append (reply_msg, &iter);
+    if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &reply))
+    {
+        XDBG_ERROR (MDBUS, "[SERVER] out of memory\n");
+        dbus_message_unref (reply_msg);
+        return FALSE;
+    }
+
+    if (!dbus_connection_send (info->conn, reply_msg, NULL))
+    {
+        XDBG_ERROR (MDBUS, "[SERVER] failed: send reply\n");
+        dbus_message_unref (reply_msg);
+        return FALSE;
+    }
+
+    XDBG_INFO (MDBUS, "[SERVER] send reply\n");
+
+    dbus_connection_flush (info->conn);
+    dbus_message_unref (reply_msg);
+
+    return TRUE;
+}
+
+static void
+_xDbgDBusServerProcessMessage (XDbgDBusServerInfo *info, DBusMessage *msg)
+{
+    XDbgDbusServerMethod **prev;
+    DBusError err;
+    char err_buf[REP_MSG_SIZE] = {0,};
+    char *argv[ARGV_NUM] = {0,};
+    int argc = 0;
+    int i;
+
+    snprintf (err_buf, REP_MSG_SIZE, "error message!\n");
+
+    dbus_error_init (&err);
+
+    XDBG_INFO (MDBUS, "[SERVER] Process a message (%s.%s)\n",
+               dbus_message_get_interface (msg), dbus_message_get_member (msg));
+
+    XDBG_RETURN_IF_FAIL (info->conn != NULL);
+
+    for (prev = &info->methods; *prev; prev = &(*prev)->next)
+    {
+        XDbgDbusServerMethod *method = *prev;
+
+        if (!strcmp (dbus_message_get_member (msg), method->name))
+        {
+            DBusMessageIter iter;
+            char reply[REP_MSG_SIZE] = {0,};
+            char *p;
+            int   len;
+
+            if (!dbus_message_iter_init (msg, &iter))
+            {
+                XDBG_ERROR (MDBUS, "[SERVER] Message has no arguments!\n");
+                snprintf (err_buf, REP_MSG_SIZE, "Message has no arguments!\n");
+                goto send_fail;
+            }
+
+            do
+            {
+                p = NULL;
+
+                if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING)
+                {
+                    XDBG_ERROR (MDBUS, "[SERVER] Argument is not string!\n");
+                    snprintf (err_buf, REP_MSG_SIZE, "Argument is not string!\n");
+                    goto send_fail;
+                }
+
+                dbus_message_iter_get_basic (&iter, &p);
+
+                if (!p)
+                {
+                    XDBG_ERROR (MDBUS, "[SERVER] Can't get string!\n");
+                    snprintf (err_buf, REP_MSG_SIZE, "Can't get string!\n");
+                    goto send_fail;
+                }
+
+                argv[argc] = strdup (p);
+                argc++;
+            } while (dbus_message_iter_has_next (&iter) &&
+                   dbus_message_iter_next (&iter) &&
+                   argc < ARGV_NUM);
+
+            len = REP_MSG_SIZE - 1;
+
+            if (method->func)
+                method->func (method->data, argc, argv, reply, &len);
+
+            _xDbgDBusServerReplyMessage (info, msg, reply);
+
+            for (i = 0; i < ARGV_NUM; i++)
+                if (argv[i])
+                    free (argv[i]);
+            dbus_error_free (&err);
+
+            return;
+        }
+    }
+
+    return;
+
+send_fail:
+   _xDbgDBusServerReplyMessage (info, msg, err_buf);
+
+    for (i = 0; i < ARGV_NUM; i++)
+        if (argv[i])
+            free (argv[i]);
+    dbus_error_free (&err);
+}
+
+static void
+_xDbgDBusServerWakeupHandler (pointer data, int error, pointer pRead)
+{
+    XDbgDBusServerInfo *info = (XDbgDBusServerInfo*)data;
+
+    if (!info || !info->conn || info->fd < 0)
+        return;
+
+    if (FD_ISSET(info->fd, (fd_set*)pRead))
+    {
+        dbus_connection_ref (info->conn);
+
+        do {
+            dbus_connection_read_write_dispatch (info->conn, 0);
+        } while (info->conn &&
+                 dbus_connection_get_is_connected (info->conn) &&
+                 dbus_connection_get_dispatch_status (info->conn) ==
+                 DBUS_DISPATCH_DATA_REMAINS);
+
+        dbus_connection_unref (info->conn);
+    }
+}
+
+static DBusHandlerResult
+_xDbgDBusServerMsgHandler (DBusConnection *connection, DBusMessage *msg, void *data)
+{
+    XDbgDBusServerInfo *info = (XDbgDBusServerInfo*)data;
+
+    if (!info || !info->conn || !msg)
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+    XDBG_INFO (MDBUS, "[SERVER] Got a message (%s.%s)\n",
+               dbus_message_get_interface (msg), dbus_message_get_member (msg));
+
+    if (!dbus_message_is_method_call (msg, XDBG_DBUS_INTERFACE, XDBG_DBUS_METHOD))
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+    _xDbgDBusServerProcessMessage (info, msg);
+
+    return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
+_xDbgDBusServerMsgFilter (DBusConnection *conn, DBusMessage *msg, void *data)
+{
+    XDbgDBusServerInfo *info = (XDbgDBusServerInfo*)data;
+
+    if (!info)
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+    if (dbus_message_is_signal (msg, DBUS_INTERFACE_LOCAL, "Disconnected"))
+    {
+        XDBG_INFO (MDBUS, "[SERVER] disconnected by signal\n");
+        _xDbgDBusServerDeinit (info);
+
+        if (info->timer)
+            TimerFree(info->timer);
+        info->timer = TimerSet(NULL, 0, 1, _xDbgDBusServerTimeout, info);
+
+        return DBUS_HANDLER_RESULT_HANDLED;
+    }
+
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static CARD32
+_xDbgDBusServerTimeout (OsTimerPtr timer, CARD32 time, pointer arg)
+{
+    XDbgDBusServerInfo *info = (XDbgDBusServerInfo*)arg;
+
+    if (!info)
+        return 0;
+
+    XDBG_DEBUG (MDBUS, "[SERVER] timeout\n");
+
+    if (_xDbgDBusServerInit (info))
+    {
+        TimerFree (info->timer);
+        info->timer = NULL;
+        return 0;
+    }
+
+    return RECONNECT_TIME;
+}
+
+static Bool
+_xDbgDBusServerInit (XDbgDBusServerInfo *info)
+{
+    DBusObjectPathVTable vtable = {.message_function = _xDbgDBusServerMsgHandler, };
+    DBusError err;
+    int ret;
+
+    dbus_error_init (&err);
+
+    XDBG_RETURN_VAL_IF_FAIL (info->conn == NULL, FALSE);
+
+    info->conn = dbus_bus_get (DBUS_BUS_SYSTEM, &err);
+    if (dbus_error_is_set (&err))
+    {
+        XDBG_ERROR (MDBUS, "[SERVER] failed: connection (%s)\n", err.message);
+        goto free_err;
+    }
+    if (!info->conn)
+    {
+        XDBG_ERROR (MDBUS, "[SERVER] failed: connection NULL\n");
+        goto free_err;
+    }
+
+    ret = dbus_bus_request_name (info->conn, XDBG_DBUS_SERVER,
+                                 DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
+    if (dbus_error_is_set (&err))
+    {
+        XDBG_ERROR (MDBUS, "[SERVER] failed: request name (%s)\n", err.message);
+        goto free_conn;
+    }
+    if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+    {
+        XDBG_ERROR (MDBUS, "[SERVER] failed: Not Primary Owner (%d)\n", ret);
+        goto free_conn;
+    }
+
+       snprintf (info->rule, sizeof (info->rule), "type='method_call',interface='%s'",
+              XDBG_DBUS_INTERFACE);
+
+    /* blocks until we get a reply. */
+    dbus_bus_add_match (info->conn, info->rule, &err);
+    if (dbus_error_is_set (&err))
+    {
+        XDBG_ERROR (MDBUS, "[SERVER] failed: add match (%s)\n", err.message);
+        goto free_name;
+    }
+
+    if (!dbus_connection_register_object_path (info->conn,
+                                               XDBG_DBUS_PATH, &vtable,
+                                               info))
+    {
+        XDBG_ERROR (MDBUS, "[SERVER] failed: register object path\n");
+        goto free_match;
+    }
+
+    dbus_connection_set_exit_on_disconnect (info->conn, FALSE);
+
+    if (!dbus_connection_add_filter (info->conn, _xDbgDBusServerMsgFilter, info, NULL))
+    {
+        XDBG_ERROR (MDBUS, "[SERVER] failed: add filter (%s)\n", err.message);
+        goto free_register;
+    }
+
+       if (!dbus_connection_get_unix_fd (info->conn, &info->fd) || info->fd < 0)
+    {
+        XDBG_ERROR (MDBUS, "[SERVER] failed: get fd\n");
+        goto free_filter;
+    }
+
+    AddGeneralSocket (info->fd);
+    RegisterBlockAndWakeupHandlers ((BlockHandlerProcPtr)NoopDDA,
+                                    _xDbgDBusServerWakeupHandler, info);
+
+    XDBG_INFO (MDBUS, "[SERVER] connected\n");
+
+    dbus_error_free (&err);
+
+    return TRUE;
+
+free_filter:
+    dbus_connection_remove_filter (info->conn, _xDbgDBusServerMsgFilter, info);
+free_register:
+    dbus_connection_unregister_object_path (info->conn, XDBG_DBUS_PATH);
+free_match:
+    dbus_bus_remove_match (info->conn, info->rule, &err);
+    dbus_error_free (&err);
+free_name:
+    dbus_bus_release_name (info->conn, XDBG_DBUS_SERVER, &err);
+    dbus_error_free (&err);
+free_conn:
+    dbus_connection_close (info->conn);
+free_err:
+    dbus_error_free (&err);
+    info->conn = NULL;
+    info->fd = -1;
+
+    return FALSE;
+}
+
+static void
+_xDbgDBusServerDeinit (XDbgDBusServerInfo *info)
+{
+    if (info->timer)
+    {
+        TimerFree (info->timer);
+        info->timer = NULL;
+    }
+
+    if (info->conn)
+    {
+        DBusError err;
+        dbus_error_init (&err);
+        dbus_connection_remove_filter (info->conn, _xDbgDBusServerMsgFilter, info);
+        dbus_connection_unregister_object_path (info->conn, XDBG_DBUS_PATH);
+        dbus_bus_remove_match (info->conn, info->rule, &err);
+        dbus_error_free (&err);
+        dbus_bus_release_name (info->conn, XDBG_DBUS_SERVER, &err);
+        dbus_error_free (&err);
+        dbus_connection_unref (info->conn);
+        info->conn = NULL;
+    }
+
+    RemoveBlockAndWakeupHandlers ((BlockHandlerProcPtr)NoopDDA,
+                                   _xDbgDBusServerWakeupHandler, info);
+    if (info->fd >= 0)
+    {
+        RemoveGeneralSocket (info->fd);
+        info->fd = -1;
+    }
+
+    XDBG_INFO (MDBUS, "[SERVER] disconnected\n");
+}
+
+Bool
+xDbgDBusServerConnect (void)
+{
+    XDBG_DEBUG (MDBUS, "[SERVER] connecting\n");
+
+    memset (&server_info, 0, sizeof(server_info));
+
+    server_info.fd = -1;
+    server_info.timer = TimerSet (NULL, 0, 1, _xDbgDBusServerTimeout, &server_info);
+
+    return TRUE;
+}
+
+void
+xDbgDBusServerDisconnect (void)
+{
+    XDBG_DEBUG (MDBUS, "[SERVER] disconnecting\n");
+
+    _xDbgDBusServerDeinit (&server_info);
+}
+
+Bool
+xDbgDBusServerAddMethod (XDbgDbusServerMethod *method)
+{
+    XDbgDbusServerMethod **prev;
+
+    for (prev = &server_info.methods; *prev; prev = &(*prev)->next);
+
+    method->next = NULL;
+    *prev = method;
+
+    return TRUE;
+}
+
+void
+xDbgDBusServerRemoveMethod (XDbgDbusServerMethod *method)
+{
+    XDbgDbusServerMethod **prev;
+
+    for (prev = &server_info.methods; *prev; prev = &(*prev)->next)
+        if (*prev == method)
+        {
+            *prev = method->next;
+            break;
+        }
+}
diff --git a/dbus/xdbg_dbus_server.h b/dbus/xdbg_dbus_server.h
new file mode 100644 (file)
index 0000000..950901f
--- /dev/null
@@ -0,0 +1,55 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __X_DEBUG_DBUS_SERVER_H__
+#define __X_DEBUG_DBUS_SERVER_H__
+
+#include <dbus/dbus.h>
+
+#include "xdbg_dbus.h"
+
+typedef void (*MethodFunc) (void *data, int argc, char **argv, char *reply, int *len);
+
+typedef struct _XDbgDbusServerMethod
+{
+    char       name[128];
+    MethodFunc func;
+    void       *data;
+
+    struct _XDbgDbusServerMethod *next;
+} XDbgDbusServerMethod;
+
+Bool xDbgDBusServerAddMethod    (XDbgDbusServerMethod *method);
+void xDbgDBusServerRemoveMethod (XDbgDbusServerMethod *method);
+Bool xDbgDBusServerConnect      (void);
+void xDbgDBusServerDisconnect   (void);
+
+#endif /* __X_DEBUG_DBUS_SERVER_H__ */
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644 (file)
index 0000000..d5c1edd
--- /dev/null
@@ -0,0 +1,45 @@
+# Copyright 2013 Samsung Electronics co., Ltd. All Rights Reserved.
+# 
+# Contact: Boram Park <boram1288.park@samsung.com>
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sub license, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+# 
+# The above copyright notice and this permission notice (including the
+# next paragraph) shall be included in all copies or substantial portions
+# of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+libxdbg_log_la_LTLIBRARIES = libxdbg-log.la
+libxdbg_log_ladir = $(libdir)
+libxdbg_log_la_LIBADD = @XDBG_LIBS@
+libxdbg_log_la_LDFLAGS = ${LDFLAGS}
+libxdbg_log_la_CFLAGS = \
+    ${CFLAGS} \
+    @XDBG_CFLAGS@ \
+    -I$(top_srcdir)/lib
+
+libxdbg_log_la_SOURCES = \
+       xdbg_log.c \
+       xdbg_log_klog.c \
+       xdbg_log_dlog.c
+
+libincludedir = $(includedir)/xdbg
+libinclude_HEADERS = \
+       xdbg.h \
+       xdbg_log.h
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = xdbg.pc
diff --git a/lib/xdbg.h b/lib/xdbg.h
new file mode 100644 (file)
index 0000000..e75182c
--- /dev/null
@@ -0,0 +1,38 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_H__
+#define __XDBG_H__
+
+/* include only headers */
+#include <xdbg_log.h>
+
+#endif  /* __XDBG_H__ */
diff --git a/lib/xdbg.pc.in b/lib/xdbg.pc.in
new file mode 100644 (file)
index 0000000..926fb0e
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: xdbg
+Description: The X debug Library
+Version: @PACKAGE_VERSION@
+Requires.private: xorg-server x11
+Cflags: -I${includedir}/xdbg
+Libs: -L${libdir} -lxdbg-log
diff --git a/lib/xdbg_log.c b/lib/xdbg_log.c
new file mode 100644 (file)
index 0000000..bd4babd
--- /dev/null
@@ -0,0 +1,272 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <stdarg.h>
+
+#include "xdbg_log.h"
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifndef MIN
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#define MAX_MODULE_NAME        4
+#define MAX_MODULE_CNT 256
+#define BUF_LEN         1024
+
+typedef struct
+{
+    unsigned int module;
+    char *name;
+    int   loglevel;
+} ModuleInfo;
+
+static ModuleInfo modules[MAX_MODULE_CNT];
+static int module_cnt = 0;
+
+extern void dLogWrapper (int loglevel, int is_module, const char * file, int line, const char * f, va_list args);
+extern void kLogWrapper (int loglevel, int is_module, const char * file, int line, const char * f, va_list args);
+static char* _LogGetName (unsigned int module);
+
+static void*
+_LogInitModule (unsigned int module, int loglevel)
+{
+    if (module_cnt >= MAX_MODULE_CNT)
+        return NULL;
+
+    modules[module_cnt].module = module;
+    modules[module_cnt].name = _LogGetName (module);
+    modules[module_cnt].loglevel = loglevel;
+    module_cnt++;
+
+    return &modules[module_cnt-1];
+}
+
+static void
+_LogModule (void * handle, int logoption, const char * file, int line, const char * f, va_list args)
+{
+    ModuleInfo *h = (ModuleInfo*)handle;
+    char *ostr[XLOG_LEVEL_MAX] = {"DD", "TT", "II", "WW", "EE"};
+    char tmpBuf[BUF_LEN];
+    int loglevel = logoption & XLOG_MASK_LOGLEVEL;
+    const char *name;
+
+    if (!h)
+        return;
+
+    name = h->name;
+
+    if (logoption & XLOG_OPTION_KLOG)
+    {
+        snprintf(tmpBuf, BUF_LEN, "[%s]%s", (name)?name:"", f);
+        kLogWrapper (loglevel, logoption, file, line, tmpBuf, args);
+    }
+
+    /* write to file */
+    if (loglevel >= XLOG_LEVEL_INFO)
+    {
+        snprintf(tmpBuf, BUF_LEN, "(%s) [%s]%s", ostr[loglevel], (name)?name:"", f);
+
+        LogVWrite (1, tmpBuf, args);
+    }
+
+    /* write to terminal */
+    if (loglevel >= h->loglevel || logoption & XLOG_OPTION_SLOG)
+    {
+        char *buf = tmpBuf;
+        int   remain = BUF_LEN;
+        int   len = 0;
+
+        len = snprintf (buf, remain, "[%s]", name?name:"");
+        buf += len;
+        remain -= len;
+
+        len += vsnprintf (buf, remain, f, args);
+
+        fwrite(tmpBuf, len, 1, stderr);
+    }
+}
+
+API int
+xDbgLogSetLevel (unsigned int module, int level)
+{
+    int i;
+    ModuleInfo * h;
+
+    if (level < XLOG_LEVEL_0 || level > XLOG_LEVEL_4)
+        return FALSE;
+
+    for (i = 0; i < module_cnt; i++)
+    {
+        if (module == modules[i].module)
+        {
+            modules[i].loglevel = level;
+            return TRUE;
+        }
+    }
+
+    h = _LogInitModule (module, level);
+    if (h == NULL)
+        return FALSE;
+
+    return TRUE;
+}
+
+API void*
+xDbgLog (unsigned int module, int logoption, const char * file, int line, const char * f, ...)
+{
+    int loglevel = logoption & XLOG_MASK_LOGLEVEL;
+    ModuleInfo *h;
+    va_list args;
+    int i;
+
+    if (module == 0)
+        return NULL;
+
+    if (loglevel < XLOG_LEVEL_0 || loglevel > XLOG_LEVEL_4)
+        return NULL;
+
+    for (i = 0; i < module_cnt; i++)
+    {
+        h = &modules[i];
+        if (module == h->module)
+            goto check_level;
+    }
+
+    h= (ModuleInfo *)_LogInitModule (module, XLOG_LEVEL_DEFAULT);
+    if(h == NULL)
+        return NULL;
+
+check_level:
+    if (logoption & (XLOG_OPTION_KLOG | XLOG_OPTION_SLOG))
+        goto write_log;
+
+    if (loglevel < XLOG_LEVEL_INFO && loglevel < h->loglevel)
+        return h;
+
+write_log:
+    va_start (args, f);
+    _LogModule (h, logoption, file, line, f, args);
+    va_end (args);
+
+    return h;
+}
+
+API int
+xDbgLogEnumModules (LOG_ENUM_MODE mode, char *buf, int *remain)
+{
+    int i, len;
+    char *p = buf;
+
+    switch (mode)
+    {
+    case MODE_NAME_ONLY:
+        for (i = 0; i < module_cnt && *remain > 0; i++)
+        {
+            len = snprintf (p, *remain, "%s", modules[i].name);
+            p += len;
+            *remain -= len;
+
+            if (i != module_cnt - 1 && *remain > 0)
+            {
+                len = snprintf (p, *remain, "/");
+                p += len;
+                *remain -= len;
+            }
+        }
+        break;
+    case MODE_WITH_STATUS:
+        for (i = 0; i < module_cnt && *remain > 0; i++)
+        {
+            len = snprintf (p, *remain, "   %12s:%d\n", modules[i].name, modules[i].loglevel);
+            p += len;
+            *remain -= len;
+        }
+        break;
+    default:
+        return 0;
+    }
+
+    return p - buf;
+}
+
+static char*
+_LogGetName (unsigned int module)
+{
+    char *name = malloc (MAX_MODULE_NAME+1);
+    char *p = name;
+    int i;
+
+    if (!name)
+        return NULL;
+
+    name[0] = '\0';
+
+    for (i = 0; i < MAX_MODULE_NAME; i++)
+    {
+        if (!_C(module, (i<<3)))
+            break;
+
+        *p = _C(module, (i<<3));
+        p++;
+    }
+
+    *p = '\0';
+
+    return name;
+}
+
+API unsigned int
+xDbgLogGetModule (char *name)
+{
+    unsigned int module = 0;
+    int i, len;
+
+    if (!name)
+        return 0;
+
+    len = strlen (name);
+    for (i = 0; i < len; i++)
+    {
+        module |= _B(*name, (i<<3));
+        name++;
+    }
+
+    return module;
+}
diff --git a/lib/xdbg_log.h b/lib/xdbg_log.h
new file mode 100644 (file)
index 0000000..7ad4de5
--- /dev/null
@@ -0,0 +1,121 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_LOG_H__
+#define __XDBG_LOG_H__
+
+#include <errno.h>
+#include <stdlib.h>
+#include <os.h>
+
+// Masks
+#define XLOG_MASK_LOGLEVEL   0x000000FF
+#define XLOG_MASK_OPTIONS    0xFFFFFF00
+
+// LogLevels
+enum
+{
+    XLOG_LEVEL_0,
+    XLOG_LEVEL_1,
+    XLOG_LEVEL_2,
+    XLOG_LEVEL_3,
+    XLOG_LEVEL_4,
+    XLOG_LEVEL_MAX,
+    XLOG_LEVEL_DEFAULT = XLOG_LEVEL_3
+};
+
+#define XLOG_LEVEL_DEBUG    XLOG_LEVEL_0
+#define XLOG_LEVEL_TRACE    XLOG_LEVEL_1
+#define XLOG_LEVEL_INFO     XLOG_LEVEL_2
+#define XLOG_LEVEL_WARNING  XLOG_LEVEL_3
+#define XLOG_LEVEL_ERROR    XLOG_LEVEL_4
+
+// Log Options
+#define XLOG_OPTION_KLOG        (1 << 8)
+#define XLOG_OPTION_SLOG        (1 << 9)    /* print to stderr always */
+
+typedef enum
+{
+    MODE_NAME_ONLY,
+    MODE_WITH_STATUS
+} LOG_ENUM_MODE;
+
+int   xDbgLogEnumModules (LOG_ENUM_MODE mode, char *buf, int *remain);
+int   xDbgLogSetLevel    (unsigned int module, int level);
+void* xDbgLog            (unsigned int module, int logoption, const char *file, int line, const char *f, ...);
+
+// defines
+#define XLOG_DEBUG(mod, ...)    xDbgLog(mod, XLOG_LEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
+#define XLOG_TRACE(mod, ...)    xDbgLog(mod, XLOG_LEVEL_TRACE, __FILE__, __LINE__, __VA_ARGS__)
+#define XLOG_INFO(mod, ...)     xDbgLog(mod, XLOG_LEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__)
+#define XLOG_WARNING(mod, ...)  xDbgLog(mod, XLOG_LEVEL_WARNING, __FILE__, __LINE__, __VA_ARGS__)
+#define XLOG_ERROR(mod, ...)    xDbgLog(mod, XLOG_LEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
+#define XLOG_KLOG(mod, ...)     xDbgLog(mod, XLOG_LEVEL_INFO|XLOG_OPTION_KLOG, __FILE__, __LINE__, __VA_ARGS__)
+#define XLOG_SLOG(mod, ...)     xDbgLog(mod, XLOG_LEVEL_INFO|XLOG_OPTION_SLOG, __FILE__, __LINE__, __VA_ARGS__)
+
+#define XDBG_DEBUG(mod, fmt, ARG...)      XLOG_DEBUG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
+#define XDBG_TRACE(mod, fmt, ARG...)      XLOG_TRACE(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
+#define XDBG_INFO(mod, fmt, ARG...)       XLOG_INFO(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
+#define XDBG_WARNING(mod, fmt, ARG...)    XLOG_WARNING(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
+#define XDBG_ERROR(mod, fmt, ARG...)      XLOG_ERROR(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
+#define XDBG_ERRNO(mod, fmt, ARG...)      XLOG_ERROR(mod, "[%s](err=%(%d)) "fmt, __FUNCTION__, strerror(errno), errno, ##ARG)
+#define XDBG_KLOG(mod, fmt, ARG...)       XLOG_KLOG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
+#define XDBG_SLOG(mod, fmt, ARG...)       XLOG_SLOG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
+
+#define XDBG_NEVER_GET_HERE(mod)          XLOG_ERROR(mod, "[%s] ** NEVER GET HERE **\n", __FUNCTION__)
+
+#define XDBG_WARNING_IF_FAIL(cond)         {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond);}}
+#define XDBG_RETURN_IF_FAIL(cond)          {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond); return; }}
+#define XDBG_RETURN_VAL_IF_FAIL(cond, val) {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond); return val; }}
+#define XDBG_RETURN_VAL_IF_ERRNO(cond, val, errno)       {if (!(cond)) { ErrorF ("[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); return val; }}
+#define XDBG_GOTO_IF_FAIL(cond, dst)       {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond); goto dst; }}
+#define XDBG_GOTO_IF_ERRNO(cond, dst, errno)       {if (!(cond)) { ErrorF ("[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); goto dst; }}
+
+#define XDBG_REPLY(fmt, ARG...)  \
+    do { \
+        if (reply && len && *len > 0) \
+        { \
+            int s = snprintf (reply, *len, fmt, ##ARG); \
+            reply += s; \
+            *len -= s; \
+        } \
+    } while (0)
+
+unsigned int xDbgLogGetModule (char *name);
+
+#define _C(b,s)             (((b) >> (s)) & 0xFF)
+#define _B(c,s)             ((((unsigned int)(c)) & 0xff) << (s))
+#define XDBG_M(a,b,c,d)     (_B(d,24)|_B(c,16)|_B(b,8)|_B(a,0))
+
+/* debug module for XDBG */
+#define MXDBG    XDBG_M('X','D','B','G')
+
+#endif  /* __XDBG_LOG_H__ */
diff --git a/lib/xdbg_log_dlog.c b/lib/xdbg_log_dlog.c
new file mode 100644 (file)
index 0000000..f5560de
--- /dev/null
@@ -0,0 +1,72 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include <stdarg.h>
+//#include <dlog.h>
+
+void dLogWrapper (int loglevel, int module, const char * file, int line, const char * f, va_list args)
+{
+#if 0
+    const char * tag;
+    int priority;
+
+    if (module & LOGOPTION_DLOG_X)
+        tag = "xserver";
+    else if (module & LOGOPTION_DLOG_EVENT)
+        tag = "dlog_event";
+    else
+        return;
+
+    switch (loglevel)
+    {
+    case LOGLEVEL_DEBUG:
+        priority = DLOG_DEBUG;
+        break;
+    case LOGLEVEL_TRACE:
+        priority = DLOG_INFO;
+        break;
+    case LOGLEVEL_INFO:
+        priority = DLOG_WARN;
+        break;
+    case LOGLEVEL_WARNING:
+        priority = DLOG_ERROR;
+        break;
+    case LOGLEVEL_ERROR:
+        priority = DLOG_FATAL;
+        break;
+    default:
+        return;
+    }
+
+    SLOG_VA (priority, tag, f, args);
+#endif
+}
+
diff --git a/lib/xdbg_log_klog.c b/lib/xdbg_log_klog.c
new file mode 100644 (file)
index 0000000..83d47ae
--- /dev/null
@@ -0,0 +1,50 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include <stdarg.h>
+#include <stdio.h>
+
+void kLogWrapper (int loglevel, int module, const char * file, int line, const char * f, va_list args)
+{
+    static FILE* fp = NULL;
+    static char init = 0;
+
+    if(!init && !fp)
+    {
+        fp = fopen("/dev/kmsg", "wt");
+        init = 1;
+    }
+
+    if(!fp) return;
+
+    vfprintf(fp, f, args);
+    fflush(fp);
+}
diff --git a/module/Makefile.am b/module/Makefile.am
new file mode 100644 (file)
index 0000000..6d987ef
--- /dev/null
@@ -0,0 +1,50 @@
+# Copyright 2013 Samsung Electronics co., Ltd. All Rights Reserved.
+# 
+# Contact: Boram Park <boram1288.park@samsung.com>
+# 
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sub license, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+# 
+# The above copyright notice and this permission notice (including the
+# next paragraph) shall be included in all copies or substantial portions
+# of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+libxdbg_la_LTLIBRARIES = libxdbg.la
+libxdbg_ladir = @moduledir@
+libxdbg_la_LIBADD = @XDBG_LIBS@ ../dbus/libdbus.la ../lib/libxdbg-log.la
+libxdbg_la_LDFLAGS = -module -avoid-version ${LDFLAGS}
+libxdbg_la_CFLAGS = \
+       ${CFLAGS} \
+       @XDBG_CFLAGS@ \
+       -I$(top_srcdir)/dbus \
+       -I$(top_srcdir)/lib \
+       -I$(top_srcdir)/module \
+       -I$(top_srcdir)/module/ds
+
+libxdbg_la_SOURCES = \
+       xdbg_module.c \
+       xdbg_module_main.c \
+       xdbg_module_options.c \
+       xdbg_module_command.c \
+       xdbg_module_clist.c \
+       xdbg_module_rlist.c \
+       xdbg_module_evlog.c \
+       xdbg_module_evlog_request.c \
+       xdbg_module_evlog_event.c \
+       ds/bintree.c \
+       ds/bool_exp_parser.c \
+       ds/bool_exp_rule_checker.c \
+       ds/bool_exp_tokenizer.c
diff --git a/module/ds/bintree.c b/module/ds/bintree.c
new file mode 100644 (file)
index 0000000..a38cf2e
--- /dev/null
@@ -0,0 +1,165 @@
+/**************************************************************************
+
+xserver-xorg-video-exynos
+
+Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "bintree.h"
+
+struct _BINARY_TREE_NODE
+{
+    BINARY_TREE_NODE left;
+    BINARY_TREE_NODE right;
+};
+
+struct _BINARY_TREE
+{
+    int size;
+    BINARY_TREE_NODE head;
+};
+
+BINARY_TREE bintree_create_tree (int size)
+{
+    BINARY_TREE tree = calloc (sizeof (struct _BINARY_TREE) + size, 1);
+
+    tree->size = size;
+    tree->head = NULL;
+
+    return tree;
+}
+
+BINARY_TREE_NODE bintree_create_node (BINARY_TREE tree)
+{
+    BINARY_TREE_NODE node = calloc (sizeof (struct _BINARY_TREE_NODE) + tree->size, 1);
+
+    node->left = NULL;
+    node->right = NULL;
+
+    return node;
+}
+
+BINARY_TREE_NODE bintree_get_head (BINARY_TREE tree)
+{
+    return tree->head;
+}
+
+void bintree_set_head (BINARY_TREE tree, BINARY_TREE_NODE head)
+{
+    tree->head = head;
+}
+
+void bintree_set_left_child (BINARY_TREE_NODE node, BINARY_TREE_NODE child)
+{
+    node->left = child;
+}
+
+void bintree_set_right_child (BINARY_TREE_NODE node, BINARY_TREE_NODE child)
+{
+    node->right = child;
+}
+
+BINARY_TREE_NODE bintree_get_left_child (BINARY_TREE_NODE node)
+{
+    return node->left;
+}
+
+BINARY_TREE_NODE bintree_get_right_child (BINARY_TREE_NODE node)
+{
+    return node->right;
+}
+
+void * bintree_get_node_data (BINARY_TREE_NODE node)
+{
+    return (void*)(node + 1);
+}
+
+void bintree_remove_node (BINARY_TREE_NODE node)
+{
+    free (node);
+}
+
+void bintree_remove_node_recursive (BINARY_TREE_NODE node)
+{
+    if (node->left)
+        bintree_remove_node_recursive (node->left);
+    if (node->right)
+        bintree_remove_node_recursive (node->right);
+
+    bintree_remove_node (node);
+}
+
+void bintree_destroy_tree (BINARY_TREE tree)
+{
+    if (tree->head)
+        bintree_remove_node_recursive (tree->head);
+
+    free (tree);
+}
+
+static int bintree_inorder_traverse_recursive (BINARY_TREE tree, BINARY_TREE_NODE node, BINARY_TREE_NODE parent, BINTREE_TRAVERSE_FUNC func, void * arg)
+{
+    if (node->left)
+        if (bintree_inorder_traverse_recursive (tree, node->left, node, func, arg) != 0)
+            return 1;
+
+    if (func (tree, node, parent, arg))
+        return 1;
+
+    if (node->right)
+        if (bintree_inorder_traverse_recursive (tree, node->right, node, func, arg) != 0)
+            return 1;
+
+    return 0;
+}
+
+void bintree_inorder_traverse (BINARY_TREE tree, BINTREE_TRAVERSE_FUNC func, void * arg)
+{
+    if (tree->head)
+        bintree_inorder_traverse_recursive (tree, tree->head, tree->head, func, arg);
+}
+
+static int bintree_postorder_traverse_recursive (BINARY_TREE tree, BINARY_TREE_NODE node, BINARY_TREE_NODE parent, BINTREE_TRAVERSE_FUNC func, void * arg)
+{
+    if (node->left)
+        if (bintree_postorder_traverse_recursive (tree, node->left, node, func, arg) != 0)
+            return 1;
+    if (node->right)
+        if (bintree_postorder_traverse_recursive (tree, node->right, node, func, arg) != 0)
+            return 1;
+
+    return func (tree, node, parent, arg);
+}
+
+void bintree_postorder_traverse (BINARY_TREE tree, BINTREE_TRAVERSE_FUNC func, void * arg)
+{
+    if (tree->head)
+        bintree_postorder_traverse_recursive (tree, tree->head, tree->head, func, arg);
+}
+
diff --git a/module/ds/bintree.h b/module/ds/bintree.h
new file mode 100644 (file)
index 0000000..be4040c
--- /dev/null
@@ -0,0 +1,67 @@
+/**************************************************************************
+
+xserver-xorg-video-exynos
+
+Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef _BOOL_EXP_BINTREE_H_
+#define _BOOL_EXP_BINTREE_H_
+
+typedef struct _BINARY_TREE_NODE * BINARY_TREE_NODE;
+typedef struct _BINARY_TREE * BINARY_TREE;
+typedef int (*BINTREE_TRAVERSE_FUNC) (BINARY_TREE tree, BINARY_TREE_NODE node, BINARY_TREE_NODE parent, void * arg);
+
+BINARY_TREE bintree_create_tree (int data_size);
+
+BINARY_TREE_NODE bintree_create_node (BINARY_TREE tree);
+
+BINARY_TREE_NODE bintree_get_head (BINARY_TREE tree);
+
+void bintree_set_head (BINARY_TREE tree, BINARY_TREE_NODE head);
+
+void bintree_set_left_child (BINARY_TREE_NODE node, BINARY_TREE_NODE child);
+
+void bintree_set_right_child (BINARY_TREE_NODE node, BINARY_TREE_NODE child);
+
+BINARY_TREE_NODE bintree_get_left_child (BINARY_TREE_NODE node);
+
+BINARY_TREE_NODE bintree_get_right_child (BINARY_TREE_NODE node);
+
+void * bintree_get_node_data (BINARY_TREE_NODE node);
+
+void bintree_remove_node (BINARY_TREE_NODE node);
+
+void bintree_remove_node_recursive (BINARY_TREE_NODE node);
+
+void bintree_destroy_tree (BINARY_TREE tree);
+
+void bintree_inorder_traverse (BINARY_TREE tree, BINTREE_TRAVERSE_FUNC func, void * arg);
+
+void bintree_postorder_traverse (BINARY_TREE tree, BINTREE_TRAVERSE_FUNC func, void * arg);
+
+#endif /* _BOOL_EXP_BINTREE_H_ */
+
diff --git a/module/ds/bool_exp_parser.c b/module/ds/bool_exp_parser.c
new file mode 100644 (file)
index 0000000..7c37a2d
--- /dev/null
@@ -0,0 +1,261 @@
+/**************************************************************************
+
+xserver-xorg-video-exynos
+
+Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+
+#include "bool_exp_tokenizer.h"
+#include "bool_exp_parser.h"
+#include "bintree.h"
+
+typedef struct _TOKEN_DATA * TOKEN_DATA;
+
+struct _TOKEN_DATA
+{
+    const char ** string;
+    TOKEN last_token;
+    const char * last_symbol;
+    int symbol_len;
+};
+
+static BINARY_TREE_NODE bool_exp_parse_line (BINARY_TREE tree, TOKEN_DATA token);
+
+#define PARSE_DEBUG 0
+
+#if PARSE_DEBUG
+#define process_token(t) _process_token(t, __LINE__)
+static void _process_token (TOKEN_DATA token, int line)
+#else
+static void process_token (TOKEN_DATA token)
+#endif
+{
+    do
+    {
+        token->last_symbol = *(token->string);
+        token->last_token = get_next_token (token->string);
+        token->symbol_len = *(token->string) - token->last_symbol;
+
+    }
+    while (token->last_token == BET_SPACE);
+#if PARSE_DEBUG
+    printf ("token : %d remained string : [%s] (line:%d)\n", token->last_token, *token->string, line);
+#endif
+}
+
+static BINARY_TREE_NODE bool_exp_parse_statement (BINARY_TREE tree, TOKEN_DATA token)
+{
+    BINARY_TREE_NODE node = NULL;
+    PARSE_DATA data = NULL;
+
+#if PARSE_DEBUG
+    printf ("%s:%d (token->last_token %d)\n", __FILE__, __LINE__, token->last_token);
+#endif
+
+    if (token->last_token == BET_L_BR)
+    {
+        process_token (token);
+
+        node = bool_exp_parse_line (tree, token);
+        if (node == NULL)
+        {
+            return NULL;
+        }
+
+        if (token->last_token != BET_R_BR)
+        {
+            goto fail;
+        }
+        process_token (token);
+
+        return node;
+    }
+
+    if (token->last_token != BET_SYMBOL)
+        goto fail;
+
+    node = bintree_create_node (tree);
+
+    data = (PARSE_DATA) bintree_get_node_data (node);
+
+    strncpy (data->variable_name, token->last_symbol, token->symbol_len);
+    data->variable_name[token->symbol_len] = '\0';
+
+    if (!strcasecmp (data->variable_name, "all"))
+    {
+        data->node_type = ALL;
+        process_token (token);
+
+        return node;
+    }
+
+    data->node_type = DATA;
+
+    process_token (token);
+
+    switch (token->last_token)
+    {
+    case BET_NOT_EQ:
+        data->compare = NOT_EQ;
+        break;
+    case BET_EQUAL:
+        data->compare = EQUAL;
+        break;
+    case BET_LSS_THAN:
+        data->compare = LESS;
+        break;
+    case BET_LSS_EQ:
+        data->compare = LESS_EQ;
+        break;
+    case BET_GRT_THAN:
+        data->compare = GREATER;
+        break;
+    case BET_GRT_EQ:
+        data->compare = GREATER_EQ;
+        break;
+    default:
+        goto fail;
+    }
+
+    process_token (token);
+
+    if (token->last_token == BET_NUMBER)
+    {
+        data->value_type = INTEGER;
+        data->value.integer = atoi (token->last_symbol);
+    }
+    else if (token->last_token == BET_SYMBOL)
+    {
+        data->value_type = STRING;
+        strncpy (data->value.string, token->last_symbol, token->symbol_len);
+        data->value.string[token->symbol_len] = '\0';
+    }
+    else
+    {
+        goto fail;
+    }
+
+    process_token (token);
+
+    return node;
+
+fail:
+    if (node)
+        bintree_remove_node_recursive (node);
+
+    return NULL;
+}
+
+static BINARY_TREE_NODE bool_exp_parse_line (BINARY_TREE tree, TOKEN_DATA token)
+{
+    BINARY_TREE_NODE node = NULL;
+    BINARY_TREE_NODE left = NULL;
+    BINARY_TREE_NODE right = NULL;
+
+    PARSE_DATA data;
+
+#if PARSE_DEBUG
+    printf ("%s:%d\n", __FILE__, __LINE__);
+#endif
+
+    node = bool_exp_parse_statement (tree, token);
+    if (node == NULL)
+    {
+        printf ("PARSE statement error\n");
+        goto fail;
+    }
+
+    while (token->last_token == BET_AND)
+    {
+        left = node;
+        node = NULL;
+
+        process_token (token);
+        right = bool_exp_parse_statement (tree, token);
+        if (right == NULL)
+            goto fail;
+
+        node = bintree_create_node (tree);
+
+        data = (PARSE_DATA) bintree_get_node_data (node);
+        data->node_type = AND;
+        bintree_set_left_child (node, left);
+        bintree_set_right_child (node, right);
+    }
+
+    if (token->last_token == BET_OR)
+    {
+        left = node;
+        node = NULL;
+
+        process_token (token);
+        right = bool_exp_parse_line (tree, token);
+        if (right == NULL)
+            goto fail;
+
+        node = bintree_create_node (tree);
+
+        data = (PARSE_DATA) bintree_get_node_data (node);
+        data->node_type = OR;
+        bintree_set_left_child (node, left);
+        bintree_set_right_child (node, right);
+    }
+
+    return node;
+
+fail:
+    if (left)
+        bintree_remove_node_recursive (left);
+    return NULL;
+}
+
+BINARY_TREE bool_exp_parse (const char * string)
+{
+    BINARY_TREE tree = bintree_create_tree (sizeof (struct _PARSE_DATA));
+    BINARY_TREE_NODE node;
+
+    struct _TOKEN_DATA token;
+
+    token.string = &string;
+    process_token (&token);
+
+    node = bool_exp_parse_line (tree, &token);
+    if (node == NULL)
+    {
+        bintree_destroy_tree (tree);
+        return NULL;
+    }
+
+    bintree_set_head (tree, node);
+
+    return tree;
+}
+
diff --git a/module/ds/bool_exp_parser.h b/module/ds/bool_exp_parser.h
new file mode 100644 (file)
index 0000000..2b0bcb5
--- /dev/null
@@ -0,0 +1,63 @@
+/**************************************************************************
+
+xserver-xorg-video-exynos
+
+Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef _BOOL_EXP_PARSER_H_
+#define _BOOL_EXP_PARSER_H_
+
+#include "bintree.h"
+
+#define STRING_MAX     64
+
+typedef enum { NONE, AND, OR, DATA, ALL } NODE_TYPE;
+typedef enum { EQUAL, LESS, GREATER, LESS_EQ, GREATER_EQ, NOT_EQ } COMPARER;
+typedef enum { INTEGER, STRING } DATA_TYPE;
+
+typedef struct _PARSE_DATA * PARSE_DATA;
+
+struct _PARSE_DATA
+{
+    NODE_TYPE node_type;
+
+    char variable_name[STRING_MAX];
+    COMPARER compare;
+    DATA_TYPE value_type;
+    union
+    {
+        char string[STRING_MAX];
+        int integer;
+    } value;
+
+    enum { BEP_UNKNOWN, BEP_TRUE, BEP_FALSE } result;
+};
+
+BINARY_TREE bool_exp_parse (const char * string);
+
+#endif /* _BOOL_EXP_PARSER_H_ */
+
diff --git a/module/ds/bool_exp_rule_checker.c b/module/ds/bool_exp_rule_checker.c
new file mode 100644 (file)
index 0000000..5c3204a
--- /dev/null
@@ -0,0 +1,400 @@
+/**************************************************************************
+
+xserver-xorg-video-exynos
+
+Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+
+#include "bool_exp_parser.h"
+#include "bool_exp_rule_checker.h"
+
+#define MAX_RULE       64
+
+typedef struct
+{
+    POLICY_TYPE policy;
+
+    BINARY_TREE tree;
+} RULE;
+
+struct _RULE_CHECKER
+{
+    RULE rules[MAX_RULE];
+
+    int count;
+};
+
+typedef struct
+{
+    int type;
+    int reqID;
+    const char * name;
+    int pid;
+    char * cmd;
+} VAL_ARGUMENTS;
+
+static int print_func (BINARY_TREE tree, BINARY_TREE_NODE node, BINARY_TREE_NODE parent, void * arg)
+{
+    int len;
+    char ** string = (char **)arg;
+    char * operators[] = { "==", "<", ">", "<=", ">=", "!=" };
+
+    PARSE_DATA data = bintree_get_node_data (node);
+
+    if (data->node_type == ALL)
+    {
+        len = sprintf (*string, "ALL");
+        (*string) += len;
+    }
+    else if (data->node_type == AND)
+    {
+        len = sprintf (*string, " and ");
+        (*string) += len;
+    }
+    else if (data->node_type == OR)
+    {
+        len = sprintf (*string, " or ");
+        (*string) += len;
+    }
+    else // data->node_type == DATA
+    {
+        if (node == bintree_get_left_child (parent))
+        {
+            **string = '(';
+            (*string) ++;
+        }
+
+        len = sprintf (*string, "%s %s ", data->variable_name, operators[data->compare]);
+        (*string) += len;
+        if (data->value_type == INTEGER)
+            len = sprintf (*string, "%d", data->value.integer);
+        else
+            len = sprintf (*string, "%s", data->value.string);
+        (*string) += len;
+
+        if (node == bintree_get_right_child (parent))
+        {
+            **string = ')';
+            (*string) ++;
+        }
+    }
+
+    return 0;
+}
+
+static int compare_string (COMPARER compare, char * str2, char * str1)
+{
+    int result = strcasecmp (str2, str1);
+    switch (compare)
+    {
+    case EQUAL:
+        return result == 0;
+    case LESS:
+        return result < 0;
+    case GREATER:
+        return result > 0;
+    case LESS_EQ:
+        return result <= 0;
+    case GREATER_EQ:
+        return result >= 0;
+    case NOT_EQ:
+        return result != 0;
+    }
+
+    return 0;
+}
+
+static int compare_int (COMPARER compare, int int2, int int1)
+{
+    switch (compare)
+    {
+    case EQUAL:
+        return int1 == int2;
+    case LESS:
+        return int1 < int2;
+    case GREATER:
+        return int1 > int2;
+    case LESS_EQ:
+        return int1 <= int2;
+    case GREATER_EQ:
+        return int1 >= int2;
+    case NOT_EQ:
+        return int1 != int2;
+    }
+
+    return 0;
+}
+
+static int validate_func (BINARY_TREE tree, BINARY_TREE_NODE node, BINARY_TREE_NODE parent, void * arg)
+{
+    VAL_ARGUMENTS * args = (VAL_ARGUMENTS*)arg;
+    BINARY_TREE_NODE left, right;
+
+    PARSE_DATA left_data = NULL, right_data = NULL;
+    PARSE_DATA data = bintree_get_node_data (node);
+
+    data->result = BEP_UNKNOWN;
+
+    if (data->node_type == AND || data->node_type == OR)
+    {
+        left = bintree_get_left_child (node);
+        right = bintree_get_right_child (node);
+        if (left == NULL || right == NULL)
+        {
+            printf ("Node error\n");
+            return -1;
+        }
+
+        left_data = bintree_get_node_data (left);
+        right_data = bintree_get_node_data (right);
+    }
+
+    if (data->node_type == ALL)
+    {
+        data->result = BEP_TRUE;
+    }
+    else if (data->node_type == DATA)
+    {
+        char major[64];
+        char * minor = NULL;
+
+        if (args->name)
+            minor = index (args->name, ':');
+        if (minor)
+        {
+            strncpy (major, args->name, minor - args->name);
+            major[minor - args->name] = '\0';
+            minor++;
+        }
+        if (!strcasecmp (data->variable_name, "TYPE"))
+        {
+            char * type_string;
+            if (args->type == 0) // EVENT
+                type_string = "EVENT";
+            else if (args->type == 1)
+                type_string = "REQUEST";
+            else if (args->type == 2)
+                type_string = "REPLY";
+            else if (args->type == 3)
+                type_string = "FLUSH";
+            else
+            {
+                fprintf (stderr, "Invalid type %d\n", args->type);
+                return -1;
+            }
+
+            if (compare_string (data->compare, data->value.string, type_string))
+                data->result = BEP_TRUE;
+            else
+                data->result = BEP_FALSE;
+        }
+        else if (!strcasecmp (data->variable_name, "MAJOR"))
+        {
+            if (minor && compare_string (data->compare, data->value.string, major))
+                data->result = BEP_TRUE;
+            else
+                data->result = BEP_FALSE;
+        }
+        else if (!strcasecmp (data->variable_name, "MINOR"))
+        {
+            if (minor && compare_string (data->compare, data->value.string, minor))
+                data->result = BEP_TRUE;
+            else
+                data->result = BEP_FALSE;
+        }
+        else if (!strcasecmp (data->variable_name, "PID"))
+        {
+            if (compare_int (data->compare, data->value.integer, args->pid))
+                data->result = BEP_TRUE;
+            else
+                data->result = BEP_FALSE;
+        }
+        else if (!strcasecmp (data->variable_name, "CMD") || !strcasecmp (data->variable_name, "COMMAND"))
+        {
+            if (args->cmd && compare_string (data->compare, data->value.string, args->cmd))
+                data->result = BEP_TRUE;
+            else
+                data->result = BEP_FALSE;
+        }
+    }
+    else if (data->node_type == AND)
+    {
+        if (left_data->result == BEP_TRUE && right_data->result == BEP_TRUE)
+            data->result = BEP_TRUE;
+        else
+            data->result = BEP_FALSE;
+    }
+    else if (data->node_type == OR)
+    {
+        if (left_data->result == BEP_TRUE || right_data->result == BEP_TRUE)
+            data->result = BEP_TRUE;
+        else
+            data->result = BEP_FALSE;
+    }
+    else
+        return -1;
+
+    return 0;
+}
+
+
+RULE_CHECKER rulechecker_init()
+{
+    RULE_CHECKER rc = calloc (sizeof (struct _RULE_CHECKER), 1);
+    if (rc == NULL)
+        return NULL;
+
+    rc->count = 0;
+
+    return rc;
+}
+
+void rulechecker_destroy (RULE_CHECKER rc)
+{
+    int i;
+    for (i=rc->count - 1; i>=0; i--)
+        rulechecker_remove_rule (rc, i);
+
+    free (rc);
+}
+
+RC_RESULT_TYPE rulechecker_add_rule (RULE_CHECKER rc, POLICY_TYPE policy, const char * rule_string)
+{
+    if (rc->count == MAX_RULE)
+        return RC_ERR_TOO_MANY_RULES;
+
+    rc->rules[rc->count].tree = bool_exp_parse (rule_string);
+    if (rc->rules[rc->count].tree == NULL)
+        return RC_ERR_PARSE_ERROR;
+    rc->rules[rc->count].policy = policy;
+
+    rc->count++;
+
+    return RC_OK;
+}
+
+RC_RESULT_TYPE rulechecker_remove_rule (RULE_CHECKER rc, int index)
+{
+    if (index < 0 || index >= rc->count)
+        return RC_ERR_NO_RULE;
+
+    bintree_destroy_tree (rc->rules[index].tree);
+
+    rc->count--;
+    if (index != rc->count)
+        memmove (&rc->rules[index], &rc->rules[index + 1], sizeof (RULE) * (rc->count - index));
+
+    return RC_OK;
+}
+
+void rulechecker_print_rule (RULE_CHECKER rc, char * rules_buf)
+{
+    char * rules_print = rules_buf;
+    int len;
+
+    int i;
+
+    len = sprintf (rules_print, " ---------------- Evlog Rules ----------------\n");
+    rules_print += len;
+
+    for (i=0; i<rc->count; i++)
+    {
+        len = sprintf (rules_print, " [Rule %d] [%s] \"", i, rc->rules[i].policy == ALLOW ? "ALLOW" : "DENY");
+        rules_print += len;
+        bintree_inorder_traverse (rc->rules[i].tree, print_func, (void*)&rules_print);
+        *rules_print = '\"';
+        rules_print++;
+        *rules_print = '\n';
+        rules_print++;
+    }
+    *rules_print = '\0';
+}
+
+const char * rulechecker_print_usage()
+{
+    return
+        "###################################################\n"
+        "###    RuleChecker 1.0 for XBerc EvLog filtering.                                \n"
+        "###                 Designed and developed by\n"
+        "###                 Boram Park <boram1288.park@samsung.com>\n"
+        "###################################################\n"
+        "\n"
+        "-----------------------------------------------------------------\n"
+        "How to read evlog messages :\n"
+        "      Client(pid: [PID]|       [CMD])   <======     [TYPE]( [MAJOR]:  [MINOR])   =====     XServer\n"
+        "\n"
+        "   ie)\n"
+        "        Client(pid:00345|        xberc)   <======    Event (       X11:SendEvent)   =====     XServer\n"
+        "             ==> type = event && pid = 345 && cmd = xberc && major = X11 && minor = SendEvent\n"
+        "        Client(pid:00111|        xeyes)     =====   Request(       SHM:ShmAttach)   ======>   XServer\n"
+        "             ==> type = request && pid = 111 && cmd = xeyes && major = SHM && minor = ShmAttach\n"
+        "\n"
+        "-----------------------------------------------------------------\n"
+        "Usage : xberc evlog_rule add [POLICY] [RULE]\n"
+        "        xberc evlog_rule remove [INDEX]\n"
+        "        xberc evlog_rule help /print\n"
+        "      [POLICY] : allow / deny \n"
+        "      [RULE] : C Language-style boolean expression syntax. [VARIABLE] [COMPAROTOR] [VALUE]\n"
+        "      [VARIABLE] : type / major / minor / command / cmd / pid\n"
+        "      [COMPARATOR] : & / && / and / | / || / or / = / == / != / > / >= / < / <=\n"
+        "      [VALUE] : string / number  \n"
+        "\n"
+        "   ie)\n"
+        "        xberc evlog_rule add allow \"(type=request) && (major == X11 and (minor = SendEvent or minor = ReceiveEvent))\"\n"
+        "        xberc evlog_rule add deny cmd!=ls\n"
+        "        xberc evlog_rule remove 1\n"
+        "\n";
+}
+
+int rulechecker_validate_rule (RULE_CHECKER rc, int type, int reqID, const char * name, int pid, char * cmd)
+{
+    VAL_ARGUMENTS args = { type, reqID, name, pid, cmd };
+    BINARY_TREE_NODE node;
+    PARSE_DATA data;
+
+    // set default value here
+    POLICY_TYPE default_policy = DENY;
+    int i;
+    for (i=rc->count - 1; i >= 0; i--)
+    {
+        bintree_postorder_traverse (rc->rules[i].tree, validate_func, &args);
+        node = bintree_get_head (rc->rules[i].tree);
+        data = bintree_get_node_data (node);
+
+        if (data->result == BEP_TRUE)
+        {
+            return rc->rules[i].policy == ALLOW;
+        }
+    }
+
+    return default_policy == ALLOW;
+}
+
diff --git a/module/ds/bool_exp_rule_checker.h b/module/ds/bool_exp_rule_checker.h
new file mode 100644 (file)
index 0000000..76c0b25
--- /dev/null
@@ -0,0 +1,55 @@
+/**************************************************************************
+
+xserver-xorg-video-exynos
+
+Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef _BOOL_EXP_RULE_CHECKER_H_
+#define _BOOL_EXP_RULE_CHECKER_H_
+
+typedef enum { UNDEFINED, ALLOW, DENY } POLICY_TYPE;
+
+typedef enum { RC_OK, RC_ERR_TOO_MANY_RULES, RC_ERR_PARSE_ERROR, RC_ERR_NO_RULE } RC_RESULT_TYPE;
+
+typedef struct _RULE_CHECKER * RULE_CHECKER;
+
+RULE_CHECKER rulechecker_init();
+
+void rulechecker_destroy (RULE_CHECKER rc);
+
+RC_RESULT_TYPE rulechecker_add_rule (RULE_CHECKER rc, POLICY_TYPE policy, const char * rule_string);
+
+RC_RESULT_TYPE rulechecker_remove_rule (RULE_CHECKER rc, int index);
+
+void rulechecker_print_rule (RULE_CHECKER rc, char * rules_buf);
+
+const char * rulechecker_print_usage (void);
+
+int rulechecker_validate_rule (RULE_CHECKER rc, int direct, int reqID, const char * name, int pid, char * cmd);
+
+#endif /* _BOOL_EXP_RULE_CHECKER_H_ */
+
diff --git a/module/ds/bool_exp_token.h b/module/ds/bool_exp_token.h
new file mode 100644 (file)
index 0000000..542ef0f
--- /dev/null
@@ -0,0 +1,54 @@
+/**************************************************************************
+
+xserver-xorg-video-exynos
+
+Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef _BOOL_EXP_TOKEN_H_
+#define _BOOL_EXP_TOKEN_H_
+
+typedef enum
+{
+    BET_UNKNOWN = 0,
+    BET_L_BR = 1,
+    BET_R_BR = 2,
+    BET_NOT_EQ = 3,
+    BET_EQUAL = 4,
+    BET_LSS_THAN = 5,
+    BET_LSS_EQ = 6,
+    BET_GRT_THAN = 7,
+    BET_GRT_EQ = 8,
+    BET_AND = 9,
+    BET_OR = 10,
+    BET_SPACE = 11,
+    BET_SYMBOL = 12,
+    BET_NUMBER = 13,
+    BET_EOS = 14,
+} TOKEN;
+
+#endif /* _BOOL_EXP_TOKEN_H_ */
+
diff --git a/module/ds/bool_exp_tokenizer.c b/module/ds/bool_exp_tokenizer.c
new file mode 100644 (file)
index 0000000..4a21015
--- /dev/null
@@ -0,0 +1,129 @@
+/**************************************************************************
+
+xserver-xorg-video-exynos
+
+Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include <string.h>
+#include <ctype.h>
+
+#include "bool_exp_tokenizer.h"
+
+//#define debugf printf
+#define debugf(...)
+
+// should be increasing order for binary search
+static struct
+{
+    const char * token_char;
+    const int token_length;
+    TOKEN token_name;
+} token_table[] =
+{
+    { "\0",    1, BET_EOS }, // 0
+    { "\t",    1, BET_SPACE }, // 9
+    { " ",     1, BET_SPACE }, // 32
+    { "!=",    2, BET_NOT_EQ }, // 33 61
+    { "&",     1, BET_AND }, // 38
+    { "&&",    2, BET_AND }, // 38 38
+    { "(",     1, BET_L_BR }, // 40
+    { ")",     1, BET_R_BR }, // 41
+    { "<",     1, BET_LSS_THAN }, // 60
+    { "<=",    2, BET_LSS_EQ }, // 60 61
+    { "<>",    2, BET_NOT_EQ }, // 60 62
+    { "=",     1, BET_EQUAL }, // 61
+    { "==",    2, BET_EQUAL }, // 61 61
+    { ">",     1, BET_GRT_THAN }, // 62
+    { ">=",    2, BET_GRT_EQ }, // 62 61
+    { "and",3, BET_AND }, // 97 110
+    { "or",    2, BET_OR }, // 111 114
+    { "|",     1, BET_OR }, // 124
+    { "||",    2, BET_OR }, // 124 124
+};
+
+TOKEN get_next_token (const char ** string)
+{
+    static int token_cnt = sizeof (token_table) / sizeof (token_table[0]);
+    int i;
+    int first = 0;
+    int last = token_cnt - 1;
+    int compare_res;
+    int found = 0;
+
+    i = (first + last) / 2;
+    while (1)
+    {
+        compare_res = strncmp (*string, token_table[i].token_char, token_table[i].token_length);
+        debugf ("string [%s] token[%s] res = %d i=%d, first=%d, last=%d\n", *string, token_table[i].token_char, compare_res, i, first, last);
+        while (compare_res == 0)
+        {
+            found = 1;
+            i++;
+            if (i == token_cnt)
+                break;
+            compare_res = strncmp (*string, token_table[i].token_char, token_table[i].token_length);
+            debugf ("string [%s] token[%s] res = %d i=%d, first=%d, last=%d\n", *string, token_table[i].token_char, compare_res, i, first, last);
+        }
+        if (found)
+        {
+            i--;
+            *string += token_table[i].token_length;
+
+            return token_table[i].token_name;
+        }
+
+        if (first >= last)
+            break;
+
+        if (compare_res > 0)
+        {
+            first = i + 1;
+        }
+        else
+        {
+            last = i - 1;
+        }
+        i = (first + last) / 2;
+    }
+    if (isalpha (**string))
+    {
+        (*string) ++;
+        while (isalpha (**string) || isdigit (**string) || **string == '_' || **string == '-')
+            (*string) ++;
+        return BET_SYMBOL;
+    }
+    if (isdigit (**string))
+    {
+        (*string) ++;
+        while (isdigit (**string))
+            (*string) ++;
+        return BET_NUMBER;
+
+    }
+
+    return BET_UNKNOWN;
+}
diff --git a/module/ds/bool_exp_tokenizer.h b/module/ds/bool_exp_tokenizer.h
new file mode 100644 (file)
index 0000000..6d3c4df
--- /dev/null
@@ -0,0 +1,38 @@
+/**************************************************************************
+
+xserver-xorg-video-exynos
+
+Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: Boram Park <boram1288.park@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef _BOOL_EXP_TOKENIZER_
+#define _BOOL_EXP_TOKENIZER_
+#include "bool_exp_token.h"
+
+TOKEN get_next_token (const char ** string);
+
+#endif /* _BOOL_EXP_TOKENIZER_ */
+
diff --git a/module/xdbg_module.c b/module/xdbg_module.c
new file mode 100644 (file)
index 0000000..b9ea47f
--- /dev/null
@@ -0,0 +1,117 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <xf86.h>
+
+#include "xdbg_module_main.h"
+#include "xdbg_module_options.h"
+
+MODULESETUPPROTO (xDbgModuleSetup);
+MODULETEARDOWNPROTO (xDbgModuleTearDown);
+
+static XF86ModuleVersionInfo ModuleVersRec =
+{
+    MODULE_NAME,
+    MODULEVENDORSTRING,
+    MODINFOSTRING1,
+    MODINFOSTRING2,
+    XORG_VERSION_CURRENT,
+    PACKAGE_VERSION_MAJOR,
+    PACKAGE_VERSION_MINOR,
+    PACKAGE_VERSION_PATCHLEVEL,
+    ABI_CLASS_NONE,
+    SET_ABI_VERSION (0,1),
+    NULL,
+    {0,0,0,0}
+};
+
+_X_EXPORT XF86ModuleData xdbgModuleData =
+{
+    &ModuleVersRec,
+    xDbgModuleSetup,
+    xDbgModuleTearDown
+};
+
+static XDbgModule module_xdbg;
+
+static void
+_xDbgModuleBlockHandler (pointer data, OSTimePtr pTimeout, pointer pRead)
+{
+    /* _xDbgModuleBlockHandler called only at the first. */
+    RemoveBlockAndWakeupHandlers(_xDbgModuleBlockHandler,
+                                 (WakeupHandlerProcPtr)NoopDDA,
+                                 NULL);
+
+    /* main */
+    xDbgModuleMain (&module_xdbg);
+}
+
+pointer
+xDbgModuleSetup (pointer module, pointer opts, int *errmaj, int *errmin)
+{
+    XF86OptionPtr pOpt = (XF86OptionPtr)opts;
+    static Bool setupDone = FALSE;
+
+    if (!setupDone)
+    {
+        setupDone = TRUE;
+
+        /* Parse Options */
+        xDbgModuleParseOptions (&module_xdbg, pOpt);
+
+        /* Register block handler */
+        RegisterBlockAndWakeupHandlers (_xDbgModuleBlockHandler,
+                                       (WakeupHandlerProcPtr)NoopDDA,
+                                       NULL);
+        return (pointer) 1;
+    }
+    else
+    {
+        if (errmaj)
+            *errmaj = LDR_ONCEONLY;
+
+        return NULL;
+    }
+}
+
+void
+xDbgModuleTearDown (pointer module)
+{
+}
diff --git a/module/xdbg_module_clist.c b/module/xdbg_module_clist.c
new file mode 100644 (file)
index 0000000..31be7e8
--- /dev/null
@@ -0,0 +1,108 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#define XREGISTRY
+#include <registry.h>
+
+#include <xdbg.h>
+
+#include "xdbg_module_types.h"
+
+
+static void
+_findSyncAwait (pointer value, XID id, pointer cdata)
+{
+    Bool *sync_await = cdata;
+
+    if (sync_await)
+        *sync_await = TRUE;
+}
+
+void
+xDbgModuleCList (XDbgModule *pMod, char *reply, int *remain)
+{
+    char *p = reply;
+    int i, len;
+    RESTYPE res_type = 0;
+    const char *name;
+
+    len = snprintf (p, *remain, "%6s   %6s   %s   %s   %s\n", "INDEX", "PID", "SYNC_AWAIT", "BLOCKED", "NAME");
+    p += len;
+    *remain -= len;
+
+    /* get the res_type of SyncAwait */
+    for (i = 0; i < lastResourceType; i++)
+    {
+        name = LookupResourceName(i + 1);
+        if (!strcmp(name, "SyncAwait"))
+        {
+            res_type = i + 1;
+            break;
+        }
+    }
+
+    for (i = 1; i < currentMaxClients && (0 < *remain); i++)
+    {
+        ClientPtr pClient = clients[i];
+        ModuleClientInfo *info;
+        Bool sync_await;
+
+        if (!pClient)
+            continue;
+
+        info = GetClientInfo (pClient);
+        if (!info)
+            continue;
+
+        /* find SyncAwait resources */
+        sync_await = FALSE;
+        FindClientResourcesByType (pClient, res_type, _findSyncAwait, &sync_await);
+
+        len = snprintf (p, *remain, "%6d   %6d    %4d         %4d      %9s\n",
+                        info->index, info->pid, sync_await, pClient->ignoreCount, info->command);
+        p += len;
+        *remain -= len;
+    }
+}
diff --git a/module/xdbg_module_clist.h b/module/xdbg_module_clist.h
new file mode 100644 (file)
index 0000000..ab4dec1
--- /dev/null
@@ -0,0 +1,39 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_MODULE_CLIST_H__
+#define __XDBG_MODULE_CLIST_H__
+
+#include "xdbg_module_types.h"
+
+void xDbgModuleCList (XDbgModule *pMod, char *reply, int *remain);
+
+#endif /* __XDBG_MODULE_CLIST_H__ */
\ No newline at end of file
diff --git a/module/xdbg_module_command.c b/module/xdbg_module_command.c
new file mode 100644 (file)
index 0000000..5c389bd
--- /dev/null
@@ -0,0 +1,456 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <windowstr.h>
+#include <xacestr.h>
+#include <xdbg.h>
+#include <xf86Priv.h>
+#include "xdbg_module_types.h"
+#include "xdbg_module_clist.h"
+#include "xdbg_module_rlist.h"
+#include "xdbg_module_evlog.h"
+#include "xdbg_module_command.h"
+
+static Bool
+_CommandSetLogFile (int pid, char *path, char *reply, int *len, XDbgModule *pMod)
+{
+    static int old_stderr = -1;
+    char fd_name[XDBG_PATH_MAX];
+    int  log_fd = -1;
+
+    if (!path || strlen (path) <= 0)
+    {
+        XDBG_REPLY ("failed: logpath is invalid\n");
+        return FALSE;
+    }
+
+    if (old_stderr == -1)
+        old_stderr = dup (STDERR_FILENO);
+
+    if (!strcmp (path, "console"))
+        snprintf (fd_name, XDBG_PATH_MAX, "/proc/%d/fd/1", pid);
+    else
+    {
+        char *temp[3] = {"/", "./", "../"};
+        Bool valid = FALSE;
+        int i;
+
+        for (i = 0; i < sizeof (temp) / sizeof (char*); i++)
+            if (path == strstr (path, temp[i]))
+            {
+                valid = TRUE;
+                break;
+            }
+
+        if (valid)
+        {
+            if (path[0] == '/')
+                snprintf (fd_name, XDBG_PATH_MAX, "%s", path);
+            else
+            {
+                char cwd[128];
+                if (getcwd (cwd, sizeof (cwd)))
+                    snprintf (fd_name, XDBG_PATH_MAX, "%s/%s", cwd, path);
+                else
+                    snprintf (fd_name, XDBG_PATH_MAX, "%s", path);
+            }
+        }
+        else
+        {
+            XDBG_REPLY ("failed: invalid option(%s)\n", path);
+            return FALSE;
+        }
+    }
+
+    log_fd = open (fd_name, O_CREAT|O_RDWR|O_APPEND, 0755);
+    if (log_fd < 0)
+    {
+        XDBG_REPLY ("failed: open file(%s)\n", fd_name);
+        return FALSE;
+    }
+
+    fflush (stderr);
+    close (STDERR_FILENO);
+    dup2 (log_fd, STDERR_FILENO);
+    close (log_fd);
+
+    if (pMod->real_log_path)
+        free (pMod->real_log_path);
+
+    pMod->real_log_path = strdup (fd_name);
+    XDBG_RETURN_VAL_IF_FAIL (pMod->real_log_path != NULL, FALSE);
+
+    XDBG_REPLY ("log path: %s\n", pMod->real_log_path);
+
+    return TRUE;
+}
+
+
+static void
+_CommandLogPath (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod)
+{
+    if (argc != 3)
+    {
+        XDBG_REPLY ("log path: %s\n", (pMod->real_log_path)?pMod->real_log_path:"stderr");
+        return;
+    }
+
+    _CommandSetLogFile (pid, argv[2], reply, len, pMod);
+}
+
+static void
+_CommandSetLogLevel (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod)
+{
+    Bool ret;
+    char *module_name;
+    int level;
+
+    if (argc < 4)
+    {
+        xDbgLogEnumModules (MODE_WITH_STATUS, reply, len);
+        return;
+    }
+
+    module_name = argv[2];
+    level = atoi (argv[3]);
+
+    if (level < 0 || level >= 5)
+    {
+        XDBG_REPLY ("Error : Not valid log level %d.\n", level);
+        return;
+    }
+
+    ret = xDbgLogSetLevel (xDbgLogGetModule (module_name), level);
+
+    if (ret)
+        XDBG_REPLY ("Log level for module %s was successfully set to %d\n",
+                  module_name, level);
+    else
+        XDBG_REPLY ("Error : An error was occured during log level setting\n");
+}
+
+static void
+_CommandClientList (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod)
+{
+    if (argc != 2)
+    {
+        XDBG_REPLY ("Error : too few arguments\n");
+        return;
+    }
+
+    xDbgModuleCList (pMod, reply, len);
+}
+
+static void
+_CommandResourceList (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod)
+{
+    char* info;
+
+    if (argc != 2)
+    {
+        XDBG_REPLY ("Error : too few arguments\n");
+        return;
+    }
+
+    info = xDbgModuleRList (pMod, reply, len);
+    if (info)
+    {
+        XDBG_REPLY ("%s", info);
+        free (info);
+    }
+}
+
+static void
+_CommandEvlog (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod)
+{
+    int on;
+
+    if (argc != 3)
+    {
+        XDBG_REPLY ("Error : too few arguments\n");
+        return;
+    }
+
+    on = atoi (argv[2]);
+
+    xDbgModuleEvlogPrintEvents (pMod, on, argv[0], reply, len);
+
+    XDBG_REPLY ("Success\n");
+}
+
+static void
+_CommandSetEvlogRule (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod)
+{
+    if (argc < 2)
+    {
+        XDBG_REPLY ("Error : invalid number of arguments.\n");
+        return;
+    }
+
+    xDbgModuleEvlogInfoSetRule (pMod, argc - 2, (const char**)&(argv[2]), reply, len);
+}
+
+static void
+_CommandSetEvlogPath (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod)
+{
+    if (argc != 3)
+    {
+        XDBG_REPLY ("evlog path: %s\n", (pMod->evlog_path)?pMod->evlog_path:"none");
+        return;
+    }
+
+    if (!argv[2] || strlen (argv[2]) <= 0)
+    {
+        XDBG_REPLY ("invalid option\n");
+        return;
+    }
+
+    if (pMod->evlog_path)
+        free (pMod->evlog_path);
+
+    if (!xDbgModuleEvlogSetEvlogPath (pMod, pid, argv[2], reply, len))
+    {
+        XDBG_REPLY ("Error: evlog path(%s)\n", argv[2]);
+        return;
+    }
+
+    pMod->evlog_path = strdup (argv[2]);
+
+    XDBG_REPLY ("evlog path: %s\n", pMod->evlog_path);
+}
+
+static void
+_CommandSetEvlogPrint (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod)
+{
+    char *evlog_path;
+
+    if (!argv[2] || strlen(argv[2]) <= 0)
+        evlog_path = pMod->evlog_path;
+    else
+        evlog_path = argv[2];
+
+    xDbgModuleEvlogPrintEvlog (pMod, pid, evlog_path, reply, len);
+}
+
+
+static struct
+{
+    const char *Cmd;
+    const char *Description;
+    const char *Options;
+
+    int       (*DynamicUsage) (int, char*, int *);
+    const char *DetailedUsage;
+
+    void (*func) (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod);
+} command_proc[] =
+{
+    {
+        "log_path", "to set log path", "[console/filepath]",
+        NULL, "[console/filepath]",
+        _CommandLogPath
+    },
+
+    {
+        "log", "to set loglevel", "[MODULE] [0-4]",
+        (int(*)(int, char*, int*))xDbgLogEnumModules, "[DEBUG:0/TRACE:1/INFO:2/WARNING:3/ERROR:4]",
+        _CommandSetLogLevel
+    },
+
+    {
+        "clist", "to print clients", "",
+        NULL, "",
+        _CommandClientList
+    },
+
+    {
+        "rlist", "to print resource list", "",
+        NULL, "",
+        _CommandResourceList
+    },
+
+    {
+        "evlog", "to print x events", "[0-1]",
+        NULL, "[OFF:0/ON:1]",
+        _CommandEvlog
+    },
+
+    {
+        "evlog_rule", "to set evlog rules", "[add/remove/print]",
+        NULL, "[add allow/deny rules / remove (index) / print]",
+        _CommandSetEvlogRule
+    },
+
+    {
+        "evlog_path", "to set filepath of evlog", "[console/filepath]",
+        NULL, "[console/filepath]",
+        _CommandSetEvlogPath
+    },
+
+    {
+        "evlog_print", "to print evlog file", "[filepath]",
+        NULL, "[filepath]",
+        _CommandSetEvlogPrint
+    },
+};
+
+static void _CommandPrintUsage (char *reply, int *len, const char * exec)
+{
+    int option_cnt = sizeof (command_proc) / sizeof (command_proc[0]);
+    int i;
+
+    XDBG_REPLY ("Usage : %s [cmd] [options]\n", exec);
+    XDBG_REPLY ("     ex)\n");
+
+    for (i=0; i<option_cnt; i++)
+        XDBG_REPLY ("          %s %s %s\n", exec, command_proc[i].Cmd, command_proc[i].Options);
+
+    XDBG_REPLY (" options :\n");
+
+    for (i=0; i<option_cnt; i++)
+    {
+        if (command_proc[i].Cmd && command_proc[i].Description)
+            XDBG_REPLY ("  %s (%s)\n", command_proc[i].Cmd, command_proc[i].Description);
+        else
+            XDBG_REPLY ("  Cmd(%p) or Descriptiont(%p).\n", command_proc[i].Cmd, command_proc[i].Description);
+
+        if (command_proc[i].DynamicUsage)
+        {
+            char dyn[1024];
+            int  dynlen = sizeof (dyn);
+            command_proc[i].DynamicUsage (MODE_NAME_ONLY, dyn, &dynlen);
+            XDBG_REPLY ("     [MODULE:%s]\n", dyn);
+        }
+
+        if (command_proc[i].DetailedUsage)
+            XDBG_REPLY ("     %s\n", command_proc[i].DetailedUsage);
+        else
+            XDBG_REPLY ("  DetailedUsage(%p).\n", command_proc[i].DetailedUsage);
+    }
+}
+
+void
+xDbgModuleCommand (void *data, int argc, char **argv, char *reply, int *len)
+{
+    XDbgModule *pMod = (XDbgModule*)data;
+    int nproc = sizeof (command_proc) / sizeof (command_proc[0]);
+    int i, pid, new_argc;
+    char **new_argv;
+
+    pid = atoi (argv[0]);
+
+    new_argc = argc - 1;
+    new_argv = (char**)malloc (new_argc * sizeof (char*));
+    if (!new_argv)
+    {
+        XDBG_REPLY ("Error : malloc new_argv\n");
+        return;
+    }
+
+    for (i = 0; i < new_argc; i++)
+        new_argv[i] = argv[i+1];
+
+    if (argc < 3)
+    {
+        _CommandPrintUsage (reply, len, new_argv[0]);
+        free (new_argv);
+        return;
+    }
+
+    for (i = 0; i < nproc; i++)
+    {
+        if (!strcmp (new_argv[1], command_proc[i].Cmd) ||
+            (new_argv[1][0] == '-' && !strcmp (1 + new_argv[1], command_proc[i].Cmd)))
+        {
+            command_proc[i].func (pid, new_argc, new_argv, reply, len, pMod);
+            free (new_argv);
+            return;
+        }
+    }
+
+    _CommandPrintUsage (reply, len, new_argv[0]);
+
+    free (new_argv);
+}
+
+Bool
+xDbgModuleCommandInitLogPath (XDbgModule *pMod)
+{
+    char reply[1024];
+    int len = sizeof (reply);
+
+    if (pMod->log_path && strlen (pMod->log_path) > 0)
+    {
+        char newname[XDBG_PATH_MAX];
+        char filename[XDBG_PATH_MAX];
+        struct stat status;
+        char *p = NULL, *last = NULL;
+        int i;
+
+        snprintf (newname, XDBG_PATH_MAX, "%s", pMod->log_path);
+
+        for (i = 0; i < strlen (newname); i++)
+        {
+            p = newname + i;
+            if (*p == '/')
+                last = p;
+        }
+
+        snprintf (filename, XDBG_PATH_MAX, "%s", last + 1);
+        snprintf (last, XDBG_PATH_MAX - (last - newname), "/prev.%s", filename);
+
+        if (!stat (pMod->log_path, &status))
+        {
+            if (rename (pMod->log_path, newname))
+            {
+                XDBG_ERROR (MXDBG, "Failed: rename %s -> %s\n", pMod->log_path, newname);
+                return FALSE;
+            }
+        }
+    }
+
+    if (pMod->log_path)
+        _CommandSetLogFile (0, pMod->log_path, reply, &len, pMod);
+    else
+        _CommandSetLogFile (0, "console", reply, &len, pMod);
+
+    return TRUE;
+}
diff --git a/module/xdbg_module_command.h b/module/xdbg_module_command.h
new file mode 100644 (file)
index 0000000..5192bf1
--- /dev/null
@@ -0,0 +1,40 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_MODULE_COMMAND_H__
+#define __XDBG_MODULE_COMMAND_H__
+
+#include "xdbg_module_types.h"
+
+void xDbgModuleCommand (void *data, int argc, char **argv, char *reply, int *len);
+Bool xDbgModuleCommandInitLogPath (XDbgModule *pMod);
+
+#endif /* __XDBG_MODULE_COMMAND_H__ */
diff --git a/module/xdbg_module_evlog.c b/module/xdbg_module_evlog.c
new file mode 100644 (file)
index 0000000..9a7b69d
--- /dev/null
@@ -0,0 +1,879 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <time.h>
+
+#define __USE_GNU
+#include <sys/socket.h>
+#include <linux/socket.h>
+
+#ifdef HAS_GETPEERUCRED
+# include <ucred.h>
+#endif
+
+#include <xace.h>
+#include <xacestr.h>
+#include <X11/Xatom.h>
+#include <X11/extensions/XI2proto.h>
+#include <windowstr.h>
+
+#include <xdbg.h>
+
+#include "xdbg_module_types.h"
+#include "xdbg_module_evlog.h"
+#include "xdbg_module_evlog_request.h"
+#include "xdbg_module_evlog_event.h"
+#include "bool_exp_rule_checker.h"
+
+#define XREGISTRY
+#include "registry.h"
+
+#define FP1616toDBL(x) ((x) * 1.0 / (1 << 16))
+
+static Bool    xev_trace_on = FALSE;
+static int  xev_trace_fd = -1;
+static int  xev_trace_record_fd = -1;
+static Atom atom_rotate = None;
+static Atom atom_client_pid = None;
+
+RULE_CHECKER rc = NULL;
+
+#define UNKNOWN_EVENT "<unknown>"
+
+typedef enum
+{
+    EVENT,
+    REQUEST,
+    REPLY,
+    FLUSH
+} evtType;
+
+#define EVTDATA_MASK_CLIENT         0x1
+#define EVTDATA_MASK_CLIENT_REQ     0x2
+#define EVTDATA_MASK_EVENT          0x4
+
+static char *evt_type[] = { "Event", "Request", "Reply", "Flush" };
+static char *evt_dir[]  = { "<====", "---->",   "<----", "*****" };
+
+static void _evtPrintF (int fd, const char * format, ...)
+{
+    va_list args;
+
+    va_start (args, format);
+    if (fd < 0)
+        VErrorF (format, args);
+    else
+        vdprintf (fd, format, args);
+    va_end (args);
+}
+
+static void evtGetReqInfo (evtType type, ClientPtr client, xEvent *ev,
+                           int *req_id, const char **req_string,
+                           char **c_cmd, int *c_index, int *c_pid)
+{
+    if (type == REQUEST)
+    {
+        REQUEST(xReq);
+        *req_id = stuff->reqType;
+        if (stuff->reqType < EXTENSION_BASE)
+            *req_string = LookupRequestName (stuff->reqType, 0);
+        else
+            *req_string = LookupRequestName (stuff->reqType, stuff->data);
+    }
+    else if (type == EVENT)
+        *req_string = LookupEventName ((int)(ev->u.u.type));
+
+    if (client)
+    {
+        ModuleClientInfo *info = GetClientInfo (client);
+        *c_index = info->index;
+        *c_pid = info->pid;
+
+        *c_cmd = rindex (info->command, '/');
+        if (*c_cmd == NULL)
+            *c_cmd = info->command;
+        else
+            *c_cmd = *c_cmd + 1;
+    }
+}
+
+static void evtRecord (CARD32 msec, evtType type, ClientPtr client, xEvent *ev)
+{
+    int mask = 0;
+    int write_len = sizeof (int) +
+                    sizeof (CARD32) +
+                    sizeof (evtType) +
+                    sizeof (int);
+
+    if (xev_trace_record_fd < 0)
+        return;
+
+    if (client)
+    {
+        mask |= EVTDATA_MASK_CLIENT;
+        write_len += sizeof (ClientRec);
+
+        if (client->requestBuffer)
+        {
+            mask |= EVTDATA_MASK_CLIENT_REQ;
+            write_len += client->req_len;
+        }
+    }
+
+    if (ev)
+    {
+        mask |= EVTDATA_MASK_EVENT;
+        write_len += sizeof (xEvent);
+    }
+
+    if (write (xev_trace_record_fd, &write_len, sizeof(int)) == -1)
+    {
+        XDBG_ERROR (MXDBG, "failed: write write_len\n");
+        return;
+    }
+    if (write (xev_trace_record_fd, &msec, sizeof(CARD32)) == -1)
+    {
+        XDBG_ERROR (MXDBG, "failed: write msec\n");
+        return;
+    }
+    if (write (xev_trace_record_fd, &type, sizeof(evtType)) == -1)
+    {
+        XDBG_ERROR (MXDBG, "failed: write type\n");
+        return;
+    }
+    if (write (xev_trace_record_fd, &mask, sizeof(int)) == -1)
+    {
+        XDBG_ERROR (MXDBG, "failed: write mask\n");
+        return;
+    }
+
+    if (client)
+    {
+        if (write (xev_trace_record_fd, client, sizeof (ClientRec)) == -1)
+        {
+            XDBG_ERROR (MXDBG, "failed: write client\n");
+            return;
+        }
+        if (client->requestBuffer)
+            if (write (xev_trace_record_fd, client->requestBuffer, client->req_len) == -1)
+            {
+                XDBG_ERROR (MXDBG, "failed: write requestBuffer\n");
+                return;
+            }
+    }
+
+    if (ev)
+        if (write (xev_trace_record_fd, ev, sizeof (xEvent)) == -1)
+        {
+            XDBG_ERROR (MXDBG, "failed: write ev\n");
+            return;
+        }
+}
+
+static void evtPrintF (int fd, CARD32 msec, evtType type, ClientPtr client, xEvent *ev)
+{
+    int   req_id = 0;
+    const char *req_string = "";
+    const char *req_detail = "";
+    char  tempbuf[256] = {0,};
+    char *c_cmd = "";
+    int   c_index = 0;
+    int   c_pid = 0;
+    static CARD32 prev;
+
+    evtGetReqInfo (type, client, ev, &req_id, &req_string, &c_cmd, &c_index, &c_pid);
+
+    if (type == REQUEST)
+    {
+        XDBG_RETURN_IF_FAIL (client != NULL);
+        xDbgModuleEvlogReqeust (client, tempbuf, sizeof (tempbuf));
+        req_detail = tempbuf;
+    }
+    else if (type == EVENT)
+    {
+        XDBG_RETURN_IF_FAIL (ev != NULL);
+        xDbgModuleEvlogEvent (ev, tempbuf, sizeof (tempbuf));
+        req_detail = tempbuf;
+    }
+    else
+        req_detail = req_string;
+
+    _evtPrintF (fd, "[%10.3f][%4ld] %15s(%2d:%4d) %s %7s (%s)\n",
+                msec / 1000.0,
+                msec - prev,
+                c_cmd, c_index, c_pid,
+                evt_dir[type],
+                evt_type[type], req_detail);
+
+    prev = msec;
+}
+
+static void evtPrint (evtType type, ClientPtr client, xEvent *ev)
+{
+    int   req_id = 0;
+    const char *req_string = "";
+    char *c_cmd = "";
+    int   c_index = 0;
+    int   c_pid = 0;
+    CARD32 curr;
+
+    if (xev_trace_on == FALSE)
+        return;
+
+    evtGetReqInfo (type, client, ev, &req_id, &req_string, &c_cmd, &c_index, &c_pid);
+
+    if (rc == NULL)
+        rc = rulechecker_init();
+
+    if (!rulechecker_validate_rule (rc, type, req_id, req_string, c_pid, c_cmd))
+        return;
+
+    curr = GetTimeInMillis ();
+
+    if (xev_trace_record_fd >= 0)
+        evtRecord (curr, type, client, ev);
+    else
+        evtPrintF (xev_trace_fd, curr, type, client, ev);
+}
+
+static void _mergeArgs (char * target, int argc, const char ** argv)
+{
+    int i;
+    int len;
+
+    for (i=0; i<argc; i++)
+    {
+        len = sprintf (target, "%s", argv[i]);
+        target += len;
+
+        if (i != argc - 1)
+            *(target++) = ' ';
+    }
+}
+
+static const char*
+_traceGetWindowName (ClientPtr client, Window window)
+{
+    int rc;
+    WindowPtr pWin;
+    Mask win_mode = DixGetPropAccess, prop_mode = DixReadAccess;
+    Atom property;
+    PropertyPtr pProp;
+    static char winname[128];
+    int datalen;
+
+    rc = dixLookupWindow (&pWin, window, client, win_mode);
+    if (rc != Success)
+        return NULL;
+
+    property = MakeAtom ("WM_NAME", strlen ("WM_NAME"), TRUE);
+    while (pWin)
+    {
+        rc = dixLookupProperty (&pProp, pWin, property, client, prop_mode);
+        if (rc == Success && pProp->data)
+        {
+            datalen = (pProp->size>127) ?127:pProp->size;
+            strncpy (winname, pProp->data, datalen);
+            winname[datalen] = 0;
+
+            return winname;
+        }
+
+        pWin = pWin->parent;
+    }
+
+    return NULL;
+}
+
+static void
+_traceFlush (CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
+{
+    evtPrint (FLUSH, NULL, NULL);
+}
+
+static void
+_traceAReply (CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
+{
+    ReplyInfoRec *pri = (ReplyInfoRec*)calldata;
+
+    evtPrint (REPLY, pri->client, NULL);
+}
+
+static void
+_traceEvent (CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
+{
+    EventInfoRec *pei = (EventInfoRec*)calldata;
+    ClientPtr pClient;
+    ModuleClientInfo *info;
+    int ev; /* event index */
+    static int xi2_opcode = -1;
+    xEvent *pev;
+    static char* ename[]=
+    {
+        "KeyPress",
+        "KeyRelease",
+        "ButtonPress",
+        "ButtonRelease",
+    };
+
+    XDBG_RETURN_IF_FAIL (pei != NULL);
+
+    pClient = pei->client;
+    XDBG_RETURN_IF_FAIL (pClient != NULL);
+
+    pev = pei->events;
+    XDBG_RETURN_IF_FAIL (pev != NULL);
+
+    info = GetClientInfo (pClient);
+    XDBG_RETURN_IF_FAIL (info != NULL);
+
+    for (ev=0; ev < pei->count; ev++, pev++)
+    {
+        int type = pev->u.u.type & 0177;
+
+        if (type < LASTEvent)
+        {
+            switch (type)
+            {
+            case KeyPress:
+            case KeyRelease:
+                XDBG_INFO (MXDBG, "%s(%d)_%d(%s.%d : %s.0x%lx) root(%d,%d) win(%d,%d)\n"
+                        , ename[type-KeyPress], pev->u.u.detail, pev->u.u.type
+                        , info->command, info->pid
+                        , _traceGetWindowName (pClient, pev->u.keyButtonPointer.event), pev->u.keyButtonPointer.event
+                        , pev->u.keyButtonPointer.rootX, pev->u.keyButtonPointer.rootY
+                        , pev->u.keyButtonPointer.eventX, pev->u.keyButtonPointer.eventY);
+                break;
+
+            case ButtonPress:
+            case ButtonRelease:
+                XDBG_INFO (MXDBG, "%s(%d)_%d(%s.%d : %s.0x%lx) root(%d,%d) win(%d,%d)\n"
+                        , ename[type-KeyPress], pev->u.u.detail, pev->u.u.type
+                        , info->command, info->pid
+                        , _traceGetWindowName (pClient, pev->u.keyButtonPointer.event), pev->u.keyButtonPointer.event
+                        , pev->u.keyButtonPointer.rootX, pev->u.keyButtonPointer.rootY
+                        , pev->u.keyButtonPointer.eventX, pev->u.keyButtonPointer.eventY);
+                break;
+            case GenericEvent:
+                if(!xi2_opcode) break;
+                if(xi2_opcode < 0)
+                {
+                    ExtensionEntry *pExt = CheckExtension("XInputExtension");
+                    if(!pExt) xi2_opcode = 0;
+                    else xi2_opcode = pExt->base;
+                }
+
+                if(((xGenericEvent*)pev)->extension != xi2_opcode) break;
+
+                xXIDeviceEvent *xidev = (xXIDeviceEvent *)pev;
+                if(xidev->deviceid==2) break;
+                if(xidev->evtype==XI_ButtonPress)
+                    XDBG_TRACE (MXDBG, "XI_ButtonPress(%d) device(%d), event win(0x%x), child(0x%x), root(%.f,%.f), win(%.f, %.f)\n", XI_ButtonPress, xidev->deviceid, xidev->event, xidev->child, FP1616toDBL(xidev->root_x), FP1616toDBL(xidev->root_y), FP1616toDBL(xidev->event_x), FP1616toDBL(xidev->event_y));
+                else if(xidev->evtype==XI_ButtonRelease)
+                    XDBG_TRACE (MXDBG, "XI_ButtonRelease(%d) device(%d), event win(0x%x), child(0x%x), root(%.f,%.f), win(%.f, %.f)\n", XI_ButtonRelease,  xidev->deviceid, xidev->event, xidev->child, FP1616toDBL(xidev->root_x), FP1616toDBL(xidev->root_y), FP1616toDBL(xidev->event_x), FP1616toDBL(xidev->event_y));
+                else if(xidev->evtype==XI_Motion)
+                    XDBG_TRACE (MXDBG, "XI_Motion(%d) device(%d), event win(0x%x), child(0x%x), root(%.f,%.f), win(%.f, %.f)\n", XI_Motion, xidev->deviceid, xidev->event, xidev->child, FP1616toDBL(xidev->root_x), FP1616toDBL(xidev->root_y), FP1616toDBL(xidev->event_x), FP1616toDBL(xidev->event_y));
+                break;
+            default:
+                break;
+            }
+        }
+
+        evtPrint (EVENT, pClient, pev);
+    }
+}
+
+static void
+_traceACoreEvents (CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    XaceCoreDispatchRec *rec = calldata;
+
+    XDBG_RETURN_IF_FAIL (rec != NULL);
+
+    evtPrint (REQUEST, rec->client, NULL);
+}
+
+static void
+_traceAExtEvents (CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    XaceExtAccessRec *rec = calldata;
+
+    XDBG_RETURN_IF_FAIL (rec != NULL);
+
+    evtPrint (REQUEST, rec->client, NULL);
+}
+
+static void
+_traceProperty (CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    XacePropertyAccessRec *rec = calldata;
+    ModuleClientInfo *info = GetClientInfo (rec->client);
+    PropertyPtr pProp = *rec->ppProp;
+    Atom name = pProp->propertyName;
+
+    /* Don't care about the new content check */
+    if (rec->client == serverClient || rec->access_mode & DixPostAccess)
+        return;
+
+    if (name == atom_client_pid && (rec->access_mode & DixWriteAccess))
+    {
+        XDBG_WARNING (MXDBG, "Invalid access X_CLINET_PID pid:%d, uid:%d\n", info->pid, info->uid);
+        rec->status = BadAccess;
+        return;
+    }
+
+    rec->status = Success;
+    return;
+}
+
+static void
+_traceResource (CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    XaceResourceAccessRec *rec = calldata;
+    Mask access_mode = rec->access_mode;
+    ModuleClientInfo *info = GetClientInfo (rec->client);
+
+    /* Perform the background none check on windows */
+    if (access_mode & DixCreateAccess && rec->rtype == RT_WINDOW)
+    {
+        WindowPtr pWin = (WindowPtr) rec->res;
+        int rc;
+        int pid = info->pid;
+
+        rc = dixChangeWindowProperty (serverClient,
+                                      pWin, atom_client_pid, XA_CARDINAL, 32,
+                                      PropModeReplace, 1, &pid, FALSE);
+        if (rc != Success)
+            XDBG_ERROR (MXDBG, "failed : set X_CLIENT_PID to %d.\n", pid);
+    }
+}
+
+static void
+_traceReceive (CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    XaceReceiveAccessRec *rec = calldata;
+
+    if (rec->events->u.u.type != VisibilityNotify)
+        return;
+
+    rec->status = BadAccess;
+}
+
+Bool
+xDbgModuleEvlogInstallHooks (XDbgModule *pMod)
+{
+    int ret = TRUE;
+
+    ret &= AddCallback (&EventCallback, _traceEvent, NULL);
+    ret &= AddCallback (&FlushCallback, _traceFlush, NULL);
+    ret &= AddCallback (&ReplyCallback, _traceAReply, NULL);
+    ret &= XaceRegisterCallback (XACE_PROPERTY_ACCESS, _traceProperty, NULL);
+    ret &= XaceRegisterCallback (XACE_RESOURCE_ACCESS, _traceResource, NULL);
+
+    /*Disable Visibility Event*/
+    ret &= XaceRegisterCallback (XACE_RECEIVE_ACCESS, _traceReceive, NULL);
+
+    if (atom_client_pid == None)
+        atom_client_pid = MakeAtom ("X_CLIENT_PID", 12, TRUE);
+    if (atom_rotate == None)
+        atom_rotate = MakeAtom ("_E_ILLUME_ROTATE_ROOT_ANGLE", 12, TRUE);
+
+    if (!ret)
+    {
+        XDBG_ERROR (MXDBG, "failed: register one or more callbacks\n");
+        return FALSE;
+    }
+
+    if (pMod->evlog_path)
+        xDbgModuleEvlogSetEvlogPath (pMod, -1, pMod->evlog_path, NULL, NULL);
+
+    return TRUE;
+}
+
+void
+xDbgModuleEvlogUninstallHooks (XDbgModule *pMod)
+{
+    DeleteCallback (&EventCallback, _traceEvent, NULL);
+    DeleteCallback (&FlushCallback, _traceFlush, NULL);
+    DeleteCallback (&ReplyCallback, _traceAReply, NULL);
+    XaceDeleteCallback (XACE_PROPERTY_ACCESS, _traceProperty, NULL);
+    XaceDeleteCallback (XACE_RESOURCE_ACCESS, _traceResource, NULL);
+}
+
+void
+xDbgModuleEvlogPrintEvents (XDbgModule *pMod, Bool on, const char * client_name, char *reply, int *len)
+{
+    int ret = TRUE;
+
+    xev_trace_on = on;
+
+    if (xev_trace_on)
+    {
+        int i;
+
+        //Find client's pid
+        for (i=1 ; i< currentMaxClients ; i++)
+        {
+            ClientPtr pClient;
+            ModuleClientInfo *info;
+
+            pClient = clients[i];
+            if (!pClient)
+                continue;
+
+            info = GetClientInfo (pClient);
+            if (!info)
+                continue;
+
+            if (strlen (info->command) > 0 && strstr (client_name, info->command))
+            {
+                char fd_name[256];
+
+                if (xev_trace_fd >= 0)
+                    close (xev_trace_fd);
+
+                snprintf (fd_name, 256, "/proc/%d/fd/1", info->pid);
+                xev_trace_fd = open (fd_name, O_RDWR);
+                if (xev_trace_fd < 0)
+                    XDBG_REPLY ("failed: open consol '%s'. (%s)\n", fd_name, strerror(errno));
+            }
+        }
+
+
+        ret &= XaceRegisterCallback (XACE_CORE_DISPATCH, _traceACoreEvents, NULL);
+        ret &= XaceRegisterCallback (XACE_EXT_DISPATCH, _traceAExtEvents, NULL);
+
+        if (!ret)
+        {
+            XDBG_REPLY ("failed: register one or more callbacks.\n");
+            return;
+        }
+    }
+    else
+    {
+        XaceDeleteCallback (XACE_CORE_DISPATCH, _traceACoreEvents, NULL);
+        XaceDeleteCallback (XACE_EXT_DISPATCH, _traceAExtEvents, NULL);
+    }
+
+    return;
+}
+
+int
+xDbgModuleEvlogInfoSetRule (XDbgModule *pMod, const int argc, const char ** argv, char *reply, int *len)
+{
+    const char * command;
+
+    if (rc == NULL)
+        rc = rulechecker_init();
+
+    if (argc == 0)
+    {
+        rulechecker_print_rule (rc, reply);
+        return 0;
+    }
+
+    command = argv[0];
+
+    if (!strcasecmp (command, "add"))
+    {
+        POLICY_TYPE policy_type;
+        RC_RESULT_TYPE result;
+        const char * policy = argv[1];
+        char rule[8192];
+
+        if (argc < 3)
+        {
+            XDBG_REPLY ("Error : Too few arguments.\n");
+            return -1;
+        }
+
+        if (!strcasecmp (policy, "ALLOW"))
+            policy_type = ALLOW;
+        else if (!strcasecmp (policy, "DENY"))
+            policy_type = DENY;
+        else
+        {
+            XDBG_REPLY ("Error : Unknown policy : [%s].\n          Policy should be ALLOW or DENY.\n", policy);
+            return -1;
+        }
+
+        _mergeArgs (rule, argc - 2, &(argv[2]));
+
+        result = rulechecker_add_rule (rc, policy_type, rule);
+        if (result == RC_ERR_TOO_MANY_RULES)
+        {
+            XDBG_REPLY ("Error : Too many rules were added.\n");
+            return -1;
+        }
+        else if (result == RC_ERR_PARSE_ERROR)
+        {
+            XDBG_REPLY ("Error : An error occured during parsing the rule [%s]\n", rule);
+            return -1;
+        }
+
+        XDBG_REPLY ("The rule was successfully added.\n\n");
+        rulechecker_print_rule (rc, reply);
+        return 0;
+    }
+    else if (!strcasecmp (command, "remove"))
+    {
+        const char * remove_idx;
+        int i;
+
+        if (argc < 2)
+        {
+            XDBG_REPLY ("Error : Too few arguments.\n");
+            return -1;
+        }
+
+        for (i=0; i<argc - 1; i++)
+        {
+            remove_idx = argv[i+1];
+
+            if (!strcasecmp (remove_idx, "all"))
+            {
+                rulechecker_destroy (rc);
+                rc = rulechecker_init();
+                XDBG_REPLY ("Every rules were successfully removed.\n");
+            }
+            else
+            {
+                int index = atoi (remove_idx);
+                if (isdigit (*remove_idx) && rulechecker_remove_rule (rc, index) == 0)
+                    XDBG_REPLY ("The rule [%d] was successfully removed.\n", index);
+                else
+                    XDBG_REPLY ("Rule remove fail : No such rule [%s].\n", remove_idx);
+            }
+        }
+        rulechecker_print_rule (rc, reply);
+        return 0;
+    }
+    else if (!strcasecmp (command, "print"))
+    {
+        rulechecker_print_rule (rc, reply);
+        return 0;
+    }
+    else if (!strcasecmp (command, "help"))
+    {
+        XDBG_REPLY ("%s", rulechecker_print_usage());
+        return 0;
+    }
+
+    XDBG_REPLY ("%s\nUnknown command : [%s].\n\n", rulechecker_print_usage(), command);
+
+    return 0;
+}
+
+Bool
+xDbgModuleEvlogSetEvlogPath (XDbgModule *pMod, int pid, char *path, char *reply, int *len)
+{
+    char fd_name[XDBG_PATH_MAX];
+    char *temp[3] = {"/", "./", "../"};
+    Bool valid = FALSE;
+    int i;
+
+    if (!path || strlen (path) <= 0)
+    {
+        XDBG_REPLY ("failed: invalid path\n");
+        return FALSE;
+    }
+
+    if (xev_trace_record_fd >= 0)
+    {
+        close (xev_trace_record_fd);
+        xev_trace_record_fd = -1;
+    }
+
+    if (!strcmp (path, "console"))
+    {
+        if (pid > 0)
+        {
+            char fd_name[256];
+
+            if (xev_trace_fd >= 0)
+                close (xev_trace_fd);
+
+            snprintf (fd_name, sizeof (fd_name), "/proc/%d/fd/1", pid);
+
+            xev_trace_fd = open (fd_name, O_RDWR);
+            if (xev_trace_fd < 0)
+                XDBG_REPLY ("failed: open consol '%s'. (%s)\n", fd_name, strerror(errno));
+        }
+
+        return TRUE;
+    }
+
+    for (i = 0; i < sizeof (temp) / sizeof (char*); i++)
+        if (path == strstr (path, temp[i]))
+        {
+            valid = TRUE;
+            break;
+        }
+
+    if (!valid)
+    {
+        XDBG_REPLY ("failed: invalid path(%s)\n", path);
+        return FALSE;
+    }
+
+    if (path[0] == '/')
+        snprintf (fd_name, XDBG_PATH_MAX, "%s", path);
+    else
+    {
+        char cwd[128];
+        if (getcwd (cwd, sizeof (cwd)))
+            snprintf (fd_name, XDBG_PATH_MAX, "%s/%s", cwd, path);
+        else
+            snprintf (fd_name, XDBG_PATH_MAX, "%s", path);
+    }
+
+    xev_trace_record_fd = open (fd_name, O_CREAT|O_RDWR|O_APPEND, 0755);
+    if (xev_trace_record_fd < 0)
+    {
+        XDBG_REPLY ("failed: open file '%s'. (%s)\n", fd_name, strerror(errno));
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+void
+xDbgModuleEvlogPrintEvlog (XDbgModule *pMod, int pid, char *evlog_path, char *reply, int *len)
+{
+    int fd = -1, cfd = -1;
+    int total, read_len;
+    int evlog_len;
+    pointer requestBuffer = NULL;
+    char fd_name[256];
+
+    if (evlog_path)
+    {
+        XDBG_REPLY ("failed: no evlog path\n");
+        return;
+    }
+
+    fd = open (evlog_path, O_RDONLY);
+    if (fd < 0)
+    {
+        XDBG_REPLY ("failed: open '%s'. (%s)\n", evlog_path, strerror(errno));
+        return;
+    }
+
+    snprintf (fd_name, sizeof (fd_name), "/proc/%d/fd/1", pid);
+    cfd = open (fd_name, O_RDWR);
+    if (cfd < 0)
+    {
+        XDBG_REPLY ("failed: open consol '%s'. (%s)\n", fd_name, strerror(errno));
+        goto print_done;
+    }
+
+    while ((read_len = read (fd, &evlog_len, sizeof (int))) == sizeof (int))
+    {
+        CARD32 msec;
+        evtType type;
+        int mask;
+        ClientRec client;
+        xEvent ev;
+
+        total = read_len;
+
+        read_len = read (fd, &msec, sizeof (CARD32));
+        XDBG_GOTO_IF_FAIL (read_len == sizeof (CARD32), print_done);
+        total += read_len;
+
+        read_len = read (fd, &type, sizeof (evtType));
+        XDBG_GOTO_IF_FAIL (read_len == sizeof (evtType), print_done);
+        total += read_len;
+
+        read_len = read (fd, &mask, sizeof (int));
+        XDBG_GOTO_IF_FAIL (read_len == sizeof (int), print_done);
+        total += read_len;
+
+        if (mask & EVTDATA_MASK_CLIENT)
+        {
+            read_len = read (fd, &client, sizeof (ClientRec));
+            XDBG_GOTO_IF_FAIL (read_len == sizeof (ClientRec), print_done);
+            total += read_len;
+
+            if (mask & EVTDATA_MASK_CLIENT_REQ && client.req_len > 0)
+            {
+                requestBuffer = malloc (client.req_len);
+                XDBG_GOTO_IF_FAIL (requestBuffer != NULL, print_done);
+
+                read_len = read (fd, requestBuffer, client.req_len);
+                XDBG_GOTO_IF_FAIL (read_len == client.req_len, print_done);
+                total += read_len;
+
+                client.requestBuffer = requestBuffer;
+            }
+        }
+
+        if (mask & EVTDATA_MASK_EVENT)
+        {
+            read_len = read (fd, &ev, sizeof (xEvent));
+            XDBG_GOTO_IF_FAIL (read_len == sizeof (xEvent), print_done);
+            total += read_len;
+        }
+
+        XDBG_GOTO_IF_FAIL (evlog_len == total, print_done);
+
+        evtPrintF (cfd, msec, type, &client, &ev);
+
+        if (requestBuffer)
+        {
+            free (requestBuffer);
+            requestBuffer = NULL;
+        }
+    }
+
+print_done:
+    if (requestBuffer)
+        free (requestBuffer);
+
+    if (cfd >= 0)
+        close (cfd);
+
+    if (fd >= 0)
+        close (fd);
+}
diff --git a/module/xdbg_module_evlog.h b/module/xdbg_module_evlog.h
new file mode 100644 (file)
index 0000000..e98b251
--- /dev/null
@@ -0,0 +1,46 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_MODULE_EVLOG_H__
+#define __XDBG_MODULE_EVLOG_H__
+
+#include "xdbg_module_types.h"
+
+Bool    xDbgModuleEvlogInstallHooks   (XDbgModule *pMod);
+void    xDbgModuleEvlogUninstallHooks (XDbgModule *pMod);
+
+void    xDbgModuleEvlogPrintEvents (XDbgModule *pMod, Bool on, const char * client_name, char *reply, int *len);
+int     xDbgModuleEvlogInfoSetRule (XDbgModule *pMod, const int argc, const char ** argv, char *reply, int *len);
+
+Bool    xDbgModuleEvlogSetEvlogPath  (XDbgModule *pMod, int pid, char *path, char *reply, int *len);
+void    xDbgModuleEvlogPrintEvlog    (XDbgModule *pMod, int pid, char *evlog_path, char *reply, int *len);
+
+#endif /* __XDBG_MODULE_EVLOG_H__ */
diff --git a/module/xdbg_module_evlog_event.c b/module/xdbg_module_evlog_event.c
new file mode 100644 (file)
index 0000000..a608546
--- /dev/null
@@ -0,0 +1,117 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <dix.h>
+#define XREGISTRY
+#include <registry.h>
+#include <xace.h>
+#include <xacestr.h>
+#include <X11/Xatom.h>
+#include <X11/extensions/damageproto.h>
+#include <X11/extensions/damagewire.h>
+#include <X11/extensions/XI2proto.h>
+#include <windowstr.h>
+
+#include <xdbg.h>
+
+#include "xdbg_module_types.h"
+#include "xdbg_module_evlog_request.h"
+
+#define UNKNOWN_EVENT "<unknown>"
+
+static ExtensionEntry *damage;
+
+static Bool
+_EvlogEventGetExtentionEntry (void)
+{
+    static int init = 0;
+    static Bool success = FALSE;
+
+    if (init)
+        return success;
+
+    init = 1;
+
+    damage = CheckExtension (DAMAGE_NAME); 
+    XDBG_RETURN_VAL_IF_FAIL (damage != NULL, FALSE);
+
+    success = TRUE;
+
+    return success;
+}
+
+Bool
+xDbgModuleEvlogEvent (xEvent *ev, char *buf, int remain)
+{
+    const char *evt_name;
+    int len;
+
+    if (!_EvlogEventGetExtentionEntry ())
+        return FALSE;
+
+    evt_name = LookupEventName ((int)(ev->u.u.type));
+    len = snprintf (buf, remain, "%s", evt_name);
+    buf += len;
+    remain -= len;
+
+    if (ev->u.u.type == damage->eventBase + XDamageNotify)
+    {
+        xDamageNotifyEvent *damage_e = (xDamageNotifyEvent*)ev;
+        snprintf (buf, remain, ": XID(%lx) area(%d,%d %dx%d) geo(%d,%d %dx%d)",
+            damage_e->drawable,
+            damage_e->area.x,
+            damage_e->area.y,
+            damage_e->area.width,
+            damage_e->area.height,
+            damage_e->geometry.x,
+            damage_e->geometry.y,
+            damage_e->geometry.width,
+            damage_e->geometry.height);
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
diff --git a/module/xdbg_module_evlog_event.h b/module/xdbg_module_evlog_event.h
new file mode 100644 (file)
index 0000000..6bb2096
--- /dev/null
@@ -0,0 +1,39 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_MODULE_EVLOG_EVENT_H__
+#define __XDBG_MODULE_EVLOG_EVENT_H__
+
+#include "xdbg_module_types.h"
+
+Bool  xDbgModuleEvlogEvent (xEvent *ev, char *buf, int remain);
+
+#endif /* __XDBG_MODULE_EVLOG_EVENT_H__ */
diff --git a/module/xdbg_module_evlog_request.c b/module/xdbg_module_evlog_request.c
new file mode 100644 (file)
index 0000000..0b4018f
--- /dev/null
@@ -0,0 +1,167 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <dix.h>
+#define XREGISTRY
+#include <registry.h>
+#include <xace.h>
+#include <xacestr.h>
+#include <X11/Xatom.h>
+#include <X11/extensions/XI2proto.h>
+#include <windowstr.h>
+
+#include <xdbg.h>
+
+#include "xdbg_module_types.h"
+#include "xdbg_module_evlog_request.h"
+
+#define UNKNOWN_EVENT "<unknown>"
+
+static ExtensionEntry *xext;
+
+static Bool
+_EvlogRequestGetExtentionEntry (void)
+{
+    static int init = 0;
+    static Bool success = FALSE;
+
+    if (init)
+        return success;
+
+    init = 1;
+
+    xext = CheckExtension (SHMNAME); 
+    XDBG_RETURN_VAL_IF_FAIL (xext != NULL, FALSE);
+
+    success = TRUE;
+
+    return success;
+}
+
+static Bool
+_EvlogRequestCore (ClientPtr client, char *buf, int remain)
+{
+    REQUEST(xReq);
+    switch (stuff->reqType)
+    {
+    case X_PutImage:
+        {
+            REQUEST(xPutImageReq);
+            snprintf (buf, remain, ": XID(%lx) size(%dx%d) dst(%d,%d)",
+                stuff->drawable,
+                stuff->width,
+                stuff->height,
+                stuff->dstX,
+                stuff->dstY);
+            return TRUE;
+        }
+    default:
+            break;
+    }
+
+    return FALSE;
+}
+
+static Bool
+_EvlogRequestShm (ClientPtr client, char *buf, int remain)
+{
+    REQUEST(xReq);
+    switch (stuff->data)
+    {
+    case X_ShmPutImage:
+        {
+            REQUEST(xShmPutImageReq);
+            snprintf (buf, remain, ": XID(%lx) size(%dx%d) src(%d,%d %dx%d) dst(%d,%d)",
+                stuff->drawable,
+                stuff->totalWidth,
+                stuff->totalHeight,
+                stuff->srcX,
+                stuff->srcY,
+                stuff->srcWidth,
+                stuff->srcHeight,
+                stuff->dstX,
+                stuff->dstY);
+            return TRUE;
+        }
+    default:
+            break;
+    }
+
+    return FALSE;
+}
+
+Bool
+xDbgModuleEvlogReqeust (ClientPtr client, char *buf, int remain)
+{
+    const char *req_name;
+    int len;
+
+    if (!_EvlogRequestGetExtentionEntry ())
+        return FALSE;
+
+    REQUEST(xReq);
+
+    if (stuff->reqType < EXTENSION_BASE)
+    {
+        req_name = LookupRequestName (stuff->reqType, 0);
+        len = snprintf (buf, remain, "%s", req_name);
+        buf += len;
+        remain -= len;
+
+        return _EvlogRequestCore (client, buf, remain);
+    }
+    else
+    {
+        req_name = LookupRequestName (stuff->reqType, stuff->data);
+        len = snprintf (buf, remain, "%s", req_name);
+        buf += len;
+        remain -= len;
+
+        if (stuff->reqType == xext->base)
+           return _EvlogRequestShm (client, buf, remain);
+    }
+
+    return FALSE;
+}
diff --git a/module/xdbg_module_evlog_request.h b/module/xdbg_module_evlog_request.h
new file mode 100644 (file)
index 0000000..f299dce
--- /dev/null
@@ -0,0 +1,39 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_MODULE_EVLOG_REQUEST_H__
+#define __XDBG_MODULE_EVLOG_REQUEST_H__
+
+#include "xdbg_module_types.h"
+
+Bool  xDbgModuleEvlogReqeust (ClientPtr pClient, char *buf, int remain);
+
+#endif /* __XDBG_MODULE_EVLOG_REQUEST_H__ */
diff --git a/module/xdbg_module_main.c b/module/xdbg_module_main.c
new file mode 100644 (file)
index 0000000..f23b491
--- /dev/null
@@ -0,0 +1,193 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <windowstr.h>
+#include <xacestr.h>
+#include <xdbg.h>
+
+#include "xdbg_dbus_server.h"
+#include "xdbg_module_types.h"
+#include "xdbg_module_command.h"
+#include "xdbg_module_evlog.h"
+
+#define __USE_GNU
+#include <sys/socket.h>
+
+DevPrivateKeyRec debug_client_key;
+
+static XDbgDbusServerMethod method;
+
+static void
+_debugClientInfo (ClientPtr client)
+{
+    int fd = XaceGetConnectionNumber (client);
+    ModuleClientInfo *info = GetClientInfo (client);
+
+    /* For local clients, try and determine the executable name */
+    if (XaceIsLocal (client))
+    {
+        struct ucred creds;
+        socklen_t len = sizeof (creds);
+        char path[PATH_MAX + 1] = {0,};
+        int bytes;
+
+        memset (&creds, 0, sizeof (creds));
+        if (getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &creds, &len) < 0)
+            goto finish;
+
+        snprintf (path, PATH_MAX + 1, "/proc/%d/cmdline", creds.pid);
+        fd = open (path, O_RDONLY);
+        if (fd < 0)
+            goto finish;
+
+        bytes = read (fd, path, PATH_MAX + 1);
+        close (fd);
+        if (bytes <= 0)
+            goto finish;
+
+        strncpy (info->command, path, PATH_MAX);
+
+        info->pid = creds.pid;
+        info->uid = creds.uid;
+        info->gid = creds.gid;
+        info->conn_fd = fd;
+        info->index = client->index;
+    }
+    else
+    {
+        info->pid = -1;
+        info->index = client->index;
+        strncpy (info->command, "REMOTE", PATH_MAX);
+    }
+
+    return;
+
+finish:
+    XDBG_ERROR (MXDBG, "Failed to make client info(index:%d)\n",
+                 client->index);
+    return;
+}
+
+static void
+_traceClientState (CallbackListPtr *list, pointer closure, pointer calldata)
+{
+    NewClientInfoRec *clientinfo = (NewClientInfoRec*)calldata;
+    ClientPtr client = clientinfo->client;
+    ModuleClientInfo *info = GetClientInfo (client);
+    static char* clientState[]=
+    {
+        "ClientStateInitial",
+        "ClientStateAuthenticating",
+        "ClientStateRunning",
+        "ClientStateRetained",
+        "ClientStateGone",
+        "ClientStateCheckingDebug",
+        "ClientStateCheckedDebug"
+    };
+
+    if (!info)
+        return;
+
+    if ((client->clientState == ClientStateInitial) || (client->clientState == ClientStateGone))
+    {
+        if (client->clientState == ClientStateInitial)
+              _debugClientInfo (client);
+
+        XDBG_INFO (MXDBG, "id:%d, conn_fd:%d, pid:%d, uid:%d, name:%s (%s)\n",
+              info->index, info->conn_fd, info->pid, info->uid, info->command,
+              clientState[client->clientState]);
+        return;
+    }
+
+    XDBG_DEBUG (MXDBG, "id:%d, conn_fd:%d, pid:%d, uid:%d, name:%s (%s)\n",
+                 info->index, info->conn_fd, info->pid, info->uid, info->command,
+                 clientState[client->clientState]);
+}
+
+Bool
+xDbgModuleMain (XDbgModule *pMod)
+{
+    Bool ret = TRUE;
+
+    if (!dixRegisterPrivateKey (DebugClientKey, PRIVATE_CLIENT, sizeof (ModuleClientInfo)))
+    {
+        XDBG_ERROR (MXDBG, "failed: dixRegisterPrivateKey\n");
+        return FALSE;
+    }
+
+    ret &= AddCallback (&ClientStateCallback, _traceClientState, pMod);
+
+    if (!ret)
+    {
+        XDBG_ERROR (MXDBG, "failed: AddCallback\n");
+        return FALSE;
+    }
+
+    xDbgModuleEvlogInstallHooks (pMod);
+
+    if (!xDbgDBusServerConnect ())
+    {
+        XDBG_ERROR (MXDBG, "failed: xDbgDBusServerConnect\n");
+        return FALSE;
+    }
+
+    if (!xDbgModuleCommandInitLogPath (pMod))
+    {
+        XDBG_ERROR (MXDBG, "failed: xDbgModuleInitLogPath\n");
+        return FALSE;
+    }
+
+    snprintf (method.name, sizeof (method.name), "%s", XDBG_DBUS_METHOD);
+    method.func = xDbgModuleCommand;
+    method.data = pMod;
+
+    xDbgDBusServerAddMethod (&method);
+
+    return TRUE;
+}
+
+void
+xDbgModuleMainExit (XDbgModule *pMod)
+{
+    DeleteCallback (&ClientStateCallback, _traceClientState, pMod);
+
+    xDbgModuleEvlogUninstallHooks (pMod);
+
+    xDbgDBusServerRemoveMethod (&method);
+
+    xDbgDBusServerDisconnect ();
+}
diff --git a/module/xdbg_module_main.h b/module/xdbg_module_main.h
new file mode 100644 (file)
index 0000000..32001d4
--- /dev/null
@@ -0,0 +1,40 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_MODULE_MAIN_H__
+#define __XDBG_MODULE_MAIN_H__
+
+#include "xdbg_module_types.h"
+
+Bool    xDbgModuleMain     (XDbgModule *pMod);
+void    xDbgModuleMainExit (XDbgModule *pMod);
+
+#endif /* __XDBG_MODULE_MAIN_H__ */
diff --git a/module/xdbg_module_options.c b/module/xdbg_module_options.c
new file mode 100644 (file)
index 0000000..f6a5bea
--- /dev/null
@@ -0,0 +1,85 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <xdbg.h>
+
+#include "xdbg_module_types.h"
+
+/* Supported options */
+typedef enum
+{
+    OPTION_LOG_PATH,
+    OPTION_EVLOG_PATH,
+} ModuleOption;
+
+static const OptionInfoRec module_options[] =
+{
+    { OPTION_LOG_PATH,         "log_path",                     OPTV_STRING,    {0},    FALSE },
+    { OPTION_EVLOG_PATH,       "evlog_path",           OPTV_STRING,    {0},    FALSE },
+    { -1,                              NULL,                           OPTV_NONE,              {0},    FALSE }
+};
+
+void
+xDbgModuleParseOptions (XDbgModule *pMod, XF86OptionPtr pOpt)
+{
+    OptionInfoPtr options = xnfalloc (sizeof (module_options));
+    char *log_path;
+
+    memcpy (options, module_options, sizeof(module_options));
+
+    xf86ProcessOptions (-1, pOpt, options);
+
+    /* log_path */
+    log_path = xf86GetOptValString (options, OPTION_LOG_PATH);
+    if (log_path)
+    {
+        XDBG_SLOG (MXDBG, "drv's log path: \"%s\"\n", log_path);
+        pMod->log_path = strdup (log_path);
+    }
+    else
+        XDBG_SLOG (MXDBG, "drv's log path: none\n");
+
+    /* evlog_path */
+    log_path = xf86GetOptValString (options, OPTION_EVLOG_PATH);
+    if (log_path)
+    {
+        XDBG_SLOG (MXDBG, "evlog path: \"%s\"\n", log_path);
+        pMod->evlog_path = strdup (log_path);
+    }
+    else
+        XDBG_SLOG (MXDBG, "evlog path: none\n");
+
+    free (options);
+}
diff --git a/module/xdbg_module_options.h b/module/xdbg_module_options.h
new file mode 100644 (file)
index 0000000..1e28c8c
--- /dev/null
@@ -0,0 +1,39 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_MODULE_OPTIONS_H__
+#define __XDBG_MODULE_OPTIONS_H__
+
+#include "xdbg_module_types.h"
+
+void    xDbgModuleParseOptions (XDbgModule *pMod, XF86OptionPtr pOpt);
+
+#endif /* __XDBG_MODULE_OPTIONS_H__ */
diff --git a/module/xdbg_module_rlist.c b/module/xdbg_module_rlist.c
new file mode 100644 (file)
index 0000000..72c01d3
--- /dev/null
@@ -0,0 +1,222 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#define __USE_GNU
+#include <sys/socket.h>
+#include <linux/socket.h>
+
+#ifdef HAS_GETPEERUCRED
+# include <ucred.h>
+#endif
+
+#include <xace.h>
+#include <xacestr.h>
+#include <X11/Xatom.h>
+#include <X11/extensions/XI2proto.h>
+#include <windowstr.h>
+
+#define XREGISTRY
+#include <registry.h>
+
+#include <compositeext.h>
+#include <xdbg.h>
+
+#include "xdbg_module_types.h"
+
+
+#if 0
+static int sum_pix_size = 0;
+
+static void
+_findRtWindow (pointer value, XID id, pointer cdata)
+{
+    WindowPtr pWin = value;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+
+    if (pWin->viewable && pWin->realized)
+    {
+        ErrorF ("xid:0x%x geo:(%5d,%5d,%5d,%5d) bpp:%2d viewable:%d realized:%d ",
+                         (unsigned int)id,
+                         pWin->drawable.x, pWin->drawable.y, pWin->drawable.width, pWin->drawable.height,
+                         pWin->drawable.bitsPerPixel,
+                         pWin->viewable,
+                         pWin->realized);
+        if (pWin->parent->parent)
+            ErrorF ("border_id:0x%x ",(unsigned int)(pWin->parent->parent)->drawable.id);
+
+        PixmapPtr pPixmap = (*pScreen->GetWindowPixmap) (pWin);
+        PixmapPtr pScrnPixmap = (*pScreen->GetScreenPixmap) (pScreen);
+        if (pPixmap == pScrnPixmap)
+        {
+            ErrorF ("flip_draw:1 ");
+        }
+
+        ErrorF ("\n");
+    }
+}
+
+static void
+_findRtCompWindow (pointer value, XID id, pointer cdata)
+{
+    WindowPtr pWin = value;
+    WindowPtr pChild = NULL;
+    WindowPtr pGrandChild = NULL;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    SECPtr pSec = SECPTR (pScrn);
+    PropertyPtr pProp = NULL;
+    int rc;
+
+    if (pWin->viewable && pWin->realized)
+    {
+        ErrorF ("xid:0x%x geo:(%5d,%5d,%5d,%5d) bpp:%2d viewable:%d realized:%d ",
+                         (unsigned int)pWin->drawable.id,
+                         pWin->drawable.x, pWin->drawable.y, pWin->drawable.width, pWin->drawable.height,
+                         pWin->drawable.bitsPerPixel,
+                         pWin->viewable,
+                         pWin->realized);
+
+        /* if pWin->child->child has a dri2 atom, the window is 3D window */
+        for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
+        {
+            for (pGrandChild = pChild->firstChild; pGrandChild; pGrandChild = pGrandChild->nextSib)
+            {
+                rc = dixLookupProperty(&pProp, pGrandChild, pSec->atom_use_dri2, serverClient, DixReadAccess);
+                if (rc == Success)
+                {
+                    ErrorF ("dri2_draw:1 ");
+                }
+            }
+        }
+
+
+
+        ErrorF ("\n");
+    }
+}
+
+static void
+_findRtPixmap (pointer value, XID id, pointer cdata)
+{
+    PixmapPtr pPix = value;
+
+    ErrorF ("xid:0x%x geo:(%5d,%5d,%5d,%5d) bpp:%2d size:%8d draw_id:0x%x\n",
+                     (unsigned int)id,
+                     pPix->drawable.x, pPix->drawable.y, pPix->drawable.width, pPix->drawable.height,
+                     pPix->drawable.bitsPerPixel,
+                     pPix->devKind*pPix->drawable.height/1024,
+                     (unsigned int)pPix->drawable.id);
+    sum_pix_size = sum_pix_size + (pPix->devKind*pPix->drawable.height);
+}
+
+char*
+xDbgModuleRList (XDbgModule *pMod, char *reply, int *len)
+{
+    SECPtr pSec = SECPTR (scrn);
+    char *out, *tmp;
+    int i, bufsize;
+
+    bufsize = currentMaxClients * (100 + 1) + 30;
+    out = tmp = malloc (bufsize);
+    if (!tmp)
+        return NULL;
+
+    for (i = 1; i < currentMaxClients && (tmp < out+bufsize); i++)
+    {
+        ClientPtr pClient = clients[i];
+        ModuleClientInfo *info;
+
+        if (!pClient)
+            continue;
+
+        info = GetClientInfo (pClient);
+        if (!info)
+            continue;
+
+        ErrorF(\r\r"\n");
+        ErrorF(\r\r"INDEX    PID   CMD\n");
+        ErrorF(\r\r"%6d %6d %10s\n", info->index, info->pid, info->command);
+        ErrorF(\r\r"  >> WINDOWS\n");
+        FindClientResourcesByType (pClient, RT_WINDOW, _findRtWindow, pClient);
+        ErrorF(\r\r"  >> CompositeClientWindow\n");
+        FindClientResourcesByType (pClient, CompositeClientWindowType, _findRtCompWindow, pClient);
+        ErrorF(\r\r"  >> PIXMAPS\n");
+        sum_pix_size = 0;
+        FindClientResourcesByType (pClient, RT_PIXMAP, _findRtPixmap, pClient);
+        ErrorF(\r\r"  SUM mem: %d\n", sum_pix_size/1024);
+    }
+
+    /*
+       Normal pixmap
+       CREATE_PIXMAP_USAGE_BACKING_PIXMAP
+       CREATE_PIXMAP_USAGE_OVERLAY
+       CREATE_PIXMAP_USAGE_DRI2_FILP_BACK
+       CREATE_PIXMAP_USAGE_FB
+       CREATE_PIXMAP_USAGE_SUB_FB
+       CREATE_PIXMAP_USAGE_DRI2_BACK
+     */
+    ErrorF ("==== sum of pixmap memory ====\n");
+    ErrorF ("Normal pixmap                      = %d\n", pSec->pix_normal/1024);
+    ErrorF ("CREATE_PIXMAP_USAGE_BACKING_PIXMAP = %d\n", pSec->pix_backing_pixmap/1024);
+    ErrorF ("CREATE_PIXMAP_USAGE_OVERLAY        = %d\n", pSec->pix_overlay/1024);
+    ErrorF ("CREATE_PIXMAP_USAGE_DRI2_FILP_BACK = %d\n", pSec->pix_dri2_flip_back/1024);
+    ErrorF ("CREATE_PIXMAP_USAGE_FB             = %d\n", pSec->pix_fb/1024);
+    ErrorF ("CREATE_PIXMAP_USAGE_SUB_FB         = %d\n", pSec->pix_sub_fb/1024);
+    ErrorF ("CREATE_PIXMAP_USAGE_DRI2_BACK      = %d\n", pSec->pix_dri2_back/1024);
+    ErrorF ("TOTAL                              = %d\n",
+            (pSec->pix_normal+pSec->pix_backing_pixmap+pSec->pix_overlay+pSec->pix_dri2_flip_back+pSec->pix_fb+pSec->pix_sub_fb+pSec->pix_dri2_back)/1024);
+    ErrorF ("==============================\n");
+
+
+    return out;
+}
+#else
+char*
+xDbgModuleRList (XDbgModule *pMod, char *reply, int *len)
+{
+    XDBG_REPLY ("rlist : Not implemented.\n");
+    return NULL;
+}
+#endif
diff --git a/module/xdbg_module_rlist.h b/module/xdbg_module_rlist.h
new file mode 100644 (file)
index 0000000..8edf685
--- /dev/null
@@ -0,0 +1,39 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_MODULE_RLIST_H__
+#define __XDBG_MODULE_RLIST_H__
+
+#include "xdbg_module_types.h"
+
+char* xDbgModuleRList (XDbgModule *pMod, char *reply, int *len);
+
+#endif /* __XDBG_MODULE_CLIENT_LIST_H__ */
\ No newline at end of file
diff --git a/module/xdbg_module_types.h b/module/xdbg_module_types.h
new file mode 100644 (file)
index 0000000..f8c424c
--- /dev/null
@@ -0,0 +1,73 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_MODULE_TYPES_H__
+#define __XDBG_MODULE_TYPES_H__
+
+#include <xf86.h>
+#include <X11/Xdefs.h> /* for Bool */
+
+#define XDBG_PATH_MAX        1024
+
+#ifndef MAX
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+#ifndef MIN
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef SWAP
+#define SWAP(a, b)  ({int t; t = a; a = b; b = t;})
+#endif
+
+typedef struct _ModuleClientInfo
+{
+    int    index;
+    int    pid;
+    int    gid;
+    int    uid;
+    int    conn_fd;
+    char   command[PATH_MAX+1];
+} ModuleClientInfo;
+
+typedef struct _XDbgModule
+{
+    char *log_path;
+    char *real_log_path;
+
+    char *evlog_path;
+} XDbgModule;
+
+extern DevPrivateKeyRec debug_client_key;
+#define DebugClientKey (&debug_client_key)
+#define GetClientInfo(pClient) ((ModuleClientInfo*)dixLookupPrivate(&(pClient)->devPrivates, DebugClientKey))
+
+#endif  /* __XDBG_MODULE_TYPES_H__ */
diff --git a/packaging/xorg-x11-module-xdbg.spec b/packaging/xorg-x11-module-xdbg.spec
new file mode 100644 (file)
index 0000000..bbaa9c0
--- /dev/null
@@ -0,0 +1,80 @@
+Name: xorg-x11-module-xdbg
+Summary: Xserver debug module
+Version: 0.1.5
+Release:    1
+Group:      System/Libraries
+License:    MIT
+Source0:    %{name}-%{version}.tar.gz
+BuildRequires:  pkgconfig(xorg-server)
+BuildRequires:  pkgconfig(x11)
+BuildRequires:  pkgconfig(xext)
+BuildRequires:  pkgconfig(xorg-macros)
+BuildRequires:  pkgconfig(dbus-1)
+BuildRequires:  pkgconfig(bigreqsproto)
+BuildRequires:  pkgconfig(compositeproto)
+BuildRequires:  pkgconfig(damageproto)
+BuildRequires:  pkgconfig(dmxproto)
+BuildRequires:  pkgconfig(dri2proto)
+BuildRequires:  pkgconfig(fixesproto)
+BuildRequires:  pkgconfig(fontsproto)
+BuildRequires:  pkgconfig(gestureproto)
+BuildRequires:  pkgconfig(inputproto)
+BuildRequires:  pkgconfig(kbproto)
+BuildRequires:  pkgconfig(randrproto)
+BuildRequires:  pkgconfig(recordproto)
+BuildRequires:  pkgconfig(renderproto)
+BuildRequires:  pkgconfig(resourceproto)
+BuildRequires:  pkgconfig(scrnsaverproto)
+BuildRequires:  pkgconfig(videoproto)
+BuildRequires:  pkgconfig(xcmiscproto)
+BuildRequires:  pkgconfig(xextproto)
+BuildRequires:  pkgconfig(xf86bigfontproto)
+BuildRequires:  pkgconfig(xf86dgaproto)
+BuildRequires:  pkgconfig(xf86driproto)
+BuildRequires:  pkgconfig(xf86vidmodeproto)
+BuildRequires:  pkgconfig(xineramaproto)
+BuildRequires:  pkgconfig(xproto)
+
+
+%description
+This package provides the runtime debug library and module for debug of inside X server.
+
+%package devel
+Summary: X server runtime debug library development package
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+Requires: pkgconfig(xorg-server)
+Requires: pkgconfig(x11)
+
+%description devel
+X server runtime debug library development package
+
+%prep
+%setup -q
+
+%build
+%reconfigure --disable-static --prefix=/usr \
+  CFLAGS="$CFLAGS -Wall -Werror" \
+  LDFLAGS="$LDFLAGS -Wl,--hash-style=both -Wl,--as-needed"
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+mkdir -p %{buildroot}/usr/share/license
+cp -af COPYING %{buildroot}/usr/share/license/%{name}
+%make_install
+
+%remove_docs
+
+%files
+%defattr(-,root,root,-)
+/usr/share/license/%{name}
+%{_bindir}/xdbg
+%{_libdir}/libxdbg-log.so.*
+%{_libdir}/xorg/modules/libxdbg.so
+
+%files devel
+%dir %{_includedir}/xdbg/
+%{_includedir}/xdbg/*.h
+%{_libdir}/libxdbg-log.so
+%{_libdir}/pkgconfig/xdbg.pc