+++ /dev/null
-
-HEADER = WindowActivator.h
-
-SRCS = main.cpp WindowActivator.cpp
-
-TARGET = WindowActivator
-
-FLAGS = -Wall
-
-#LDFLAGS = -lstdc++ -lX11
-LDFLAGS = -lstdc++ -framework IOKit -framework ApplicationServices
-
-all: $(TARGET)
-
-$(TARGET): $(SRCS) $(HEADER)
- $(CC) -o $@ $(FLAGS) $(SRCS) $(LDFLAGS)
-
-clean:
- rm $(TARGET)
-
+++ /dev/null
-/*\r
- * Window Activator\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- *\r
- * Jaewon Lim <jaewon81.lim@samsung.com>\r
- * Juyoung Kim <j0.kim@samsung.com>\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-\r
-\r
-\r
-/**\r
- * @summary\r
- * @create date : 2011. 8. 16.\r
- * @author(create) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core\r
- * @revision date : 2011. 8. 16.\r
- * @author(revision) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core\r
- * @refactoring date : 2012. 4. 14\r
- * @author(refactoring) : Jaewon Lim / jaewon81.lim@samsung.com / S-Core\r
- */\r
-\r
-#include "WindowActivator.h"\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-WindowActivator::WindowActivator()\r
-{\r
-}\r
-\r
-WindowActivator::~WindowActivator()\r
-{\r
-}\r
-\r
-bool WindowActivator::ActivateWindow(const std::string pid)\r
-{\r
- return ActivateWindow(atoi(pid.c_str()));\r
-}\r
-\r
-\r
-#ifdef _WIN32 || _WIN64\r
-#include <windows.h>\r
-//#using <System.dll>\r
-//using namespace System;\r
-//using namespace System::Diagnostics;\r
-//using namespace System::ComponentModel;\r
-\r
-ULONG ProcIDFromWnd(HWND hwnd);\r
-HWND GetWinHandle(ULONG pid);\r
-void ActiveWindow(HWND hWnd);\r
-\r
-bool WindowActivator::ActivateWindow(int pid)\r
-{\r
- ActiveWindow(GetWinHandle(pid));\r
- return true;\r
-}\r
-\r
-ULONG ProcIDFromWnd(HWND hwnd)\r
-{\r
- ULONG idProc;\r
- GetWindowThreadProcessId( hwnd, &idProc );\r
- return idProc;\r
-}\r
-\r
-HWND GetWinHandle(ULONG pid)\r
-{\r
-// Process^ fproc = Process::GetProcessById(pid);\r
-// return (HWND)fproc->MainWindowHandle.ToPointer();\r
-\r
- HWND tempHwnd = FindWindow(NULL,NULL);\r
-\r
- while(tempHwnd != NULL )\r
- {\r
- if(GetParent(tempHwnd) == NULL )\r
- {\r
- if(GetWindow(tempHwnd, GW_OWNER) == NULL)\r
- {\r
- if( pid == ProcIDFromWnd(tempHwnd) )\r
- return tempHwnd;\r
- }\r
- }\r
- tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT);\r
- }\r
- return NULL;\r
-}\r
-\r
-void ActiveWindow(HWND hWnd)\r
-{\r
- HWND hWndForeground = ::GetForegroundWindow();\r
- if(hWndForeground == hWnd)\r
- {\r
- printf("same as foreground window\n");\r
- return;\r
- }\r
-\r
- DWORD Strange = ::GetWindowThreadProcessId(hWndForeground, NULL);\r
- DWORD My = ::GetWindowThreadProcessId(hWnd, NULL);\r
- if( !::AttachThreadInput(Strange, My, TRUE) )\r
- {\r
- // ASSERT(0);\r
- }\r
- ::SetForegroundWindow(hWnd);\r
- ::BringWindowToTop(hWnd);\r
- if( !::AttachThreadInput(Strange, My, FALSE) )\r
- {\r
- // ASSERT(0);\r
- }\r
- if (::IsIconic(hWnd))\r
- ::ShowWindow(hWnd, SW_RESTORE);\r
-}\r
-\r
-#elif __linux // if Linux\r
-\r
-#include <X11/Xlib.h>\r
-#include <X11/Xatom.h>\r
-\r
-#define PERROR(...) fprintf(stderr, __VA_ARGS__)\r
-\r
-bool findWindow(Display *disp, int idepid);\r
-Window* getClientList(Display *disp, unsigned long *size);\r
-char *getProperty(Display *disp, Window win, Atom xaPropType, const char *propName, unsigned long *size);\r
-char *getWindowTitle(Display *disp, Window win);\r
-int findProcessID(Display *disp, Window win);\r
-void activateWindow(Display *disp, Window win);\r
-bool sendEvent(Display *disp, Window win, char *msg, unsigned long data0, unsigned long data1, unsigned long data2, unsigned long data3, unsigned long data4);\r
-\r
-bool WindowActivator::ActivateWindow(int pid)\r
-{\r
-\r
- Display *disp;\r
-\r
- if (!(disp = XOpenDisplay(NULL)))\r
- {\r
- PERROR("XOpenDisplay error");\r
- return false;\r
- }\r
-\r
- findWindow(disp, pid);\r
- return true;\r
-}\r
-\r
-bool findWindow(Display *disp, int idepid)\r
-{\r
- unsigned long clientListSize;\r
- unsigned long i;\r
- Window *clientList;\r
- Window activate = 0;\r
-\r
- if ((clientList = getClientList(disp, &clientListSize)) == NULL)\r
- {\r
- return false;\r
- }\r
-\r
- for (i = 0; i < clientListSize / sizeof(Window); i++)\r
- {\r
- int pid = 0;\r
- pid = findProcessID(disp, clientList[i]);\r
-\r
- if (pid == 0)\r
- {\r
- continue;\r
- }\r
-\r
- if(pid == idepid)\r
- {\r
- activate = clientList[i];\r
- break;\r
- }\r
- }\r
-\r
- free(clientList);\r
-\r
- if (activate)\r
- {\r
- activateWindow(disp, activate);\r
- return true;\r
- }\r
- else\r
- {\r
- return false;\r
- }\r
-}\r
-\r
-Window* getClientList(Display *disp, unsigned long *size)\r
-{\r
- Window *clientList;\r
-\r
- if ((clientList = (Window *)getProperty(disp, DefaultRootWindow(disp), XA_WINDOW, (char*)"_NET_CLIENT_LIST", size)) == NULL)\r
- {\r
- if ((clientList = (Window *)getProperty(disp, DefaultRootWindow(disp), XA_CARDINAL, (char*)"_WIN_CLIENT_LIST", size)) == NULL)\r
- {\r
- PERROR("Can not get a client list");\r
- return NULL;\r
- }\r
- }\r
- return clientList;\r
-}\r
-\r
-char* getProperty(Display *disp, Window win, Atom xaPropType, const char *propName, unsigned long *size)\r
-{\r
- Atom xaPropName;\r
- Atom xaRetType;\r
- int retFormat;\r
- unsigned long retItems;\r
- unsigned long retBytesAfter;\r
- unsigned long tmpSize;\r
- unsigned char *retProp;\r
- char *ret;\r
-\r
- xaPropName = XInternAtom(disp, propName, False);\r
-\r
- int returnValue = XGetWindowProperty(disp, win, xaPropName, 0, 1024, False, xaPropType, &xaRetType, &retFormat, &retItems, &retBytesAfter, &retProp);\r
- PERROR("XGetWindowProperty %d ", returnValue);\r
-\r
- if (returnValue != Success)\r
- {\r
- PERROR("Can not get a %s property", propName);\r
- return NULL;\r
- }\r
-\r
- if (xaRetType != xaPropType)\r
- {\r
- PERROR("Invalid type of %s property.", propName);\r
- XFree(retProp);\r
- return NULL;\r
- }\r
-\r
- // null terminate the result to make string handling easier /\r
- tmpSize = (retFormat / 8) * retItems;\r
- // Correct 64 Architecture implementation of 32 bit data /\r
- if(retFormat==32) tmpSize *= sizeof(long)/4;\r
- ret = (char*)malloc(tmpSize + 1);\r
- memcpy(ret, retProp, tmpSize);\r
- ret[tmpSize] = '\0';\r
-\r
- if (size) {\r
- *size = tmpSize;\r
- }\r
-\r
- XFree(retProp);\r
- return ret;\r
-}\r
-\r
-int findProcessID(Display *disp, Window win)\r
-{\r
- int pid = 0;\r
- unsigned long *netWmPid;\r
-\r
- netWmPid = (unsigned long*)getProperty(disp, win, XA_CARDINAL, (const char*)"_NET_WM_PID", NULL);\r
-\r
- if(netWmPid)\r
- {\r
- pid = (int)*netWmPid;\r
- free(netWmPid);\r
- }\r
-\r
- PERROR("findProcessID %d ", pid);\r
- return pid;\r
-}\r
-\r
-bool sendEvent(Display *disp, Window win, char *msg,\r
- unsigned long data0, unsigned long data1,\r
- unsigned long data2, unsigned long data3,\r
- unsigned long data4)\r
-{\r
- XEvent event;\r
- long mask = SubstructureRedirectMask | SubstructureNotifyMask;\r
-\r
- event.xclient.type = ClientMessage;\r
- event.xclient.serial = 0;\r
- event.xclient.send_event = True;\r
- event.xclient.message_type = XInternAtom(disp, msg, False);\r
- event.xclient.window = win;\r
- event.xclient.format = 32;\r
- event.xclient.data.l[0] = data0;\r
- event.xclient.data.l[1] = data1;\r
- event.xclient.data.l[2] = data2;\r
- event.xclient.data.l[3] = data3;\r
- event.xclient.data.l[4] = data4;\r
-\r
- if (XSendEvent(disp, DefaultRootWindow(disp), False, mask, &event))\r
- {\r
- return true;\r
- }\r
- else\r
- {\r
- PERROR("Can not send %s event", msg);\r
- return false;\r
- }\r
-}\r
-\r
-\r
-void activateWindow (Display *disp, Window win)\r
-{\r
- unsigned long *desktop = NULL;\r
-\r
- // desktop ID /\r
- if ((desktop = (unsigned long *)getProperty(disp, win, XA_CARDINAL, (const char*)"_NET_WM_DESKTOP", NULL)) == NULL)\r
- {\r
- if ((desktop = (unsigned long *)getProperty(disp, win, XA_CARDINAL, (const char*)"_WIN_WORKSPACE", NULL)) == NULL)\r
- {\r
- PERROR("Can not find desktop ID");\r
- }\r
- }\r
-\r
- if (desktop)\r
- {\r
- if (sendEvent(disp, DefaultRootWindow(disp), (char*)"_NET_CURRENT_DESKTOP", *desktop, 0, 0, 0, 0) != EXIT_SUCCESS)\r
- {\r
- PERROR("Can not switch desktop.");\r
- }\r
- free(desktop);\r
- }\r
-\r
- sendEvent(disp, win, (char*)"_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0);\r
- XMapRaised(disp, win);\r
-\r
- XFlush(disp);\r
- XCloseDisplay (disp);\r
-}\r
-#elif __APPLE__\r
-\r
-#include <getopt.h>\r
-#include <IOKit/graphics/IOGraphicsLib.h>\r
-#include <ApplicationServices/ApplicationServices.h>\r
-\r
-bool WindowActivator::ActivateWindow(int pid)\r
-{\r
-\r
- ProcessSerialNumber psn;\r
- if(noErr == GetProcessForPID(pid, &psn))\r
- {\r
- SetFrontProcess(&psn);\r
- exit(0);\r
- }\r
- return 0;\r
-}\r
-\r
-#endif // end Linux\r
+++ /dev/null
-/*\r
- * Window Activator\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- *\r
- * Jaewon Lim <jaewon91.lim@samsung.com>\r
- * Juyoung Kim <j0.kim@samsung.com>\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-\r
-\r
-/**\r
- * @summary :\r
- * @create date : 2011. 8. 16.\r
- * @author(create) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core\r
- * @revision date : 2011. 8. 16.\r
- * @author(revision) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core\r
- */\r
-\r
-\r
-#ifndef WINDOWACTIVATOR_H_\r
-#define WINDOWACTIVATOR_H_\r
-\r
-#include <string>\r
-\r
-class WindowActivator\r
-{\r
-private:\r
- WindowActivator();\r
- virtual ~WindowActivator();\r
-\r
-public:\r
- static bool ActivateWindow(const std::string pid);\r
- static bool ActivateWindow(int pid);\r
-};\r
-\r
-#endif /* WINDOWACTIVATOR_H_ */\r
+++ /dev/null
-#! /bin/bash
-
-abspath="$(cd "${0%/*}" 2>/dev/null; echo $PWD/${0##*/})"
-absdir=`dirname "$abspath"`
-
-PWD=`pwd`
-
-ACTIVATOR=MacOSWindowActivator
-ACTIVATOR_PATH=${absdir}
-
-# for coredump file
-ulimit -c unlimited
-
-${ACTIVATOR_PATH}/${ACTIVATOR} "$@"
-
+++ /dev/null
-/*
- * Window Activator
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- *
- * Changhun Lim <changhun.lim@samsung.com>
- * Gyeongmin Ju <gyeongmin.ju@samsung.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include <iostream>
-#include <string>
-#include "WindowActivator.h"
-
-using namespace std;
-
-static void printUsage(const string appname)
-{
- cout << "* error : missing required paramaters" << endl;
- cout << "* usage : " << endl;
- cout << "\t to activate a window :" << endl;
- cout << "\t\t" << appname << " pid" << endl;
-}
-
-int main(int argc, char **argv)
-{
- if (argc < 2)
- {
- printUsage(argv[0]);
- }
- else
- {
- WindowActivator::ActivateWindow(argv[1]);
- }
-
- return 0;
-}
-
+++ /dev/null
-rem # find & move absolute path
-set ABS_PATH=%~dp0
-cd %ABS_PATH%
-
-set PWD=%CD%
-set ACTIVATOR_PATH=%PWD%
-set ACTIVATOR_BIN=WindowActivator.exe
-set PATH=%ACTIVATOR_PATH%;%PATH%
-
-%ACTIVATOR_PATH%\%ACTIVATOR_BIN% %*
+++ /dev/null
-#! /bin/bash
-
-abspath="$(cd "${0%/*}" 2>/dev/null; echo $PWD/${0##*/})"
-absdir=`dirname "$abspath"`
-
-PWD=`pwd`
-
-ACTIVATOR=WindowActivator
-ACTIVATOR_PATH=${absdir}
-
-# for coredump file
-ulimit -c unlimited
-
-${ACTIVATOR_PATH}/${ACTIVATOR} "$@"
-
+++ /dev/null
-Set fso = CreateObject("Scripting.FileSystemObject")
-activatorPath = fso.GetParentFolderName(Wscript.scriptFullName)
-activatorScript=activatorPath & "\windowactivator.bat"
-
-For i = 0 To WScript.Arguments.Count - 1
- args = args & Chr(34) & WScript.Arguments(i) & Chr(34) & " "
-Next
-
-set WshShell=WScript.CreateObject("WScript.Shell")
-WshShell.run activatorScript & " " & args,0,False
-Set WshShell=Nothing
FLAGS = -pthread -Wall
TARGET = da_manager
+DASCRIPT = da_command
all: $(TARGET)
install:
[ -d "$(DESTDIR)/$(INSTALLDIR)" ] || mkdir -p $(DESTDIR)/$(INSTALLDIR)
- install $(TARGET) $(DESTDIR)/$(INSTALLDIR)/
+ install $(TARGET) $(DASCRIPT) $(DESTDIR)/$(INSTALLDIR)/
clean:
rm $(TARGET)
--- /dev/null
+#!/bin/bash
+
+KILL=/usr/bin/killall
+MANAGER=/usr/bin/da_manager
+EVENT=/usr/bin/da_event
+
+print_usage()
+{
+ echo "usage: da_command [options]"
+ echo "Options:"
+ echo "killmanager terminate da_manager"
+ echo "killapp apppath terminate application"
+ echo "runmanager execute da_manager"
+ echo "runevent record|play execute da_event"
+}
+
+kill_manager()
+{
+ $KILL $MANAGER
+}
+
+kill_app()
+{
+ $KILL $APPPATH
+}
+
+run_manager()
+{
+ $MANAGER
+}
+
+run_event()
+{
+ case "$EVENTOPTION" in
+ record)
+ EVENTMODE="-r"
+ ;;
+ play)
+ EVENTMODE="-s"
+ ;;
+ *)
+ echo "Invalid event option!"
+ print_usage
+ exit 1
+ ;;
+ esac
+
+ $EVENT $EVENTMODE
+}
+
+if test $# -gt 2 -o $# -lt 1; then
+ print_usage
+ exit 1
+fi
+
+if test -n "$2"; then
+ case "$1" in
+ runevent)
+ EVENTOPTION=$2
+ ;;
+ killapp)
+ APPPATH=$2
+ ;;
+ *)
+ print_usage
+ exit 1
+ ;;
+ esac
+fi
+
+case "$1" in
+ killmanager)
+ kill_manager
+ ;;
+ killapp)
+ kill_app
+ ;;
+ runmanager)
+ run_manager
+ ;;
+ runevent)
+ run_event
+ ;;
+ *)
+ echo "Unknown option!"
+ print_usage
+ ;;
+esac
+
#define LAUNCH_APP_NAME "launch_app"
#define DA_PRELOAD_EXEC "__AUL_SDK_DYNAMIC_ANALYSIS"
#define DA_PRELOAD(AppType) AppType ? DA_PRELOAD_OSP : DA_PRELOAD_TIZEN
-#define DA_PRELOAD_TIZEN "LD_PRELOAD=/home/developer/sdk_tools/da/da_probe_tizen.so"
-#define DA_PRELOAD_OSP "LD_PRELOAD=/home/developer/sdk_tools/da/da_probe_osp.so"
+#define DA_PRELOAD_TIZEN "LD_PRELOAD=/usr/lib/da_probe_tizen.so"
+#define DA_PRELOAD_OSP "LD_PRELOAD=/usr/lib/da_probe_osp.so"
#define BATT_LOG_FILE "/home/developer/sdk_tools/da/battery/"
#define SHELL_CMD "/bin/sh"
+++ /dev/null
-Jaewon Lim <jaewon81.lim@samsung.com>
-Woojin Jung <woojin2.jung@samsung.com>
-Yeongtaik Byeon <yeongtaik.byeon@samsung.com>
-Jooyoul Lee <jy.exe.lee@samsung.com>
-Sanghyun Lee <sanghyunnim.lee@samsung.com>
-Juyoung Kim <j0.kim@samsung.com>
-HyunGoo Kang <hyungoo1.kang@samsung.com>
+++ /dev/null
- Apache License\r
- Version 2.0, January 2004\r
- http://www.apache.org/licenses/\r
-\r
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
-\r
- 1. Definitions.\r
-\r
- "License" shall mean the terms and conditions for use, reproduction,\r
- and distribution as defined by Sections 1 through 9 of this document.\r
-\r
- "Licensor" shall mean the copyright owner or entity authorized by\r
- the copyright owner that is granting the License.\r
-\r
- "Legal Entity" shall mean the union of the acting entity and all\r
- other entities that control, are controlled by, or are under common\r
- control with that entity. For the purposes of this definition,\r
- "control" means (i) the power, direct or indirect, to cause the\r
- direction or management of such entity, whether by contract or\r
- otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
- outstanding shares, or (iii) beneficial ownership of such entity.\r
-\r
- "You" (or "Your") shall mean an individual or Legal Entity\r
- exercising permissions granted by this License.\r
-\r
- "Source" form shall mean the preferred form for making modifications,\r
- including but not limited to software source code, documentation\r
- source, and configuration files.\r
-\r
- "Object" form shall mean any form resulting from mechanical\r
- transformation or translation of a Source form, including but\r
- not limited to compiled object code, generated documentation,\r
- and conversions to other media types.\r
-\r
- "Work" shall mean the work of authorship, whether in Source or\r
- Object form, made available under the License, as indicated by a\r
- copyright notice that is included in or attached to the work\r
- (an example is provided in the Appendix below).\r
-\r
- "Derivative Works" shall mean any work, whether in Source or Object\r
- form, that is based on (or derived from) the Work and for which the\r
- editorial revisions, annotations, elaborations, or other modifications\r
- represent, as a whole, an original work of authorship. For the purposes\r
- of this License, Derivative Works shall not include works that remain\r
- separable from, or merely link (or bind by name) to the interfaces of,\r
- the Work and Derivative Works thereof.\r
-\r
- "Contribution" shall mean any work of authorship, including\r
- the original version of the Work and any modifications or additions\r
- to that Work or Derivative Works thereof, that is intentionally\r
- submitted to Licensor for inclusion in the Work by the copyright owner\r
- or by an individual or Legal Entity authorized to submit on behalf of\r
- the copyright owner. For the purposes of this definition, "submitted"\r
- means any form of electronic, verbal, or written communication sent\r
- to the Licensor or its representatives, including but not limited to\r
- communication on electronic mailing lists, source code control systems,\r
- and issue tracking systems that are managed by, or on behalf of, the\r
- Licensor for the purpose of discussing and improving the Work, but\r
- excluding communication that is conspicuously marked or otherwise\r
- designated in writing by the copyright owner as "Not a Contribution."\r
-\r
- "Contributor" shall mean Licensor and any individual or Legal Entity\r
- on behalf of whom a Contribution has been received by Licensor and\r
- subsequently incorporated within the Work.\r
-\r
- 2. Grant of Copyright License. Subject to the terms and conditions of\r
- this License, each Contributor hereby grants to You a perpetual,\r
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
- copyright license to reproduce, prepare Derivative Works of,\r
- publicly display, publicly perform, sublicense, and distribute the\r
- Work and such Derivative Works in Source or Object form.\r
-\r
- 3. Grant of Patent License. Subject to the terms and conditions of\r
- this License, each Contributor hereby grants to You a perpetual,\r
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
- (except as stated in this section) patent license to make, have made,\r
- use, offer to sell, sell, import, and otherwise transfer the Work,\r
- where such license applies only to those patent claims licensable\r
- by such Contributor that are necessarily infringed by their\r
- Contribution(s) alone or by combination of their Contribution(s)\r
- with the Work to which such Contribution(s) was submitted. If You\r
- institute patent litigation against any entity (including a\r
- cross-claim or counterclaim in a lawsuit) alleging that the Work\r
- or a Contribution incorporated within the Work constitutes direct\r
- or contributory patent infringement, then any patent licenses\r
- granted to You under this License for that Work shall terminate\r
- as of the date such litigation is filed.\r
-\r
- 4. Redistribution. You may reproduce and distribute copies of the\r
- Work or Derivative Works thereof in any medium, with or without\r
- modifications, and in Source or Object form, provided that You\r
- meet the following conditions:\r
-\r
- (a) You must give any other recipients of the Work or\r
- Derivative Works a copy of this License; and\r
-\r
- (b) You must cause any modified files to carry prominent notices\r
- stating that You changed the files; and\r
-\r
- (c) You must retain, in the Source form of any Derivative Works\r
- that You distribute, all copyright, patent, trademark, and\r
- attribution notices from the Source form of the Work,\r
- excluding those notices that do not pertain to any part of\r
- the Derivative Works; and\r
-\r
- (d) If the Work includes a "NOTICE" text file as part of its\r
- distribution, then any Derivative Works that You distribute must\r
- include a readable copy of the attribution notices contained\r
- within such NOTICE file, excluding those notices that do not\r
- pertain to any part of the Derivative Works, in at least one\r
- of the following places: within a NOTICE text file distributed\r
- as part of the Derivative Works; within the Source form or\r
- documentation, if provided along with the Derivative Works; or,\r
- within a display generated by the Derivative Works, if and\r
- wherever such third-party notices normally appear. The contents\r
- of the NOTICE file are for informational purposes only and\r
- do not modify the License. You may add Your own attribution\r
- notices within Derivative Works that You distribute, alongside\r
- or as an addendum to the NOTICE text from the Work, provided\r
- that such additional attribution notices cannot be construed\r
- as modifying the License.\r
-\r
- You may add Your own copyright statement to Your modifications and\r
- may provide additional or different license terms and conditions\r
- for use, reproduction, or distribution of Your modifications, or\r
- for any such Derivative Works as a whole, provided Your use,\r
- reproduction, and distribution of the Work otherwise complies with\r
- the conditions stated in this License.\r
-\r
- 5. Submission of Contributions. Unless You explicitly state otherwise,\r
- any Contribution intentionally submitted for inclusion in the Work\r
- by You to the Licensor shall be under the terms and conditions of\r
- this License, without any additional terms or conditions.\r
- Notwithstanding the above, nothing herein shall supersede or modify\r
- the terms of any separate license agreement you may have executed\r
- with Licensor regarding such Contributions.\r
-\r
- 6. Trademarks. This License does not grant permission to use the trade\r
- names, trademarks, service marks, or product names of the Licensor,\r
- except as required for reasonable and customary use in describing the\r
- origin of the Work and reproducing the content of the NOTICE file.\r
-\r
- 7. Disclaimer of Warranty. Unless required by applicable law or\r
- agreed to in writing, Licensor provides the Work (and each\r
- Contributor provides its Contributions) on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
- implied, including, without limitation, any warranties or conditions\r
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
- PARTICULAR PURPOSE. You are solely responsible for determining the\r
- appropriateness of using or redistributing the Work and assume any\r
- risks associated with Your exercise of permissions under this License.\r
-\r
- 8. Limitation of Liability. In no event and under no legal theory,\r
- whether in tort (including negligence), contract, or otherwise,\r
- unless required by applicable law (such as deliberate and grossly\r
- negligent acts) or agreed to in writing, shall any Contributor be\r
- liable to You for damages, including any direct, indirect, special,\r
- incidental, or consequential damages of any character arising as a\r
- result of this License or out of the use or inability to use the\r
- Work (including but not limited to damages for loss of goodwill,\r
- work stoppage, computer failure or malfunction, or any and all\r
- other commercial damages or losses), even if such Contributor\r
- has been advised of the possibility of such damages.\r
-\r
- 9. Accepting Warranty or Additional Liability. While redistributing\r
- the Work or Derivative Works thereof, You may choose to offer,\r
- and charge a fee for, acceptance of support, warranty, indemnity,\r
- or other liability obligations and/or rights consistent with this\r
- License. However, in accepting such obligations, You may act only\r
- on Your own behalf and on Your sole responsibility, not on behalf\r
- of any other Contributor, and only if You agree to indemnify,\r
- defend, and hold each Contributor harmless for any liability\r
- incurred by, or claims asserted against, such Contributor by reason\r
- of your accepting any such warranty or additional liability.\r
-\r
- END OF TERMS AND CONDITIONS\r
-\r
- APPENDIX: How to apply the Apache License to your work.\r
-\r
- To apply the Apache License to your work, attach the following\r
- boilerplate notice, with the fields enclosed by brackets "[]"\r
- replaced with your own identifying information. (Don't include\r
- the brackets!) The text should be enclosed in the appropriate\r
- comment syntax for the file format. We also recommend that a\r
- file or class name and description of purpose be included on the\r
- same "printed page" as the copyright notice for easier\r
- identification within third-party archives.\r
-\r
- Copyright [yyyy] [name of copyright owner]\r
-\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-\r
-\r
-\r
+++ /dev/null
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users. We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors. You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
- To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights. Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received. You must make sure that they, too, receive
-or can get the source code. And you must show them these terms so they
-know their rights.
-
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
- For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software. For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
- Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so. This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software. The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable. Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products. If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
- Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary. To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
- You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- b) The work must carry prominent notices stating that it is
- released under this License and any conditions added under section
- 7. This requirement modifies the requirement in section 4 to
- "keep intact all notices".
-
- c) You must license the entire work, as a whole, under this
- License to anyone who comes into possession of a copy. This
- License will therefore apply, along with any applicable section 7
- additional terms, to the whole of the work, and all its parts,
- regardless of how they are packaged. This License gives no
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- Corresponding Source from a network server at no charge.
-
- c) Convey individual copies of the object code with a copy of the
- written offer to provide the Corresponding Source. This
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- d) Convey the object code by offering access from a designated
- place (gratis or for a charge), and offer equivalent access to the
- Corresponding Source in the same way through the same place at no
- further charge. You need not require recipients to copy the
- Corresponding Source along with the object code. If the place to
- copy the object code is a network server, the Corresponding Source
- may be on a different server (operated by you or a third party)
- that supports equivalent copying facilities, provided you maintain
- clear directions next to the object code saying where to find the
- Corresponding Source. Regardless of what server hosts the
- Corresponding Source, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
- A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
- "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
- The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
- When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- those licensors and authors.
-
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
- 8. Termination.
-
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
- Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
- 9. Acceptance Not Required for Having Copies.
-
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
-nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
- 10. Automatic Licensing of Downstream Recipients.
-
- Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
-for enforcing compliance by third parties with this License.
-
- An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
- 11. Patents.
-
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
- In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
- A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
- 13. Use with the GNU Affero General Public License.
-
- Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work. The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
- 15. Disclaimer of Warranty.
-
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-Also add information on how to contact you by electronic and paper mail.
-
- If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
- <program> Copyright (C) <year> <name of author>
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
- You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-<http://www.gnu.org/licenses/>.
-
- The GNU General Public License does not permit incorporating your program
-into proprietary programs. If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License. But first, please read
-<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+++ /dev/null
-Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
-Except as noted, this software is licensed under Apache License, Version 2.
-Please, see the LICENSE.APLv2 file for Apache License terms and conditions.
-
-readelf_arm, readelf_x86 file is licensed under GNU Public License , Version 3.
-Please, see LICENSE.GPLv3 file for GNU Public License , Version 3 terms and conditions.
-
+++ /dev/null
-
-HEADER = WindowActivator.h
-
-SRCS = main.cpp WindowActivator.cpp
-
-TARGET = WindowActivator
-
-FLAGS = -Wall
-
-#LDFLAGS = -lstdc++ -lX11
-LDFLAGS = -lstdc++ -framework IOKit -framework ApplicationServices
-
-all: $(TARGET)
-
-$(TARGET): $(SRCS) $(HEADER)
- $(CC) -o $@ $(FLAGS) $(SRCS) $(LDFLAGS)
-
-clean:
- rm $(TARGET)
-
+++ /dev/null
-/*\r
- * Window Activator\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- *\r
- * Jaewon Lim <jaewon81.lim@samsung.com>\r
- * Juyoung Kim <j0.kim@samsung.com>\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-\r
-\r
-\r
-/**\r
- * @summary\r
- * @create date : 2011. 8. 16.\r
- * @author(create) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core\r
- * @revision date : 2011. 8. 16.\r
- * @author(revision) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core\r
- * @refactoring date : 2012. 4. 14\r
- * @author(refactoring) : Jaewon Lim / jaewon81.lim@samsung.com / S-Core\r
- */\r
-\r
-#include "WindowActivator.h"\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-WindowActivator::WindowActivator()\r
-{\r
-}\r
-\r
-WindowActivator::~WindowActivator()\r
-{\r
-}\r
-\r
-bool WindowActivator::ActivateWindow(const std::string pid)\r
-{\r
- return ActivateWindow(atoi(pid.c_str()));\r
-}\r
-\r
-\r
-#ifdef _WIN32 || _WIN64\r
-#include <windows.h>\r
-//#using <System.dll>\r
-//using namespace System;\r
-//using namespace System::Diagnostics;\r
-//using namespace System::ComponentModel;\r
-\r
-ULONG ProcIDFromWnd(HWND hwnd);\r
-HWND GetWinHandle(ULONG pid);\r
-void ActiveWindow(HWND hWnd);\r
-\r
-bool WindowActivator::ActivateWindow(int pid)\r
-{\r
- ActiveWindow(GetWinHandle(pid));\r
- return true;\r
-}\r
-\r
-ULONG ProcIDFromWnd(HWND hwnd)\r
-{\r
- ULONG idProc;\r
- GetWindowThreadProcessId( hwnd, &idProc );\r
- return idProc;\r
-}\r
-\r
-HWND GetWinHandle(ULONG pid)\r
-{\r
-// Process^ fproc = Process::GetProcessById(pid);\r
-// return (HWND)fproc->MainWindowHandle.ToPointer();\r
-\r
- HWND tempHwnd = FindWindow(NULL,NULL);\r
-\r
- while(tempHwnd != NULL )\r
- {\r
- if(GetParent(tempHwnd) == NULL )\r
- {\r
- if(GetWindow(tempHwnd, GW_OWNER) == NULL)\r
- {\r
- if( pid == ProcIDFromWnd(tempHwnd) )\r
- return tempHwnd;\r
- }\r
- }\r
- tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT);\r
- }\r
- return NULL;\r
-}\r
-\r
-void ActiveWindow(HWND hWnd)\r
-{\r
- HWND hWndForeground = ::GetForegroundWindow();\r
- if(hWndForeground == hWnd)\r
- {\r
- printf("same as foreground window\n");\r
- return;\r
- }\r
-\r
- DWORD Strange = ::GetWindowThreadProcessId(hWndForeground, NULL);\r
- DWORD My = ::GetWindowThreadProcessId(hWnd, NULL);\r
- if( !::AttachThreadInput(Strange, My, TRUE) )\r
- {\r
- // ASSERT(0);\r
- }\r
- ::SetForegroundWindow(hWnd);\r
- ::BringWindowToTop(hWnd);\r
- if( !::AttachThreadInput(Strange, My, FALSE) )\r
- {\r
- // ASSERT(0);\r
- }\r
- if (::IsIconic(hWnd))\r
- ::ShowWindow(hWnd, SW_RESTORE);\r
-}\r
-\r
-#elif __linux // if Linux\r
-\r
-#include <X11/Xlib.h>\r
-#include <X11/Xatom.h>\r
-\r
-#define PERROR(...) fprintf(stderr, __VA_ARGS__)\r
-\r
-bool findWindow(Display *disp, int idepid);\r
-Window* getClientList(Display *disp, unsigned long *size);\r
-char *getProperty(Display *disp, Window win, Atom xaPropType, const char *propName, unsigned long *size);\r
-char *getWindowTitle(Display *disp, Window win);\r
-int findProcessID(Display *disp, Window win);\r
-void activateWindow(Display *disp, Window win);\r
-bool sendEvent(Display *disp, Window win, char *msg, unsigned long data0, unsigned long data1, unsigned long data2, unsigned long data3, unsigned long data4);\r
-\r
-bool WindowActivator::ActivateWindow(int pid)\r
-{\r
-\r
- Display *disp;\r
-\r
- if (!(disp = XOpenDisplay(NULL)))\r
- {\r
- PERROR("XOpenDisplay error");\r
- return false;\r
- }\r
-\r
- findWindow(disp, pid);\r
- return true;\r
-}\r
-\r
-bool findWindow(Display *disp, int idepid)\r
-{\r
- unsigned long clientListSize;\r
- unsigned long i;\r
- Window *clientList;\r
- Window activate = 0;\r
-\r
- if ((clientList = getClientList(disp, &clientListSize)) == NULL)\r
- {\r
- return false;\r
- }\r
-\r
- for (i = 0; i < clientListSize / sizeof(Window); i++)\r
- {\r
- int pid = 0;\r
- pid = findProcessID(disp, clientList[i]);\r
-\r
- if (pid == 0)\r
- {\r
- continue;\r
- }\r
-\r
- if(pid == idepid)\r
- {\r
- activate = clientList[i];\r
- break;\r
- }\r
- }\r
-\r
- free(clientList);\r
-\r
- if (activate)\r
- {\r
- activateWindow(disp, activate);\r
- return true;\r
- }\r
- else\r
- {\r
- return false;\r
- }\r
-}\r
-\r
-Window* getClientList(Display *disp, unsigned long *size)\r
-{\r
- Window *clientList;\r
-\r
- if ((clientList = (Window *)getProperty(disp, DefaultRootWindow(disp), XA_WINDOW, (char*)"_NET_CLIENT_LIST", size)) == NULL)\r
- {\r
- if ((clientList = (Window *)getProperty(disp, DefaultRootWindow(disp), XA_CARDINAL, (char*)"_WIN_CLIENT_LIST", size)) == NULL)\r
- {\r
- PERROR("Can not get a client list");\r
- return NULL;\r
- }\r
- }\r
- return clientList;\r
-}\r
-\r
-char* getProperty(Display *disp, Window win, Atom xaPropType, const char *propName, unsigned long *size)\r
-{\r
- Atom xaPropName;\r
- Atom xaRetType;\r
- int retFormat;\r
- unsigned long retItems;\r
- unsigned long retBytesAfter;\r
- unsigned long tmpSize;\r
- unsigned char *retProp;\r
- char *ret;\r
-\r
- xaPropName = XInternAtom(disp, propName, False);\r
-\r
- int returnValue = XGetWindowProperty(disp, win, xaPropName, 0, 1024, False, xaPropType, &xaRetType, &retFormat, &retItems, &retBytesAfter, &retProp);\r
- PERROR("XGetWindowProperty %d ", returnValue);\r
-\r
- if (returnValue != Success)\r
- {\r
- PERROR("Can not get a %s property", propName);\r
- return NULL;\r
- }\r
-\r
- if (xaRetType != xaPropType)\r
- {\r
- PERROR("Invalid type of %s property.", propName);\r
- XFree(retProp);\r
- return NULL;\r
- }\r
-\r
- // null terminate the result to make string handling easier /\r
- tmpSize = (retFormat / 8) * retItems;\r
- // Correct 64 Architecture implementation of 32 bit data /\r
- if(retFormat==32) tmpSize *= sizeof(long)/4;\r
- ret = (char*)malloc(tmpSize + 1);\r
- memcpy(ret, retProp, tmpSize);\r
- ret[tmpSize] = '\0';\r
-\r
- if (size) {\r
- *size = tmpSize;\r
- }\r
-\r
- XFree(retProp);\r
- return ret;\r
-}\r
-\r
-int findProcessID(Display *disp, Window win)\r
-{\r
- int pid = 0;\r
- unsigned long *netWmPid;\r
-\r
- netWmPid = (unsigned long*)getProperty(disp, win, XA_CARDINAL, (const char*)"_NET_WM_PID", NULL);\r
-\r
- if(netWmPid)\r
- {\r
- pid = (int)*netWmPid;\r
- free(netWmPid);\r
- }\r
-\r
- PERROR("findProcessID %d ", pid);\r
- return pid;\r
-}\r
-\r
-bool sendEvent(Display *disp, Window win, char *msg,\r
- unsigned long data0, unsigned long data1,\r
- unsigned long data2, unsigned long data3,\r
- unsigned long data4)\r
-{\r
- XEvent event;\r
- long mask = SubstructureRedirectMask | SubstructureNotifyMask;\r
-\r
- event.xclient.type = ClientMessage;\r
- event.xclient.serial = 0;\r
- event.xclient.send_event = True;\r
- event.xclient.message_type = XInternAtom(disp, msg, False);\r
- event.xclient.window = win;\r
- event.xclient.format = 32;\r
- event.xclient.data.l[0] = data0;\r
- event.xclient.data.l[1] = data1;\r
- event.xclient.data.l[2] = data2;\r
- event.xclient.data.l[3] = data3;\r
- event.xclient.data.l[4] = data4;\r
-\r
- if (XSendEvent(disp, DefaultRootWindow(disp), False, mask, &event))\r
- {\r
- return true;\r
- }\r
- else\r
- {\r
- PERROR("Can not send %s event", msg);\r
- return false;\r
- }\r
-}\r
-\r
-\r
-void activateWindow (Display *disp, Window win)\r
-{\r
- unsigned long *desktop = NULL;\r
-\r
- // desktop ID /\r
- if ((desktop = (unsigned long *)getProperty(disp, win, XA_CARDINAL, (const char*)"_NET_WM_DESKTOP", NULL)) == NULL)\r
- {\r
- if ((desktop = (unsigned long *)getProperty(disp, win, XA_CARDINAL, (const char*)"_WIN_WORKSPACE", NULL)) == NULL)\r
- {\r
- PERROR("Can not find desktop ID");\r
- }\r
- }\r
-\r
- if (desktop)\r
- {\r
- if (sendEvent(disp, DefaultRootWindow(disp), (char*)"_NET_CURRENT_DESKTOP", *desktop, 0, 0, 0, 0) != EXIT_SUCCESS)\r
- {\r
- PERROR("Can not switch desktop.");\r
- }\r
- free(desktop);\r
- }\r
-\r
- sendEvent(disp, win, (char*)"_NET_ACTIVE_WINDOW", 0, 0, 0, 0, 0);\r
- XMapRaised(disp, win);\r
-\r
- XFlush(disp);\r
- XCloseDisplay (disp);\r
-}\r
-#elif __APPLE__\r
-\r
-#include <getopt.h>\r
-#include <IOKit/graphics/IOGraphicsLib.h>\r
-#include <ApplicationServices/ApplicationServices.h>\r
-\r
-bool WindowActivator::ActivateWindow(int pid)\r
-{\r
-\r
- ProcessSerialNumber psn;\r
- if(noErr == GetProcessForPID(pid, &psn))\r
- {\r
- SetFrontProcess(&psn);\r
- exit(0);\r
- }\r
- return 0;\r
-}\r
-\r
-#endif // end Linux\r
+++ /dev/null
-/*\r
- * Window Activator\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- *\r
- * Jaewon Lim <jaewon91.lim@samsung.com>\r
- * Juyoung Kim <j0.kim@samsung.com>\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-\r
-\r
-/**\r
- * @summary :\r
- * @create date : 2011. 8. 16.\r
- * @author(create) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core\r
- * @revision date : 2011. 8. 16.\r
- * @author(revision) : Lee JaeYeol / jaeyeol148.lee@samsung.com / S-Core\r
- */\r
-\r
-\r
-#ifndef WINDOWACTIVATOR_H_\r
-#define WINDOWACTIVATOR_H_\r
-\r
-#include <string>\r
-\r
-class WindowActivator\r
-{\r
-private:\r
- WindowActivator();\r
- virtual ~WindowActivator();\r
-\r
-public:\r
- static bool ActivateWindow(const std::string pid);\r
- static bool ActivateWindow(int pid);\r
-};\r
-\r
-#endif /* WINDOWACTIVATOR_H_ */\r
+++ /dev/null
-#! /bin/bash
-
-abspath="$(cd "${0%/*}" 2>/dev/null; echo $PWD/${0##*/})"
-absdir=`dirname "$abspath"`
-
-PWD=`pwd`
-
-ACTIVATOR=MacOSWindowActivator
-ACTIVATOR_PATH=${absdir}
-
-# for coredump file
-ulimit -c unlimited
-
-${ACTIVATOR_PATH}/${ACTIVATOR} "$@"
-
+++ /dev/null
-/*
- * Window Activator
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- *
- * Changhun Lim <changhun.lim@samsung.com>
- * Gyeongmin Ju <gyeongmin.ju@samsung.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#include <iostream>
-#include <string>
-#include "WindowActivator.h"
-
-using namespace std;
-
-static void printUsage(const string appname)
-{
- cout << "* error : missing required paramaters" << endl;
- cout << "* usage : " << endl;
- cout << "\t to activate a window :" << endl;
- cout << "\t\t" << appname << " pid" << endl;
-}
-
-int main(int argc, char **argv)
-{
- if (argc < 2)
- {
- printUsage(argv[0]);
- }
- else
- {
- WindowActivator::ActivateWindow(argv[1]);
- }
-
- return 0;
-}
-
+++ /dev/null
-rem # find & move absolute path
-set ABS_PATH=%~dp0
-cd %ABS_PATH%
-
-set PWD=%CD%
-set ACTIVATOR_PATH=%PWD%
-set ACTIVATOR_BIN=WindowActivator.exe
-set PATH=%ACTIVATOR_PATH%;%PATH%
-
-%ACTIVATOR_PATH%\%ACTIVATOR_BIN% %*
+++ /dev/null
-#! /bin/bash
-
-abspath="$(cd "${0%/*}" 2>/dev/null; echo $PWD/${0##*/})"
-absdir=`dirname "$abspath"`
-
-PWD=`pwd`
-
-ACTIVATOR=WindowActivator
-ACTIVATOR_PATH=${absdir}
-
-# for coredump file
-ulimit -c unlimited
-
-${ACTIVATOR_PATH}/${ACTIVATOR} "$@"
-
+++ /dev/null
-Set fso = CreateObject("Scripting.FileSystemObject")
-activatorPath = fso.GetParentFolderName(Wscript.scriptFullName)
-activatorScript=activatorPath & "\windowactivator.bat"
-
-For i = 0 To WScript.Arguments.Count - 1
- args = args & Chr(34) & WScript.Arguments(i) & Chr(34) & " "
-Next
-
-set WshShell=WScript.CreateObject("WScript.Shell")
-WshShell.run activatorScript & " " & args,0,False
-Set WshShell=Nothing
+++ /dev/null
-CURDIR = `pwd`
-INSTALLDIR = usr/bin
-
-UNAME := $(shell uname -sm)
-ifneq (,$(findstring 86,$(UNAME)))
- HOST_ARCH := x86
-endif
-
-TARGET_ARCH = $(HOST_ARCH)
-ifeq ($(TARGET_ARCH),)
- TARGET_ARCH := arm
-endif
-
-ifeq ($(TARGET_ARCH),arm)
- DEVICE = -DDEVICE_ONLY
-endif
-
-INC := -I/usr/include \
- -I/usr/include/system \
- -I/usr/include/telephony \
- -I/usr/include/vconf
-
-DAEMON_SRCS := \
- da_daemon.c \
- utils.c \
- sys_stat.c
-
-LDLIBS_PATH := -L/usr/lib -L./lib/
-LIBS_TIZEN :=# -lcapi-system-runtime-info \
- -lcapi-telephony-network-info \
- -lcapi-telephony-call \
- -lSLP-tapi \
- -lsecurity-server-client \
- -lbundle \
- -lail \
- -lxdgmime \
- -ldlog \
- -lSLP-db-util
-LIBS_COMMON := -lglib-2.0 \
- -lvconf \
- -laul \
- -lcapi-system-info
-
-DEBUG_ON := -DDEBUG=1
-FLAGS = -pthread -Wall
-
-TARGET = da_manager
-
-all: $(TARGET)
-
-$(TARGET): $(DAEMON_SRCS)
- $(CC) $(INC) $(FLAGS) $(DEBUG_ON) $(DEVICE) -o $@ $(DAEMON_SRCS) $(LDLIBS_PATH) $(LIBS_COMMON) $(LIBS_TIZEN)
-
-localtest:
- $(CC) -DLOCALTEST $(INC) $(FLAGS) -o $(TARGET) $(DEBUG_ON) $(DEVICE) $(LDLIBS_PATH) $(LIBS_COMMON) $(DAEMON_SRCS)
-
-install:
- [ -d "$(DESTDIR)/$(INSTALLDIR)" ] || mkdir -p $(DESTDIR)/$(INSTALLDIR)
- install $(TARGET) $(DESTDIR)/$(INSTALLDIR)/
-
-clean:
- rm $(TARGET)
-
+++ /dev/null
-/*
-* DA manager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-*
-* Jaewon Lim <jaewon81.lim@samsung.com>
-* Woojin Jung <woojin2.jung@samsung.com>
-* Juyoung Kim <j0.kim@samsung.com>
-*
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-#include <stdio.h>
-#include <stdlib.h> // for realpath
-#include <string.h> // for strtok, strcpy, strncpy
-#include <assert.h> // for assert
-#include <limits.h> // for realpath
-
-#define __USE_GNU
-#include <sys/types.h> // for socket, mkdir, opendir, readdir
-#include <sys/socket.h> // for socket
-#include <sys/un.h> // for sockaddr_un
-#include <arpa/inet.h> // for sockaddr_in, socklen_t
-#include <sys/stat.h> // for chmod, mkdir
-#include <sys/time.h> // for setitimer
-#include <signal.h> // for sigemptyset, sigset_t, sigaddset, ...
-#include <unistd.h> // for unlink
-#include <pthread.h> // for pthread_mutex_t
-#include <sys/epoll.h> // for epoll apis
-#include <sys/ipc.h> // for shmctl
-#include <sys/shm.h> // for shared memory operation
-#include <dirent.h> // for opendir, readdir
-
-#include "utils.h"
-#include "sys_stat.h"
-#include "da_debug.h"
-
-#define MAX_PATH_LENGTH 256
-#define TARGET_CLIENT_COUNT_MAX 8
-#define READ_BUF_MAX 4096+8
-#define DA_LOG_MAX 4096
-#define APP_INSTALL_PATH_MAX 1024
-#define UDS_NAME "/tmp/da.socket"
-#define DA_INSTALL_DIR "/home/developer/sdk_tools/da/"
-#define DA_INSTALL_PATH "/home/developer/sdk_tools/da/da_install_path"
-#define DA_BUILD_OPTION "/home/developer/sdk_tools/da/da_build_option"
-#define DA_BASE_ADDRESS "/home/developer/sdk_tools/da/da_base_address"
-#define DA_READELF_PATH "/home/developer/sdk_tools/da/readelf"
-#define SCREENSHOT_DIR "/tmp/da"
-#define HOST_MSG_LENGTH 3
-#define SHAREDMEMKEY ((key_t)463825)
-
-#define TIMER_INTERVAL_SEC 1
-#define TIMER_INTERVAL_USEC 0
-
-#define SECOND_INTERVAL
-#define MONITORING_INTERVAL 1 // 1 second
-
-#ifdef SECOND_INTERVAL
-#define __sleep sleep
-#else
-#define __sleep usleep
-#endif
-
-#define RUN_APP_LOADER 1
-
-enum TargetMessageType
-{
- MSG_DEVICE = 1,
- MSG_TIME = 2,
- MSG_SAMPLE = 3,
- MSG_RESOURCE = 4,
- MSG_LOG = 5,
- MSG_IMAGE = 6,
- MSG_TERMINATE = 7,
- MSG_PID = 8,
- MSG_MSG = 9,
- MSG_APPNAME = 10,
- MSG_ERROR = 11
-};
-
-enum HostMessageType
-{
- MSG_HOST_BEGIN = 100,
- MSG_START = 100,
- MSG_STOP = 101,
- MSG_PAUSE = 102,
- MSG_OPTION = 103,
- MSG_ISALIVE = 104,
- MSG_ALIVE = 105,
- MSG_BATT_START = 106,
- MSG_BATT_STOP = 107,
- MSG_HOST_END = 107
-};
-
-enum DAState
-{
- DAS_NONE = 0,
- DAS_START_BEGIN = 1,
- DAS_TARGET_ARM_START = 1,
- DAS_TARGET_X86_START = 2,
- DAS_EMUL_ARM_START = 3,
- DAS_EMUL_X86_START = 4,
- DAS_TARGET_ARM_BATT_START = 5,
- DAS_TARGET_X86_BATT_START = 6,
- DAS_EMUL_ARM_BATT_START = 7,
- DAS_EMUL_X86_BATT_START = 8,
- DAS_START_END = 8,
- DAS_STOP = 9,
- DAS_TERMINATE = 10
-};
-
-typedef struct
-{
- int type;
- int length;
- char data[DA_LOG_MAX];
-} log_t;
-
-//TODO :
-typedef struct
-{
- enum DAState status;
- int serverSockFD;
- int clientSockFD;
-} __daHostInfo;
-
-typedef struct
-{
- enum DAState status;
- int serverSockFD;
- int connectCount;
- int pidCount;
- int clientSockFD[TARGET_CLIENT_COUNT_MAX];
- int execPID[TARGET_CLIENT_COUNT_MAX]; // exec PID by target
-} __daTargetInfo;
-
-typedef struct
-{
- long long allocsize;
- long launch_flag;
-} __daSharedInfo;
-
-typedef struct
-{
- int memid;
- __daSharedInfo* pvalue;
-} __daSharedMem;
-
-typedef struct
-{
- pthread_t timer_thread;
- pthread_mutex_t sendMutex;
- char appPath[128]; // application executable path
- __daSharedMem sharedmem;
- __daHostInfo iHost;
- __daTargetInfo iTarget;
-}__daManager;
-
-__daManager manager =
-{
- -1, // timer_thread handle
- PTHREAD_MUTEX_INITIALIZER, // pthread_mutex_t sendMutex
- { 0, }, // char appPath[128]
- { -1, (void*)-1 }, // __daSharedMem sharedmem
- { DAS_NONE, -1, -1 }, // __daHostInfo iHost
- { DAS_NONE, -1, 0, 0, {0, }, {0, }} // __daTargetInfo iTarget
-};
-
-int aul_terminate_pid(int pid);
-static void* terminate_thread(void* data);
-static void terminate_error(char* errstr, int sendtohost);
-
-#ifdef LOCALTEST
-int aul_terminate_pid(int pid)
-{
- return kill(pid, SIGTERM);
-}
-#endif
-
-int _terminate_pid(int pid)
-{
- int ret;
- pid_t* pids;
- pthread_t term_thread;
-
- ret = aul_terminate_pid(pid);
-
- pids = (pid_t*)malloc(2 * sizeof(pid_t));
- pids[0] = pid;
- pids[1] = -2;
-
- pthread_create(&term_thread, NULL, terminate_thread, pids);
-
- return ret;
-}
-
-// return 0 if succeed
-// return -1 if error occured
-static int remove_indir(const char *dirname)
-{
- DIR *dir;
- struct dirent *entry;
- char path[MAX_PATH_LENGTH];
-
- dir = opendir(dirname);
- if(dir == NULL)
- {
- return -1;
- }
-
- while((entry = readdir(dir)) != NULL)
- {
- if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
- {
- snprintf(path, (size_t) MAX_PATH_LENGTH, "%s/%s", dirname, entry->d_name);
- if (entry->d_type != DT_DIR) // file
- {
- unlink(path);
- }
- else { } // directory
- }
- }
- closedir(dir);
-
- return 0;
-}
-
-// index is started from 0
-int set_launch_flag(int index, int bOn)
-{
- int ret = 0;
- // set launch flag before execute application
- if(__builtin_expect(manager.sharedmem.pvalue != (void*)-1, 1))
- {
- if(bOn != 0)
- manager.sharedmem.pvalue->launch_flag |= (1 << index);
- else
- manager.sharedmem.pvalue->launch_flag &= ~(1 << index);
- }
- else
- ret = -1;
-
- return ret;
-}
-
-long long get_total_alloc_size()
-{
- if(__builtin_expect(manager.sharedmem.pvalue != (void*)-1, 1))
- {
- return manager.sharedmem.pvalue->allocsize;
- }
- else
- {
- return 0L;
- }
-}
-
-// return 0 for normal case
-static int __makeTargetServerSockFD()
-{
- struct sockaddr_un serverAddrUn;
-
- if(manager.iTarget.serverSockFD != -1)
- return -1; // should be never happend
-
- // remove pre unix domain socket file
- // remove(UDS_NAME);
- unlink(UDS_NAME);
-
- if ((manager.iTarget.serverSockFD = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
- {
- LOGE("Target server socket creation failed\n");
- return -1;
- }
- bzero(&serverAddrUn, sizeof(serverAddrUn));
- serverAddrUn.sun_family = AF_UNIX;
- sprintf(serverAddrUn.sun_path, "%s", UDS_NAME);
-
- if (-1 == bind(manager.iTarget.serverSockFD, (struct sockaddr*) &serverAddrUn,
- sizeof(serverAddrUn)))
- {
- LOGE("Target server socket binding failed\n");
- close(manager.iTarget.serverSockFD);
- return -1;
- }
-
- chmod(serverAddrUn.sun_path, 0777);
-
- if (-1 == listen(manager.iTarget.serverSockFD, 5))
- {
- LOGE("Target server socket listening failed\n");
- close(manager.iTarget.serverSockFD);
- return -1;
- }
-
- LOGI("Created TargetSock %d\n", manager.iTarget.serverSockFD);
- return 0;
-}
-
-// return 0 for normal case
-static int __makeHostServerSockFD()
-{
- struct sockaddr_in serverAddrIn;
- int opt = 1;
-
- if(manager.iHost.serverSockFD != -1)
- return -1; // should be never happened
-
- if ((manager.iHost.serverSockFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
- {
- LOGE("Host server socket creation failed\n");
- return -1;
- }
-
- setsockopt(manager.iHost.serverSockFD, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
- memset(&serverAddrIn, 0, sizeof(serverAddrIn));
- serverAddrIn.sin_family = AF_INET;
- serverAddrIn.sin_addr.s_addr = htonl(INADDR_ANY);
- serverAddrIn.sin_port = htons(8001);
-
- // bind address to server socket
- if (-1 == bind(manager.iHost.serverSockFD, (struct sockaddr*) &serverAddrIn, sizeof(serverAddrIn)))
- {
- LOGE("Host server socket binding failed\n");
- close(manager.iHost.serverSockFD);
- return -1;
- }
-
- // enter listen state from client
- if (-1 == listen(manager.iHost.serverSockFD, 5))
- {
- LOGE("Host server socket listening failed\n");
- close(manager.iHost.serverSockFD);
- return -1;
- }
-
- LOGI("Created HostSock %d\n", manager.iHost.serverSockFD);
- return 0;
-}
-
-static int __destroySharedMemory()
-{
- int ret = 0;
- if(manager.sharedmem.pvalue != (void*)-1)
- {
- ret = shmdt(manager.sharedmem.pvalue);
- if(ret == 0)
- manager.sharedmem.pvalue = (void*)-1;
- }
-
- if(manager.sharedmem.memid != -1)
- {
- ret = shmctl(manager.sharedmem.memid, IPC_RMID, 0);
- if(ret == 0)
- manager.sharedmem.memid = -1;
- }
-
- return ret;
-}
-
-// return 0 for normal case
-// return -1 for error case
-static int __createSharedMemory()
-{
- manager.sharedmem.memid = shmget(SHAREDMEMKEY, sizeof(__daSharedInfo), IPC_CREAT | 0666);
- if(manager.sharedmem.memid == -1)
- {
- return -1;
- }
- else
- {
- manager.sharedmem.pvalue = (__daSharedInfo*)shmat(manager.sharedmem.memid, NULL, 0);
- if(manager.sharedmem.pvalue == (void*)-1)
- {
- __destroySharedMemory();
- return -1;
- }
- else
- {
- manager.sharedmem.pvalue->allocsize = 0;
- manager.sharedmem.pvalue->launch_flag = 0;
- return 0;
- }
- }
-}
-
-/*
-static log_t * parsLogData(log_t * log, char* logStr)
-{
-#if 1
- int i, nPos;
-
- if (logStr == NULL || log == NULL)
- return NULL;
-
- //msgType
- for (i = 0, nPos = 0; i < READ_BUF_MAX; i++)
- {
- if (logStr[i] == '|')
- {
- logStr[i] = '\0';
- log->type = atoi(&logStr[nPos]);
- i++;
- break;
- }
- if (logStr[i] == '\0')
- return NULL;
- }
- //length
- for (nPos = i; i < READ_BUF_MAX; i++)
- {
- if (logStr[i] == '|' || logStr[i] == '\0')
- {
- logStr[i] = '\0';
- log->length = atoi(&logStr[nPos]);
- i++;
- break;
- }
- }
- //data
- if ((log->length > 0) && (log->length < DA_LOG_MAX))
- {
- strncpy(log->data, &logStr[i], log->length);
- log->data[log->length] = '\0';
- }
-
- return log;
-
-#else
-
- int i;
- char * startPos = logStr;
- char tempBuf[READ_BUF_MAX];
-
- if(logStr && log)
- {
- log->type = -1;
- log->length = 0;
- log->data[0]='\0';
- //type,length
- for(i=0; i<READ_BUF_MAX; i++)
- {
- if(logStr[i]=='|')
- {
- logStr[i]='\0';
- if(log->type == -1)
- {
- log->type = atoi(startPos);
- startPos = &logStr[i+1];
- }
- else {
- log->length = atoi(startPos);
- startPos = &logStr[i+1];
- break;
- }
- }
- }
- //data
- if((log->length > 0) && (log->length < DA_LOG_MAX) && (startPos))
- {
- strncpy(log->data, startPos, log->length);
- log->data[log->length] = '\0';
- }
- LOGI("log type : %d, length : %d, data : %s\n", log->type, log->length, log->data);
- return log;
- }
- else
- return NULL;
-#endif
-}
-*/
-
-static int get_app_type(void)
-{
- int fd;
- char buf[DA_LOG_MAX];
-
- sprintf(buf, "%s.exe", manager.appPath);
- fd = open(buf, O_RDONLY);
- if(fd != -1)
- {
- close(fd);
- return APP_TYPE_OSP;
- }
- else
- {
- return APP_TYPE_TIZEN;
- }
-}
-
-static int get_executable(char* buf, int buflen)
-{
- int fd;
-
- sprintf(buf, "%s.exe", manager.appPath);
- fd = open(buf, O_RDONLY);
- if(fd != -1)
- {
- close(fd);
- }
- else
- {
- strcpy(buf, manager.appPath);
- }
- return 0;
-}
-
-static int get_app_install_path(char *strAppInstall, int length)
-{
- FILE *fp;
- char buf[DA_LOG_MAX];
- char *p;
- int i;
-
- if ((fp = fopen(DA_INSTALL_PATH, "r")) == NULL)
- {
- LOGE("Failed to open %s\n", DA_INSTALL_PATH);
- return -1;
- }
-
- /*ex : <15> DW_AT_comp_dir : (indirect string, offset: 0x25f): /home/yt/workspace/templatetest/Debug-Tizen-Emulator */
- while (fgets(buf, DA_LOG_MAX, fp) != NULL)
- {
- //name
- p = buf;
- for (i = 0; i < DA_LOG_MAX; i++)
- {
- if (*p == ':')
- break;
- p++;
- }
-
- if (*p != ':')
- break;
- else
- p++;
-
- //(...,offset:...)
- for (; i < DA_LOG_MAX; i++)
- {
- if (*p == '(')
- {
- while (*p != ')')
- {
- p++;
- }
- }
- if (*p == ':')
- break;
- p++;
- }
-
- //find
- if (*p != ':')
- break;
- for (; i < DA_LOG_MAX; i++)
- {
- if (*p == ':' || *p == ' ' || *p == '\t')
- p++;
- else
- break;
- }
-
- //name
- if (strlen(p) <= length)
- {
- sprintf(strAppInstall, "%s", p);
- for (i = 0; i < strlen(p); i++)
- {
- if (strAppInstall[i] == '\n' || strAppInstall[i] == '\t')
- {
- strAppInstall[i] = '\0';
- break;
- }
- }
- fclose(fp);
- return 1;
- }
- }
- fclose(fp);
- return -1;
-}
-
-static int is_app_built_pie(void)
-{
- int result;
- FILE *fp;
- char buf[DA_LOG_MAX];
-
- if((fp = fopen(DA_BUILD_OPTION, "r")) == NULL)
- {
- LOGE("Failed to open %s\n", DA_BUILD_OPTION);
- return -1;
- }
-
- if(fgets(buf, DA_LOG_MAX, fp) != NULL)
- {
- if(strcmp(buf, "DYN\n") == 0)
- result = 1;
- else if(strcmp(buf, "EXEC\n") == 0)
- result = 0;
- else
- result = -1;
- }
- else
- {
- result = -1;
- }
- fclose(fp);
-
- return result;
-}
-
-static int get_app_base_address(int *baseAddress)
-{
- int res;
- FILE *fp;
- char buf[DA_LOG_MAX];
-
- if((fp = fopen(DA_BASE_ADDRESS, "r")) == NULL)
- {
- LOGE("Failed to open %s\n", DA_BASE_ADDRESS);
- return -1;
- }
-
- if(fgets(buf, DA_LOG_MAX, fp) != NULL)
- {
- res = sscanf(buf, "%x", baseAddress);
- }
- else
- {
- res = -1;
- }
- fclose(fp);
-
- return res;
-}
-
-static int is_same_app_process(int pid)
-{
- int ret = 0;
- FILE *fp;
- char buf[DA_LOG_MAX];
- char cmdPath[PATH_MAX];
- char execPath[PATH_MAX];
-
- get_executable(execPath, PATH_MAX);
- sprintf(cmdPath, "/proc/%d/cmdline", pid);
-
- if((fp = fopen(cmdPath, "r")) == NULL)
- {
- return 0;
- }
-
- if(fgets(buf, DA_LOG_MAX, fp) != NULL)
- {
-#if RUN_APP_LOADER
- if(strcmp(buf, manager.appPath) == 0)
-#else
- // use execPath instead of manager.appPath
- if(strcmp(buf, execPath) == 0)
-#endif
- ret = 1;
- else
- ret = 0;
- }
- fclose(fp);
-
- return ret;
-}
-
-static int sendMsgStrToHost(char* str, int msgType, int targetNo)
-{
- static int initialized = 0;
- int pid;
- int is_pie_build;
- int base_address;
- int app_type;
- char log[DA_LOG_MAX];
- char bufDeviceInfo[DA_LOG_MAX];
- char bufAppInstall[APP_INSTALL_PATH_MAX];
-
- switch (msgType)
- {
- case MSG_LOG:
- case MSG_RESOURCE:
- case MSG_SAMPLE:
- case MSG_ERROR:
- if(__builtin_expect(initialized == 0, 0))
- return -1;
- sprintf(log, "%d|%s\n", msgType, str);
- break;
- case MSG_PID:
- LOGI("MSG_PID handling : %s\n", str);
- pid = atoi(str);
- if ((manager.iTarget.execPID[targetNo] != -1) && (pid != manager.iTarget.execPID[targetNo]))
- {
- LOGE("Failed to check pid, pid of msg(%d), stored pid(%d)\n", pid, manager.iTarget.execPID[targetNo]);
- return -1;
- }
- LOGI("pid[%d]=%d\n",targetNo,pid);
- manager.iTarget.execPID[targetNo] = pid;
- manager.iTarget.pidCount++;
-
- {
- char execPath[PATH_MAX];
- char realPath[PATH_MAX];
- char mapsPath[PATH_MAX];
- char appInstallCommand[PATH_MAX];
-
- get_executable(execPath, PATH_MAX);
- if(realpath(execPath, realPath) == NULL)
- {
- LOGW("Failed to get realpath of app\n");
- strcpy(realPath, execPath);
- }
-
- sprintf(mapsPath, "/proc/%d/maps", manager.iTarget.execPID[targetNo]);
- sprintf(appInstallCommand,
- "cat %s | grep %s | cut -d\"-\" -f1 > %s", mapsPath,
- realPath, DA_BASE_ADDRESS);
- LOGI("appInstallCommand is %s\n", appInstallCommand);
-
- do {
- if(access(mapsPath, F_OK) != 0)
- return -1;
- if(is_same_app_process(manager.iTarget.execPID[targetNo]) == 0)
- return -1;
-
- system(appInstallCommand);
- if(get_app_base_address(&base_address) == 1)
- break;
- sleep(0);
- }
- while(1);
- }
- return 0;
- break;
- case MSG_TIME:
- LOGI("MSG_TIME handling : %s\n", str);
- if (strlen(manager.appPath) > 0)
- {
- is_pie_build = is_app_built_pie();
- get_app_base_address(&base_address);
- app_type = get_app_type();
- bufAppInstall[0] = '\0';
- get_app_install_path(bufAppInstall, APP_INSTALL_PATH_MAX);
- get_device_info(bufDeviceInfo, DA_LOG_MAX);
- if (strlen(bufAppInstall) > 0)
- {
- char buf[PATH_MAX];
- get_executable(buf, PATH_MAX);
- sprintf(log, "%d|%s`,%d`,%s`,%d`,%u`,%d`,%s/%s\n", MSG_DEVICE, bufDeviceInfo,
- manager.iTarget.execPID[targetNo], str, is_pie_build, base_address, app_type,
- bufAppInstall, get_app_name(buf));
- }
- else
- sprintf(log, "%d|%s`,%d`,%s`,%d`,%u`,%d`,\n", MSG_DEVICE, bufDeviceInfo,
- manager.iTarget.execPID[targetNo], str, is_pie_build, base_address, app_type);
- LOGI("MSG_DEVICE msg : %s\n", log);
- }
- else
- {
- sprintf(log, "%d|%d`,%s", MSG_PID, manager.iTarget.execPID[targetNo], str);
- LOGI("MSG_DEVICE msg without appname : %s\n", log);
- }
- initialized = 1;
- break;
- case MSG_TERMINATE:
- LOGI("MSG_TERMINATE handling : connectCount(%d)\n", manager.iTarget.connectCount);
- if(manager.iTarget.connectCount == 1 ){
- sprintf(log, "%d|\n", msgType);
- pthread_mutex_lock(&(manager.sendMutex));
-#ifndef LOCALTEST
- send(manager.iHost.clientSockFD, log, strlen(log), 0);
-#else
- LOGI("send to host : %s\n", log);
-#endif
- pthread_mutex_unlock(&(manager.sendMutex));
- }
- return 0;
- default:
- sprintf(log, "%d|%s\n", msgType, str);
- break;
- }
-
- if(manager.iHost.status >= DAS_TARGET_ARM_BATT_START && manager.iHost.status <= DAS_EMUL_X86_BATT_START)
- {
- LOGI("write batt log\n");
- write_batt_log(log);
- }
- else
- {
- if (manager.iHost.clientSockFD != -1)
- {
- pthread_mutex_lock(&(manager.sendMutex));
-#ifndef LOCALTEST
- send(manager.iHost.clientSockFD, log, strlen(log), 0);
-#else
- LOGI("send to host : %s\n", log);
-#endif
- pthread_mutex_unlock(&(manager.sendMutex));
- }
- }
- return 0;
-}
-
-static void* timerThread(void* data)
-{
- int err, signo;
- char buf[DA_LOG_MAX];
- sigset_t waitsigmask;
-
- LOGI("Timer thread started\n");
-
- sigemptyset(&waitsigmask);
- sigaddset(&waitsigmask, SIGALRM);
- sigaddset(&waitsigmask, SIGUSR1);
-
- while(1)
- {
- err = sigwait(&waitsigmask, &signo);
- if(err != 0)
- {
- LOGE("Failed to sigwait() in timer thread\n");
- continue;
- }
-
- if(signo == SIGALRM)
- {
- get_resource_info(buf, DA_LOG_MAX, manager.iTarget.execPID, manager.iTarget.pidCount);
- sendMsgStrToHost(buf, MSG_RESOURCE, -1);
-
- if (manager.iTarget.status < DAS_START_BEGIN || manager.iTarget.status > DAS_START_END )
- break;
- }
- else if(signo == SIGUSR1)
- {
- // end this thread
- break;
- }
- else
- {
- // not happened
- LOGE("This should not be happend in timer thread\n");
- }
- }
-
- LOGI("Timer thread ended\n");
- return NULL;
-}
-
-// return 0 if normal case
-// return minus value if critical error
-// return plus value if non-critical error
-static int timerStart()
-{
- sigset_t newsigmask;
- struct itimerval timerval;
-// char buf[DA_LOG_MAX];
-
- if(manager.timer_thread != -1) // already started
- return 1;
-
- sigemptyset(&newsigmask);
- sigaddset(&newsigmask, SIGALRM);
- sigaddset(&newsigmask, SIGUSR1);
- if(pthread_sigmask(SIG_BLOCK, &newsigmask, NULL) != 0)
- {
- LOGE("Failed to signal masking for main thread\n");
- return -1;
- }
-
- if(pthread_create(&(manager.timer_thread), NULL, timerThread, NULL) < 0)
- {
- LOGE("Failed to create timer thread\n");
- return -1;
- }
-
- timerval.it_interval.tv_sec = TIMER_INTERVAL_SEC;
- timerval.it_interval.tv_usec = TIMER_INTERVAL_USEC;
- timerval.it_value.tv_sec = TIMER_INTERVAL_SEC;
- timerval.it_value.tv_usec = TIMER_INTERVAL_USEC;
- setitimer(ITIMER_REAL, &timerval, NULL);
-
- // commected because this resource log send to host before receiving MSG_TIME message from target process
- // send initial value of profiling
-// get_resource_info(buf, DA_LOG_MAX, manager.iTarget.execPID, manager.iTarget.pidCount);
-// sendMsgStrToHost(buf, MSG_RESOURCE, -1);
-
- return 0;
-}
-
-static int timerStop()
-{
- if(manager.timer_thread != -1)
- {
-// int status;
-// sigset_t oldsigmask;
- struct itimerval stopval;
-
-// sigemptyset(&oldsigmask);
-// sigaddset(&oldsigmask, SIGALRM);
-// sigaddset(&oldsigmask, SIGUSR1);
-
- stopval.it_interval.tv_sec = 0;
- stopval.it_interval.tv_usec = 0;
- stopval.it_value.tv_sec = 0;
- stopval.it_value.tv_usec = 0;
-
- // stop timer
- setitimer(ITIMER_REAL, &stopval, NULL);
-
- pthread_kill(manager.timer_thread, SIGUSR1);
-// pthread_join(manager.timer_thread, (void**) &status);
-
-// if(sigprocmask(SIG_UNBLOCK, &oldsigmask, NULL) < 0)
-// {
-// LOGE("Failed to pthread_sigmask\n");
-// }
- manager.timer_thread = -1;
- }
- __destroySharedMemory();
-
- return 0;
-}
-
-#ifdef USE_BATT_LOG
-static void wait_for_starting()
-{
- static int chargerfd = -1;
- while (get_file_status(&chargerfd, CHARGERFD))
- {
- LOGI("wait for starting ... \n");
- __sleep(MONITORING_INTERVAL);
- }
-}
-#endif
-
-static int startProfiling(char* execpath, enum DAState status, long launchflag)
-{
- if(__createSharedMemory() < 0)
- {
- LOGE("Failed to create shared memory\n");
- return -1;
- }
-
- // set launch flag before execute application
- manager.sharedmem.pvalue->launch_flag = launchflag;
-
- // remove previous screen capture files
- remove_indir(SCREENSHOT_DIR);
- mkdir(SCREENSHOT_DIR, 0777);
-
- // execute application
- if (exec_app(execpath, get_app_type()))
- {
- manager.iTarget.status = status;
- if(timerStart() < 0)
- {
- return -1;
- }
- LOGI("Timer Started\n");
- }
- else
- {
- return -1;
- }
-
- return 0;
-}
-
-static void* terminate_thread(void* data)
-{
- int i;
- FILE* fp;
- size_t readbyte;
- char cmd[MAX_PATH_LENGTH];
- pid_t* pids = (pid_t*)data;
-
- sleep(1);
- for(i = 0; pids[i] != -2; i++)
- {
- if(pids[i] != -1)
- {
- sprintf(cmd, "ps ax | grep %d | grep -v grep", pids[i]);
- fp = popen(cmd, "r");
- if(fp)
- {
- readbyte = fread(cmd, MAX_PATH_LENGTH - 1, 1, fp);
- if(readbyte > 0) // process is still alive
- {
- sprintf(cmd, "kill -9 %d", pids[i]);
- system(cmd);
- }
- pclose(fp);
- }
- }
- }
-
- free(pids);
-
- return NULL;
-}
-
-static void terminate_all_target()
-{
- int i;
- pthread_t term_thread;
- pid_t* pids;
-
- pids = (pid_t*)malloc((manager.iTarget.pidCount + 1) * sizeof(pid_t));
-
- for (i = 0; i < manager.iTarget.pidCount; i++)
- {
- pids[i] = manager.iTarget.execPID[i];
- if(manager.iTarget.execPID[i] != -1)
- {
- LOGI("TERMINATE process(%d) by terminate_all_target()\n", manager.iTarget.execPID[i]);
- aul_terminate_pid(manager.iTarget.execPID[i]);
- manager.iTarget.execPID[i] = -1;
- }
- }
- pids[manager.iTarget.pidCount] = -2;
-
- pthread_create(&term_thread, NULL, terminate_thread, pids);
-
- manager.iTarget.pidCount = 0;
-}
-
-static void terminate_error(char* errstr, int sendtohost)
-{
- LOGE("%s, status(%d)\n", errstr, manager.iHost.status);
- manager.iHost.status = DAS_STOP;
-
- terminate_all_target();
-
- timerStop();
-
- if(sendtohost)
- sendMsgStrToHost(errstr, MSG_ERROR, -1);
-}
-
-
-// return 0 if normal case
-// return plus value if non critical error occur
-// return minus value if critical error occur
-static int hostMessageHandler(log_t * log)
-{
- int ret = 0;
- long flag = 0;
- char *barloc, *tmploc;
- char execPath[PATH_MAX];
-
- if (log == NULL)
- return 1;
-
- switch (log->type)
- {
- case MSG_START:
- LOGI("MSG_START handling : %s\n", log->data);
- if (manager.iHost.status >= DAS_START_BEGIN && manager.iHost.status <= DAS_START_END)
- {
- LOGE("MSG_START status check : %d\n", manager.iHost.status);
- return 1; // already started, then ignore this MSG_START message
- }
-
- if(log->length == 0)
- return -1; // wrong message format
-
- // parsing for host start status
- tmploc = log->data;
- barloc = strchr(tmploc, '|');
- if(barloc != NULL)
- {
- manager.iHost.status = 0;
- while(tmploc < barloc)
- {
- manager.iHost.status = (manager.iHost.status * 2) + (*tmploc - '0');
- tmploc++;
- }
- manager.iHost.status += 1;
-
- if(manager.iHost.status < DAS_START_BEGIN || manager.iHost.status > DAS_START_END)
- {
- manager.iHost.status = DAS_EMUL_X86_START;
- ret = 1;
- }
- }
- else
- {
- return -1; // wrong message format
- }
-
- // parsing for target launch option flag
- tmploc = barloc + 1;
- barloc = strchr(tmploc, '|');
- if(barloc != NULL)
- {
- while(tmploc < barloc)
- {
- flag = (flag * 2) + (*tmploc - '0');
- tmploc++;
- }
- }
- else
- {
- return -1; // wrong message format
- }
-
- // parsing for application package name
- tmploc = barloc + 1;
- strcpy(manager.appPath, tmploc);
-
-#ifdef USE_BATT_LOG
- if(manager.iHost.status == DAS_EMUL_ARM_BATT_START ||
- manager.iHost.status == DAS_EMUL_X86_BATT_START)
- wait_for_starting();
-#endif
-
- get_executable(execPath, PATH_MAX); // get exact app executable file name
-#if RUN_APP_LOADER
- kill_app(manager.appPath);
-#else
- // use execPath instead of manager.appPath
- kill_app(execPath);
-#endif
- sleep(0);
-
- LOGI("executable app path %s\n", manager.appPath);
-
- {
- char appInstallCommand[PATH_MAX];
-
- //save app install path
- mkdir(DA_INSTALL_DIR, 0775);
- sprintf(appInstallCommand,
- "%s -Wwi %s | grep DW_AT_comp_dir > %s", DA_READELF_PATH,
- execPath, DA_INSTALL_PATH);
- LOGI("appInstallCommand %s\n", appInstallCommand);
- system(appInstallCommand);
-
- sprintf(appInstallCommand,
- "%s -h %s | grep Type | cut -d\" \" -f33 > %s", DA_READELF_PATH,
- execPath, DA_BUILD_OPTION);
- LOGI("appInstallCommand %s\n", appInstallCommand);
- system(appInstallCommand);
-
-#if RUN_APP_LOADER
- if(startProfiling(manager.appPath, manager.iHost.status, flag) < 0)
-#else
- // use execPath instead of manager.appPath
- if(startProfiling(execPath, manager.iHost.status, flag) < 0)
-#endif
- {
- terminate_error("Cannot start profiling", 1);
- return -1;
- }
- }
- break;
- case MSG_STOP:
- LOGI("MSG_STOP handling\n");
- if (manager.iHost.status < DAS_START_BEGIN || manager.iHost.status > DAS_START_END)
- {
- // already stopped, not possible, ignore MSG_STOP message
- LOGE("MSG_STOP status check : %d\n", manager.iHost.status);
- return 1;
- }
-
- manager.iHost.status = DAS_STOP;
- terminate_all_target();
- timerStop();
- break;
- case MSG_OPTION:
- if(log->length > 0)
- {
- if(log->data[0] == '0')
- {
- set_launch_flag(1, 0);
- LOGI("Snapshot disabled\n");
- }
- else if(log->data[0] == '1')
- {
- set_launch_flag(1, 1);
- LOGI("Snapshot enabled\n");
- }
- else
- {
- LOGI("Wrong option message from host\n");
- }
- }
- break;
- case MSG_ISALIVE:
- sendMsgStrToHost(NULL, MSG_ALIVE, 0);
- break;
-
-#ifdef USE_BATT_LOG
- case MSG_BATT_START:
- {
- manager.iHost.status = DAS_BATT_START;
- sprintf(manager.appPath, "%s", log->data);
- create_open_batt_log(get_app_name(manager.appPath));
- wait_for_starting();
- if(startProfiling(manager.appPath, DAS_BATT_START, flag) < 0)
- {
- terminate_error("Cannot start profiling", 1);
- return -1;
- }
-// batt_start(manager.appPath);
- }
- break;
- case MSG_BATT_STOP:
- manager.iHost.status = DAS_BATT_STOP;
- timerStop();
-// batt_stop();
- break;
-#endif
-
- default:
- LOGW("Unknown msg\n");
- }
-
- return ret;
-}
-
-static int parseHostMessage(log_t* log, char* msg)
-{
- int i;
- int bfind = 0;
-
- if(log == NULL || msg == NULL)
- return 0;
-
- // Host message looks like this
- // MSG_TYPE|MSG_LENGTH|MSG_STRING
- // MSG_TYPE is always 3 digits number
- if(msg[3] == '|')
- {
- msg[3] = '\0';
- log->type = atoi(msg);
-
- if(log->type < MSG_HOST_BEGIN || log->type > MSG_HOST_END)
- return 0;
-
- msg = msg + 4;
- for(i = 0; msg[i] != '\0'; i++)
- {
- if(msg[i] == '|')
- {
- bfind = 1;
- msg[i] = '\0';
- break;
- }
- }
-
- if(bfind != 0)
- {
- int msglen;
- log->length = atoi(msg);
- msg = msg + i + 1;
- msglen = strlen(msg);
-
- if(log->length == 0)
- {
- log->data[0] = '\0';
- }
- else
- {
- if(msglen == log->length)
- strcpy(log->data, msg);
- else if(msglen > log->length) // parsing error but deal as nonerror
- strncpy(log->data, msg, log->length);
- else
- return 0; // parsing error
-
- log->data[log->length] = '\0';
- }
- }
- else
- {
- return 0; // parsing error
- }
-
- return 1; // parsing success
- }
- else
- {
- return 0; // parsing error
- }
-}
-
-#define EPOLL_SIZE 10
-#define MAX_CONNECT_SIZE 12
-#define MAX_INAROW_TARGET_MSG 10
-
-// return 0 for normal case
-static int work()
-{
- struct sockaddr_un clientAddrUn; //target
- struct sockaddr_in clientAddrIn; //host
- int i, k, find;
- ssize_t recvLen;
- char recvBuf[READ_BUF_MAX];
- log_t log;
-
- struct epoll_event ev, *events;
- int efd; // epoll fd
- int numevent; // number of occured events
-
- // initialize epoll event pool
- events = (struct epoll_event*) malloc(sizeof(struct epoll_event) * EPOLL_SIZE);
- if(events == NULL)
- {
- LOGE("Out of memory when allocate epoll event pool\n");
- return -1;
- }
- if((efd = epoll_create(MAX_CONNECT_SIZE)) < 0)
- {
- LOGE("epoll creation error\n");
- free(events);
- return -1;
- }
-
- // add server sockets to epoll event pool
- ev.events = EPOLLIN;
- ev.data.fd = manager.iHost.serverSockFD;
- if(epoll_ctl(efd, EPOLL_CTL_ADD, manager.iHost.serverSockFD, &ev) < 0)
- {
- LOGE("Host server socket epoll_ctl error\n");
- free(events);
- close(efd);
- return -1;
- }
- ev.events = EPOLLIN;
- ev.data.fd = manager.iTarget.serverSockFD;
- if(epoll_ctl(efd, EPOLL_CTL_ADD, manager.iTarget.serverSockFD, &ev) < 0)
- {
- LOGE("Target server socket epoll_ctl error\n");
- free(events);
- close(efd);
- return -1;
- }
-
- // handler loop
- while (1)
- {
- numevent = epoll_wait(efd, events, EPOLL_SIZE, -1);
- if(numevent <= 0)
- {
- LOGE("Failed to epoll_wait : num of event(%d), errno(%d)\n", numevent, errno);
- continue;
- }
-
- for(i = 0; i < numevent; i++)
- {
- find = 0;
- for(k = 0; k < manager.iTarget.connectCount; k++)
- {
- if(events[i].data.fd == manager.iTarget.clientSockFD[k])
- {
- // read from target process
- recvLen = recv(manager.iTarget.clientSockFD[k], &log,
- sizeof(log.type) + sizeof(log.length), 0);
-
- // send to host
- if (recvLen > 0)
- {
- int count = 0;
- do {
- if (log.length > 0)
- recv(manager.iTarget.clientSockFD[k], log.data, log.length, 0);
- log.data[log.length] = '\0';
- if(log.type == 5) // MSG_LOG
- {
- switch(log.data[0])
- {
- case '2': // UI control creation log
- case '3': // UI event log
- case '6': // UI lifecycle log
- case '7': // screnshot log
- case '8': // scene transition log
- LOGI("%dclass|%s\n", log.data[0] - '0', log.data);
- break;
- default:
- break;
- }
- }
- else if(log.type == 6) // MSG_IMAGE
- {
- LOGI("MSG_IMAGE received\n");
- }
- else // not MSG_LOG and not MSG_IMAGE
- {
- LOGI("Extra MSG TYPE (%d|%d|%s)\n", log.type, log.length, log.data);
- }
- sendMsgStrToHost(log.data, log.type, k);
- if(count++ > MAX_INAROW_TARGET_MSG)
- break;
- } while ((recvLen = recv(manager.iTarget.clientSockFD[k],
- &log, sizeof(log.type) + sizeof(log.length), MSG_DONTWAIT)) > 0);
- }
-
- // close request from target client socket
- if(recvLen == 0)
- {
- LOGI("target close = %d(total %d)\n", manager.iTarget.clientSockFD[k], manager.iTarget.connectCount - 1);
- if(epoll_ctl(efd, EPOLL_CTL_DEL, manager.iTarget.clientSockFD[k], NULL) < 0)
- {
- LOGE("Failed to epoll_ctl delete fd from event poll\n");
- }
- close(manager.iTarget.clientSockFD[k]);
- LOGI("Terminate %dth pid(%d)\n", k, manager.iTarget.execPID[k]);
- // consume that target process is already in terminating phase
-// _terminate_pid(manager.iTarget.execPID[k]);
- manager.iTarget.connectCount--;
- if(manager.iTarget.execPID[k] != -1)
- manager.iTarget.pidCount--;
-// assert(manager.iTarget.connectCount == manager.iTarget.pidCount);
- if (manager.iTarget.connectCount == 0) // all target client are closed
- {
- manager.iTarget.status = DAS_TERMINATE;
-
- LOGI("Exit daemon process\n");
- manager.iTarget.clientSockFD[k] = -1;
- manager.iTarget.execPID[k] = -1;
- timerStop();
- free(events);
- close(efd);
- return 0;
- }
- else
- {
- manager.iTarget.clientSockFD[k] = manager.iTarget.clientSockFD[manager.iTarget.connectCount];
- manager.iTarget.clientSockFD[manager.iTarget.connectCount] = -1;
- manager.iTarget.execPID[k] = manager.iTarget.execPID[manager.iTarget.pidCount];
- manager.iTarget.execPID[manager.iTarget.pidCount] = -1;
- }
- }
-
- find = 1;
- break;
- }
- }
- if(find == 0) // this event is not from target client socket
- {
- // connect request from target
- if(events[i].data.fd == manager.iTarget.serverSockFD)
- {
- socklen_t addrlen;
- addrlen = sizeof(clientAddrUn);
- manager.iTarget.clientSockFD[manager.iTarget.connectCount] =
- accept(manager.iTarget.serverSockFD, (struct sockaddr *) &clientAddrUn, &addrlen);
-
- if(manager.iTarget.clientSockFD[manager.iTarget.connectCount] >= 0) // accept succeed
- {
- ev.events = EPOLLIN;
- ev.data.fd = manager.iTarget.clientSockFD[manager.iTarget.connectCount];
- if(epoll_ctl(efd, EPOLL_CTL_ADD, manager.iTarget.clientSockFD[manager.iTarget.connectCount], &ev) < 0)
- {
- // consider as accept fail
- LOGE("Target client epoll_ctl error\n");
- manager.iTarget.clientSockFD[manager.iTarget.connectCount] = -1;
- }
- else
- {
- LOGI("target connect = %d(total%d)\n",
- manager.iTarget.clientSockFD[manager.iTarget.connectCount], manager.iTarget.connectCount + 1);
- manager.iTarget.connectCount++;
- }
- }
- else // accept error
- {
- LOGE("Failed to accept from target server socket\n");
- }
- }
- // connect request from host
- else if(events[i].data.fd == manager.iHost.serverSockFD)
- {
- socklen_t addrlen;
- addrlen = sizeof(clientAddrIn);
- if(manager.iHost.clientSockFD != -1)
- {
- if(epoll_ctl(efd, EPOLL_CTL_DEL, manager.iHost.clientSockFD, NULL) < 0)
- {
- LOGE("Failed to delete host client socket from epoll ctrl queue\n");
- }
- close(manager.iHost.clientSockFD);
- LOGI("Host client socket is closed, fd(%d)\n", manager.iHost.clientSockFD);
- }
- manager.iHost.clientSockFD = accept(manager.iHost.serverSockFD, (struct sockaddr *) &clientAddrIn, &addrlen);
-
- if(manager.iHost.clientSockFD >= 0) // accept succeed
- {
- ev.events = EPOLLIN;
- ev.data.fd = manager.iHost.clientSockFD;
- if(epoll_ctl(efd, EPOLL_CTL_ADD, manager.iHost.clientSockFD, &ev) < 0)
- {
- // consider as accept fail
- close(manager.iHost.clientSockFD);
- manager.iHost.clientSockFD = -1;
- terminate_error("Host client epoll_ctl error", 1);
- }
- else
- {
- LOGI("host connect = %d\n", manager.iHost.clientSockFD);
- }
- }
- else // accept error
- {
- LOGE("Failed to accept from host server socket\n");
- }
- }
- // message from host
- else if(events[i].data.fd == manager.iHost.clientSockFD)
- {
- // host log format xxx|length|str
- LOGI("Host client socket selected(Message from host)\n");
- recvLen = recv(manager.iHost.clientSockFD, recvBuf, READ_BUF_MAX, 0);
-
- if (recvLen > 0)
- {
- recvBuf[recvLen] = '\0';
- LOGI("host sent this msg len(%d) str(%s)\n", recvLen, recvBuf);
- if(parseHostMessage(&log, recvBuf) == 0)
- {
- // error to parse host message
- sendMsgStrToHost("host log message is unrecognizable", MSG_ERROR, -1);
- continue;
- }
-
- //host msg command handling
- if(hostMessageHandler(&log) < 0)
- {
- terminate_error("Host message handling error", 1);
- free(events);
- close(efd);
- return 0;
- }
- }
- else // close request from HOST
- {
- // work loop quit
- if(manager.iHost.status >= DAS_START_BEGIN && manager.iHost.status <= DAS_START_END)
- {
- // host client socket end unexpectly
- terminate_error("Host client socket closed unexpectly", 0);
- }
- LOGI("host close = %d\n", manager.iHost.clientSockFD);
- free(events);
- close(efd);
- return 0;
- }
- }
- else
- {
- // never happened
- LOGW("Unknown socket fd\n");
- }
- }
- }
- }
-
- free(events);
- close(efd);
- return 0;
-}
-
-// return 0 for normal case
-static int initialize_manager()
-{
- int i;
- // make server socket
- if(__makeTargetServerSockFD() != 0)
- return -1;
- if(__makeHostServerSockFD() != 0)
- return -1;
-
- // initialize target client sockets
- for (i = 0; i < TARGET_CLIENT_COUNT_MAX; i++)
- {
- manager.iTarget.clientSockFD[i] = -1;
- manager.iTarget.execPID[i] = -1;
- }
-
- // initialize sendMutex
- pthread_mutex_init(&(manager.sendMutex), NULL);
-
- if(initialize_system_info() < 0)
- return -1;
-
- return 0;
-}
-
-static int finalize_manager()
-{
- int i;
-
- finalize_system_info();
-
- terminate_all_target();
-
- LOGI("Finalize daemon\n");
-
- // finalize target client sockets
- for (i = 0; i < TARGET_CLIENT_COUNT_MAX; i++)
- {
- if(manager.iTarget.clientSockFD[i] != -1)
- close(manager.iTarget.clientSockFD[i]);
- }
-
- // close host client socket
- if(manager.iHost.clientSockFD != -1)
- close(manager.iHost.clientSockFD);
-
- // close server socket
- if(manager.iHost.serverSockFD != -1)
- close(manager.iHost.serverSockFD);
- if(manager.iTarget.serverSockFD != -1)
- close(manager.iTarget.serverSockFD);
-
- return 0;
-}
-
-static void __attribute((destructor)) exit_func()
-{
- __destroySharedMemory();
-}
-
-int main()
-{
-#if DEBUG
- write_log();
-#endif
-
- //for terminal exit
- signal(SIGHUP, SIG_IGN);
- chdir("/");
-
- //new session reader
- setsid();
-
- // initialize manager
- if(initialize_manager() == 0)
- {
- //daemon work
- work();
-
- finalize_manager();
- return 0;
- }
- else
- return 1;
-}
+++ /dev/null
-/*
-* DA manager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-*
-* Jaewon Lim <jaewon81.lim@samsung.com>
-* Woojin Jung <woojin2.jung@samsung.com>
-* Juyoung Kim <j0.kim@samsung.com>
-*
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-#ifndef _DA_DEBUG_H_
-#define _DA_DEBUG_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if DEBUG
- #define LOGI(...) do{ fprintf(stderr, "[INF]" __VA_ARGS__ ); fflush(stderr); } while(0)
- #define LOGE(...) do{ fprintf(stderr, "[ERR]" __VA_ARGS__ ); fflush(stderr); } while(0)
- #define LOGW(...) do{ fprintf(stderr, "[WRN]" __VA_ARGS__ ); fflush(stderr); } while(0)
-#else
- #define LOGI(...) do{} while(0)
- #define LOGE(...) do{} while(0)
- #define LOGW(...) do{} while(0)
-#endif
-
-
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // _DA_DEBUG_H_
+++ /dev/null
-/*
-* DA manager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-*
-* Jaewon Lim <jaewon81.lim@samsung.com>
-* Woojin Jung <woojin2.jung@samsung.com>
-* Juyoung Kim <j0.kim@samsung.com>
-*
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <dirent.h>
-
-#ifndef LOCALTEST
-#include <system_info.h>
-#include <runtime_info.h>
-#include <telephony_network.h>
-#include <call.h>
-#endif
-
-#define USE_VCONF
-
-#ifdef USE_VCONF
-#include "vconf.h"
-#endif
-
-#include "sys_stat.h"
-#include "da_debug.h"
-
-// defines for runtime environment
-#define FOR_EACH_CPU
-
-
-#define BUFFER_MAX 1024
-#define LARGE_BUFFER 512
-#define MIDDLE_BUFFER 256
-#define SMALL_BUFFER 64
-#define PROCPATH_MAX 32
-#define STATUS_STRING_MAX 16
-#define MAX_NUM_OF_FREQ 16
-
-#define MEM_SLOT_TOTAL 0
-#define MEM_SLOT_FREE 1
-#define MEM_SLOT_BUFFER 2
-#define MEM_SLOT_CACHED 3
-#define MEM_SLOT_MAX 4
-
-#define MIN_TICKS_FOR_LOAD 8
-#define MIN_TOTAL_TICK 10
-#define SYS_INFO_TICK 100 // TODO : change to (Hertz * profiling period)
-
-#define CPUMHZ "cpu MHz"
-#define DA_PROBE_TIZEN_SONAME "da_probe_tizen.so"
-#define DA_PROBE_OSP_SONAME "da_probe_osp.so"
-
-#ifndef likely
-#define likely(x) __builtin_expect((x), 1)
-#define unlikely(x) __builtin_expect((x), 0)
-#endif
-
-enum PROCESS_DATA
-{
- PROCDATA_STAT,
- PROCDATA_SMAPS
-};
-
-long long get_total_alloc_size();
-
-// declared by greatim
-static int Hertz = 0;
-static int num_of_cpu = 0;
-static int num_of_freq = 0;
-static unsigned long mem_slot_array[MEM_SLOT_MAX];
-static CPU_t* cpus = NULL;
-static unsigned long probe_so_size = 0;
-
-// utility function
-int get_flag_num(unsigned int flag)
-{
- int i;
- for(i = 0; flag != 0; i++)
- {
- flag &= (flag - 1);
- }
- return i;
-}
-
-
-
-// daemon api : get status from file
-// pfd must not be null
-int get_file_status(int* pfd, const char* filename)
-{
- int status = 0;
-
-#ifndef LOCALTEST
- if(likely(pfd != NULL))
- {
- char buf[STATUS_STRING_MAX];
-
- if(unlikely(*pfd < 0)) // open file first
- {
- *pfd = open(filename, O_RDONLY);
- if(unlikely(*pfd == -1))
- {
- return -(errno);
- }
- }
- else
- {
- lseek(*pfd, 0, SEEK_SET); // rewind to start of file
- }
-
- // read from file
- if(unlikely(read(*pfd, buf, STATUS_STRING_MAX) == -1))
- {
- status = -(errno);
- }
- else
- {
- status = atoi(buf);
- }
- }
-#endif
-
- return status;
-}
-
-// ==============================================================================
-// device status information getter functions
-// ==============================================================================
-static int get_wifi_status()
-{
- int wifi_status = 0;
-
-#ifndef LOCALTEST
- #ifdef USE_VCONF
- if (unlikely(vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_status) < 0))
- {
- wifi_status = VCONFKEY_WIFI_OFF;
- }
- #else
- if (unlikely(runtime_info_get_value_int(
- RUNTIME_INFO_KEY_WIFI_STATUS, &wifi_status) < 0))
- {
- wifi_status = RUNTIME_INFO_WIFI_STATUS_DISABLED;
- }
- #endif // USE_VCONF
-#endif
-
- return wifi_status;
-}
-
-static int get_bt_status()
-{
- int bt_status = false;
-
-#ifndef LOCALTEST
- #ifdef USE_VCONF
- if (unlikely(vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0))
- {
- bt_status = VCONFKEY_BT_STATUS_OFF;
- }
- #else
- if (unlikely(runtime_info_get_value_bool(
- RUNTIME_INFO_KEY_BLUETOOTH_ENABLED, (bool*)&bt_status) < 0))
- {
- bt_status = 0;
- }
- #endif // USE_VCONF
-#endif
-
- return bt_status;
-}
-
-static int get_gps_status()
-{
- int gps_status = 0;
-
-#ifndef LOCALTEST
- #ifdef USE_VCONF
- if(unlikely(vconf_get_bool(VCONFKEY_LOCATION_ENABLED, &gps_status) < 0))
- {
- gps_status = VCONFKEY_LOCATION_GPS_OFF;
- }
- else if(gps_status != 0)
- {
- if (unlikely(vconf_get_int(VCONFKEY_LOCATION_GPS_STATE, &gps_status) < 0))
- {
- gps_status = VCONFKEY_LOCATION_GPS_OFF;
- }
- }
- #else
- if (unlikely(runtime_info_get_value_bool(
- RUNTIME_INFO_KEY_LOCATION_SERVICE_ENABLED, (bool*)&gps_status) < 0))
- {
- gps_status = 0;
- }
- else if(gps_status != 0)
- {
- if (unlikely(runtime_info_get_value_bool(
- RUNTIME_INFO_KEY_LOCATION_ADVANCED_GPS_ENABLED, (bool*)&gps_status) < 0))
- {
- gps_status = 0;
- }
- else if(gps_status != 0)
- {
- if(unlikely(runtime_info_get_value_int(
- RUNTIME_INFO_KEY_GPS_STATUS, &gps_status) < 0))
- {
- gps_status = 0;
- }
- else
- {
- // do nothing (gps_status is real gps status)
- }
- }
- else
- {
- // do nothing (gps_status == 0)
- }
- }
- else
- {
- // do nothing (gps_status == 0)
- }
- #endif // USE_VCONF
-#endif
-
- return gps_status;
-}
-
-static int get_brightness_status()
-{
- static int brightnessfd = -1;
- int brightness_status = 0;
-
-#ifndef LOCALTEST
- #ifdef DEVICE_ONLY
- DIR* dir_info;
- struct dirent* dir_entry;
- char fullpath[PATH_MAX];
-
- dir_info = opendir(BRIGHTNESS_PARENT_DIR);
- if(dir_info != NULL)
- {
- while((dir_entry = readdir(dir_info)) != NULL)
- {
- if(strcmp(dir_entry->d_name, ".") == 0 || strcmp(dir_entry->d_name, "..") == 0)
- continue;
- else // first directory
- {
- sprintf(fullpath, BRIGHTNESS_PARENT_DIR "/%s/" BRIGHTNESS_FILENAME, dir_entry->d_name);
- brightness_status = get_file_status(&brightnessfd, fullpath);
- }
- }
- }
- else
- {
- // do nothing
- }
- #else
- brightness_status = get_file_status(&brightnessfd, EMUL_BRIGHTNESSFD);
- #endif
-#endif // LOCALTEST
-
- return brightness_status;
-}
-
-static int get_max_brightness()
-{
- int maxbrightnessfd = -1;
- static int max_brightness = -1;
-
-#ifndef LOCALTEST
- if(__builtin_expect(max_brightness < 0, 0))
- {
- #ifdef DEVICE_ONLY
- DIR* dir_info;
- struct dirent* dir_entry;
- char fullpath[PATH_MAX];
-
- dir_info = opendir(BRIGHTNESS_PARENT_DIR);
- if(dir_info != NULL)
- {
- while((dir_entry = readdir(dir_info)) != NULL)
- {
- if(strcmp(dir_entry->d_name, ".") == 0 || strcmp(dir_entry->d_name, "..") == 0)
- continue;
- else // first directory
- {
- sprintf(fullpath, BRIGHTNESS_PARENT_DIR "/%s/" MAX_BRIGHTNESS_FILENAME, dir_entry->d_name);
- max_brightness = get_file_status(&maxbrightnessfd, fullpath);
- }
- }
- }
- else
- {
- // do nothing
- }
- #else
- max_brightness = get_file_status(&maxbrightnessfd, EMUL_MAX_BRIGHTNESSFD);
- #endif
- }
-
- if(maxbrightnessfd != -1)
- close(maxbrightnessfd);
-#endif // LOCALTEST
-
- return max_brightness;
-}
-
-static int get_video_status()
-{
- static int videofd = -1;
- int video_status = 0;
-
-#ifndef LOCALTEST
- video_status = get_file_status(&videofd, MFCFD);
- if (video_status > 1)
- video_status = 0;
-#endif
-
- return video_status;
-}
-
-static int get_rssi_status()
-{
-#ifndef LOCALTEST
- int flightmode_status;
-
- #ifdef USE_VCONF
- int rssi_status;
- if(unlikely(vconf_get_bool(VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL,
- &flightmode_status) < 0))
- {
- flightmode_status = 0;
- }
-
- if(!flightmode_status)
- {
- if(unlikely(vconf_get_int(VCONFKEY_TELEPHONY_RSSI, &rssi_status) < 0))
- {
- rssi_status = VCONFKEY_TELEPHONY_RSSI_0;
- }
- }
- else
- {
- rssi_status = VCONFKEY_TELEPHONY_RSSI_0;
- }
-
- return rssi_status;
- #else
- network_info_rssi_e rssi_status;
-
- if(unlikely(runtime_info_get_value_bool(
- RUNTIME_INFO_KEY_FLIGHT_MODE_ENABLED, (bool*)&flightmode_status) < 0))
- {
- flightmode_status = 0;
- }
-
- if(!flightmode_status)
- {
- if(unlikely(network_info_get_rssi(&rssi_status) < 0))
- {
- rssi_status = NETWORK_INFO_RSSI_0;
- }
- }
- else
- {
- rssi_status = NETWORK_INFO_RSSI_0;
- }
-
- return (int)rssi_status;
- #endif // USE_VCONF
-#else
- return 0;
-#endif
-}
-
-static int get_call_status()
-{
- int call_status = 0;
-
-#ifndef LOCALTEST
- #ifdef USE_VCONF
- if(unlikely(vconf_get_int(VCONFKEY_CALL_STATE, &call_status) < 0))
- {
- call_status = VCONFKEY_CALL_OFF;
- }
- #else
- call_state_e call_state;
- if(unlikely(call_get_voice_call_state(&call_state) < 0))
- {
- if(unlikely(call_get_video_call_state(&call_state) < 0))
- {
- call_status = 0; // call idle
- }
- else
- {
- // return video call state
- if(call_state == CALL_STATE_CONNECTING)
- call_status = 3;
- else if(call_state == CALL_STATE_ACTIVE)
- call_status = 4;
- }
- }
- else if(call_state == CALL_STATE_IDLE) // voice call state is idle
- {
- if(unlikely(call_get_video_call_state(&call_state) < 0))
- {
- call_status = 0;
- }
- else
- {
- // return video call state
- if(call_state == CALL_STATE_CONNECTING)
- call_status = 3;
- else if(call_state == CALL_STATE_ACTIVE)
- call_status = 4;
- }
- }
- else
- {
- // return voice call state
- if(call_state == CALL_STATE_CONNECTING)
- call_status = 1;
- else if(call_state == CALL_STATE_ACTIVE)
- call_status = 2;
- }
- #endif // USE_VCONF
-#endif
-
- return call_status;
-}
-
-// dnet means 3G?
-static int get_dnet_status()
-{
- int dnet_status = false;
-
-#ifndef LOCALTEST
- #ifdef USE_VCONF
- if(unlikely(vconf_get_int(VCONFKEY_DNET_STATE, &dnet_status) < 0))
- {
- dnet_status = VCONFKEY_DNET_OFF;
- }
- #else
- if(unlikely(runtime_info_get_value_bool(
- RUNTIME_INFO_KEY_PACKET_DATA_ENABLED, (bool*)&dnet_status) < 0))
- {
- dnet_status = 0;
- }
- #endif // USE_VCONF
-#endif
-
- return dnet_status;
-}
-
-static int get_camera_status()
-{
- int camera_status = 0;
-
-#ifndef LOCALTEST
-#if 0
- #ifdef USE_VCONF
- if(unlikely(vconf_get_int(VCONFKEY_CAMERA_STATE, &camera_status) < 0))
- {
- camera_status = VCONFKEY_CAMERA_OFF;
- }
- #endif // USE_VCONF
-#endif
-#endif
-
- return camera_status;
-}
-
-// this means silent mode?
-static int get_sound_status()
-{
- int sound_status = 0;
-
-#ifndef LOCALTEST
- #ifdef USE_VCONF
- if(unlikely(vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL,
- &sound_status) < 0))
- {
- sound_status = 0;
- }
- #else
- if(unlikely(runtime_info_get_value_bool(
- RUNTIME_INFO_KEY_SILENT_MODE_ENABLED, (bool*)&sound_status) < 0))
- {
- sound_status = 0;
- }
- else
- {
- sound_status = (sound_status == 1) ? 0 : 1; // slient mode
- }
- #endif // USE_VCONF
-#endif
-
- return sound_status;
-}
-
-static int get_audio_status()
-{
- int audio_state = 0;
-
-#ifndef LOCALTEST
-
-#ifdef DEVICE_ONLY
- int ret = 0;
- char dev[40];
- char state[3];
- FILE *fp = NULL;
-
- fp = fopen(AUDIOFD, "r");
- if(fp == NULL)
- return -1;
-
- while(ret != EOF)
- {
- ret = fscanf(fp, "%[^:] %*c %[^\n] ", dev, state);
- if(strncmp(dev,"SPKR",4) == 0 && strncmp(state, "On",2) == 0)
- {
- audio_state = 1;
- }
- else if(ret == 2 && strncmp(dev,"Head",4) == 0 && strncmp(state, "On",2) == 0)
- {
- audio_state = 2;
- break;
- }
- }
-
- fclose(fp);
-#endif
-
-#endif // LOCALTEST
-
- return audio_state;
-}
-
-static int get_vibration_status()
-{
- int vibration_status = 0;
-
-#ifndef LOCALTEST
- #ifdef USE_VCONF
- if(unlikely(vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL,
- &vibration_status) < 0))
- {
- vibration_status = 0;
- }
- #else
- if(unlikely(runtime_info_get_value_bool(
- RUNTIME_INFO_KEY_VIBRATION_ENABLED, (bool*)&vibration_status) < 0))
- {
- vibration_status = 0;
- }
- #endif // USE_VCONF
-#endif
-
- return vibration_status;
-}
-
-static int get_voltage_status()
-{
- static int voltagefd = -2;
- return get_file_status(&voltagefd, VOLTAGEFD);
-}
-
-// =====================================================================
-// cpu information getter functions
-// =====================================================================
-static int get_cpu_frequency()
-{
- static int frequencyfd = -2;
- int ret = -1;
-
- if(frequencyfd != -1) // first time or file is exist
- ret = get_file_status(&frequencyfd, FREQFD);
-
- if(ret < 0) // error occured
- {
- FILE* cpufp;
- char buf[SMALL_BUFFER];
- int strsize = strlen(CPUMHZ);
- double freq;
-
- cpufp = fopen(PROCCPUINFO, "r");
- if(likely(cpufp != NULL))
- {
- while(fgets(buf, SMALL_BUFFER, cpufp) != NULL)
- {
- if(strncmp(buf, CPUMHZ, strsize) == 0)
- {
- freq = atof(strchr(buf, ':') + 1);
- ret = (int)(freq * 1000.0);
- break;
- }
- }
-
- fclose(cpufp);
- }
- else
- { // do nothing
- }
- }
-
- if(ret < 0)
- ret = 0;
-
- return ret;
-}
-
-// ========================================================================
-// get cpu and memory info for each process and whole system
-// ========================================================================
-typedef struct _proc_node {
- proc_t proc_data;
- unsigned long long saved_utime;
- unsigned long long saved_stime;
- int found;
- struct _proc_node *next;
-} procNode;
-
-static procNode *prochead = NULL;
-static procNode *thread_prochead = NULL;
-
-static procNode* find_node(procNode *head, pid_t pid)
-{
- procNode *t = head;
-
- while (t != NULL) {
- if (t->proc_data.pid == pid)
- {
- t->found = 1;
- break;
- }
- t = t->next;
- }
- return t;
-}
-
-static procNode* add_node(procNode **head, pid_t pid)
-{
- procNode *n;
-
- n = (procNode *) malloc(sizeof(procNode));
- if (n == NULL) {
- LOGE("Not enough memory, add cpu info node failied");
- return NULL;
- }
-
- n->proc_data.pid = pid;
- n->found = 1;
- n->next = *head;
- *head = n;
-
- return n;
-}
-
-static int del_node(procNode **head, pid_t pid)
-{
- procNode *t;
- procNode *prev;
-
- t = *head;
- prev = NULL;
- while (t != NULL) {
- if (t->proc_data.pid == pid) {
- if (prev != NULL)
- prev->next = t->next;
- else
- *head = (*head)->next;
- free(t);
- break;
- }
- prev = t;
- t = t->next;
- }
-
- return 0;
-}
-
-static int del_notfound_node(procNode **head)
-{
- procNode *proc, *prev;
- prev = NULL;
- for(proc = *head; proc != NULL; )
- {
- if(proc->found == 0)
- {
- if(prev != NULL)
- {
- prev->next = proc->next;
- free(proc);
- proc = prev->next;
- }
- else
- {
- *head = (*head)->next;
- free(proc);
- proc = *head;
- }
- }
- else
- {
- prev = proc;
- proc = proc->next;
- }
- }
- return 0;
-}
-
-static int reset_found_node(procNode *head)
-{
- procNode* proc;
- for(proc = head; proc != NULL; proc = proc->next)
- {
- proc->found = 0;
- }
- return 0;
-}
-
-// return 0 for normal case
-// return negative value for error case
-static int parse_proc_stat_file_bypid(char *path, proc_t* P)
-{
- char filename[PROCPATH_MAX];
- char buf[BUFFER_MAX];
- int fd, num;
- char *abuf, *bbuf;
-
- // read from stat file
- sprintf(filename, "%s/stat", path);
- fd = open(filename, O_RDONLY, 0);
-
- if(unlikely(fd == -1))
- return -1;
-
- num = read(fd, buf, BUFFER_MAX);
- close(fd);
-
- if(unlikely(num <= 0))
- return -1;
-
- buf[num] = '\0';
-
- // scan from buffer
- // copy command name
- abuf = strchr(buf, '(') + 1;
- bbuf = strrchr(buf, ')');
- num = bbuf - abuf;
- if(unlikely(num >= sizeof(P->command)))
- num = sizeof(P->command) - 1;
- memcpy(P->command, abuf, num);
- P->command[num] = '\0';
- abuf = bbuf + 2;
-
- // scan data
-
- sscanf(abuf,
- "%c "
- "%d %d %d %d %d "
- "%lu %lu %lu %lu %lu "
- "%Lu %Lu %Lu %Lu " // utime stime cutime cstime
- "%ld %ld "
- "%d "
- "%ld "
- "%Lu " // start_time
- "%lu "
- "%ld",
- &P->state,
- &P->ppid, &P->pgrp, &P->sid, &P->tty_nr, &P->tty_pgrp,
- &P->flags, &P->minor_fault, &P->cminor_fault, &P->major_fault, &P->cmajor_fault,
- &P->utime, &P->stime, &P->cutime, &P->cstime,
- &P->priority, &P->nice,
- &P->numofthread,
- &P->dummy,
- &P->start_time,
- &P->vir_mem,
- &P->res_memblock
- );
-
- if(P->numofthread == 0)
- P->numofthread = 1;
-
- return 0;
-}
-
-// return 0 for normal case
-// return negative value for error case
-static int parse_proc_smaps_file_bypid(char *path, proc_t* P)
-{
-#define MIN_SMAP_BLOCKLINE 50
-
- char filename[PROCPATH_MAX];
- char buf[MIDDLE_BUFFER];
- char numbuf[SMALL_BUFFER];
- FILE* fp;
-
- // reset pss size of proc_t
- P->pss = 0;
-
- // read from smaps file
- sprintf(filename, "%s/smaps", path);
- fp = fopen(filename, "r");
-
- if(fp == NULL)
- return -1;
-
- if(unlikely(probe_so_size == 0)) // probe so size is not abtained
- {
- int is_probe_so = 0;
- while(fgets(buf, MIDDLE_BUFFER, fp) != NULL)
- {
- if(strncmp(buf, "Pss:", 4) == 0) // line is started with "Pss:"
- {
- sscanf(buf, "Pss:%s kB", numbuf);
- P->pss += atoi(numbuf);
- if(is_probe_so == 1)
- {
- probe_so_size += atoi(numbuf);
- is_probe_so = 0; // reset search flag
- }
- }
- else // not Pss line
- {
- if(is_probe_so == 0 && strlen(buf) > MIN_SMAP_BLOCKLINE) // first we find probe so section
- {
- if(strstr(buf, DA_PROBE_TIZEN_SONAME) != NULL ||
- strstr(buf, DA_PROBE_OSP_SONAME) != NULL) // found probe.so
- {
- is_probe_so = 1;
- }
- else
- {
- // do nothing
- }
- }
- else
- {
- // do nothing
- }
- }
- }
- }
- else // we know about probe.so size already
- {
- while(fgets(buf, MIDDLE_BUFFER, fp) != NULL)
- {
- if(strncmp(buf, "Pss:", 4) == 0)
- {
- sscanf(buf, "Pss:%s kB", numbuf);
- P->pss += atoi(numbuf);
- }
- }
- }
-
- P->pss -= probe_so_size;
-
- fclose(fp);
-
- return 0;
-}
-
-// return 0 for normal case
-// return positive value for non critical case
-// return negative value for critical case
-static int update_process_data(int* pidarray, int pidcount, enum PROCESS_DATA datatype)
-{
- static struct stat sb;
- int i, ret = 0;
- char buf[PROCPATH_MAX];
- procNode* procnode;
-
- for(i = 0; i < pidcount; i++)
- {
- if (pidarray[i] == 0) // pid is invalid
- {
- ret = 1;
- continue;
- }
-
- sprintf(buf, "/proc/%d", pidarray[i]);
- if (unlikely(stat(buf, &sb) == -1)) // cannot access anymore
- {
- del_node(&prochead, pidarray[i]);
- ret = errno;
- continue;
- }
-
- if ((procnode = find_node(prochead, pidarray[i])) == NULL) // new process
- {
- procnode = add_node(&prochead, pidarray[i]);
- if(datatype == PROCDATA_STAT)
- {
- if (unlikely((ret = parse_proc_stat_file_bypid(buf, &(procnode->proc_data))) < 0))
- {
- LOGE("Failed to get proc stat file by pid(%d)\n", pidarray[i]);
- }
- else
- {
- procnode->saved_utime = procnode->proc_data.utime;
- procnode->saved_stime = procnode->proc_data.stime;
- }
- }
- else if(datatype == PROCDATA_SMAPS)
- {
- if (unlikely((ret = parse_proc_smaps_file_bypid(buf, &(procnode->proc_data))) < 0))
- {
- LOGE("Failed to get proc smaps file by pid(%d)\n", pidarray[i]);
- }
- else
- { // do nothing
- }
- }
- else
- { // impossible
- }
- }
- else
- {
- if(datatype == PROCDATA_STAT)
- {
- if (unlikely((ret = parse_proc_stat_file_bypid(buf, &(procnode->proc_data))) < 0))
- {
- LOGE("Failed to get proc stat file by pid(%d)\n", pidarray[i]);
- }
- else
- { // do nothing
- }
- }
- else if(datatype == PROCDATA_SMAPS)
- {
- if (unlikely((ret = parse_proc_smaps_file_bypid(buf, &(procnode->proc_data))) < 0))
- {
- LOGE("Failed to get proc smaps file by pid(%d)\n", pidarray[i]);
- }
- else
- { // do nothing
- }
- }
- else
- { // impossible
- }
- }
- }
-
- del_notfound_node(&prochead);
- reset_found_node(prochead);
-
- return ret;
-}
-
-static int update_system_cpu_frequency(int cur_index)
-{
- char buf[SMALL_BUFFER];
- char filename[SMALL_BUFFER];
- int i, j;
- FILE* fp;
-
- // execute this block only once
- if(unlikely(num_of_freq <= 0))
- {
- FILE* fp;
- num_of_freq = 0;
- if((fp = fopen(CPUNUM_OF_FREQ, "r")) != NULL)
- {
- while(fgets(buf, SMALL_BUFFER, fp) != NULL)
- {
- num_of_freq++;
- }
- fclose(fp);
- }
- else
- {
- LOGW("Cannot open cpu0 frequency file\n");
- return -11;
- }
-
- for(i = 0; i < num_of_cpu; i++)
- {
- if(cpus[i].pfreq == NULL)
- {
- cpus[i].pfreq = (cpufreq_t*) calloc(num_of_freq, sizeof(cpufreq_t));
- }
- }
- }
-
- sprintf(filename, CPUNUM_OF_FREQ);
- // update cpu frequency information
- for(i = 0; i < num_of_cpu; i++)
- {
- filename[27] = (char)('0' + i);
- fp = fopen(filename, "r");
- if(fp != NULL)
- {
- for(j = 0; j < num_of_freq; j++)
- {
- if(fgets(buf, SMALL_BUFFER, fp) != NULL)
- {
- sscanf(buf, "%lu %Lu", &(cpus[i].pfreq[j].freq),
- &(cpus[i].pfreq[j].tick));
- }
- else // cannot read anymore from frequency info file
- break;
- }
-
- fclose(fp);
- cpus[i].cur_freq_index = cur_index;
- }
- else // cannot load cpu frequency information
- { // do nothing
- }
- }
-
- return 0;
-}
-
-// return 0 for normal case
-// return negative value for error
-static int update_system_cpu_data(int cur_index)
-{
- static FILE* fp = NULL;
- int num;
- char buf[BUFFER_MAX];
-
- if(fp == NULL)
- {
- if((fp = fopen(PROCSTAT, "r")) == NULL)
- {
- LOGE("Failed to open " PROCSTAT "\n");
- return -1;
- }
- }
-
- rewind(fp);
- fflush(fp);
-
- if(fgets(buf, sizeof(buf), fp) == NULL)
- {
- LOGE("Failed to read first line of " PROCSTAT "\n");
-// fclose(fp);
- return -1;
- }
-
- cpus[num_of_cpu].x = 0;
- cpus[num_of_cpu].y = 0;
- cpus[num_of_cpu].z = 0;
- num = sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
- &cpus[num_of_cpu].u,
- &cpus[num_of_cpu].n,
- &cpus[num_of_cpu].s,
- &cpus[num_of_cpu].i,
- &cpus[num_of_cpu].w,
- &cpus[num_of_cpu].x,
- &cpus[num_of_cpu].y,
- &cpus[num_of_cpu].z
- );
- cpus[num_of_cpu].cur_load_index = cur_index;
- if(num < 4)
- {
- LOGE("Failed to read from " PROCSTAT "\n");
-// fclose(fp);
- return -1;
- }
-
-#ifdef FOR_EACH_CPU
- // and just in case we're 2.2.xx compiled without SMP support...
- if(num_of_cpu == 1)
- {
- cpus[0].id = cpus[1].id = 0;
- memcpy(cpus, &cpus[1], sizeof(tic_t) * 8);
- cpus[0].cur_load_index = cur_index;
- }
- else if(num_of_cpu > 1)
- {
- int i;
- // now value each separate cpu's tics
- for(i = 0; i < num_of_cpu; i++)
- {
- if(fgets(buf, sizeof(buf), fp) != NULL)
- {
- cpus[i].x = 0;
- cpus[i].y = 0;
- cpus[i].z = 0;
- num = sscanf(buf, "cpu%u %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu",
- &cpus[i].id,
- &cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i,
- &cpus[i].w, &cpus[i].x, &cpus[i].y, &cpus[i].z);
- if(num > 4)
- {
- LOGI("Readed %d stats of %dth cpu\n", num, i);
- cpus[i].cur_load_index = cur_index;
- }
- else // buf is not cpu core tick information
- { // do nothing
- }
- }
- else // cannot read anymore from /proc/stat file
- { // do nothing
- }
- }
- }
- else
- {
- // not possible
-// fclose(fp);
- return -1;
- }
-#endif
-
-// fclose(fp);
- return 0;
-}
-
-// return 0 for normal case
-// return negative value for error
-static int update_system_memory_data(unsigned long *memtotal, unsigned long *memused)
-{
- static int meminfo_fd = -1;
- char *head, *tail;
- int i, num;
- char buf[BUFFER_MAX];
- static const mem_t mem_table[] = {
- {"Buffers", &mem_slot_array[MEM_SLOT_BUFFER]},
- {"Cached", &mem_slot_array[MEM_SLOT_CACHED]},
- {"MemFree", &mem_slot_array[MEM_SLOT_FREE]},
- {"MemTotal", &mem_slot_array[MEM_SLOT_TOTAL]},
- };
- const int mem_table_size = sizeof(mem_table) / sizeof(mem_t);
-
- if(meminfo_fd == -1 && (meminfo_fd = open(PROCMEMINFO, O_RDONLY)) == -1)
- {
- LOGE("Failed to open " PROCMEMINFO "\n");
- return -1;
- }
- lseek(meminfo_fd, 0L, SEEK_SET);
- if((num = read(meminfo_fd, buf, BUFFER_MAX)) < 0)
- {
- LOGE("Failed to read from " PROCMEMINFO "\n");
- return -1;
- }
- buf[num] = '\0';
-
- num = 0; // number of found element
- head = buf;
- for( ;num < mem_table_size ; )
- {
- tail = strchr(head, ':');
- if(!tail)
- break;
- *tail = '\0';
- for(i = 0; i < mem_table_size; i++)
- {
- if(strcmp(head, mem_table[i].name) == 0) // found
- {
- head = tail + 1;
- *(mem_table[i].slot) = strtoul(head, &tail, 10);
- num++;
- break;
- }
- }
- if(i == mem_table_size) // cannot find entry
- head = tail + 1;
- tail = strchr(head, '\n');
- if(tail == NULL)
- break;
- head = tail + 1;
- }
-
- if(num == mem_table_size) // find all element
- {
- *memtotal = mem_slot_array[MEM_SLOT_TOTAL];
- *memused = mem_slot_array[MEM_SLOT_TOTAL] - mem_slot_array[MEM_SLOT_FREE] -
- mem_slot_array[MEM_SLOT_BUFFER] - mem_slot_array[MEM_SLOT_CACHED];
-
- *memtotal *= 1024; // change to Byte
- *memused *= 1024; // change to Byte
- return 0;
- }
- else
- {
- LOGE("Cannot find all neccessary element in meminfo\n");
- return -1;
- }
-}
-
-// return 0 for error case
-// return system total memory in MB
-static unsigned long get_system_total_memory()
-{
- int meminfo_fd = -1;
- char *head, *tail;
- int num;
- char buf[BUFFER_MAX];
- static const char* memtotalstr = "MemTotal";
- unsigned long totalmem = 0;
-
- if((meminfo_fd = open(PROCMEMINFO, O_RDONLY)) == -1)
- {
- LOGE("Failed to open " PROCMEMINFO "\n");
- return 0;
- }
- if((num = read(meminfo_fd, buf, BUFFER_MAX)) < 0)
- {
- LOGE("Failed to read from " PROCMEMINFO "\n");
- return 0;
- }
- buf[num] = '\0';
- close(meminfo_fd);
-
- head = buf;
- for( ; ; )
- {
- tail = strchr(head, ':');
- if(!tail)
- break;
- *tail = '\0';
- if(strcmp(head, memtotalstr) == 0) // found
- {
- head = tail + 1;
- totalmem = strtoul(head, &tail, 10);
- break;
- }
-
- head = tail + 1;
- tail = strchr(head, '\n');
- if(tail == NULL)
- break;
- head = tail + 1;
- }
-
- return (totalmem * 1024);
-}
-
-// ===============================================================
-// disk information getter functions
-// ===============================================================
-static int get_fsinfo(const char* path, int type)
-{
- struct statfs buf;
- int total;
- int free;
-
- if (statfs(path, &buf) < 0)
- {
- return -errno;
- }
-
- total = (int)((long long)(buf.f_bsize / 1024LL * buf.f_blocks) / 1024LL);
- free = (int)((long long)(buf.f_bsize / 1024LL * buf.f_bavail) / 1024LL);
-
- LOGI("File storage total(%d), free(%d)\n", total, free);
- if (type == FSINFO_TYPE_TOTAL)
- {
- return total;
- }
- else if (type == FSINFO_TYPE_FREE)
- {
- return free;
- }
-
- return -1;
-}
-
-static int stat_get_storageinfo(int type)
-{
- return get_fsinfo(UMSFD, type);
-}
-
-static int stat_get_cardinfo(int type)
-{
- if (access(MMCBLKFD, F_OK) < 0)
- {
- return -1;
- }
-
- return get_fsinfo(MMCFD, type);
-}
-
-
-static int get_total_drive()
-{
- int total = 0;
- int storage = stat_get_storageinfo(FSINFO_TYPE_TOTAL);
- int card = stat_get_cardinfo(FSINFO_TYPE_TOTAL);
-
- if (storage < 0 && card < 0)
- {
- return -1;
- }
-
- total = storage + card;
-
- return total;
-}
-
-static int get_total_used_drive()
-{
- int total = 0;
- int free = 0;
- int storage = stat_get_storageinfo(FSINFO_TYPE_FREE);
- int card = stat_get_cardinfo(FSINFO_TYPE_FREE);
-
- if (storage < 0 && card < 0)
- {
- return -1;
- }
-
- free = storage + card;
- total = get_total_drive() - free;
-
- return total;
-}
-
-static int update_thread_data(int pid)
-{
- static struct stat sb;
- int ret = 0;
- char path[PROCPATH_MAX];
- char buf[PROCPATH_MAX];
- procNode* procnode;
- DIR *taskdir = NULL;
- struct dirent *entry = NULL;
- unsigned int tid;
-
- sprintf(path, "/proc/%d/task", pid);
-
- if(!(taskdir = opendir(path)))
- {
- return -1;
- }
-
- while((entry = readdir(taskdir)) != NULL)
- {
- if(*entry->d_name > '0' && *entry->d_name <= '9')
- {
- tid = atoi(entry->d_name);
- sprintf(buf, "/proc/%d/task/%d", pid, tid);
-
- if(unlikely(stat(buf, &sb) == -1))
- {
- del_node(&thread_prochead, tid);
- ret = errno;
- continue;
- }
-
- if((procnode = find_node(thread_prochead, tid)) == NULL)
- {
- procnode = add_node(&thread_prochead, tid);
- if(unlikely((ret = parse_proc_stat_file_bypid(buf, &(procnode->proc_data))) < 0))
- {
- LOGE("Failed to get proc stat file by tid(%d)\n", tid);
- }
- else
- {
- procnode->saved_utime = procnode->proc_data.utime;
- procnode->saved_stime = procnode->proc_data.stime;
- }
- }
- else
- {
- if(unlikely((ret = parse_proc_stat_file_bypid(buf, &(procnode->proc_data))) < 0))
- {
- LOGE("Failed to get proc stat file by tid(%d)\n", tid);
- }
- }
- }
- }
-
- del_notfound_node(&thread_prochead);
- reset_found_node(thread_prochead);
-
- closedir(taskdir);
- return ret;
-}
-
-// ========================================================================
-// overall information getter functions
-// ========================================================================
-
-// this code is not necessary anymore
-/*
-static void get_app_info(const char* binary_path, char* width,
- char* height, char* theme, char* version,
- char* scale, char* removable,
- char* comment)
-{
- int fd = 0;
- int res = 0;
- int i = 0;
- int j = 0;
- char pkg_info_path [PATH_MAX];
- char buffer [BUFFER_MAX];
-
- sprintf(pkg_info_path, "/opt/share/applications/%s.desktop", pkg_name);
-
- fd = open(pkg_info_path, O_RDONLY);
- if (fd < 0)
- {
- LOGE("Cannot open %s", pkg_info_path);
- return;
- }
-
- fcntl( fd, F_SETFD, FD_CLOEXEC );
-
- LOGI("get_app_info - After open pkg_info_path\n");
-
- for (;;)
- {
- res = read(fd, buffer, BUFFER_MAX);
- if (res == 0)
- {
- break;
- }
- if (res < 0)
- {
- if (errno == EINTR)
- continue;
- else
- break;
- }
-
- LOGI("read buffer ===%s===\n", buffer);
- for (i = 0; i < res; i++)
- {
- if (i < res - 22 && strncmp(&buffer[i], "X-SLP-BaseLayoutWidth=", 22) == 0)
- {
- for (j = 0; j < res; j ++)
- {
- if (buffer[i+j] == '\n' || buffer[i+j] == '\t')
- {
- LOGI("width :::: ");
- strncpy(width, &(buffer[i+22]), j-22);
- LOGI("%s\n", width);
- break;
- }
- }
- i = i + j;
- }
- else if (i < res - 23 && strncmp(&buffer[i], "X-SLP-BaseLayoutHeight=", 23) == 0)
- {
- for (j = 0; j < res; j ++)
- {
- if (buffer[i+j] == '\n' || buffer[i+j] == '\t')
- {
- LOGI("height :::: ");
- strncpy(height, &(buffer[i+23]), j-23);
- LOGI("%s\n", height);
- break;
- }
- }
- i = i + j;
- }
- else if (i < res - 6 && (strncmp(&buffer[i], "theme=", 6) == 0 || strncmp(&buffer[i], "Theme=", 6) == 0))
- {
- for (j = 0; j < res; j ++)
- {
- if (buffer[i+j] == '\n' || buffer[i+j] == '\t')
- {
- LOGI("theme :::: ");
- strncpy(theme, &(buffer[i+6]), j-6);
- LOGI("%s\n", theme);
- break;
- }
- }
- i = i + j;
- }
- else if (i < res - 8 && (strncmp(&buffer[i], "Version=", 8) == 0 || strncmp(&buffer[i], "version=", 8) == 0))
- {
- for (j = 0; j < res; j ++)
- {
- if (buffer[i+j] == '\n' || buffer[i+j] == '\t')
- {
- LOGI("version :::: ");
- strncpy(version, &(buffer[i+8]), j-8);
- LOGI("%s\n", version);
- break;
- }
- }
- i = i + j;
- }
- else if (i < res - 24 && strncmp(&buffer[i], "X-SLP-IsHorizontalScale=", 24) == 0)
- {
- for (j = 0; j < res; j ++)
- {
- if (buffer[i+j] == '\n' || buffer[i+j] == '\t')
- {
- LOGI("scale :::: ");
- strncpy(scale, &(buffer[i+24]), j-24);
- LOGI("%s\n", scale);
- break;
- }
- }
- i = i + j;
- }
- else if (i < res - 16 && strncmp(&buffer[i], "X-SLP-Removable=", 16) == 0)
- {
- for (j = 0; j < res; j ++)
- {
- if (buffer[i+j] == '\n' || buffer[i+j] == '\t')
- {
- LOGI("removable :::: ");
- strncpy(removable, &(buffer[i+16]), j-16);
- LOGI("%s\n", removable);
- break;
- }
- }
- i = i + j;
- }
- else if (i < res - 8 && (strncmp(&buffer[i], "Comment=", 8) == 0 || strncmp(&buffer[i], "comment=", 8) == 0))
- {
- for (j = 0; j < res; j ++)
- {
- if (buffer[i+j] == '\n' || buffer[i+j] == '\t')
- {
- LOGI("comments :::: ");
- strncpy(comment, &(buffer[i+8]), j-8);
- LOGI("%s\n", comment);
- break;
- }
- }
- i = i + j;
- }
- }
- }
-
- close(fd);
-}
-*/
-
-static int get_device_availability_info(char* buf, int buflen)
-{
- int camera_count = 0;
- bool blue_support = false;
- bool gps_support = false;
- bool wifi_support = false;
- char* networktype = NULL;
- int loglen = 0;
-
-#ifndef LOCALTEST
- system_info_get_value_bool(SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED, &blue_support);
- system_info_get_value_int(SYSTEM_INFO_KEY_CAMERA_COUNT, &camera_count);
- system_info_get_value_bool(SYSTEM_INFO_KEY_GPS_SUPPORTED, &gps_support);
- system_info_get_value_string(SYSTEM_INFO_KEY_NETWORK_TYPE, &networktype);
- system_info_get_value_bool(SYSTEM_INFO_KEY_WIFI_SUPPORTED, &wifi_support);
-#endif
-
- loglen += sprintf(buf, "%d`,%d`,%d`,%d`,",
- (int)blue_support,
- (int)gps_support,
- (int)wifi_support,
- camera_count);
-
- if(networktype != NULL)
- {
- loglen += sprintf(buf + loglen, "%s", networktype);
- free(networktype);
- }
- else
- {
- // do nothing
- }
-
- return loglen;
-}
-
-int get_device_info(char* buffer, int buffer_len)
-{
- int res = 0;
-/*
- char width[BUFFER_MAX];
- char height[BUFFER_MAX];
- char theme[BUFFER_MAX];
- char version[BUFFER_MAX];
- char scale[BUFFER_MAX];
- char removable[BUFFER_MAX];
- char comment[BUFFER_MAX * 2];
-
- memset(width, 0, sizeof(width));
- memset(height, 0, sizeof(height));
- memset(theme, 0, sizeof(theme));
- memset(version, 0, sizeof(version));
- memset(scale, 0, sizeof(scale));
- memset(removable, 0, sizeof(removable));
- memset(comment, 0, sizeof(comment));
-*/
- res += sprintf(buffer, "%lu`,%d`,", get_system_total_memory(), get_total_drive());
- res += get_device_availability_info(buffer + res, buffer_len - res);
- res += sprintf(buffer + res, "`,%d", get_max_brightness());
-
- res += sprintf(buffer + res, "`,`,`,`,`,`,`,");
-// res += sprintf(buffer + res, "`,%s`,%s`,%s`,%s`,%s`,%s`,%s", width, height, theme, version, scale, removable, comment);
-
- return res;
-}
-
-// return log length (>0) for normal case
-// return negative value for error
-int get_resource_info(char* buffer, int buffer_len, int* pidarray, int pidcount)
-{
- static struct timeval old_time = {0, 0};
- static int event_num = 0;
-
- int res = 0;
- int i, j;
- float elapsed;
- float factor;
- procNode* proc;
- CPU_t* cpuptr;
- struct timeval current_time;
-
- // data variable
- unsigned long virtual = 0;
- unsigned long resident = 0;
- unsigned long shared = 0;
- unsigned long pssmem = 0;
- int num_thread = 0;
- unsigned long long ticks = 0, freqsum;
- float app_cpu_usage, sys_usage, thread_load;
- unsigned long sysmemtotal = 0;
- unsigned long sysmemused = 0;
- unsigned long curtime;
-// long long idle_tick_sum = 0, total_tick_sum = 0;
- int call_time = 0;
- int rssi_time = 0;
-
- // buffers
- char thread_loadbuf[LARGE_BUFFER] = {0, };
- char thread_loadtmpbuf[SMALL_BUFFER];
- char freqbuf[MIDDLE_BUFFER];
- char cpuload[SMALL_BUFFER];
- int freqbufpos = 0;
- int cpuloadpos = 0;
-// unsigned int failed_cpu = 0;
-
- LOGI("PID count : %d\n", pidcount);
-
- if(update_process_data(pidarray, pidcount, PROCDATA_STAT) < 0)
- {
- LOGE("Failed to update process stat data\n");
- return -1;
- }
-
- // this position is optimized position of timestamp.
- // just before get system cpu data and just after get process cpu data
- // because cpu data is changed so fast and variance is so remarkable
- gettimeofday(¤t_time, NULL); // DO NOT MOVE THIS SENTENCE!
-
- if(update_system_cpu_data(event_num) < 0)
- {
- LOGE("Failed to update system cpu data\n");
- return -1;
- }
-
- // freqbufpos is temporary used
- freqbufpos = update_system_cpu_frequency(event_num);
-
- // memory data is changed slowly and variance is not remarkable
- // so memory data is less related with timestamp then cpu data
- if(update_process_data(pidarray, pidcount, PROCDATA_SMAPS) < 0)
- {
- LOGE("Failed to update process smaps data\n");
- return -1;
- }
-
- if(update_thread_data(pidarray[0]) < 0)
- {
- LOGE("Failed to update thread stat data\n");
- return -1;
- }
-
- if(update_system_memory_data(&sysmemtotal, &sysmemused) < 0)
- {
- LOGE("Failed to update system memory data\n");
- return -1;
- }
-
- // prepare calculate
- elapsed = (current_time.tv_sec - old_time.tv_sec) +
- ((float)(current_time.tv_usec - old_time.tv_usec) / 1000000.0f);
- old_time.tv_sec = current_time.tv_sec;
- old_time.tv_usec = current_time.tv_usec;
- curtime = ((unsigned long)current_time.tv_sec * 10000) +
- ((unsigned long)current_time.tv_usec / 100);
-
- factor = 100.0f / ((float)Hertz * elapsed * num_of_cpu);
-
-
- // calculate process for process
- for(proc = prochead; proc != NULL; proc = proc->next)
- {
- num_thread += proc->proc_data.numofthread;
- virtual += proc->proc_data.vir_mem; // Byte
- resident += (proc->proc_data.res_memblock * 4); // KByte
- pssmem += (proc->proc_data.pss); // KByte
- ticks += (proc->proc_data.utime + proc->proc_data.stime - proc->saved_utime - proc->saved_stime);
-
- proc->saved_utime = proc->proc_data.utime;
- proc->saved_stime = proc->proc_data.stime;
- }
- app_cpu_usage = (float)ticks * factor;
- if(app_cpu_usage > 100.0f)
- app_cpu_usage = 100.0f;
- resident = resident * 1024; // change to Byte
- pssmem = pssmem * 1024; // change to Byte
-
- // calculate thread load
- for(proc = thread_prochead; proc != NULL; proc = proc->next)
- {
- thread_load = (float)(proc->proc_data.utime + proc->proc_data.stime - proc->saved_utime - proc->saved_stime)
- * factor;
- if(thread_load > 100.0f)
- thread_load = 100.0f;
-
- sprintf(thread_loadtmpbuf, "%d,%.1f,", proc->proc_data.pid, thread_load);
- strcat(thread_loadbuf, thread_loadtmpbuf);
-
- proc->saved_utime = proc->proc_data.utime;
- proc->saved_stime = proc->proc_data.stime;
- }
-
- // calculate for system cpu load
-#ifdef FOR_EACH_CPU
- for(i = 0; i < num_of_cpu; i++)
-#else
- for(i = num_of_cpu; i <= num_of_cpu; i++)
-#endif
- {
- cpuptr = &(cpus[i]);
-
- if(cpuptr->cur_load_index == event_num)
- {
- if(cpuptr->sav_load_index == event_num - 1) // previous sampling is just before 1 period
- {
- cpuptr->idle_ticks = cpuptr->i - cpuptr->i_sav;
- if(unlikely(cpuptr->idle_ticks < 0))
- {
- cpuptr->idle_ticks = 0;
- }
- cpuptr->total_ticks = (cpuptr->u - cpuptr->u_sav) +
- (cpuptr->s - cpuptr->s_sav) +
- (cpuptr->n - cpuptr->n_sav) +
- cpuptr->idle_ticks +
- (cpuptr->w - cpuptr->w_sav) +
- (cpuptr->x - cpuptr->x_sav) +
- (cpuptr->y - cpuptr->y_sav) +
- (cpuptr->z - cpuptr->z_sav);
- if(cpuptr->total_ticks < MIN_TOTAL_TICK)
- {
- cpuptr->cpu_usage = 0.0f;
- }
- else
- {
- cpuptr->cpu_usage = (1.0f - ((float)cpuptr->idle_ticks / (float)cpuptr->total_ticks)) * 100.0f;
- }
-// if(i != num_of_cpu)
-// {
-// idle_tick_sum += cpuptr->idle_ticks;
-// total_tick_sum += cpuptr->total_ticks;
-// }
- LOGI("System cpu usage log : %d, %Ld, %Ld\n", i, cpuptr->idle_ticks, cpuptr->total_ticks);
- if(unlikely(cpuptr->cpu_usage < 0))
- {
- cpuptr->cpu_usage = 0.0f;
- }
- }
- else // previous sampling is not just before 1 period
- {
- // assume non idle ticks happen in 1 profiling period
- // because sampling is not available just before 1 profiling period
- cpuptr->idle_ticks = (cpuptr->u - cpuptr->u_sav) +
- (cpuptr->s - cpuptr->s_sav) +
- (cpuptr->n - cpuptr->n_sav) +
- (cpuptr->w - cpuptr->w_sav) +
- (cpuptr->x - cpuptr->x_sav) +
- (cpuptr->y - cpuptr->y_sav) +
- (cpuptr->z - cpuptr->z_sav);
- cpuptr->total_ticks = (long long)(Hertz * elapsed);
- if(unlikely(cpuptr->total_ticks < 1))
- cpuptr->total_ticks = 1;
- cpuptr->cpu_usage = ((float)cpuptr->idle_ticks / (float)cpuptr->total_ticks) * 100.0f;
- if(unlikely(cpuptr->cpu_usage > 100.0f))
- {
- cpuptr->cpu_usage = 100.0f;
- }
- }
-
- // save new value
- cpuptr->u_sav = cpuptr->u;
- cpuptr->s_sav = cpuptr->s;
- cpuptr->n_sav = cpuptr->n;
- cpuptr->i_sav = cpuptr->i;
- cpuptr->w_sav = cpuptr->w;
- cpuptr->x_sav = cpuptr->x;
- cpuptr->y_sav = cpuptr->y;
- cpuptr->z_sav = cpuptr->z;
- cpuptr->sav_load_index = cpuptr->cur_load_index;
- }
- else
- {
- cpuptr->cpu_usage = 0.0f;
- }
- }
-
-#ifdef FOR_EACH_CPU
- // calculate for cpu core load that failed to get tick information
-/*
- if(failed_cpu != 0)
- {
- LOGI("ticks1 : %Ld, %Ld\n", idle_tick_sum, total_tick_sum);
- idle_tick_sum = cpus[num_of_cpu].idle_ticks - idle_tick_sum;
- total_tick_sum = cpus[num_of_cpu].total_ticks - total_tick_sum;
- LOGI("ticks2 : %Ld, %Ld\n", idle_tick_sum, total_tick_sum);
- if(total_tick_sum >= MIN_TICKS_FOR_LOAD)
- sys_usage = (1.0f - ((float)idle_tick_sum / (float)total_tick_sum)) * 100.0f;
- else
- sys_usage = 0.0f;
- if(sys_usage < 0.0f) sys_usage = 0.0f;
- else if(sys_usage > 100.0f) sys_usage = 100.0f;
-
- for(i = 0; i < num_of_cpu; i++)
- {
- if(failed_cpu & (1 << i))
- {
- cpus[i].cpu_usage = sys_usage;
- }
- }
- }
-*/
-
- // calculate for whole cpu load by average all core load
- sys_usage = 0.0f;
- for(i = 0 ; i < num_of_cpu; i++)
- {
- sys_usage += cpus[i].cpu_usage;
- }
- cpus[num_of_cpu].cpu_usage = sys_usage / num_of_cpu;
-
- // make cpu load string
- for(i = 0; i <= num_of_cpu; i++)
- {
- cpuloadpos += sprintf(cpuload + cpuloadpos, "%.1f,", cpus[i].cpu_usage);
- }
- cpuload[cpuloadpos - 1] = '\0'; // remove last ,
-#else
- sprintf(cpuload, "%.1f", cpus[num_of_cpu].cpu_usage);
-#endif
-
- // calculate for system cpu frequency
- if(freqbufpos >= 0)
- {
- sys_usage = 0.0f;
- freqbufpos = 0;
- ticks = 0;
- freqsum = 0;
- for(i = 0; i < num_of_cpu; i++)
- {
- cpuptr = &(cpus[i]);
-
- if(cpuptr->cur_freq_index == event_num)
- {
- if(cpuptr->sav_freq_index == event_num - 1)
- {
- for(j = 0; j < num_of_freq; j++)
- {
- freqsum += (cpuptr->pfreq[j].freq *
- (cpuptr->pfreq[j].tick - cpuptr->pfreq[j].tick_sav));
- ticks += (cpuptr->pfreq[j].tick - cpuptr->pfreq[j].tick_sav);
- }
- }
- else
- { // do nothing
- }
-
- for(j = 0; j < num_of_freq; j++)
- {
- cpuptr->pfreq[j].tick_sav = cpuptr->pfreq[j].tick; // restore last tick value
- }
- cpuptr->sav_freq_index = cpuptr->cur_freq_index;
- }
-
-#ifdef FOR_EACH_CPU
- if(ticks != 0)
- {
- if(sys_usage == 0.0f)
- sys_usage = (float)freqsum / (float)ticks;
- freqbufpos += sprintf(freqbuf + freqbufpos, "%.0f,", (float)freqsum / (float)ticks);
- }
- else
- {
- freqbufpos += sprintf(freqbuf + freqbufpos, "%.0f,", sys_usage);
- }
- ticks = 0;
- freqsum = 0;
-#endif
- }
-#ifndef FOR_EACH_CPU
- freqbufpos += sprintf(freqbuf + freqbufpos, "%.0f", (float)freqsum / (float)ticks);
-#else
- freqbuf[freqbufpos - 1] = '\0'; // remove last ,
-#endif
- }
- else // update system cpu frequency is failed
- {
- freqbufpos = get_cpu_frequency();
- sprintf(freqbuf, "%d", (freqbufpos > 0)? freqbufpos : 0);
- }
-
- // print log
- res = sprintf(buffer, "9`,"
- "%d`,%d`,%lu`," // event number, reserved, current time
- "%d`,%d`,%d`," // device status(wifi, bt, gps)
- "%d`,%d`,%d`," // device status(bright, camera, sound)
- "%d`,%d`,%d`," // device status(audio, vibration, voltage)
- "%d`,%d`,%d`,%d`," // device status(rssi, video, call, dnet status)
- "%d`,%d`," // device status(call_time, rssi_time)
- "%s`,%.1f`,%s`," // cpu frequency and usage (app, system)
- "%lu`,%lu`,%lu`,%lu`,%Ld`," // process memory
- "%lu`,%lu`," // system total memory, used memory
- "%d`," // system drive
- "%d`," // number of thread
- "%s`,\n", // thread load
- event_num, 0, curtime, // 0 is reserved value
- get_wifi_status(), get_bt_status(), get_gps_status(),
- get_brightness_status(), get_camera_status(), get_sound_status(),
- get_audio_status(), get_vibration_status(), get_voltage_status(),
- get_rssi_status(), get_video_status(), get_call_status(), get_dnet_status(),
- call_time, rssi_time,
- freqbuf, app_cpu_usage, cpuload,
- virtual, resident, shared, pssmem, get_total_alloc_size(),
- sysmemtotal, sysmemused,
- get_total_used_drive(),
- num_thread,
- thread_loadbuf
- );
-
- LOGI("get_resource_info result : %s", buffer);
-
- event_num++;
- return res;
-}
-
-int initialize_system_info()
-{
- int i;
-
- num_of_cpu = sysconf(_SC_NPROCESSORS_ONLN);
- if(num_of_cpu < 1)
- num_of_cpu = 1;
- Hertz = sysconf(_SC_CLK_TCK);
- LOGI("Hertz : %d\n", Hertz);
-
- // alloc for cpus
- if(cpus == NULL)
- cpus = (CPU_t*) calloc((num_of_cpu + 1), sizeof(CPU_t));
- if(cpus != NULL)
- {
- for(i = 0; i <= num_of_cpu; i++)
- {
- cpus[i].cur_load_index = cpus[i].sav_load_index = -1;
- cpus[i].cur_freq_index = cpus[i].sav_freq_index = -1;
- }
- }
- else
- {
- LOGE("Failed to alloc memory for cpu information\n");
- return -1;
- }
-
- return 0;
-}
-
-int finalize_system_info()
-{
- int i;
-
- if(cpus != NULL)
- {
- for(i = 0; i < num_of_cpu; i++)
- {
- if(cpus[i].pfreq != NULL)
- free(cpus[i].pfreq);
- }
-
- free(cpus);
- }
-
- return 0;
-}
-
+++ /dev/null
-/*
-* DA manager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-*
-* Jaewon Lim <jaewon81.lim@samsung.com>
-* Woojin Jung <woojin2.jung@samsung.com>
-* Juyoung Kim <j0.kim@samsung.com>
-*
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-#ifndef _SYS_STAT_
-#define _SYS_STAT_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <string.h>
-#include <pthread.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/vfs.h>
-
-#define CHARGERFD "/sys/class/power_supply/battery/charge_now"
-#define VOLTAGEFD "/sys/class/power_supply/battery/voltage_now"
-
-#define BRIGHTNESS_FILENAME "brightness"
-#define MAX_BRIGHTNESS_FILENAME "max_brightness"
-#define BRIGHTNESS_PARENT_DIR "/sys/class/backlight"
-
-#define EMUL_BRIGHTNESSFD "/sys/class/backlight/emulator/brightness"
-#define EMUL_MAX_BRIGHTNESSFD "/sys/class/backlight/emulator/max_brightness"
-
-
-#define AUDIOFD "/sys/devices/platform/soc-audio/dapm_widget"
-
-#define MFCFD "/sys/devices/platform/s3c-mfc/mfc/mfc_status"
-
-#define FREQFD "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
-
-#define CPUDIR "/sys/devices/system/cpu"
-#define CPUFREQ_FILE "cpufreq/stats/time_in_state"
-#define CPUNUM_OF_FREQ CPUDIR"/cpu0/"CPUFREQ_FILE
-
-
-#define MEMINFOFD "/sys/class/memnotify/meminfo"
-#define UMSFD "/mnt/ums"
-#define MMCBLKFD "/dev/mmcblk1"
-#define MMCFD "/mnt/mmc"
-
-#define PROCSTAT "/proc/stat"
-#define PROCMEMINFO "/proc/meminfo"
-#define PROCCPUINFO "/proc/cpuinfo"
-
-#define MEM_TYPE_TOTAL 1
-#define MEM_TYPE_USED 2
-#define MEM_TYPE_FREE 3
-
-#define FSINFO_TYPE_TOTAL 1
-#define FSINFO_TYPE_FREE 2
-
-#define MAXNAMESIZE 16
-
-typedef unsigned long long tic_t;
-
-typedef struct {
- unsigned int pid;
- char command[MAXNAMESIZE];
- char state;
- int ppid;
- int pgrp;
- int sid;
- int tty_nr;
- int tty_pgrp;
- unsigned long flags;
- unsigned long minor_fault;
- unsigned long cminor_fault;
- unsigned long major_fault;
- unsigned long cmajor_fault;
- unsigned long long utime;
- unsigned long long stime;
- unsigned long long cutime;
- unsigned long long cstime;
- long priority;
- long nice;
- int numofthread;
- long dummy;
- unsigned long long start_time;
- unsigned long vir_mem;
- long res_memblock;
- unsigned long pss;
-} proc_t;
-
-typedef struct {
- unsigned long freq;
- tic_t tick;
- tic_t tick_sav;
-} cpufreq_t;
-
-typedef struct {
- tic_t u, n, s, i, w, x, y, z;
- tic_t u_sav, n_sav, s_sav, i_sav, w_sav, x_sav, y_sav, z_sav;
- unsigned int id; // cpu id
- float cpu_usage; // cpu load for this core
- int sav_load_index; // saved cpu load sampling index
- int cur_load_index; // current cpu load sampling index
- cpufreq_t* pfreq; // frequency information of cpu
- int sav_freq_index; // sav cpu frequency sampling index
- int cur_freq_index; // current cpu frequency sampling index
- long long idle_ticks;
- long long total_ticks;
-} CPU_t; // for each cpu core
-
-typedef struct _mem_t {
- const char* name; // memory slot name
- unsigned long* slot; // memory value slot
-} mem_t;
-
-int get_device_info(char* buffer, int buffer_len);
-
-int get_resource_info(char* buffer, int buffer_len, int* pidarray, int pidcount);
-
-int get_file_status(int* pfd, const char* filename);
-
-int initialize_system_info();
-
-int finalize_system_info();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-/*
-* DA manager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-*
-* Jaewon Lim <jaewon81.lim@samsung.com>
-* Woojin Jung <woojin2.jung@samsung.com>
-* Juyoung Kim <j0.kim@samsung.com>
-*
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-#include <stdlib.h>
-#include <pthread.h>
-#include "utils.h"
-#include "da_debug.h"
-
-#define BUFFER_MAX 1024
-
-static int file_fd = -1;
-
-static pthread_mutex_t write_mutex;
-
-// get application name from executable binary path
-char* get_app_name(char* binary_path)
-{
- char* pos;
-
- pos = strrchr(binary_path, '/');
- if(pos != NULL)
- pos++;
-
- return pos;
-}
-
-// execute applcation with executable binary path
-// return 0 to fail to execute
-// return 1 to succeed to execute
-int exec_app(const char* exec_path, int app_type)
-{
- pid_t pid;
- char command[PATH_MAX];
-
- if (exec_path == NULL || strlen(exec_path) <= 0)
- {
- LOGE("Executable path is not correct\n");
- return 0;
- }
-
- if (( pid = fork()) < 0) // fork error
- return 0;
-
- else if(pid > 0)
- return 1; // exit parent process with successness
-
- sprintf(command, "%s %s", DA_PRELOAD(app_type), exec_path);
- LOGI("launch app path is %s, executable path is %s\n", LAUNCH_APP_PATH, exec_path);
- execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL);
-
- return 1;
-}
-
-#ifdef USE_LAUNCH_PAD
-// execute application by launch pad
-// return 0 to fail to execute
-// return 1 to succeed to execute
-int exec_app_by_launchpad(const char* pkg_name)
-{
- pid_t pid;
-
- if (pkg_name == NULL || strlen(pkg_name) <= 0)
- {
- LOGE("Package name is not correct\n");
- return 0;
- }
-
- if (( pid = fork()) < 0) // fork error
- return 0;
-
- else if(pid > 0)
- return 1; // exit parent process with successness
-
- LOGI("launch app path is %s, pkg name is %s\n", LAUNCH_APP_PATH, pkg_name);
- execl(LAUNCH_APP_PATH, LAUNCH_APP_NAME, pkg_name, DA_PRELOAD_EXEC, NULL);
-
- return 1;
-}
-#endif
-
-#if 0
-void kill_app(const char* binary_path) // fork version
-{
- pid_t pid;
- pid_t pkg_pid;
- char command[PATH_MAX];
-
- if (( pid = fork()) < 0)
- return;
-
- //exit parent process
- else if(pid > 0)
- return;
-
- pkg_pid = find_pid_from_path(binary_path);
-
- if(pkg_pid > 0)
- {
- sprintf(command, "kill -9 %d", pkg_pid);
- LOGI(" : %s\n", command);
- execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL);
- }
- else
- {
- exit(0);
- }
-}
-#else
-void kill_app(const char* binary_path) // non fork version
-{
- pid_t pkg_pid;
- char command[PATH_MAX];
-
- pkg_pid = find_pid_from_path(binary_path);
-
- if(pkg_pid > 0)
- {
- sprintf(command, "kill -9 %d", pkg_pid);
- LOGI("kill app : %s\n", command);
- system(command);
- }
-}
-#endif
-
-// find process id from executable binary path
-pid_t find_pid_from_path(const char* path)
-{
- pid_t status = -1;
-
- char buffer [BUFFER_MAX];
- char command [BUFFER_MAX];
-
- sprintf(command, "/bin/pidof %s", path);
-
- FILE *fp = popen(command, "r");
- if (!fp)
- {
- LOGE("Getting pidof %s is failed\n", path);
- return status;
- }
-
- while (fgets(buffer, BUFFER_MAX, fp) != NULL)
- {
- LOGI("result of 'pidof' is %s\n", buffer);
- }
-
- pclose(fp);
-
- if (strlen(buffer) > 0)
- {
- if (sscanf(buffer,"%d\n", &status) != 1)
- {
- LOGE("Failed to read result buffer of 'pidof', status(%d)\n", status);
- return -1;
- }
- }
-
- return status;
-}
-
-static void mkdirs()
-{
- mkdir("/home/developer/sdk_tools/da", 0775);
- mkdir("/home/developer/sdk_tools/da/battery", 0775);
-}
-
-int create_open_batt_log(const char* app_name)
-{
- char log_path[PATH_MAX];
-
- pthread_mutex_init(&write_mutex, NULL);
- sprintf(log_path, "%s%s", BATT_LOG_FILE, app_name);
-
- if ((file_fd = open(log_path, O_WRONLY|O_CREAT|O_TRUNC)) == -1)
- {
- mkdirs();
- if ((file_fd = open(log_path, O_WRONLY|O_CREAT|O_TRUNC)) == -1)
- {
- LOGE("Failed to open batt log file\n");
- return 0;
- }
- }
-
- return file_fd;
-}
-
-int get_batt_fd()
-{
- return file_fd;
-}
-
-int write_batt_log(const char* msg)
-{
- int length = -1;
-
- if (file_fd == -1 )
- {
- return -1;
- }
-
- pthread_mutex_lock(&write_mutex);
-
- length = write(file_fd, msg, strlen(msg));
-
- pthread_mutex_unlock(&write_mutex);
-
- return length;
-}
-
-void close_batt_fd()
-{
- close(file_fd);
- file_fd = -1;
-}
-
-#if DEBUG
-void write_log()
-{
- int fd;
-
- fd = open("/dev/null", O_RDONLY);
- dup2(fd, 0);
-
- fd = open("/tmp/da_daemon.log", O_WRONLY | O_CREAT | O_TRUNC, 0640);
- if(fd < 0) {
- fd = open("/dev/null", O_WRONLY);
- }
- dup2(fd, 1);
- dup2(fd, 2);
-
- fprintf(stderr,"--- da starting (pid %d) ---\n", getpid());
-}
-#endif
-
-
+++ /dev/null
-/*
-* DA manager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-*
-* Jaewon Lim <jaewon81.lim@samsung.com>
-* Woojin Jung <woojin2.jung@samsung.com>
-* Juyoung Kim <j0.kim@samsung.com>
-*
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-#ifndef _UTILS_
-#define _UTILS_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <linux/limits.h>
-
-#define LAUNCH_APP_PATH "/usr/bin/launch_app"
-#define KILL_APP_PATH "/usr/bin/pkill"
-#define LAUNCH_APP_NAME "launch_app"
-#define DA_PRELOAD_EXEC "__AUL_SDK_DYNAMIC_ANALYSIS"
-#define DA_PRELOAD(AppType) AppType ? DA_PRELOAD_OSP : DA_PRELOAD_TIZEN
-#define DA_PRELOAD_TIZEN "LD_PRELOAD=/home/developer/sdk_tools/da/da_probe_tizen.so"
-#define DA_PRELOAD_OSP "LD_PRELOAD=/home/developer/sdk_tools/da/da_probe_osp.so"
-#define BATT_LOG_FILE "/home/developer/sdk_tools/da/battery/"
-#define SHELL_CMD "/bin/sh"
-
-enum ApplicationType
-{
- APP_TYPE_TIZEN = 0,
- APP_TYPE_OSP = 1
-};
-
-char* get_app_name(char* binary_path);
-
-int exec_app(const char* exec_path, int app_type);
-
-void kill_app(const char* binary_path);
-
-pid_t find_pid_from_path(const char* path);
-
-int create_open_batt_log(const char* app_name);
-
-int get_batt_fd();
-
-int write_batt_log(const char* message);
-
-void close_batt_fd();
-
-#if DEBUG
-void write_log();
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
%defattr(-,root,root,-)
%{_prefix}/bin/da_manager
%{_prefix}/bin/da_event
-
+%{_prefix}/bin/da_command
%changelog
+++ /dev/null
-CURDIR = `pwd`
-INSTALLDIR = usr/bin
-
-SRCS := eventutil.c
-
-TARGET = da_event
-
-all: $(TARGET)
-
-$(TARGET): $(SRCS)
- $(CC) -Wall -o $@ $(SRCS)
-
-install:
- [ -d "$(DESTDIR)/$(INSTALLDIR)" ] || mkdir -p $(DESTDIR)/$(INSTALLDIR)
- install $(TARGET) $(DESTDIR)/$(INSTALLDIR)/
-
-clean:
- rm $(TARGET)
-
+++ /dev/null
-/*
-* DA manager
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-*
-* Jaewon Lim <jaewon81.lim@samsung.com>
-* Woojin Jung <woojin2.jung@samsung.com>
-* Juyoung Kim <j0.kim@samsung.com>
-*
- * Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <dirent.h>
-#include <signal.h>
-#include <linux/input.h>
-
-#define BUF_SIZE 1024
-#define INPUT_ID_STR_KEY "ID_INPUT_KEY=1"
-#define INPUT_ID_STR_TOUCH "ID_INPUT_TOUCHSCREEN=1"
-#define INPUT_ID_STR_KEYBOARD "ID_INPUT_KEYBOARD=1"
-#define INPUT_ID_STR_TABLET "ID_INPUT_TABLET=1"
-#define MAX_DEVICE 10
-#define MAX_FILENAME 128
-
-#define INPUT_ID_TOUCH 0
-#define INPUT_ID_KEY 1
-#define STR_TOUCH "TOUCH"
-#define STR_KEY "KEY"
-#define ARRAY_END (-11)
-
-#define DAEMON_SENDER 0x01
-#define DAEMON_RECEIVER 0x10
-
-typedef struct _input_dev
-{
- int fd;
- char fileName[MAX_FILENAME];
-} input_dev;
-
-// ====================================================================
-// helper functions
-// ====================================================================
-
-// return bytes size of readed data
-// return 0 if no data readed or error occurred
-static int _file_read(FILE* fp, char *buffer, int size)
-{
- int ret = 0;
-
- if(fp != NULL && size > 0)
- {
- ret = fread((void*)buffer, sizeof(char), size, fp);
- }
- else
- {
- // fp is null
- if(size > 0)
- buffer[0] = '\0';
-
- ret = 0; // error case
- }
-
- return ret;
-}
-
-// get input id of given input device
-static int get_input_id(char* inputname)
-{
- static int query_cmd_type = 0; // 1 if /lib/udev/input_id, 2 if udevadm
- FILE* cmd_fp;
- char buffer[BUF_SIZE];
- char command[MAX_FILENAME];
- int ret = -1;
-
- // determine input_id query command
- if(__builtin_expect(query_cmd_type == 0, 0))
- {
- sprintf(command, "ls /lib/udev/input_id; echo cmd_ret:$?;");
- cmd_fp = popen(command, "r");
- _file_read(cmd_fp, buffer, BUF_SIZE);
- if(strstr(buffer, "cmd_ret:0")) // there is /lib/udev/input_id
- {
- query_cmd_type = 1;
- }
- else // there is not /lib/udev/input_id
- {
- query_cmd_type = 2;
- }
- pclose(cmd_fp);
- }
-
- // make command string
- if(query_cmd_type == 1)
- {
- sprintf(command, "/lib/udev/input_id /class/input/%s", inputname);
- }
- else if(query_cmd_type == 2)
- {
- sprintf(command, "udevadm info --name=input/%s --query=property", inputname);
- }
- else
- {
- // not impossible
- perror("query cmd type is not valid");
- exit(0);
- }
-
- // run command
- cmd_fp = popen(command, "r");
- _file_read(cmd_fp, buffer, BUF_SIZE);
-
- // determine input id
- if(strstr(buffer, INPUT_ID_STR_KEY)) // key
- {
- ret = INPUT_ID_KEY;
- }
- else if(strstr(buffer, INPUT_ID_STR_TOUCH)) // touch
- {
- ret = INPUT_ID_TOUCH;
- }
- else if(strstr(buffer, INPUT_ID_STR_KEYBOARD)) // keyboard
- {
- ret = INPUT_ID_KEY;
- }
- else if(strstr(buffer, INPUT_ID_STR_TABLET)) // touch (emulator)
- {
- ret = INPUT_ID_TOUCH;
- }
-
- pclose(cmd_fp);
- return ret;
-}
-
-// get filename and fd of given input type devices
-static void _get_fds(input_dev *dev, int input_id)
-{
- DIR *dp;
- struct dirent *d;
- int count = 0;
-
- dp = opendir("/sys/class/input");
-
- while((d = readdir(dp)) != NULL)
- {
- if(!strncmp(d->d_name, "event", 5)) // start with "event"
- {
- // event file
- if(input_id == get_input_id(d->d_name))
- {
- sprintf(dev[count].fileName, "/dev/input/%s", d->d_name);
- dev[count].fd = open(dev[count].fileName, O_RDWR);
- count++;
- }
- }
- }
-
- closedir(dp);
-
- dev[count].fd = ARRAY_END; // end of input_dev array
-}
-
-// ================================================================
-// device write function
-// ================================================================
-
-static void _device_write(input_dev *dev, struct input_event* in_ev)
-{
- int i;
- for(i = 0; dev[i].fd != ARRAY_END; i++)
- {
- if(dev[i].fd >= 0)
- write(dev[i].fd, in_ev, sizeof(struct input_event));
- }
-}
-
-// =================================================================
-// file descriptor manipulation functions
-// =================================================================
-
-static void _fd_insert(fd_set* fdset, input_dev *dev)
-{
- int i;
- for(i = 0; dev[i].fd != ARRAY_END; i++)
- {
- if(dev[i].fd >= 0)
- {
- FD_SET(dev[i].fd, fdset);
- }
- }
-}
-
-static int _fd_isset(fd_set* fdset, input_dev *dev)
-{
- int i;
- for(i = 0; dev[i].fd != ARRAY_END; i++)
- {
- if(dev[i].fd >= 0)
- {
- if(FD_ISSET(dev[i].fd, fdset))
- {
- return i;
- }
- }
- }
-
- return -1;
-}
-
-
-int _get_maxfd(input_dev *touch, input_dev *key)
-{
- int i;
- int maxfd = -1;
-
- for(i = 0 ; touch[i].fd != ARRAY_END; i++)
- {
- if(touch[i].fd > maxfd)
- maxfd = touch[i].fd;
- }
-
- for(i = 0 ; key[i].fd != ARRAY_END; i++)
- {
- if(key[i].fd > maxfd)
- maxfd = key[i].fd;
- }
-
- return maxfd;
-}
-
-// ============================================================================
-// sender and receiver functions
-// ============================================================================
-
-static int sender()
-{
- struct input_event in_ev;
- char eventType[MAX_FILENAME];
-
- input_dev key_dev[MAX_DEVICE];
- input_dev touch_dev[MAX_DEVICE];
-
- _get_fds(key_dev, INPUT_ID_KEY);
- _get_fds(touch_dev, INPUT_ID_TOUCH);
-
- while(1)
- {
- scanf("%s %hx %hx %d", eventType, &in_ev.type, &in_ev.code, &in_ev.value);
- if(!strncmp(eventType, STR_TOUCH, strlen(STR_TOUCH)))
- {
- _device_write(touch_dev, &in_ev);
- }
- else if(!strncmp(eventType, STR_KEY, strlen(STR_KEY)))
- {
- _device_write(key_dev, &in_ev);
- }
- }
-
- return 0;
-}
-
-static int receiver()
-{
- fd_set allfds, readfds;
- int maxfd;
- int index;
- struct input_event in_ev;
-
- input_dev key_dev[MAX_DEVICE];
- input_dev touch_dev[MAX_DEVICE];
-
- _get_fds(key_dev, INPUT_ID_KEY);
- _get_fds(touch_dev, INPUT_ID_TOUCH);
-
- FD_ZERO(&readfds);
- _fd_insert(&readfds, key_dev);
- _fd_insert(&readfds, touch_dev);
-
- maxfd = _get_maxfd(touch_dev, key_dev);
-
- while(1)
- {
- allfds = readfds;
-
- select(maxfd + 1, &allfds, NULL, NULL, NULL);
-
- if((index = _fd_isset(&allfds, touch_dev)) != -1)
- {
- //touch read
- read(touch_dev[index].fd, &in_ev, sizeof(struct input_event));
- printf("%s %s %ld %ld %x %x %d\n",
- STR_TOUCH, touch_dev[index].fileName, in_ev.time.tv_sec,
- in_ev.time.tv_usec, in_ev.type, in_ev.code, in_ev.value);
- }
- else if ((index = _fd_isset(&allfds, key_dev)) != -1)
- {
- //key read
- read(key_dev[index].fd, &in_ev, sizeof(struct input_event));
- printf("%s %s %ld %ld %x %x %d\n",
- STR_KEY, key_dev[index].fileName, in_ev.time.tv_sec,
- in_ev.time.tv_usec, in_ev.type, in_ev.code, in_ev.value);
- }
- }
-
- return 0;
-}
-
-// ======================================================================
-// main function and end signal handler
-// ======================================================================
-
-static void end_program(int sig)
-{
- exit(0);
-}
-
-int main(int argc, char **argv)
-{
- int opt;
- unsigned int commandType = 0;
- signal(SIGINT, end_program);
-
- while((opt = getopt(argc, argv, "sr")) != -1)
- {
- switch(opt)
- {
- case 's': // send
- commandType |= DAEMON_SENDER;
- break;
- case 'r': // receive
- commandType |= DAEMON_RECEIVER;
- break;
- default: // unknown option
- commandType = 0;
- break;
- }
-
- if(commandType == 0)
- break;
- }
-
- if(commandType == DAEMON_SENDER)
- {
- sender();
- }
- else if(commandType == DAEMON_RECEIVER)
- {
- receiver();
- }
- else
- {
- // TODO : print help text
- }
-
- return 0;
-}
-