Serperate the osp-app-service
authorjh0522.choi <jh0522.choi@samsung.com>
Fri, 5 Oct 2012 04:47:28 +0000 (13:47 +0900)
committerjh0522.choi <jh0522.choi@samsung.com>
Fri, 5 Oct 2012 04:47:28 +0000 (13:47 +0900)
54 files changed:
.cproject [new file with mode: 0644]
.project [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0755]
data/app-launch-condition-handlers.ini [new file with mode: 0644]
data/app-launch-conditions.ini [new file with mode: 0644]
icons/screen-density-xhigh/mainmenu.png [new file with mode: 0644]
inc/AppService.h [new file with mode: 0755]
inc/FApp_AppManagerService.h [new file with mode: 0644]
inc/FApp_AppManagerStub.h [new file with mode: 0644]
inc/FApp_CommunicationDispatcher.h [new file with mode: 0644]
inc/FApp_ConditionHandler.h [new file with mode: 0644]
inc/FApp_ConditionManagerService.h [new file with mode: 0644]
inc/FApp_ConditionManagerStub.h [new file with mode: 0644]
inc/FApp_ContextManager.h [new file with mode: 0644]
inc/FApp_ICommunicationRequestListener.h [new file with mode: 0644]
inc/FApp_NotificationManagerService.h [new file with mode: 0755]
inc/FApp_NotificationManagerStub.h [new file with mode: 0755]
inc/FApp_PackageManagerStub.h [new file with mode: 0644]
inc/FApp_StringKeyHashMapUtil.h [new file with mode: 0644]
inc/FSys_AccessoryManagerService.h [new file with mode: 0644]
inc/FSys_DeviceManagerService.h [new file with mode: 0644]
inc/FSys_SystemService.h [new file with mode: 0644]
manifest.xml [new file with mode: 0755]
packaging/osp-app-service.spec [new file with mode: 0755]
plugins/CMakeLists.txt [new file with mode: 0755]
plugins/accessory-condition-handler/AccessoryConditionHandler.cpp [new file with mode: 0644]
plugins/accessory-condition-handler/AccessoryConditionHandler.h [new file with mode: 0644]
plugins/accessory-condition-handler/AccessoryMonitor.cpp [new file with mode: 0644]
plugins/accessory-condition-handler/AccessoryMonitor.h [new file with mode: 0644]
plugins/accessory-condition-handler/CMakeLists.txt [new file with mode: 0755]
plugins/alarm-condition-handler/AlarmConditionHandler.cpp [new file with mode: 0644]
plugins/alarm-condition-handler/AlarmConditionHandler.h [new file with mode: 0644]
plugins/alarm-condition-handler/CMakeLists.txt [new file with mode: 0755]
plugins/nfc-condition-handler/.cproject [new file with mode: 0644]
plugins/nfc-condition-handler/.project [new file with mode: 0644]
plugins/nfc-condition-handler/CMakeLists.txt [new file with mode: 0755]
plugins/nfc-condition-handler/NfcConditionHandler.cpp [new file with mode: 0644]
res/etc/rc.d/init.d/osp-app-service.sh [new file with mode: 0755]
src/AppService.cpp [new file with mode: 0755]
src/AppServiceEntry.cpp [new file with mode: 0644]
src/FApp_AppManagerService.cpp [new file with mode: 0644]
src/FApp_AppManagerStub.cpp [new file with mode: 0644]
src/FApp_CommunicationDispatcher.cpp [new file with mode: 0644]
src/FApp_ConditionHandler.cpp [new file with mode: 0644]
src/FApp_ConditionManagerService.cpp [new file with mode: 0644]
src/FApp_ConditionManagerStub.cpp [new file with mode: 0644]
src/FApp_ContextManager.cpp [new file with mode: 0644]
src/FApp_NotificationManagerService.cpp [new file with mode: 0755]
src/FApp_NotificationManagerStub.cpp [new file with mode: 0755]
src/FApp_PackageManagerStub.cpp [new file with mode: 0644]
src/FSys_AccessoryManagerService.cpp [new file with mode: 0644]
src/FSys_DeviceManagerService.cpp [new file with mode: 0644]
src/FSys_SystemService.cpp [new file with mode: 0644]
system-service-export.ver [new file with mode: 0755]

diff --git a/.cproject b/.cproject
new file mode 100644 (file)
index 0000000..54a7953
--- /dev/null
+++ b/.cproject
@@ -0,0 +1,496 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?>
+
+<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+       <storageModule moduleId="org.eclipse.cdt.core.settings">
+               <cconfiguration id="org.tizen.nativecpp.config.sbi.gcc45.app.debug.emulator.1513716767">
+                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="org.tizen.nativecpp.config.sbi.gcc45.app.debug.emulator.1513716767" moduleId="org.eclipse.cdt.core.settings" name="Debug-Tizen-Emulator">
+                               <externalSettings/>
+                               <extensions>
+                                       <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
+                                       <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                               </extensions>
+                       </storageModule>
+                       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+                               <configuration artifactExtension="exe" artifactName="osp-app-service" buildArtefactType="org.tizen.nativecpp.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.tizen.nativecpp.buildArtefactType.app" description="" errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;" id="org.tizen.nativecpp.config.sbi.gcc45.app.debug.emulator.1513716767" name="Debug-Tizen-Emulator" parent="org.tizen.nativecpp.config.sbi.gcc45.app.debug.emulator">
+                                       <folderInfo id="org.tizen.nativecpp.config.sbi.gcc45.app.debug.emulator.1513716767." name="/" resourcePath="">
+                                               <toolChain id="org.tizen.nativecpp.toolchain.sbi.gcc45.app.debug.emulator.1856007750" name="Tizen Native Toolchain" superClass="org.tizen.nativecpp.toolchain.sbi.gcc45.app.debug.emulator">
+                                                       <targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="org.tizen.nativeide.target.sbi.gnu.platform.base.2028954227" osList="linux,win32" superClass="org.tizen.nativeide.target.sbi.gnu.platform.base"/>
+                                                       <builder buildPath="${workspace_loc:/ospappservice/Debug-Tizen-Emulator}" id="org.tizen.nativecpp.target.sbi.gnu.builder.181320118" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Tizen Application Builder" superClass="org.tizen.nativecpp.target.sbi.gnu.builder"/>
+                                                       <tool id="org.tizen.nativecpp.tool.sbi.gnu.archiver.1304103336" name="Archiver" superClass="org.tizen.nativecpp.tool.sbi.gnu.archiver"/>
+                                                       <tool command="i386-linux-gnueabi-g++" id="org.tizen.nativecpp.tool.sbi.gnu.cpp.compiler.273236926" name="C++ Compiler" superClass="org.tizen.nativecpp.tool.sbi.gnu.cpp.compiler">
+                                                               <option id="gnu.cpp.compiler.option.optimization.level.800623014" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
+                                                               <option id="gnu.cpp.compiler.option.debugging.level.978993155" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
+                                                               <option id="sbi.gnu.cpp.compiler.option.built_in_cflags.cpp.406598399" name="SLP-Built-In-Cflags" superClass="sbi.gnu.cpp.compiler.option.built_in_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value="-D__PROJECT__=&quot;\&quot;osp-app-service\&quot;&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.963132519" name="Tizen-Target" superClass="sbi.gnu.cpp.compiler.option" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="tizen-emulator-2.0.cpp_gcc45.i386.cpp.app"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.compiler.option.include.paths.1990372141" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/inc}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/appfw&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/lib/glib-2.0/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/glib-2.0&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="../../../../../../external/chromium"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/base/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/app/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/security/inc"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/libxml2&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/osp&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/io/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/system/inc"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.frameworks_inc.cpp.1474373758" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.cpp.compiler.option.frameworks_inc.cpp" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/libxml2&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;/home/jungmin76park/tizen-sdk/library&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/osp&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.frameworks_cflags.cpp.899040922" name="Tizen-Frameworks-Other-Cflags" superClass="sbi.gnu.cpp.compiler.option.frameworks_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value=""/>
+                                                                       <listOptionValue builtIn="false" value=" -fPIE"/>
+                                                                       <listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.frameworks.cpp.238268597" name="Tizen-Frameworks" superClass="sbi.gnu.cpp.compiler.option.frameworks.cpp" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="osp"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.compiler.option.preprocessor.def.1950602481" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols">
+                                                                       <listOptionValue builtIn="false" value="_DEBUG"/>
+                                                               </option>
+                                                               <inputType id="sbi.gnu.cpp.compiler.tizen.inputType.1607874703" superClass="sbi.gnu.cpp.compiler.tizen.inputType"/>
+                                                       </tool>
+                                                       <tool command="i386-linux-gnueabi-gcc" id="org.tizen.nativecpp.tool.sbi.gnu.c.compiler.938089844" name="C Compiler" superClass="org.tizen.nativecpp.tool.sbi.gnu.c.compiler">
+                                                               <option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.905287776" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" valueType="enumerated"/>
+                                                               <option id="gnu.c.compiler.option.debugging.level.485814453" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
+                                                               <option id="sbi.gnu.c.compiler.option.built_in_cflags.cpp.1971875430" name="SLP-Built-In-Cflags" superClass="sbi.gnu.c.compiler.option.built_in_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value="-D__PROJECT__=&quot;\&quot;osp-app-service\&quot;&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.735231782" name="Tizen-Target" superClass="sbi.gnu.c.compiler.option" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="tizen-emulator-2.0.cpp_gcc45.i386.cpp.app"/>
+                                                               </option>
+                                                               <option id="gnu.c.compiler.option.include.paths.361316810" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/inc}&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.frameworks.cpp.106467824" name="Tizen-Frameworks" superClass="sbi.gnu.c.compiler.option.frameworks.cpp" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="osp"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.frameworks_inc.cpp.1313226590" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.c.compiler.option.frameworks_inc.cpp" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/libxml2&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;/home/jungmin76park/tizen-sdk/library&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/osp&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.frameworks_cflags.cpp.35714900" name="Tizen-Frameworks-Other-Cflags" superClass="sbi.gnu.c.compiler.option.frameworks_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value=""/>
+                                                                       <listOptionValue builtIn="false" value=" -fPIE"/>
+                                                                       <listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
+                                                               </option>
+                                                               <option id="gnu.c.compiler.option.preprocessor.def.symbols.681143614" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
+                                                                       <listOptionValue builtIn="false" value="_DEBUG"/>
+                                                               </option>
+                                                               <inputType id="sbi.gnu.c.compiler.tizen.inputType.878911418" superClass="sbi.gnu.c.compiler.tizen.inputType"/>
+                                                       </tool>
+                                                       <tool id="org.tizen.nativeide.tool.sbi.gnu.c.linker.base.1859805976" name="C Linker" superClass="org.tizen.nativeide.tool.sbi.gnu.c.linker.base"/>
+                                                       <tool command="i386-linux-gnueabi-g++" id="org.tizen.nativecpp.tool.sbi.gnu.cpp.linker.47936281" name="C++ Linker" superClass="org.tizen.nativecpp.tool.sbi.gnu.cpp.linker">
+                                                               <option id="gnu.cpp.link.option.paths.633750796" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/lib}&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.linker.option.frameworks_lflags.cpp.434370398" name="Tizen-Frameworks-Other-Lflags" superClass="sbi.gnu.cpp.linker.option.frameworks_lflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value="-Xlinker --as-needed"/>
+                                                                       <listOptionValue builtIn="false" value=""/>
+                                                                       <listOptionValue builtIn="false" value="-pie -lpthread "/>
+                                                                       <listOptionValue builtIn="false" value="-Xlinker -rpath=\$$ORIGIN/.. -Xlinker -rpath=\$$ORIGIN/../lib"/>
+                                                                       <listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="-L&quot;${SBI_SYSROOT}/usr/lib&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="-L&quot;${SBI_SYSROOT}/usr/lib/osp&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-appfw"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-uifw"/>
+                                                                       <listOptionValue builtIn="false" value="-lpthread"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-content"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-locations"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-telephony"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-uix"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-media"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-messaging"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-web"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-social"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-wifi"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-bluetooth"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-nfc"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-face"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-speech-tts"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-speech-stt"/>
+                                                                       <listOptionValue builtIn="false" value="-lxml2"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.link.option.libs.266394189" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
+                                                                       <listOptionValue builtIn="false" value="chromium"/>
+                                                                       <listOptionValue builtIn="false" value="bluetooth-media-control"/>
+                                                                       <listOptionValue builtIn="false" value="capi-system-media-key"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1613312030" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
+                                                                       <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
+                                                                       <additionalInput kind="additionalinput" paths="$(LIBS)"/>
+                                                               </inputType>
+                                                       </tool>
+                                                       <tool command="i386-linux-gnueabi-as" id="org.tizen.nativeapp.tool.sbi.gnu.assembler.base.1540098273" name="Assembler" superClass="org.tizen.nativeapp.tool.sbi.gnu.assembler.base">
+                                                               <option id="gnu.both.asm.option.include.paths.503378959" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/osp-app-service/osp-app-service/inc}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="${SBI_SYSROOT}/usr/include"/>
+                                                                       <listOptionValue builtIn="false" value="${SBI_SYSROOT}/usr/include/appfw"/>
+                                                                       <listOptionValue builtIn="false" value="${SBI_SYSROOT}/lib/glib-2.0/include"/>
+                                                                       <listOptionValue builtIn="false" value="${SBI_SYSROOT}/usr/include/glib-2.0"/>
+                                                                       <listOptionValue builtIn="false" value="/home/jungmin76park/workspace/git/osp/external/chromium"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/io/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/system/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/base/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/app/service"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/app/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/security/inc"/>
+                                                                       <listOptionValue builtIn="false" value="${SBI_SYSROOT}/usr/include/libxml2"/>
+                                                                       <listOptionValue builtIn="false" value="${SBI_SYSROOT}/usr/include/osp"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.assembler.input.209647128" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+                                                       </tool>
+                                                       <tool id="org.tizen.nativecpp.tool.sbi.po.compiler.1336818758" name="PO Resource Compiler" superClass="org.tizen.nativecpp.tool.sbi.po.compiler"/>
+                                                       <tool id="org.tizen.nativecpp.tool.sbi.edc.compiler.466731463" name="EDC Resource Compiler" superClass="org.tizen.nativecpp.tool.sbi.edc.compiler"/>
+                                               </toolChain>
+                                       </folderInfo>
+                                       <sourceEntries>
+                                               <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="inc"/>
+                                               <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
+                                               <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="res"/>
+                                       </sourceEntries>
+                               </configuration>
+                       </storageModule>
+                       <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+               </cconfiguration>
+               <cconfiguration id="org.tizen.nativecpp.config.sbi.gcc45.app.debug.device.1974495537">
+                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="org.tizen.nativecpp.config.sbi.gcc45.app.debug.device.1974495537" moduleId="org.eclipse.cdt.core.settings" name="Debug-Tizen-Device">
+                               <externalSettings/>
+                               <extensions>
+                                       <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
+                                       <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                               </extensions>
+                       </storageModule>
+                       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+                               <configuration artifactExtension="exe" artifactName="${ProjName}" buildArtefactType="org.tizen.nativecpp.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.tizen.nativecpp.buildArtefactType.app" description="" errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;" id="org.tizen.nativecpp.config.sbi.gcc45.app.debug.device.1974495537" name="Debug-Tizen-Device" parent="org.tizen.nativecpp.config.sbi.gcc45.app.debug.device">
+                                       <folderInfo id="org.tizen.nativecpp.config.sbi.gcc45.app.debug.device.1974495537." name="/" resourcePath="">
+                                               <toolChain id="org.tizen.nativecpp.toolchain.sbi.gcc45.app.debug.device.1370738044" name="Tizen Native Toolchain" superClass="org.tizen.nativecpp.toolchain.sbi.gcc45.app.debug.device">
+                                                       <targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="org.tizen.nativeide.target.sbi.gnu.platform.base.951668646" osList="linux,win32" superClass="org.tizen.nativeide.target.sbi.gnu.platform.base"/>
+                                                       <builder buildPath="${workspace_loc:/ospappservice/Debug-Tizen-Device}" id="org.tizen.nativecpp.target.sbi.gnu.builder.1410928584" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Tizen Application Builder" superClass="org.tizen.nativecpp.target.sbi.gnu.builder"/>
+                                                       <tool id="org.tizen.nativecpp.tool.sbi.gnu.archiver.1904784495" name="Archiver" superClass="org.tizen.nativecpp.tool.sbi.gnu.archiver"/>
+                                                       <tool command="arm-linux-gnueabi-g++" id="org.tizen.nativecpp.tool.sbi.gnu.cpp.compiler.1785375124" name="C++ Compiler" superClass="org.tizen.nativecpp.tool.sbi.gnu.cpp.compiler">
+                                                               <option id="gnu.cpp.compiler.option.optimization.level.308776561" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
+                                                               <option id="gnu.cpp.compiler.option.debugging.level.1333525793" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
+                                                               <option id="sbi.gnu.cpp.compiler.option.built_in_cflags.cpp.1134840522" name="SLP-Built-In-Cflags" superClass="sbi.gnu.cpp.compiler.option.built_in_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value="-D__PROJECT__=&quot;\&quot;osp-app-service\&quot;&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.1166585254" name="Tizen-Target" superClass="sbi.gnu.cpp.compiler.option" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="tizen-device-2.0.cpp_gcc45.armel.cpp.app"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.compiler.option.include.paths.1226801087" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/inc}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/appfw&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/lib/glib-2.0/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/glib-2.0&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="../../../../external/chromium"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/base/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/app/service"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/app/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/security/inc"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/libxml2&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/osp&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/io/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/system/inc"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.frameworks_inc.cpp.1307717513" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.cpp.compiler.option.frameworks_inc.cpp" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/libxml2&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;/home/jungmin76park/tizen-sdk/library&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/osp&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.frameworks_cflags.cpp.651188651" name="Tizen-Frameworks-Other-Cflags" superClass="sbi.gnu.cpp.compiler.option.frameworks_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value=""/>
+                                                                       <listOptionValue builtIn="false" value=" -fPIE"/>
+                                                                       <listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.frameworks.cpp.723842038" name="Tizen-Frameworks" superClass="sbi.gnu.cpp.compiler.option.frameworks.cpp" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="osp"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.compiler.option.preprocessor.def.289369098" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols">
+                                                                       <listOptionValue builtIn="false" value="_DEBUG"/>
+                                                               </option>
+                                                               <inputType id="sbi.gnu.cpp.compiler.tizen.inputType.932832319" superClass="sbi.gnu.cpp.compiler.tizen.inputType"/>
+                                                       </tool>
+                                                       <tool command="arm-linux-gnueabi-gcc" id="org.tizen.nativecpp.tool.sbi.gnu.c.compiler.808285802" name="C Compiler" superClass="org.tizen.nativecpp.tool.sbi.gnu.c.compiler">
+                                                               <option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.2113439567" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" valueType="enumerated"/>
+                                                               <option id="gnu.c.compiler.option.debugging.level.1445955937" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
+                                                               <option id="sbi.gnu.c.compiler.option.built_in_cflags.cpp.256728628" name="SLP-Built-In-Cflags" superClass="sbi.gnu.c.compiler.option.built_in_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value="-D__PROJECT__=&quot;\&quot;osp-app-service\&quot;&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.610638838" name="Tizen-Target" superClass="sbi.gnu.c.compiler.option" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="tizen-device-2.0.cpp_gcc45.armel.cpp.app"/>
+                                                               </option>
+                                                               <option id="gnu.c.compiler.option.include.paths.1482696349" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/inc}&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.frameworks.cpp.340464035" name="Tizen-Frameworks" superClass="sbi.gnu.c.compiler.option.frameworks.cpp" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="osp"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.frameworks_inc.cpp.798442043" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.c.compiler.option.frameworks_inc.cpp" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/libxml2&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;/home/jungmin76park/tizen-sdk/library&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/osp&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.frameworks_cflags.cpp.1555572788" name="Tizen-Frameworks-Other-Cflags" superClass="sbi.gnu.c.compiler.option.frameworks_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value=""/>
+                                                                       <listOptionValue builtIn="false" value=" -fPIE"/>
+                                                                       <listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
+                                                               </option>
+                                                               <option id="gnu.c.compiler.option.preprocessor.def.symbols.1253822767" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
+                                                                       <listOptionValue builtIn="false" value="_DEBUG"/>
+                                                               </option>
+                                                               <inputType id="sbi.gnu.c.compiler.tizen.inputType.1146188953" superClass="sbi.gnu.c.compiler.tizen.inputType"/>
+                                                       </tool>
+                                                       <tool id="org.tizen.nativeide.tool.sbi.gnu.c.linker.base.317984680" name="C Linker" superClass="org.tizen.nativeide.tool.sbi.gnu.c.linker.base"/>
+                                                       <tool command="arm-linux-gnueabi-g++" id="org.tizen.nativecpp.tool.sbi.gnu.cpp.linker.1055785774" name="C++ Linker" superClass="org.tizen.nativecpp.tool.sbi.gnu.cpp.linker">
+                                                               <option id="gnu.cpp.link.option.paths.25666363" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/lib}&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.linker.option.frameworks_lflags.cpp.2048425592" name="Tizen-Frameworks-Other-Lflags" superClass="sbi.gnu.cpp.linker.option.frameworks_lflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value="-Xlinker --as-needed"/>
+                                                                       <listOptionValue builtIn="false" value=""/>
+                                                                       <listOptionValue builtIn="false" value="-pie -lpthread "/>
+                                                                       <listOptionValue builtIn="false" value="-Xlinker -rpath=\$$ORIGIN/.. -Xlinker -rpath=\$$ORIGIN/../lib"/>
+                                                                       <listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="-L&quot;${SBI_SYSROOT}/usr/lib&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="-L&quot;${SBI_SYSROOT}/usr/lib/osp&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-appfw"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-uifw"/>
+                                                                       <listOptionValue builtIn="false" value="-lpthread"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-content"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-locations"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-telephony"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-uix"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-media"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-messaging"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-web"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-social"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-wifi"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-bluetooth"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-nfc"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-face"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-speech-tts"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-speech-stt"/>
+                                                                       <listOptionValue builtIn="false" value="-lxml2"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.link.option.libs.1310183952" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
+                                                                       <listOptionValue builtIn="false" value="chromium"/>
+                                                                       <listOptionValue builtIn="false" value="bluetooth-media-control"/>
+                                                                       <listOptionValue builtIn="false" value="capi-system-media-key"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1345855227" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
+                                                                       <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
+                                                                       <additionalInput kind="additionalinput" paths="$(LIBS)"/>
+                                                               </inputType>
+                                                       </tool>
+                                                       <tool command="arm-linux-gnueabi-as" id="org.tizen.nativeapp.tool.sbi.gnu.assembler.base.548128242" name="Assembler" superClass="org.tizen.nativeapp.tool.sbi.gnu.assembler.base">
+                                                               <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1027441876" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+                                                       </tool>
+                                                       <tool id="org.tizen.nativecpp.tool.sbi.po.compiler.1991405690" name="PO Resource Compiler" superClass="org.tizen.nativecpp.tool.sbi.po.compiler"/>
+                                                       <tool id="org.tizen.nativecpp.tool.sbi.edc.compiler.1424958363" name="EDC Resource Compiler" superClass="org.tizen.nativecpp.tool.sbi.edc.compiler"/>
+                                               </toolChain>
+                                       </folderInfo>
+                                       <sourceEntries>
+                                               <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
+                                               <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="res"/>
+                                               <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="inc"/>
+                                       </sourceEntries>
+                               </configuration>
+                       </storageModule>
+                       <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+               </cconfiguration>
+               <cconfiguration id="org.tizen.nativecpp.config.sbi.gcc45.app.release.971807173">
+                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="org.tizen.nativecpp.config.sbi.gcc45.app.release.971807173" moduleId="org.eclipse.cdt.core.settings" name="Release">
+                               <externalSettings/>
+                               <extensions>
+                                       <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
+                                       <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                               </extensions>
+                       </storageModule>
+                       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+                               <configuration artifactExtension="exe" artifactName="${ProjName}" buildArtefactType="org.tizen.nativecpp.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.tizen.nativecpp.buildArtefactType.app" description="" errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;" id="org.tizen.nativecpp.config.sbi.gcc45.app.release.971807173" name="Release" parent="org.tizen.nativecpp.config.sbi.gcc45.app.release">
+                                       <folderInfo id="org.tizen.nativecpp.config.sbi.gcc45.app.release.971807173." name="/" resourcePath="">
+                                               <toolChain id="org.tizen.nativecpp.toolchain.sbi.gcc45.app.release.92836649" name="Tizen Native Toolchain" superClass="org.tizen.nativecpp.toolchain.sbi.gcc45.app.release">
+                                                       <targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="org.tizen.nativeide.target.sbi.gnu.platform.base.627915779" osList="linux,win32" superClass="org.tizen.nativeide.target.sbi.gnu.platform.base"/>
+                                                       <builder buildPath="${workspace_loc:/ospappservice/Release}" id="org.tizen.nativecpp.target.sbi.gnu.builder.510443919" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Tizen Application Builder" superClass="org.tizen.nativecpp.target.sbi.gnu.builder"/>
+                                                       <tool id="org.tizen.nativecpp.tool.sbi.gnu.archiver.2121885383" name="Archiver" superClass="org.tizen.nativecpp.tool.sbi.gnu.archiver"/>
+                                                       <tool command="arm-linux-gnueabi-g++" id="org.tizen.nativecpp.tool.sbi.gnu.cpp.compiler.1287303852" name="C++ Compiler" superClass="org.tizen.nativecpp.tool.sbi.gnu.cpp.compiler">
+                                                               <option id="gnu.cpp.compiler.option.optimization.level.696322659" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
+                                                               <option id="gnu.cpp.compiler.option.debugging.level.1237688243" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
+                                                               <option id="sbi.gnu.cpp.compiler.option.built_in_cflags.cpp.1536628149" name="SLP-Built-In-Cflags" superClass="sbi.gnu.cpp.compiler.option.built_in_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value="-D__PROJECT__=&quot;\&quot;osp-app-service\&quot;&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.1174124708" name="Tizen-Target" superClass="sbi.gnu.cpp.compiler.option" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="tizen-device-2.0.cpp_gcc45.armel.cpp.app"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.compiler.option.include.paths.1521479953" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/inc}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/appfw&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/lib/glib-2.0/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/glib-2.0&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="../../../../external/chromium"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/base/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/app/service"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/app/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/security/inc"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/libxml2&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/osp&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/io/inc"/>
+                                                                       <listOptionValue builtIn="false" value="../../../src/system/inc"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.frameworks_inc.cpp.1295221744" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.cpp.compiler.option.frameworks_inc.cpp" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/libxml2&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;/home/jungmin76park/tizen-sdk/library&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/osp&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.frameworks_cflags.cpp.153925549" name="Tizen-Frameworks-Other-Cflags" superClass="sbi.gnu.cpp.compiler.option.frameworks_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value=""/>
+                                                                       <listOptionValue builtIn="false" value=" -fPIE"/>
+                                                                       <listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.compiler.option.frameworks.cpp.649355937" name="Tizen-Frameworks" superClass="sbi.gnu.cpp.compiler.option.frameworks.cpp" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="osp"/>
+                                                               </option>
+                                                               <inputType id="sbi.gnu.cpp.compiler.tizen.inputType.1287918812" superClass="sbi.gnu.cpp.compiler.tizen.inputType"/>
+                                                       </tool>
+                                                       <tool command="arm-linux-gnueabi-gcc" id="org.tizen.nativecpp.tool.sbi.gnu.c.compiler.1493790431" name="C Compiler" superClass="org.tizen.nativecpp.tool.sbi.gnu.c.compiler">
+                                                               <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.308835412" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" valueType="enumerated"/>
+                                                               <option id="gnu.c.compiler.option.debugging.level.666103717" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
+                                                               <option id="sbi.gnu.c.compiler.option.built_in_cflags.cpp.147063867" name="SLP-Built-In-Cflags" superClass="sbi.gnu.c.compiler.option.built_in_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value="-D__PROJECT__=&quot;\&quot;osp-app-service\&quot;&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.36933758" name="Tizen-Target" superClass="sbi.gnu.c.compiler.option" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="tizen-device-2.0.cpp_gcc45.armel.cpp.app"/>
+                                                               </option>
+                                                               <option id="gnu.c.compiler.option.include.paths.314497321" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/inc}&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.frameworks.cpp.1859898599" name="Tizen-Frameworks" superClass="sbi.gnu.c.compiler.option.frameworks.cpp" valueType="userObjs">
+                                                                       <listOptionValue builtIn="false" value="osp"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.frameworks_inc.cpp.1378709332" name="Tizen-Frameworks-Include-Path" superClass="sbi.gnu.c.compiler.option.frameworks_inc.cpp" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/libxml2&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;/home/jungmin76park/tizen-sdk/library&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${SBI_SYSROOT}/usr/include/osp&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.c.compiler.option.frameworks_cflags.cpp.1639023741" name="Tizen-Frameworks-Other-Cflags" superClass="sbi.gnu.c.compiler.option.frameworks_cflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value=""/>
+                                                                       <listOptionValue builtIn="false" value=" -fPIE"/>
+                                                                       <listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
+                                                               </option>
+                                                               <inputType id="sbi.gnu.c.compiler.tizen.inputType.831658303" superClass="sbi.gnu.c.compiler.tizen.inputType"/>
+                                                       </tool>
+                                                       <tool id="org.tizen.nativeide.tool.sbi.gnu.c.linker.base.430210616" name="C Linker" superClass="org.tizen.nativeide.tool.sbi.gnu.c.linker.base"/>
+                                                       <tool command="arm-linux-gnueabi-g++" id="org.tizen.nativecpp.tool.sbi.gnu.cpp.linker.1751178860" name="C++ Linker" superClass="org.tizen.nativecpp.tool.sbi.gnu.cpp.linker">
+                                                               <option id="gnu.cpp.link.option.paths.922964707" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
+                                                                       <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/lib}&quot;"/>
+                                                               </option>
+                                                               <option id="sbi.gnu.cpp.linker.option.frameworks_lflags.cpp.1708409674" name="Tizen-Frameworks-Other-Lflags" superClass="sbi.gnu.cpp.linker.option.frameworks_lflags.cpp" valueType="stringList">
+                                                                       <listOptionValue builtIn="false" value="-Xlinker --as-needed"/>
+                                                                       <listOptionValue builtIn="false" value=""/>
+                                                                       <listOptionValue builtIn="false" value="-pie -lpthread "/>
+                                                                       <listOptionValue builtIn="false" value="-Xlinker -rpath=\$$ORIGIN/.. -Xlinker -rpath=\$$ORIGIN/../lib"/>
+                                                                       <listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="-L&quot;${SBI_SYSROOT}/usr/lib&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="-L&quot;${SBI_SYSROOT}/usr/lib/osp&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-appfw"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-uifw"/>
+                                                                       <listOptionValue builtIn="false" value="-lpthread"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-content"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-locations"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-telephony"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-uix"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-media"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-messaging"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-web"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-social"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-wifi"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-bluetooth"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-nfc"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-face"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-speech-tts"/>
+                                                                       <listOptionValue builtIn="false" value="-losp-speech-stt"/>
+                                                                       <listOptionValue builtIn="false" value="-lxml2"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.link.option.libs.1423223298" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
+                                                                       <listOptionValue builtIn="false" value="chromium"/>
+                                                                       <listOptionValue builtIn="false" value="bluetooth-media-control"/>
+                                                                       <listOptionValue builtIn="false" value="capi-system-media-key"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.872564487" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
+                                                                       <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
+                                                                       <additionalInput kind="additionalinput" paths="$(LIBS)"/>
+                                                               </inputType>
+                                                       </tool>
+                                                       <tool command="arm-linux-gnueabi-as" id="org.tizen.nativeapp.tool.sbi.gnu.assembler.base.1037430498" name="Assembler" superClass="org.tizen.nativeapp.tool.sbi.gnu.assembler.base">
+                                                               <inputType id="cdt.managedbuild.tool.gnu.assembler.input.783954508" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+                                                       </tool>
+                                                       <tool id="org.tizen.nativecpp.tool.sbi.po.compiler.2018559094" name="PO Resource Compiler" superClass="org.tizen.nativecpp.tool.sbi.po.compiler"/>
+                                                       <tool id="org.tizen.nativecpp.tool.sbi.edc.compiler.910919006" name="EDC Resource Compiler" superClass="org.tizen.nativecpp.tool.sbi.edc.compiler"/>
+                                               </toolChain>
+                                       </folderInfo>
+                                       <sourceEntries>
+                                               <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
+                                               <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="res"/>
+                                               <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="inc"/>
+                                       </sourceEntries>
+                               </configuration>
+                       </storageModule>
+                       <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+               </cconfiguration>
+       </storageModule>
+       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+               <project id="ospappservice.org.tizen.nativecpp.target.sbi.gcc45.app.380975827" name="Tizen Application" projectType="org.tizen.nativecpp.target.sbi.gcc45.app"/>
+       </storageModule>
+       <storageModule moduleId="scannerConfiguration">
+               <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               <scannerConfigBuildInfo instanceId="org.tizen.nativecpp.config.sbi.gcc45.app.release.971807173">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.tizen.nativecommon.TizenGCCManagedMakePerProjectProfileCPP"/>
+               </scannerConfigBuildInfo>
+               <scannerConfigBuildInfo instanceId="org.tizen.nativecpp.config.sbi.gcc45.app.debug.device.1974495537">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.tizen.nativecommon.TizenGCCManagedMakePerProjectProfileCPP"/>
+               </scannerConfigBuildInfo>
+               <scannerConfigBuildInfo instanceId="org.tizen.nativecpp.config.sbi.gcc45.app.debug.emulator.1513716767">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.tizen.nativecommon.TizenGCCManagedMakePerProjectProfileCPP"/>
+               </scannerConfigBuildInfo>
+       </storageModule>
+       <storageModule moduleId="com.samsung.tizen.nativeapp.projectInfo" version="1.0.0"/>
+       <storageModule moduleId="refreshScope"/>
+</cproject>
diff --git a/.project b/.project
new file mode 100644 (file)
index 0000000..42f95e5
--- /dev/null
+++ b/.project
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>osp-app-service</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+                       <triggers>clean,full,incremental,</triggers>
+                       <arguments>
+                               <dictionary>
+                                       <key>?name?</key>
+                                       <value></value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.append_environment</key>
+                                       <value>true</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.autoBuildTarget</key>
+                                       <value>all</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.buildArguments</key>
+                                       <value></value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.buildCommand</key>
+                                       <value>sbi-make</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.buildLocation</key>
+                                       <value>${workspace_loc:/ospappservice/Debug-Tizen-Emulator}</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
+                                       <value>clean</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.contents</key>
+                                       <value>org.eclipse.cdt.make.core.activeConfigSettings</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
+                                       <value>false</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
+                                       <value>true</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.enableFullBuild</key>
+                                       <value>true</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.fullBuildTarget</key>
+                                       <value>all</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.stopOnError</key>
+                                       <value>true</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
+                                       <value>true</value>
+                               </dictionary>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+                       <triggers>full,incremental,</triggers>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.tizen.nativecpp.apichecker.core.builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.cdt.core.cnature</nature>
+               <nature>org.eclipse.cdt.core.ccnature</nature>
+               <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+               <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+               <nature>org.tizen.nativecpp.apichecker.core.tizenCppNature</nature>
+       </natures>
+</projectDescription>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..aef7095
--- /dev/null
@@ -0,0 +1,80 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET (this_target osp-app-service)
+SET (APPID aospd00043)
+
+SET(CMAKE_EXECUTABLE_SUFFIX ".exe")
+SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/output")
+
+ADD_SUBDIRECTORY(plugins)
+
+INCLUDE_DIRECTORIES (
+       /usr/include/glib-2.0
+       /usr/lib/glib-2.0/include
+       /usr/include/appfw
+       /usr/include/network
+       /usr/include/notification
+       /usr/include/osp
+       /usr/include/osp/app
+       /usr/include/osp/base
+       /usr/include/osp/io
+       /usr/include/osp/system
+       /usr/include/osp/security
+       /usr/include/chromium
+       inc
+       )
+
+SET (${this_target}_SOURCE_FILES
+       src/FApp_AppManagerService.cpp
+       src/FApp_AppManagerStub.cpp
+       src/FApp_ConditionManagerService.cpp
+       src/FApp_ConditionManagerStub.cpp
+       src/FApp_ConditionHandler.cpp
+       src/FApp_ContextManager.cpp
+       src/FApp_CommunicationDispatcher.cpp
+       src/FApp_PackageManagerStub.cpp
+       src/FApp_NotificationManagerStub.cpp
+       src/FApp_NotificationManagerService.cpp
+       src/FSys_DeviceManagerService.cpp
+       src/FSys_SystemService.cpp
+       src/FSys_AccessoryManagerService.cpp
+       src/AppService.cpp
+       src/AppServiceEntry.cpp
+       )
+
+## SET EXTRA COMPILER FLAGS
+SET(EXTRA_CFLAGS  "${EXTRA_CFLAGS} -fPIE -Wall -pthread -g3" )
+#SET(EXTRA_CFLAGS  "${EXTRA_CFLAGS} -fstack-protector -Wstack-protector" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_EXECUTABLE (${this_target} ${${this_target}_SOURCE_FILES})
+
+TARGET_LINK_LIBRARIES(${this_target} -Xlinker --no-undefined -Xlinker --as-needed -pie)
+TARGET_LINK_LIBRARIES(${this_target} -Xlinker --version-script=${CMAKE_CURRENT_SOURCE_DIR}/system-service-export.ver)
+TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw -lchromium")
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-system-media-key" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-network-bluetooth" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-application" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-app-manager" )
+TARGET_LINK_LIBRARIES(${this_target} "-lnotification" )
+
+
+ADD_CUSTOM_COMMAND(TARGET ${this_target}
+        POST_BUILD
+                               COMMAND ${CMAKE_COMMAND} -E copy ${EXECUTABLE_OUTPUT_PATH}/${this_target}${CMAKE_EXECUTABLE_SUFFIX} ${EXECUTABLE_OUTPUT_PATH}/debug/${this_target}${CMAKE_EXECUTABLE_SUFFIX}
+                               COMMAND ${CMAKE_STRIP} --strip-unneeded --remove-section .comment ${EXECUTABLE_OUTPUT_PATH}/${this_target}${CMAKE_EXECUTABLE_SUFFIX}
+        COMMENT "strip ${this_target}"
+)  
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/etc/rc.d/init.d/osp-app-service.sh DESTINATION ../etc/rc.d/init.d)
+INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/${this_target}.exe DESTINATION ../opt/apps/${APPID}/bin)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/manifest.xml DESTINATION ../opt/apps/${APPID}/info)
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/ DESTINATION ../opt/apps/${APPID}/data FILES_MATCHING PATTERN "*.ini")
+INSTALL(FILES ${EXECUTABLE_OUTPUT_PATH}/debug/${this_target}${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ../opt/apps/debug)
\ No newline at end of file
diff --git a/data/app-launch-condition-handlers.ini b/data/app-launch-condition-handlers.ini
new file mode 100644 (file)
index 0000000..389b082
--- /dev/null
@@ -0,0 +1,11 @@
+#libosp-cond-alarm.so
+Key=DateTime,LaunchPeriod,DueTime
+Filename=libosp-cond-alarm.so
+
+#libosp-cond-nfc.so
+Key=NFC
+Filename=libosp-cond-nfc.so
+
+#libosp-cond-accessory.so
+Key=ACCESSORY,Serial
+Filename=libosp-cond-accessory.so
diff --git a/data/app-launch-conditions.ini b/data/app-launch-conditions.ini
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/icons/screen-density-xhigh/mainmenu.png b/icons/screen-density-xhigh/mainmenu.png
new file mode 100644 (file)
index 0000000..b0979b1
Binary files /dev/null and b/icons/screen-density-xhigh/mainmenu.png differ
diff --git a/inc/AppService.h b/inc/AppService.h
new file mode 100755 (executable)
index 0000000..833984a
--- /dev/null
@@ -0,0 +1,121 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+#ifndef _APP_SERVICE_H_
+#define _APP_SERVICE_H_
+
+
+#include <FSystem.h>
+#include <FAppTypes.h>
+#include <FAppPackageManager.h>
+
+#include <FApp_IAppManagerEventListener.h>
+
+namespace Osp { namespace App
+{
+class _AppManagerStub;
+class _ConditionManagerStub;
+class _ContextManager;
+class _CommunicationDispatcher;
+class _PackageManagerStub;
+class _NotificationManagerStub;
+}}
+
+namespace Osp { namespace Io
+{
+class _IpcServer;
+}}
+
+namespace Osp { namespace System
+{
+class _DeviceManagerService;
+class _SystemService;
+class _AccessoryManagerService;
+}}
+
+/**
+ * @class      AppService
+ * @brief      This creates and initializes major system services such as channel, appmanager, and others.
+ * And ContextManager watchs running apps(processes) and callbacks to appmanager when app destroyed.
+ *
+ * @ remarks AppService is system service of OSP, and starts at first among them.
+ */
+class AppService
+       : public Osp::App::ServiceApp
+       , public Osp::App::IPackageEventListener
+       , public Osp::App::_IAppManagerEventListener
+       , virtual public Osp::Base::Runtime::IEventListener
+{
+public:
+       static Osp::App::ServiceApp* CreateInstance(void);
+
+       AppService();
+       virtual ~AppService();
+
+       virtual bool OnAppInitializing(Osp::App::AppRegistry& appRegistry);
+       virtual bool OnAppInitialized(void);
+       virtual bool OnAppTerminating(Osp::App::AppRegistry& appRegistry, bool forcedTermination = false);
+       virtual void OnLowMemory(void);
+       virtual void OnBatteryLevelChanged(Osp::System::BatteryLevel batteryLevel);
+       virtual void OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList *pArgs);
+
+       // IPackageEventListener
+       virtual void OnPackageInstallationCompleted(Osp::App::PackageType type, const Osp::App::AppId& appId, const Osp::Base::String& packageName, Osp::App::PackageErrorType errorType);
+       virtual void OnPackageUninstallationCompleted(Osp::App::PackageType type, const Osp::App::AppId& appId, const Osp::Base::String& packageName, Osp::App::PackageErrorType errorType);
+       virtual void OnPackageInstallationInProgress(Osp::App::PackageType type, const Osp::App::AppId& appId, const Osp::Base::String& packageName, int progress);
+
+       bool InitializeServices(void);
+
+       static void OnPowerOffNotiReceived(void* pData);
+
+private:
+       bool LaunchSystemServices(void);
+       bool LaunchUserServices(void);
+       bool LaunchChannelService(void);
+       Osp::Base::Collection::ArrayList* GetPackageEventArgsN(const Osp::App::AppId& appId, const Osp::Base::String& packageName);
+       virtual void OnApplicationLaunched(const Osp::App::AppId& appId, const Osp::Base::String& executableName, Osp::App::AppType type);
+       virtual void OnApplicationTerminated(const Osp::App::AppId& appId, const Osp::Base::String& executableName, Osp::App::AppType type);
+
+private:
+       class _TaskHandlerThread
+               : public Osp::Base::Runtime::Thread
+       {
+       public:
+               _TaskHandlerThread(AppService& mgr);
+               virtual ~_TaskHandlerThread(void);
+
+               virtual bool OnStart(void);
+               virtual void OnStop(void);
+               virtual void OnUserEventReceivedN(RequestId reqId, Osp::Base::Collection::IList* pArgs);
+
+       private:
+               AppService&     __mgr;
+       };
+
+       Osp::App::_CommunicationDispatcher* __pCommunicationDispatcher;
+       Osp::App::_ContextManager* __pContextMgr;
+       Osp::App::_AppManagerStub* __pAppManagerStub;
+       Osp::App::_ConditionManagerStub* __pConditionManagerStub;
+       _TaskHandlerThread      __handlerThread;
+       Osp::System::_DeviceManagerService* __pDeviceManagerService;
+       Osp::System::_SystemService* __pSystemService;
+       Osp::System::_AccessoryManagerService* __pAccessoryManagerService;
+       Osp::App::_PackageManagerStub* __pPackageManagerStub;
+       Osp::App::_NotificationManagerStub* __pNotificationManagerStub;
+};     // AppService
+
+#endif
diff --git a/inc/FApp_AppManagerService.h b/inc/FApp_AppManagerService.h
new file mode 100644 (file)
index 0000000..72e38f5
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_AppManagerService.h
+ * @brief      This is the header file of the _AppManagerService class.
+ *
+ * This header file contains the declarations of the _AppManagerService class.
+ */
+
+#ifndef _FAPP_INTERNAL_APP_MANAGER_SERVICE_H_
+#define _FAPP_INTERNAL_APP_MANAGER_SERVICE_H_
+
+#include <FBase.h>
+#include <FSystem.h>
+#include <FIo.h>
+#include <FAppTypes.h>
+
+#include <FApp_IAppManager.h>
+
+#include "FApp_ContextManager.h"
+
+
+namespace Osp { namespace App {
+
+class _IAppManagerServiceEventListener;
+
+/**
+ * @class              _AppManagerService
+ * @brief              Manages and control applications.
+ * @since              3.0
+ */
+class _AppManagerService
+       : public Osp::Base::Object
+       , public _IAppManager
+       , public _IContextManagerEventListener
+       , virtual public Osp::Base::Runtime::IEventListener
+{
+public:
+       _AppManagerService(void);
+
+       virtual ~_AppManagerService(void);
+
+       result Construct(_ContextManager* pContextMgr, _IAppManagerServiceEventListener* pStub);
+
+       virtual result LaunchApplication(const AppId& appId, const Osp::Base::String& executableName, int req);
+       virtual result TerminateApplication(const AppId& appId, const Osp::Base::String& executableName);
+       virtual bool IsRunning(const AppId& appId, const Osp::Base::String& executableName);
+       virtual result GetRunningAppList(Osp::Base::Collection::ArrayList* pArray);
+       virtual result RegisterApplication(const AppId& appId, const Osp::Base::String& executableName, AppType appType, int pid);
+       virtual result RegisterApplication(const AppId& appId, const Osp::Base::String& executableName, AppType appType, int pid, int clientId);
+       virtual result UnregisterApplication(int pid);
+
+       virtual result InitEventListener( _IAppManagerServiceEventListener* pListener);
+       virtual result AddEventListener(int clientId);//, _IAppManagerServiceEventListener* pListener);
+       virtual result RemoveEventListener(int clientId);//, _IAppManagerServiceEventListener* pListener);
+       virtual void OnApplicationTerminated(const _AppContext& appInfo);
+
+       // helper
+//     const _AppContext* GetAppInfoSimple(const AppId& appId) const;
+
+private:
+       result SendEventToAllListeners(const _AppManagerEventArg& arg);
+
+private:
+       typedef Osp::Base::Collection::HashMapT<int, _IAppManagerServiceEventListener*> _AppManagerServiceEventListeners;
+       typedef Osp::Base::Collection::IMapEnumeratorT <int, _IAppManagerServiceEventListener*> _AppManagerServiceEventListenerEnum;
+
+       _ContextManager*        __pContextMgr;
+       _AppManagerServiceEventListeners        __eventListeners;
+       _IAppManagerServiceEventListener*       __pStub;
+       _IAppManagerServiceEventListener*       __pProxy;
+
+       void Dump(void);
+
+friend class UTs_AppManagerServiceP;
+};     //_AppManagerService
+
+}}//Osp::App
+
+#endif//_APP_MANAGER_SERVICE_H_
diff --git a/inc/FApp_AppManagerStub.h b/inc/FApp_AppManagerStub.h
new file mode 100644 (file)
index 0000000..4c2942e
--- /dev/null
@@ -0,0 +1,101 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_AppManagerStub.h
+ * @brief      This is the header file of the _AppManagerStub class.
+ *
+ * This header file contains the declarations of the _AppManagerStub class.
+ */
+
+#ifndef _FAPP_INTERNAL_APP_MANAGER_STUB_H_
+#define _FAPP_INTERNAL_APP_MANAGER_STUB_H_
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FBaseRtIEventListener.h>
+#include <FSystem.h>
+#include <FIo.h>
+#include <FAppTypes.h>
+
+#include <FIo_IIpcServerEventListener.h>
+#include <FApp_IAppManager.h>
+#include <FApp_IAppManagerServiceEventListener.h>
+
+
+namespace Osp { namespace App {
+
+class _AppManagerService;
+class _ContextManager;
+
+/**
+ * @class              _AppManagerStub
+ * @brief              Handles IPC requests and calls real methods.
+ * @since              3.0
+ */
+class _AppManagerStub
+       : public Osp::Base::Object
+       , public Osp::Io::_IIpcServerEventListener
+       , public _IAppManagerServiceEventListener
+       , virtual public Osp::Base::Runtime::IEventListener
+{
+public:
+       _AppManagerStub(void);
+
+       virtual ~_AppManagerStub(void);
+
+       result Construct(_ContextManager* pContextMgr);
+
+       // handlers
+       bool OnLaunchApplication(const AppId& appID, const Osp::Base::String& serviceId, int req);
+       bool OnTerminateApplication(const AppId& appID, const Osp::Base::String& executableName, result *pRes);
+       bool OnIsRunning(const AppId& appID, const Osp::Base::String& executableName, bool *pRes);
+       bool OnGetRunningAppList(Osp::Base::Collection::ArrayList* pArray, result *pRes);
+       bool OnRegisterApplication(const AppId& appID, const Osp::Base::String& executableName, int appType, int pid);
+       bool OnUnregisterApplication(int pid);
+       bool OnAddEventListener(int pid);
+       bool OnRemoveEventListener(int pid);
+
+       // send message to client
+
+       // _IIpcServerEventListener
+       virtual void OnIpcServerStarted(const Osp::Io::_IpcServer& server);
+       virtual void OnIpcServerStopped(const Osp::Io::_IpcServer& server);
+       virtual void OnIpcClientConnected(const Osp::Io::_IpcServer& server, int clientId);
+       virtual void OnIpcClientDisconnected(const Osp::Io::_IpcServer&server, int clientId);
+       virtual void OnIpcRequestReceived(Osp::Io::_IpcServer& server, const IPC::Message& message);
+
+       // to client
+       virtual result OnServiceEventReceived(int clientId, const _AppManagerEventArg& arg);
+       virtual result OnTerminateApplicationRequested(int clientId);
+
+private:
+       result StartIpcServer(void);
+       _AppManagerStub(const _AppManagerStub& value);
+       _AppManagerStub& operator =(const _AppManagerStub& source);
+
+private:
+       typedef Osp::Base::Collection::HashMapT<int, Osp::Base::String*> _AppManagerEventListeners;
+       typedef Osp::Base::Collection::IMapEnumeratorT <int, Osp::Base::String*> _AppManagerEventListenersEnumerator;
+
+       Osp::Io::_IpcServer *__pIpcServer;
+       _AppManagerService* __pAppManagerService;
+};     //_AppManagerStub
+
+}}//Osp::App
+
+#endif//_FAPP_INTERNAL_APP_MANAGER_STUB_H_
diff --git a/inc/FApp_CommunicationDispatcher.h b/inc/FApp_CommunicationDispatcher.h
new file mode 100644 (file)
index 0000000..54ded3b
--- /dev/null
@@ -0,0 +1,103 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_CommunicationDispatcher.h
+ * @brief      This is the header file of the _CommunicationDispatcher class.
+ *
+ * This header file contains the declarations of the _CommunicationDispatcher class.
+ */
+#include <FApp.h>
+#include <FBase.h>
+#include <FIo.h>
+
+#include <FApp_IAppManagerEventListener.h>
+#include <FIo_IIpcServerEventListener.h>
+#include "FApp_ICommunicationRequestListener.h"
+
+#ifndef _FAPP_INTERNAL_COMMNUICATION_DISPATCHER_H_
+#define _FAPP_INTERNAL_COMMNUICATION_DISPATCHER_H_
+
+namespace Osp { namespace App
+{
+class _AppManagerImpl;
+}}
+
+namespace Osp { namespace Base
+{
+namespace Runtime
+{
+class Mutex;
+}
+}}
+
+namespace Osp { namespace Io
+{
+class _IpcServer;
+}}
+
+namespace Osp { namespace App {
+
+/**
+ * @class      _CommunicationDispatcher
+ * @brief      This class contains implementaion of communication feature for external application.
+ * @since      3.0
+ */
+class _CommunicationDispatcher
+       : public Osp::Io::_IIpcServerEventListener
+       , public _IAppManagerEventListener
+       , virtual public Osp::Base::Runtime::IEventListener
+{
+
+public:
+       static _CommunicationDispatcher* GetInstance(void);
+
+       result AddCommunicationEventListener(Osp::App::_ICommunicationRequestListener& listener);
+       result RemoveCommunicationEventListener(Osp::App::_ICommunicationRequestListener& listener);
+
+       virtual void OnIpcServerStarted(const Osp::Io::_IpcServer& server) {}
+       virtual void OnIpcServerStopped(const Osp::Io::_IpcServer& server) {}
+       virtual void OnIpcClientConnected(const Osp::Io::_IpcServer& server, int clientId) {}
+       virtual void OnIpcClientDisconnected(const Osp::Io::_IpcServer& server, int clientId) {}
+       virtual void OnIpcRequestReceived(Osp::Io::_IpcServer& server, const IPC::Message& message);
+
+       virtual void OnApplicationLaunched(const AppId& appId, const Osp::Base::String& executableName, AppType type);
+       virtual void OnApplicationTerminated(const AppId& appId, const Osp::Base::String& executableName, AppType type);
+
+       bool OnRequestOccured(const Osp::Base::Collection::ArrayList& request, Osp::Base::Collection::ArrayList* response);
+       result SendData(const Osp::App::AppId appId, Osp::Base::Collection::ArrayList& data);
+
+private:
+       _CommunicationDispatcher(void);
+       virtual ~_CommunicationDispatcher(void);
+       Osp::Base::Integer* GetClientId(const Osp::App::AppId& appId, const Osp::Base::String& componentId) const;
+       result AddClientId(Osp::App::AppId appId, Osp::Base::String componentId, Osp::Base::Integer clientId);
+       result RemoveClientId(Osp::App::AppId appId, Osp::Base::String componentId, Osp::Base::Integer clientId);
+       result RemoveClientId(Osp::App::AppId appId, Osp::Base::String componentId);
+       result RemoveClientId(Osp::App::AppId appId);
+
+private:
+       Osp::Io::_IpcServer*                    __pIpcServer;
+       Osp::Base::Collection::ArrayList*       __pRegisteredAppList;
+       Osp::App::AppId                         __currentAppId;
+       Osp::Base::Integer                      __currentClientId;
+       Osp::Base::Runtime::Mutex               __Mutex;
+       _AppManagerImpl*                        __pAppManagerImpl;
+};     //_CommunicationDispatcher
+
+}} //Osp::App
+#endif /* _FAPP_INTERNAL_COMMNUICATION_DISPATCHER_H_ */
diff --git a/inc/FApp_ConditionHandler.h b/inc/FApp_ConditionHandler.h
new file mode 100644 (file)
index 0000000..863061d
--- /dev/null
@@ -0,0 +1,126 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+//
+// 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.
+//
+
+/**
+ * @file        FApp_ConditionHandler.h
+ * @brief      This is the header file of the _ConditionHandler class.
+ *
+ * This header file contains the declarations of the _ConditionManagerService class.
+ */
+
+#ifndef _FAPP_INTERNAL_CONDITION_HANDLER_H_
+#define _FAPP_INTERNAL_CONDITION_HANDLER_H_
+
+
+#include <FBase.h>
+#include <FBaseCol.h>
+#include <FAppTypes.h>
+
+#include <FApp_AppLaunchConditionHandlerBase.h>
+#include "FApp_StringKeyHashMapUtil.h"
+
+namespace Osp { namespace Base { namespace Runtime { class Library; }}}
+namespace Osp { namespace App  {
+
+
+class _ConditionHandler;
+
+/**
+ * @class              _ConditionPlugInInfo
+ * @brief              Contains plugin info of registry.(ConditionHandlerPlugins.ini)
+ * @since              3.0
+ */
+class _ConditionPlugInInfo :
+       public Osp::Base::Object
+{
+public:
+       const Osp::Base::String typeString;
+       const Osp::Base::String name; // or fileName
+       const _ConditionHandler* pHandler;
+public:
+       _ConditionPlugInInfo(const Osp::Base::String _typeString, const Osp::Base::String _name, const _ConditionHandler* _pHandler)
+       :typeString(_typeString), name(_name),pHandler(_pHandler) {}
+
+};     //_ConditionPlugInInfo
+
+typedef _AppLaunchConditionHandlerBase* (*create_plugin)(void);
+typedef void (*destroy_plugin)(_AppLaunchConditionHandlerBase* p);
+
+/**
+ * @class              _ConditionHandler
+ * @brief              Manages each conditional operations and handler instance.
+ * @since              3.0
+ */
+class _ConditionHandler
+       : public Osp::Base::Object
+       , public Osp::App::_IAppLaunchConditionEventListener
+       , virtual public Osp::Base::Runtime::IEventListener
+{
+       typedef Osp::Base::Collection::MultiHashMapT<Osp::Base::String, _AppLaunchCondition*> _AppLaunchConditions;
+//     typedef Osp::Base::Collection::IMapEnumeratorT <Osp::Base::String, _AppLaunchCondition*> _AppLaunchConditionEnumerator;
+       typedef Osp::Base::Collection::IEnumeratorT <_AppLaunchCondition*> _AppLaunchConditionEnumerator;
+
+public :
+       _ConditionHandler(const Osp::Base::String& fileName,  const Osp::Base::String& typesString);
+       virtual ~_ConditionHandler(void);
+       result Construct(void);
+       result AddCondition( _AppLaunchCondition& operation);
+       result RemoveCondition(const AppId& appId, const Osp::Base::String& executableName, const Osp::Base::String* pCondition);
+       _AppLaunchCondition* Find(const AppId& appId, const Osp::Base::String *pCondition);
+       result CreateUniqueId(Osp::Base::String& uniqueId);
+       bool HasCondition(const AppId& appId, const Osp::Base::String& executableName, const Osp::Base::String *pCondition) const ;
+       bool CanHandleType(const Osp::Base::String& type ) const;
+
+       void Dump(void) const;
+
+private:
+       _AppLaunchCondition* FindItemBySectionName(const Osp::Base::String& sectionName) const;
+       virtual void OnAppLaunchConditionMet(const _AppLaunchCondition& operation);
+       result LoadPlugin(void);
+       _ConditionHandler(const _ConditionHandler& value);
+       _ConditionHandler& operator =(const _ConditionHandler& source);
+
+private:
+       Osp::Base::String __typesString;
+       Osp::Base::String __pluginFileName;
+       _AppLaunchConditionHandlerBase* __pPluginInstance;
+       _AppLaunchConditions __conditionalOperations;
+       _StringComparerT __strComparer;
+       _StringHashMapProviderT __strHashMapProvider;
+
+       Osp::Base::Runtime::Library* __pLib;
+       destroy_plugin __pfDestroyPlugin;
+};     //_ConditionHandler
+
+
+/**
+ * @class              _ConditionRegistryHelper
+ * @brief
+ * @since              3.0
+ */
+
+class _ConditionRegistryHelper
+{
+public:
+               static result AddToRegistry(const Osp::Base::String& sectionName, const AppId& appId, const Osp::Base::String& executableName, const Osp::Base::String& condition, const Osp::Base::Collection::IList *pArgs);
+               static result RemoveFromRegistry(const Osp::Base::String& sectionName);
+               static result GetAllParamsN(const Osp::Base::Collection::IMap& map, Osp::Base::String& appId, Osp::Base::String& executableName, Osp::Base::String& condition, Osp::Base::Collection::ArrayList*& pArgs);
+};     //_ConditionRegistryHelper
+
+
+}} //Osp::App
+#endif // _FAPP_INTERNAL_CONDITION_HANDLER_H_
diff --git a/inc/FApp_ConditionManagerService.h b/inc/FApp_ConditionManagerService.h
new file mode 100644 (file)
index 0000000..8a3a517
--- /dev/null
@@ -0,0 +1,88 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+//
+// 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.
+//
+
+/**
+ * @file        FApp_ConditionManagerService.h
+ * @brief      This is the header file of the _ConditionManagerService class.
+ *
+ * This header file contains the declarations of the _ConditionManagerService class.
+ */
+
+#ifndef _FAPP_INTERNAL_CONDITION_MANAGER_SERVICE_H_
+#define _FAPP_INTERNAL_CONDITION_MANAGER_SERVICE_H_
+
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+
+#include "FApp_ConditionHandler.h"
+
+namespace Osp { namespace Base { namespace Collection { class IList; }}}
+namespace Osp { namespace App  {
+
+
+class _ConditionHandler;
+
+/**
+ * @class      _ConditionManagerService
+ * @brief      This class contains implementaion of conditional app launch feature.
+ * @since      3.0
+ * @see                AppManager, _ConditionManagerProxy
+ */
+class _ConditionManagerService
+       : public Osp::Base::Object
+{
+       typedef Osp::Base::Collection::ArrayListT<_ConditionHandler*> _ConditionHandlers;
+       typedef Osp::Base::Collection::HashMapT<Osp::Base::String, _ConditionHandler*> _ConditionHandlerMap;
+
+
+public:
+       _ConditionManagerService(void);
+       virtual ~_ConditionManagerService(void);
+       result Construct(void);
+
+       result RegisterAppLaunch(const AppId& appId, const Osp::Base::String& executableName, const Osp::Base::String& condition, const Osp::Base::Collection::IList* pArguments, AppManager::LaunchOption option = AppManager::LAUNCH_OPTION_DEFAULT, const Osp::Base::String* pSectionName = null);
+       result UnregisterAppLaunch(const AppId& appId, const Osp::Base::String& executableName, const Osp::Base::String* pCondition);
+       bool IsAppLaunchRegistered(const AppId& appId, const Osp::Base::String& executableName, const Osp::Base::String* pCondition = null);
+
+private:
+       // internal
+       result InitializePlugins(void);
+       result InitializePluginEntry(Osp::Base::Collection::IMap& map);
+       result InitializeConditionalOperations(void);
+       result InitializeConditionalOperationEntry(const Osp::Base::String& sectionName, const Osp::Base::Collection::IMap& map);
+       _ConditionHandler* GetLaunchConditionHandler(const Osp::Base::String& pluginName);
+       _ConditionHandler* GetHandlerByCondition(const Osp::Base::String& condition);
+
+       result ValidateArguments(const Osp::Base::Collection::IList* pArguments) const;
+
+       static void DumpArguments(const Osp::Base::Collection::IList* pArguments);
+       void Dump(void) const;
+
+private:
+       _ConditionHandlers __handlers;
+       _ConditionHandlerMap __handlerLookupTable;
+
+       _StringComparerT __strComparer;
+       _StringHashMapProviderT __strHashMapProvider;
+
+       friend class UTs_ConditionManagerServiceP;
+};     //_ConditionManagerService
+
+}} //Osp::App
+#endif // _FAPP_INTERNAL_CONDITION_MANAGER_SERVICE_H_
diff --git a/inc/FApp_ConditionManagerStub.h b/inc/FApp_ConditionManagerStub.h
new file mode 100644 (file)
index 0000000..882c36c
--- /dev/null
@@ -0,0 +1,77 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+//
+// 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.
+//
+
+/**
+ * @file        FApp_ConditionManagerStub.h
+ * @brief      This is the header file of the _ConditionManagerStub class.
+ *
+ * This header file contains the declarations of the _ConditionManagerStub class.
+ */
+
+#ifndef _FAPP_INTERNAL_CONDITION_MANAGER_SERVER_H_
+#define _FAPP_INTERNAL_CONDITION_MANAGER_SERVER_H_
+
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+
+#include <FIo_IIpcServerEventListener.h>
+
+
+namespace Osp { namespace App {
+
+class _ConditionManagerService;
+
+
+class _ConditionManagerStub :
+       public Osp::Base::Object,
+       public Osp::Io::_IIpcServerEventListener
+{
+
+public:
+       _ConditionManagerStub(void);
+       virtual ~_ConditionManagerStub(void);
+       result Construct(void);
+
+       void OnInstallComplete(const AppId& appId, const Osp::Base::String& executableName, const Osp::Base::String& packageName );
+       void OnUninstallComplete(const AppId& appId, const Osp::Base::String& executableName);
+
+private:
+       // ipc handlers.
+       bool OnRegisterAppLaunch(const AppId& appId, const Osp::Base::String& executableName, const Osp::Base::String& cond, const Osp::Base::Collection::ArrayList& args , int flag, result *pRes);
+       bool OnUnregisterAppLaunch(const AppId& appId, const Osp::Base::String& executableName, const Osp::Base::String& cond, result *pRes);
+       bool OnIsAppLaunchRegistered(const AppId& appId, const Osp::Base::String& executableName, const Osp::Base::String& cond, bool *pIsAppLaunchRegistered, result *pException);
+       result ExtractDueAndPeriod(const Osp::Base::String& src, Osp::Base::String& dueTime, Osp::Base::String& period);
+
+       // _IIpcServerEventListener
+       virtual void OnIpcServerStarted(const Osp::Io::_IpcServer& server);
+       virtual void OnIpcServerStopped(const Osp::Io::_IpcServer& server);
+       virtual void OnIpcClientConnected(const Osp::Io::_IpcServer& server, int clientId);
+       virtual void OnIpcClientDisconnected(const Osp::Io::_IpcServer&server, int clientId);
+       virtual void OnIpcRequestReceived(Osp::Io::_IpcServer& server, const IPC::Message& message);
+
+       // internal
+       result StartIpcServer(void);
+
+private:
+       Osp::Io::_IpcServer *__pIpcServer;
+       _ConditionManagerService* __pConditionManagerService;
+};     //_ConditionManagerStub
+
+}} //Osp::App
+#endif // _FAPP_INTERNAL_CONDITION_MANAGER_SERVER_H_
diff --git a/inc/FApp_ContextManager.h b/inc/FApp_ContextManager.h
new file mode 100644 (file)
index 0000000..9cd1ccf
--- /dev/null
@@ -0,0 +1,145 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_ContextManager.h
+ * @brief      This is the header file of the _ContextManager class.
+ *
+ * This header file contains the declarations of the _ContextManager class.
+ */
+
+#ifndef _FAPP_INTERNAL_CONTEXT_MANAGER_H_
+#define _FAPP_INTERNAL_CONTEXT_MANAGER_H_
+
+#include <map>
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FBaseColArrayListT.h>
+#include <FAppTypes.h>
+#include <FBaseRtIEventListener.h>
+
+#include <FApp_Types.h>
+
+namespace Osp { namespace Base { namespace Collection { class ArrayList; } } }
+
+namespace Osp { namespace App {
+
+enum _OomAppType
+{
+       OOM_APP_TYPE_SYSTEM,
+       OOM_APP_TYPE_LAUNCHING,
+       OOM_APP_TYPE_FOREGROUND_HIGH,
+       OOM_APP_TYPE_SERVICE_HIGH,
+       OOM_APP_TYPE_FOREGROUND,
+       OOM_APP_TYPE_SERVICE_MID,
+       OOM_APP_TYPE_BACKGROUND_HIGH,
+       OOM_APP_TYPE_SERVICE_LOW,
+       OOM_APP_TYPE_BACKGROUND
+};
+
+class _AppContext
+{
+public:
+       _AppContext(const Osp::Base::String& appId,
+                       const Osp::Base::String& executableName,
+                       AppType appType,
+                       int pid,
+                       int ipcClientId,
+                       bool isSystemService
+                       );
+
+       ~_AppContext(void)
+       {
+       }
+
+       Osp::Base::String ToString(void) const;
+
+public:
+       AppId appId;
+       Osp::Base::String executableName;
+       AppType appType;
+       int pId;
+       int ipcClientId;
+       AppUiState uiState;
+       bool isRegistered;
+       bool isSystemService;
+};     //_AppContext
+
+class _IContextManagerEventListener
+       : virtual public Osp::Base::Runtime::IEventListener
+{
+public:
+       virtual void OnApplicationTerminated(const _AppContext& appInfo) = 0;
+};
+
+/**
+ * @class       _ContextManager
+ * @brief
+ * @since      3.0
+ *
+ *
+ */
+class _ContextManager
+{
+       typedef std::map<int, _AppContext*> AppContexts;
+
+public:
+       _ContextManager(void);
+       ~_ContextManager(void);
+
+       result Construct(void);
+       result Register(const AppId& appId, const Osp::Base::String& executableName, AppType appType, int pid, int ipcClientId, bool isSystemService);
+       result Unregister(int pid);
+       const _AppContext* Find(const AppId& appId, const Osp::Base::String& executableName) const;
+       const _AppContext* Find(int pid);
+       result GetAppListN(Osp::Base::Collection::ArrayList* pArray) const;
+       void SetEventListener(_IContextManagerEventListener& listener);
+
+       void AbonormalAppTerminationHanlder(int pid, const AppId& appId, const Osp::Base::String& execName);
+       static int OnAppTerminate(int pid, void *data);// app_dead_signal_listener
+       void Dump(void) const;
+
+
+private:
+       _ContextManager(const _ContextManager& rhs);
+       _ContextManager& operator=(const _ContextManager& rhs);
+       _OomAppType GetOomAppType(const AppId& appId, const int pid) const;
+       bool IsErrorProneApp(const AppId& appId) const;
+
+public:
+       /**
+        * This is static helper class
+        */
+       class _Util
+       {
+       public:
+               static Osp::Base::String QueryFeatureFromPackageManager(const Osp::Base::String& appId, const Osp::Base::String& execName, const Osp::Base::String& feature);
+//             static Osp::Base::String GetExecNameFromPackageName(const Osp::Base::String& packageName);
+       };
+
+private:
+       const unsigned long __magic;
+       AppContexts __appContexts;
+       _IContextManagerEventListener* __pEventListener;
+       Osp::Base::Collection::ArrayListT<Osp::Base::String> __errorProneAppIds;
+};     //_ContextManager
+
+} } // Osp::App
+
+#endif //_FAPP_INTERNAL_CONTEXT_MANAGER_H_
+
diff --git a/inc/FApp_ICommunicationRequestListener.h b/inc/FApp_ICommunicationRequestListener.h
new file mode 100644 (file)
index 0000000..5b5da87
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file       FApp_ICommunicationRequestListener.h
+ * @brief      This is the header file for the %_ICommunicationRequestListener class.
+ *
+ * This header file contains the declarations of the %_ICommunicationRequestListener class.
+ */
+
+#ifndef _FAPP_ICOMMUNICATION_EVENT_LISTENER_H_
+#define _FAPP_ICOMMUNICATION_EVENT_LISTENER_H_
+
+#include <FAppPackageManager.h>
+#include <FBaseRtIEventListener.h>
+#include <FBase.h>
+
+
+namespace Osp { namespace App
+{
+
+class _OSP_EXPORT_ _ICommunicationRequestListener
+       : virtual public Osp::Base::Runtime::IEventListener
+{
+public:
+       virtual ~_ICommunicationRequestListener(void) {}
+       virtual Osp::Base::String GetId(void) = 0;
+       virtual void OnRequestOccured(AppId appId, Osp::Base::Collection::ArrayList* request, Osp::Base::Collection::ArrayList* response) = 0;
+       virtual void OnApplicationTerminated(const AppId& appId, const Osp::Base::String& executableName, AppType type) = 0;
+
+}; // _ICommunicationRequestListener
+
+}} // Osp::App
+
+#endif // _FAPP_ICOMMUNICATION_EVENT_LISTENER_H_
diff --git a/inc/FApp_NotificationManagerService.h b/inc/FApp_NotificationManagerService.h
new file mode 100755 (executable)
index 0000000..4a368c2
--- /dev/null
@@ -0,0 +1,64 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+//
+// 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.
+//
+
+/**
+ * @file        FApp_NotificationManagerService.h
+ * @brief      This is the header file of the _NotificationManagerService class.
+ *
+ * This header file contains the declarations of the _NotificationManagerService class.
+ */
+
+#ifndef _FAPP_INTERNAL_NOTIFICATION_MANAGER_SERVICE_H_
+#define _FAPP_INTERNAL_NOTIFICATION_MANAGER_SERVICE_H_
+
+
+#include <appsvc/appsvc.h>
+#include <bundle.h>
+#include <notification/notification.h>
+#include <appfw/app.h>
+#include <appfw/app_manager.h>
+#include <appfw/app_ui_notification.h>
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+
+
+namespace Osp { namespace App  {
+
+/**
+ * @class      _NotificationManagerService
+ * @brief      This class contains implementaion of NotificationManager feature.
+ * @since      3.0
+ * @see                AppManager, _ConditionManagerProxy
+ */
+class _NotificationManagerService
+       : public Osp::Base::Object
+{
+
+public:
+       _NotificationManagerService(void);
+       virtual ~_NotificationManagerService(void);
+       result Construct(void);
+
+       result NotifyMessage(const AppId& appId,const NotificationMessage& notiMessage, bool OnGoing);
+       result RemoveNotification(const AppId& appId, bool Ongoing);
+
+};
+
+}} //Osp::App
+#endif // _FAPP_INTERNAL_NOTIFICATION_MANAGER_SERVICE_H_
diff --git a/inc/FApp_NotificationManagerStub.h b/inc/FApp_NotificationManagerStub.h
new file mode 100755 (executable)
index 0000000..0340d6a
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_NotificationManagerStub.h
+ * @brief      This is the header file of the _NotificationManagerStub class.
+ *
+ * This header file contains the declarations of the _NotificationManagerStub class.
+ */
+
+#ifndef _FAPP_INTERNAL_NOTIFICATION_MANAGER_STUB_H_
+#define _FAPP_INTERNAL_NOTIFICATION_MANAGER_STUB_H_
+
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+
+#include <FIo_IIpcServerEventListener.h>
+
+
+namespace Osp { namespace App {
+
+class _NotificationManagerService;
+
+class _NotificationManagerStub :
+       public Osp::Base::Object,
+       public Osp::Io::_IIpcServerEventListener
+{
+
+public:
+       _NotificationManagerStub(void);
+       virtual ~_NotificationManagerStub(void);
+       result Construct(void);
+
+       // ipc handlers.
+       void OnNotifyMessage(const Osp::App::AppId& appId, const Osp::App::NotificationMessage& notimessage, bool OnGoing, result* pRes);
+       void OnRemoveNotification(const Osp::App::AppId& appId, bool Ongoing, result* pRes);
+
+private:
+       _NotificationManagerStub(const _NotificationManagerStub& value);
+       _NotificationManagerStub& operator =(const _NotificationManagerStub& source);
+
+       // _IIpcServerEventListener
+       virtual void OnIpcServerStarted(const Osp::Io::_IpcServer& server);
+       virtual void OnIpcServerStopped(const Osp::Io::_IpcServer& server);
+       virtual void OnIpcClientConnected(const Osp::Io::_IpcServer& server, int clientId);
+       virtual void OnIpcClientDisconnected(const Osp::Io::_IpcServer&server, int clientId);
+       virtual void OnIpcRequestReceived(Osp::Io::_IpcServer& server, const IPC::Message& message);
+
+       // internal
+       result StartIpcServer(void);
+
+private:
+       Osp::Io::_IpcServer* __pIpcServer;
+       _NotificationManagerService* __pNotificationManagerService;
+};     //_NotificationManagerStub
+
+}} //Osp::App
+
+#endif // _FAPP_INTERNAL_NOTIFICATION_MANAGER_STUB_H_
diff --git a/inc/FApp_PackageManagerStub.h b/inc/FApp_PackageManagerStub.h
new file mode 100644 (file)
index 0000000..d0fa9b1
--- /dev/null
@@ -0,0 +1,76 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_PackageManagerStub.h
+ * @brief      This is the header file of the _PackageManagerStub class.
+ *
+ * This header file contains the declarations of the _PackageManagerStub class.
+ */
+
+#ifndef _FAPP_INTERNAL_PACKAGE_MANAGER_STUB_H_
+#define _FAPP_INTERNAL_PACKAGE_MANAGER_STUB_H_
+
+
+#include <FBaseObject.h>
+#include <FBaseString.h>
+#include <FAppTypes.h>
+
+#include <FIo_IIpcServerEventListener.h>
+
+
+namespace Osp { namespace App {
+
+class _PackageManagerImpl;
+
+
+class _PackageManagerStub :
+       public Osp::Base::Object,
+       public Osp::Io::_IIpcServerEventListener
+{
+
+public:
+       _PackageManagerStub(void);
+       virtual ~_PackageManagerStub(void);
+       result Construct(void);
+
+       // ipc handlers.
+       void OnInstallPackage(const Osp::Base::String& packagePath, const Osp::Base::String& licensePath, result* pRes);
+       void OnUninstallPackage(const AppId& appId, result* pRes);
+
+private:
+       _PackageManagerStub(const _PackageManagerStub& value);
+       _PackageManagerStub& operator =(const _PackageManagerStub& source);
+
+       // _IIpcServerEventListener
+       virtual void OnIpcServerStarted(const Osp::Io::_IpcServer& server);
+       virtual void OnIpcServerStopped(const Osp::Io::_IpcServer& server);
+       virtual void OnIpcClientConnected(const Osp::Io::_IpcServer& server, int clientId);
+       virtual void OnIpcClientDisconnected(const Osp::Io::_IpcServer&server, int clientId);
+       virtual void OnIpcRequestReceived(Osp::Io::_IpcServer& server, const IPC::Message& message);
+
+       // internal
+       result StartIpcServer(void);
+
+private:
+       Osp::Io::_IpcServer* __pIpcServer;
+       _PackageManagerImpl* __pPackageManagerImpl;
+};     //_PackageManagerStub
+
+}} //Osp::App
+
+#endif // _FAPP_INTERNAL_PACKAGE_MANAGER_STUB_H_
diff --git a/inc/FApp_StringKeyHashMapUtil.h b/inc/FApp_StringKeyHashMapUtil.h
new file mode 100644 (file)
index 0000000..ac0db85
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_StringKeyHashMapUtil.h
+ *
+ * This header file contains the implementation of the _StringComparerT, _StringHashMapProviderT class.
+ */
+
+
+#ifndef FAPP_INTERNAL_STRINGKEY_HASHMAP_UTIL_H_
+#define FAPP_INTERNAL_STRINGKEY_HASHMAP_UTIL_H_
+
+class _StringComparerT
+       : public Osp::Base::Collection::IComparerT <Osp::Base::String>
+       , public Osp::Base::Object
+{
+public:
+       _StringComparerT(void){}
+       virtual ~_StringComparerT(void){}
+
+       virtual result Compare(const Osp::Base::String& obj1, const Osp::Base::String& obj2, int& cmp) const
+       {
+               cmp = obj1.CompareTo(obj2);
+               return E_SUCCESS;
+       }
+};     //_StringComparerT
+
+
+class _StringHashMapProviderT
+       : public Osp::Base::Collection::IHashCodeProviderT <Osp::Base::String>
+       , public Osp::Base::Object
+{
+public:
+       _StringHashMapProviderT(void) {}
+       virtual ~_StringHashMapProviderT(void) {}
+       virtual int GetHashCode(const Osp::Base::String& obj) const
+       {
+               return obj.GetHashCode();
+       }
+};     //__StringHashMapProviderT
+
+
+
+
+#endif // FAPP_INTERNAL_STRINGKEY_HASHMAP_UTIL_H_
diff --git a/inc/FSys_AccessoryManagerService.h b/inc/FSys_AccessoryManagerService.h
new file mode 100644 (file)
index 0000000..ac1018b
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+//
+// 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.
+//
+
+/**
+ * @file        FSys_AccessoryManagerService.h
+ * @brief      This is the header file of the _AccessoryManagerService class.
+ *
+ * This header file contains the declarations of the _AccessoryManagerService class.
+ */
+#include <FApp.h>
+#include <FBase.h>
+#include "FApp_CommunicationDispatcher.h"
+#include "FApp_ICommunicationRequestListener.h"
+
+#ifndef _FSYS_INTERNAL_ACCESSORY_MANAGER_SERVICE_H_
+#define _FSYS_INTERNAL_ACCESSORY_MANAGER_SERVICE_H_
+
+namespace Osp { namespace Base { namespace Runtime {
+class Library;
+}}}
+namespace Osp { namespace System {
+
+typedef void (*OnRequestOccuredFunction)(Osp::App::AppId appId, Osp::Base::Collection::ArrayList* request, Osp::Base::Collection::ArrayList* response);
+typedef void (*RemoveOwnerApplicationFunction)(const Osp::App::AppId appId, const Osp::Base::String& executableName);
+
+/**
+ * @class      _AccessoryManagerService
+ * @brief      This class contains implementaion of device control.
+ * @since      3.0
+ */
+class _AccessoryManagerService
+       : public Osp::App::_ICommunicationRequestListener
+{
+private:
+       _AccessoryManagerService(void);
+       virtual ~_AccessoryManagerService(void);
+
+public:
+       virtual Osp::Base::String GetId(void);
+       virtual void OnRequestOccured(Osp::App::AppId appId, Osp::Base::Collection::ArrayList* request, Osp::Base::Collection::ArrayList* response);
+       virtual void OnApplicationTerminated(const Osp::App::AppId& appId, const Osp::Base::String& executableName, Osp::App::AppType type);
+       result SendData(Osp::App::AppId appId, Osp::Base::Collection::ArrayList* data);
+       static _AccessoryManagerService* GetInstance(void);
+
+private:
+       _AccessoryManagerService(const _AccessoryManagerService& value);
+       _AccessoryManagerService& operator =(const _AccessoryManagerService& value);
+       Osp::Base::Runtime::Library*            __pLib;
+       Osp::App::_CommunicationDispatcher*     __pCommunicationDispatcher;
+       OnRequestOccuredFunction                __pOnRequestOccuredFunction;
+       RemoveOwnerApplicationFunction          __pRemoveOwnerApplicationFunction;
+};     //_AccessoryManagerService
+
+}} //Osp::System
+#endif /* _FSYS_INTERNAL_ACCESSORY_MANAGER_SERVICE_H_ */
diff --git a/inc/FSys_DeviceManagerService.h b/inc/FSys_DeviceManagerService.h
new file mode 100644 (file)
index 0000000..0d82b2e
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FSys_DeviceManagerService.h
+ * @brief      This is the header file of the _DeviceManagerService class.
+ *
+ * This header file contains the declarations of the _DeviceManagerService class.
+ */
+#include <FApp.h>
+#include <FBase.h>
+#include <FSys_IDeviceManagerEventListener.h>
+#include "FApp_ICommunicationRequestListener.h"
+
+#ifndef _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_
+#define _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_
+
+namespace Osp { namespace System {
+
+/**
+ * @class      _DeviceManagerService
+ * @brief      This class contains implementaion of device control.
+ * @since      3.0
+ */
+class _DeviceManagerService
+       : public Osp::App::_ICommunicationRequestListener
+       , public Osp::System::_IDeviceManagerEventListener
+{
+private:
+       _DeviceManagerService(void);
+       virtual ~_DeviceManagerService(void);
+public:
+       virtual Osp::Base::String GetId(void);
+       virtual void OnRequestOccured(Osp::App::AppId appId, Osp::Base::Collection::ArrayList* request, Osp::Base::Collection::ArrayList* response);
+       virtual void OnApplicationTerminated(const Osp::App::AppId& appId, const Osp::Base::String& executableName, Osp::App::AppType type);
+       virtual void OnBluetoothEventOccured(int code);
+       void SendEvent(Osp::Base::String event);
+       void SetBluetoothStatus(bool status);
+       bool GetBluetoothStatus(void);
+       static _DeviceManagerService* GetInstance(void);
+
+private:
+       void AddInterestedApp(Osp::App::AppId appId);
+       void RemoveInterestedApp(Osp::App::AppId appId);
+       Osp::Base::Collection::ArrayList __interestedAppList;
+       Osp::App::_CommunicationDispatcher* __pCommunicationDispatcher;
+       bool isBluetoothHeadSetConnected;
+       static _DeviceManagerService* __pDeviceManagerService;
+
+};     //_DeviceManagerService
+
+}} //Osp::System
+#endif /* _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_ */
diff --git a/inc/FSys_SystemService.h b/inc/FSys_SystemService.h
new file mode 100644 (file)
index 0000000..6549e2c
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FSys_SystemService.h
+ * @brief      This is the header file of the _SystemService class.
+ *
+ * This header file contains the declarations of the _SystemService class.
+ */
+#include <FApp.h>
+#include <FBase.h>
+#include "FApp_ICommunicationRequestListener.h"
+
+#ifndef _FSYS_INTERNAL_SYSTEM_SERVICE_H_
+#define _FSYS_INTERNAL_SYSTEM_SERVICE_H_
+
+namespace Osp { namespace System {
+
+/**
+ * @class      _SystemService
+ * @brief      This class contains implementaion of device control.
+ * @since      3.0
+ */
+class _SystemService
+       : public Osp::App::_ICommunicationRequestListener
+{
+private:
+       _SystemService(void);
+       virtual ~_SystemService(void);
+public:
+       virtual Osp::Base::String GetId(void);
+       virtual void OnRequestOccured(Osp::App::AppId appId, Osp::Base::Collection::ArrayList* request, Osp::Base::Collection::ArrayList* response);
+       virtual void OnApplicationTerminated(const Osp::App::AppId& appId, const Osp::Base::String& executableName, Osp::App::AppType type);
+       static _SystemService* GetInstance(void);
+
+private:
+       Osp::App::_CommunicationDispatcher* __pCommunicationDispatcher;
+       static _SystemService* __pSystemService;
+
+};     //_SystemService
+
+}} //Osp::System
+#endif /* _FSYS_INTERNAL_SYSTEM_SERVICE_H_ */
diff --git a/manifest.xml b/manifest.xml
new file mode 100755 (executable)
index 0000000..d7f5c24
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<Manifest xmlns="http://schemas.tizen.org/2012/06/manifest">
+    <Id>aospd00043</Id>
+    <Version>1.0.0</Version>
+    <Type>C++App</Type>
+    <Vendors>
+        <Vendor Locale="eng-GB">Samsung Electronics</Vendor>
+    </Vendors>
+    <Descriptions/>
+    <Url/>
+    <Requirements/>
+    <Apps>
+        <ApiVersion>3.0</ApiVersion>
+        <Secret>9C645DDBA19C71BAD1204DA4DAA7A0B9</Secret>
+        <Privileges>
+            <Privilege>APPLICATION_SERVICE</Privilege>
+            <Privilege>APPLICATION_MANAGER</Privilege>
+            <Privilege>SYSTEM_SERVICE</Privilege>
+            <Privilege>PACKAGE_INFORMATION</Privilege>
+        </Privileges>
+        <ServiceApp AutoRestart="False" Default="True" ExecutableName="osp-app-service" LaunchOnBoot="False">
+            <Names>
+                <Name Locale="eng-GB">osp-app-service</Name>
+            </Names>
+            <Icons/>
+            <AppControls/>
+            <DataControls/>
+            <LaunchConditions/>
+                       <Notifications/>
+        </ServiceApp>
+    </Apps>
+</Manifest>
diff --git a/packaging/osp-app-service.spec b/packaging/osp-app-service.spec
new file mode 100755 (executable)
index 0000000..350c257
--- /dev/null
@@ -0,0 +1,72 @@
+%define debug_package %{nil}
+%define __strip /bin/true
+
+Name:          osp-app-service
+Summary:       osp application service
+Version:       1.3.0.0
+Release:       1
+Group:         TO_BE/FILLED_IN
+License:       TO_BE/FILLED_IN
+Source0:       %{name}-%{version}.tar.gz
+BuildRequires:  cmake
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(chromium)
+BuildRequires:  pkgconfig(capi-system-media-key)
+BuildRequires:  pkgconfig(capi-network-bluetooth)
+BuildRequires:  pkgconfig(capi-appfw-application)
+BuildRequires:  pkgconfig(capi-appfw-app-manager)
+BuildRequires:  pkgconfig(notification)
+BuildRequires:  pkgconfig(osp-foundation)
+BuildRequires:  osp-foundation-internal-devel
+
+# runtime requires
+Requires: osp-foundation 
+Requires: osp-installer 
+
+%description
+osp application service
+
+%package debug
+Summary:    osp application serivce (Development)
+Group:      TO_BE/FILLED_IN
+Requires:   %{name} = %{version}-%{release}
+
+%description debug
+osp application serivce (DEV)
+
+%prep
+%setup -q
+
+%build 
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%ifarch %{ix86}
+CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+%else
+CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -D_OSP_DEBUG_ -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+%endif
+
+# Call make instruction with smp support
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}/etc/rc.d/rc3.d/
+ln -s ../init.d/osp-app-service.sh %{buildroot}/etc/rc.d/rc3.d/S99osp-app-service
+
+%post
+/bin/rm -f /etc/ld.so.cache
+/sbin/ldconfig
+
+/usr/etc/package-manager/backend/tpk -i /opt/apps/aospd00043
+chmod +x /etc/rc.d/init.d/osp-app-service.sh
+
+%postun -p /sbin/ldconfig
+
+%files
+/opt/apps/*
+/etc/*
+
+%files debug
+/opt/apps/debug/*
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..ff76c3e
--- /dev/null
@@ -0,0 +1,17 @@
+#Set Project name
+PROJECT(plugins)
+
+SET(PLUGIN_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
+
+MACRO(OSP_STRIP _target)
+       ADD_CUSTOM_COMMAND(TARGET ${_target}
+               POST_BUILD
+               COMMAND ${CMAKE_COMMAND} -E copy ${PLUGIN_INSTALL_DIR}/data/${CMAKE_SHARED_LIBRARY_PREFIX}${_target}${CMAKE_SHARED_LIBRARY_SUFFIX} ${EXECUTABLE_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${_target}${CMAKE_SHARED_LIBRARY_SUFFIX}
+               COMMAND ${CMAKE_STRIP} --strip-unneeded --remove-section .comment ${PLUGIN_INSTALL_DIR}/data/${CMAKE_SHARED_LIBRARY_PREFIX}${_target}${CMAKE_SHARED_LIBRARY_SUFFIX}
+               COMMENT "strip ${_target}"
+               )       
+ENDMACRO(OSP_STRIP)
+
+ADD_SUBDIRECTORY(alarm-condition-handler)
+ADD_SUBDIRECTORY(nfc-condition-handler)
+ADD_SUBDIRECTORY(accessory-condition-handler)
diff --git a/plugins/accessory-condition-handler/AccessoryConditionHandler.cpp b/plugins/accessory-condition-handler/AccessoryConditionHandler.cpp
new file mode 100644 (file)
index 0000000..d84c319
--- /dev/null
@@ -0,0 +1,299 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file       AccessoryConditionHandler.cpp
+ * @brief      This is the implementation file of the AccessoryConditionHandler class.
+ *
+ */
+
+#include <new>
+#include <string.h>
+
+#include <FApp_AppManagerImpl.h>
+#include <FApp_AppLaunchConditionHandlerBase.h>
+#include <FBase_StringConverter.h>
+#include "AccessoryConditionHandler.h"
+#include "AccessoryMonitor.h"
+
+using namespace Osp::App;
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+
+const static char ACCESSORY_SERIAL_COMMAND_MESSAGE[] = {"Osp:Msg"};
+const static char ACCESSORY_SERIAL_COMMAND_REQUEST[] = {"Osp:Req"};
+const static char ACCESSORY_SERIAL_COMMAND_RESPONSE[] = {"Osp:Res"};
+const static char ACCESSORY_SERIAL_COMMAND_HELLO[] = {"Hello"};
+const static char ACCESSORY_SERIAL_COMMAND_OK[] = {"OK"};
+const static char ACCESSORY_SERIAL_COMMAND_SUCCESS[] = {"Susccess"};
+const static char ACCESSORY_SERIAL_COMMAND_FAIL[] = {"Fail"};
+
+AccessoryConditionHandler::AccessoryConditionHandler()
+       :__pAccessoryMonitor(null)
+{
+       result r = E_SUCCESS;
+       SysLog(NID_SYS, "AccessoryConditionHandler is initialized");
+
+       __pAccessoryMonitor = AccessoryMonitor::GetInstance();
+       r = __pAccessoryMonitor->Construct(this);
+
+       if (IsFailed(r))
+       {
+               SysLogException(NID_SYS, r, "Failed to initialize AccessoryMonitor");
+               return;
+       }
+
+       r = __appConditionList.Construct();
+
+       if (IsFailed(r))
+       {
+               SysLogException(NID_SYS, r, "Failed to initialize Condition List");
+       }
+}
+
+AccessoryConditionHandler::~AccessoryConditionHandler()
+{
+       if (__pAccessoryMonitor != null)
+       {
+               __pAccessoryMonitor->ReleaseInstance();
+       }
+}
+
+result
+AccessoryConditionHandler::Register(_AppLaunchCondition& operation)
+{
+       SysLog(NID_SYS, "Request to register accessory process");
+       __appConditionList.Remove(operation.GetAppId());
+       __appConditionList.Add(operation.GetAppId(), operation.GetConditionString());
+       return E_SUCCESS;
+}
+
+result
+AccessoryConditionHandler::Unregister(_AppLaunchCondition& operation)
+{
+       SysLog(NID_SYS, "Request to unregister accessory process");
+       __appConditionList.Remove(operation.GetAppId());
+       return E_SUCCESS;
+}
+
+char*
+AccessoryConditionHandler::GetValueFromCommandN(const char* command, int length)
+{
+       if (command == null || length <= 0)
+               return null;
+
+       int valueLength = 0;
+       char* value = null;
+
+       char* indexStart = strstr(const_cast < char* > (command), "'");
+
+       if (indexStart == null)
+               return null;
+
+       indexStart ++;
+
+       char* indexEnd = strstr(indexStart, "'");
+
+       if (indexEnd == null)
+               return null;
+
+       valueLength = indexEnd - indexStart;
+
+       value = new (std::nothrow) char[valueLength + 1];
+       memset(value, 0, valueLength + 1);
+
+       strncpy(value, indexStart, valueLength);
+
+       return value;
+}
+
+bool
+AccessoryConditionHandler::MessageCommandHandle(const char* command, int length)
+{
+       result r = E_SUCCESS;
+       bool resultValue = true;
+       char* commandValue = GetValueFromCommandN(command, length);
+       char* response = null;
+
+       SysTryCatch(NID_IO, commandValue != null, resultValue = false, E_SYSTEM, "[E_SYSTEM] there is no message command");
+
+       SysLog(NID_IO, "Message command is [%s]", commandValue);
+
+       if (strcmp(commandValue, ACCESSORY_SERIAL_COMMAND_HELLO) == 0)
+       {
+               SysLog(NID_IO, "This is hello request");
+
+               int responseLength = strlen(ACCESSORY_SERIAL_COMMAND_MESSAGE) + strlen(ACCESSORY_SERIAL_COMMAND_OK) + 5;
+               response = new (std::nothrow) char[responseLength];
+               memset(response, 0, responseLength);
+
+               response = strcat(response, ACCESSORY_SERIAL_COMMAND_MESSAGE);
+               response = strcat(response, "='");
+               response = strcat(response, ACCESSORY_SERIAL_COMMAND_OK);
+               response = strcat(response, "'\r\n");
+
+               r = __pAccessoryMonitor->SendData(response, strlen(response));
+
+               SysTryCatch(NID_IO, r == E_SUCCESS, resultValue = true, E_SYSTEM, "[%s] Fail to send data");
+       }
+       else
+       {
+               SysLog(NID_IO, "[%s] is not supported command", commandValue);
+       }
+
+CATCH:
+       delete [] commandValue;
+       delete [] response;
+
+       return resultValue;
+}
+
+bool
+AccessoryConditionHandler::RequestCommandHandle(const char* command, int length)
+{
+       result r = E_SUCCESS;
+       bool resultValue = true;
+       bool executed = false;
+       char* commandValue = GetValueFromCommandN(command, length);
+       char* registered = null;
+       char* executionCondition = null;
+       char* response = null;
+
+       IMapEnumerator* pMapEnum = null;
+
+       AppId* pAppId = null;
+       String* pCondition = null;
+
+       SysTryCatch(NID_IO, commandValue != null, resultValue = false, E_SYSTEM, "[E_SYSTEM] there is no message command");
+
+       SysLog(NID_IO, "Request command is [%s]", commandValue);
+
+       pMapEnum = __appConditionList.GetMapEnumeratorN();
+
+       SysTryCatch(NID_IO, pMapEnum != null, resultValue = false, E_SYSTEM, "[E_SYSTEM] There is wrong app list");
+
+       //if conditional popup is required, it can be implemented here.
+       while(pMapEnum->MoveNext() == E_SUCCESS)
+       {
+               pAppId = static_cast< AppId* >(pMapEnum->GetKey());
+               pCondition = static_cast< String* >(pMapEnum->GetValue());
+
+               registered = _StringConverter::CopyToCharArrayN(*pCondition);
+
+               executionCondition = GetValueFromCommandN(registered, strlen(registered));
+
+               if (strcmp(commandValue, executionCondition) == 0)
+               {
+                       //Launch applicaiton.
+                       r = _AppManagerImpl::GetInstance()->LaunchApplication(*pAppId, null, null, AppManager::LAUNCH_OPTION_DEFAULT);
+
+                       if (r != E_SUCCESS)
+                       {
+                               executed = false;
+                       }
+                       else
+                       {
+                               executed = true;
+                       }
+                       break;
+               }
+
+               delete [] executionCondition;
+               delete [] registered;
+               executionCondition = null;
+               registered = null;
+       }
+
+       if (executed == true)
+       {
+               int responseLength = strlen(ACCESSORY_SERIAL_COMMAND_RESPONSE) + strlen(ACCESSORY_SERIAL_COMMAND_SUCCESS) + 5;
+               response = new (std::nothrow) char[responseLength];
+               memset(response, 0, responseLength);
+
+               response = strcat(response, ACCESSORY_SERIAL_COMMAND_RESPONSE);
+               response = strcat(response, "='");
+               response = strcat(response, ACCESSORY_SERIAL_COMMAND_SUCCESS);
+               response = strcat(response, "'\r\n");
+       }
+       else
+       {
+               int responseLength = strlen(ACCESSORY_SERIAL_COMMAND_RESPONSE) + strlen(ACCESSORY_SERIAL_COMMAND_FAIL) + 5;
+               response = new (std::nothrow) char[responseLength];
+               memset(response, 0, responseLength);
+
+               response = strcat(response, ACCESSORY_SERIAL_COMMAND_RESPONSE);
+               response = strcat(response, "='");
+               response = strcat(response, ACCESSORY_SERIAL_COMMAND_FAIL);
+               response = strcat(response, "'\r\n");
+       }
+
+       r = __pAccessoryMonitor->SendData(response, strlen(response)+1);
+       SysTryCatch(NID_IO, r == E_SUCCESS, resultValue = true, E_SYSTEM, "[%s] Fail to send data");
+
+CATCH:
+       delete [] commandValue;
+       delete [] registered;
+       delete [] executionCondition;
+       delete [] response;
+       delete pMapEnum;
+
+       return resultValue;
+}
+
+bool
+AccessoryConditionHandler::ProcessPrimitiveCommand(const char* command, int length)
+{
+       bool resultValue = false;
+
+       SysLog(NID_IO, "serial data is forwarded to ProcessPrimitiveCommand [%s]", command);
+       SysTryCatch(NID_IO, command != null && length > 0, resultValue = false, E_INVALID_ARG, "[E_INVALID_ARG] There is no available data");
+
+       if (strncmp(command, ACCESSORY_SERIAL_COMMAND_MESSAGE, strlen(ACCESSORY_SERIAL_COMMAND_MESSAGE)) == 0)
+       {
+               resultValue = MessageCommandHandle(command, length);
+               SysLog(NID_SYS, "Message result: %d", resultValue);
+       }
+       else if (strncmp(command, ACCESSORY_SERIAL_COMMAND_REQUEST, strlen(ACCESSORY_SERIAL_COMMAND_REQUEST)) == 0)
+       {
+               resultValue = RequestCommandHandle(command, length);
+               SysLog(NID_SYS, "Request result: %d", resultValue);
+       }
+
+CATCH:
+       SysLog(NID_SYS, "result: %d", resultValue);
+       return resultValue;
+
+}
+
+/////////////////////////////////////////////////////////////////////////
+//     All plugins must provide both a creation and a destruction function
+/////////////////////////////////////////////////////////////////////////
+extern "C"
+{
+_OSP_EXPORT_ _AppLaunchConditionHandlerBase*
+CreatePlugin(void)
+{
+       SysLog(NID_IO, "CreatePlugin is called");
+    return new (std::nothrow) AccessoryConditionHandler;
+}
+
+_OSP_EXPORT_ void
+DestroyPlugin(_AppLaunchConditionHandlerBase* p)
+{
+    delete p;
+}
+}//extern "C"
diff --git a/plugins/accessory-condition-handler/AccessoryConditionHandler.h b/plugins/accessory-condition-handler/AccessoryConditionHandler.h
new file mode 100644 (file)
index 0000000..8488248
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file       AccessoryConditionHandler.cpp
+ * @brief      This is the declaration file of the AccessoryConditionHandler class.
+ */
+
+#ifndef _ACCESSORY_CONDITION_HANDLER_H_
+#define _ACCESSORY_CONDITION_HANDLER_H_
+
+#include <FApp_AppLaunchConditionHandlerBase.h>
+#include <FBase.h>
+
+
+class AccessoryMonitor;
+
+class AccessoryConditionHandler
+       :public Osp::App::_AppLaunchConditionHandlerBase
+{
+public:
+       AccessoryConditionHandler();
+       ~AccessoryConditionHandler();
+       bool ProcessPrimitiveCommand(const char* command, int length);
+
+       virtual result Register(Osp::App::_AppLaunchCondition& operation);
+       virtual result Unregister(Osp::App::_AppLaunchCondition& operation);
+private:
+       char* GetValueFromCommandN(const char* command, int length);
+       bool MessageCommandHandle(const char* command, int length);
+       bool RequestCommandHandle(const char* command, int length);
+       AccessoryMonitor* __pAccessoryMonitor;
+       Osp::Base::Collection::HashMap __appConditionList;
+};
+
+#endif //_ACCESSORY_CONDITION_HANDLER_H_
diff --git a/plugins/accessory-condition-handler/AccessoryMonitor.cpp b/plugins/accessory-condition-handler/AccessoryMonitor.cpp
new file mode 100644 (file)
index 0000000..827484b
--- /dev/null
@@ -0,0 +1,292 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file       AccessoryMonitor.cpp
+ * @brief      This is the implementation file of the AccessoryMonitor class.
+ *
+ */
+
+#include "AccessoryMonitor.h"
+#include "AccessoryConditionHandler.h"
+
+using namespace Osp::App;
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Io;
+
+namespace{
+       const String SERIAL_COMMAND_OPEN(L"Open");
+       const String SERIAL_COMMAND_CLOSE(L"Close");
+       const String SERIAL_COMMAND_WRITE(L"Write");
+       const String SERIAL_COMMAND_DATA(L"Data");
+       const String SERIAL_COMMAND_ERROR(L"Error");
+       const String SERIAL_COMMAND_OK(L"OK");
+       const String SERIAL_SERVICE_ID(L"osp.accessory.serial.service");
+       const String ACCESSORY_COMPONENT_ID(L"osp.accessorymanager.service");
+
+       const int SERIAL_DATA_HEAD = 1;
+       const int SERIAL_DATA_BODY = 2;
+}
+
+
+typedef result (*SendDataFunction)(AppId appId, ArrayList* data);
+SendDataFunction sendFunction = null;
+static AccessoryMonitor* gpAccessoryMonitor = null;
+static int gReferenceCount = 0;
+
+AccessoryMonitor::AccessoryMonitor()
+: __pAccessoryConditionHandler(null)
+, __pDataRouter(null)
+{
+}
+
+AccessoryMonitor::~AccessoryMonitor()
+{
+}
+
+AppId
+AccessoryMonitor::GetClientId(void) const
+{
+       return __clientAppId;
+}
+
+void
+AccessoryMonitor::SetClientId(AppId appId)
+{
+       __clientAppId = appId;
+}
+
+void
+AccessoryMonitor::RemoveClientId(AppId appId)
+{
+       StringComparer strComparer;
+       int cmp = 0;
+       strComparer.Compare(appId, __clientAppId, cmp);
+       if(cmp == 0)
+       {
+               __clientAppId = "";
+       }
+}
+
+_DataRouter*
+AccessoryMonitor::GetDataRouter(void) const
+{
+       return __pDataRouter;
+}
+
+result
+AccessoryMonitor::Construct(AccessoryConditionHandler* pConditionHandler)
+{
+       result r = E_SUCCESS;
+       SysTryReturnResult(NID_APP, pConditionHandler != null, E_INVALID_ARG, "pConditionHandler is empty");
+
+       __pAccessoryConditionHandler = pConditionHandler;
+       SysTryReturnResult(NID_APP, __pDataRouter == null, E_INVALID_STATE, "AccessoryMonitor is already constructed.");
+
+       __clientAppId = "";
+       __pDataRouter = _DataRouter::GetInstance();
+       r = __pDataRouter->Construct(*this);
+       SysTryReturnResult(NID_APP, r == E_SUCCESS, E_SYSTEM, "DataRouter is not constructed.");
+
+       return E_SUCCESS;
+}
+
+AccessoryMonitor*
+AccessoryMonitor::GetInstance(void)
+{
+       if(gpAccessoryMonitor == null)
+               gpAccessoryMonitor = new (std::nothrow) AccessoryMonitor();
+
+       gReferenceCount ++;
+       return gpAccessoryMonitor;
+}
+
+void
+AccessoryMonitor::ReleaseInstance(void)
+{
+       if(gReferenceCount == 0)
+               return;
+
+       gReferenceCount --;
+       if(gReferenceCount == 0)
+       {
+               delete gpAccessoryMonitor;
+               gpAccessoryMonitor = null;
+       }
+}
+
+void
+AccessoryMonitor::OnDataRouterDataReceivedN(const char* buffer, int length)
+{
+       SysLog(NID_IO, "serial data is forwarded to AccessoryMonitor class");
+       SysTryReturnVoidResult(NID_APP, buffer != null, E_INVALID_ARG, "[E_INVALID_ARG] buffer should not be null.");
+
+       bool primitiveCommand = false;
+       if(__pAccessoryConditionHandler != null)
+       {
+               primitiveCommand = __pAccessoryConditionHandler->ProcessPrimitiveCommand(buffer, length);
+       }
+
+       if(primitiveCommand == false)
+       {
+               SysLog(NID_IO, "Requested data is not command. it will be forwarded to current application");
+               if(__clientAppId.GetLength() > 0)
+               {
+                       ArrayList* pDataList = new (std::nothrow) ArrayList();
+                       ByteBuffer* pByteBuffer = new (std::nothrow) ByteBuffer();
+
+                       String* pCommand = new (std::nothrow) String(SERIAL_COMMAND_DATA);
+                       String* pComponentId= new (std::nothrow) String(ACCESSORY_COMPONENT_ID);
+                       char* pIterator = const_cast<char*>(buffer);
+
+                       pByteBuffer->Construct(length);
+
+                       for(int i = 0; i < length; i++)
+                       {
+                               pByteBuffer->SetByte((byte)(*pIterator));
+                               pIterator++;
+                       }
+
+                       pDataList->Construct();
+                       pDataList->Add(*pComponentId);
+                       pDataList->Add(*pCommand);
+                       pDataList->Add(*pByteBuffer);
+
+                       if(sendFunction!=null)
+                       {
+                               SysLog(NID_IO, "Data is forwarded to [%ls]", __clientAppId.GetPointer());
+                               sendFunction(__clientAppId, pDataList);
+                       }
+
+                       pDataList->RemoveAll(true);
+                       delete(pDataList);
+               }
+       }
+}
+
+result
+AccessoryMonitor::SendData(char* buffer, int length)
+{
+       SysTryReturnResult(NID_APP, __pDataRouter != null, E_INVALID_STATE, "[E_INVALID_STATE] AccessoryMonitor is not constructed.");
+       return __pDataRouter->Write(buffer, length);
+}
+void
+AccessoryMonitor::OnDataRouterStateChanged(_DataRouterState state)
+{
+       SysLog(NID_IO, "STATE is changed %d", (int)state);
+}
+
+
+/////////////////////////////////////////////////////////////////////////
+//     Exported functions for _CommunicationDispatcher
+/////////////////////////////////////////////////////////////////////////
+extern "C"
+{
+
+_OSP_EXPORT_ void
+RegisterSendData(SendDataFunction function)
+{
+       sendFunction = function;
+}
+
+_OSP_EXPORT_ void
+RemoveOwnerApplication(const AppId appId, const String& executableName)
+{
+       if(gpAccessoryMonitor != null)
+       {
+               SysLog(NID_IO, "Accessory Owner is removed [%ls, %ls]", appId.GetPointer(), executableName.GetPointer());
+               gpAccessoryMonitor->RemoveClientId(appId);
+       }
+}
+
+_OSP_EXPORT_ bool
+OnRequestOccured(AppId appId, ArrayList* pRequest, ArrayList* pResponse)
+{
+       String* pCommand = null;
+
+       result r = E_SUCCESS;
+       SysTryCatch(NID_APP, pRequest != null, r = E_SYSTEM, E_SYSTEM, "There is no pRequest");
+       SysTryCatch(NID_APP, pResponse != null, r = E_SYSTEM, E_SYSTEM, "There is no pResponse");
+       SysTryCatch(NID_APP, gpAccessoryMonitor != null, r = E_SYSTEM, E_SYSTEM, "AccessoryMonitor is not ready");
+
+       pCommand = static_cast< String* > (pRequest->GetAt(SERIAL_DATA_HEAD));
+
+       SysTryCatch(NID_APP, pCommand != null, , E_SYSTEM, "There is no command");
+
+       SysLog(NID_IO, "Request: %ls", pCommand->GetPointer());
+
+       if(pCommand->Equals(SERIAL_COMMAND_OPEN, true))
+       {
+               SysLog(NID_IO, "Serial open is required");
+               SysTryCatch(NID_APP, gpAccessoryMonitor->GetClientId().GetLength() == 0, , E_SYSTEM, "Serial port is already used by [%ls]", gpAccessoryMonitor->GetClientId().GetPointer());
+               gpAccessoryMonitor->SetClientId(appId);
+               String* pResult = new (std::nothrow) String(SERIAL_COMMAND_OK);
+
+               pResponse->Add(*pResult);
+       }
+       else
+       {
+               SysTryCatch(NID_APP, gpAccessoryMonitor->GetClientId().GetLength() > 0, , E_SYSTEM, "Serial port is not created");
+               if(pCommand->Equals(SERIAL_COMMAND_WRITE, true))
+               {
+                       SysLog(NID_IO, "Serial write is required");
+                       char* buffer = null;
+                       char* pIterator = null;
+                       int length = 0;
+
+                       ByteBuffer* pByteBuffer = null;
+                       pByteBuffer = static_cast < ByteBuffer* > (pRequest->GetAt(SERIAL_DATA_BODY));
+
+                       buffer = new (std::nothrow) char[pByteBuffer->GetCapacity()];
+                       memset(buffer, 0, pByteBuffer->GetCapacity());
+
+                       pIterator = buffer;
+
+                       pByteBuffer->SetPosition(0);
+                       for(int i = 0; i<pByteBuffer->GetCapacity(); i++)
+                       {
+                               r = pByteBuffer->GetByte(*(byte*)pIterator);
+                               if (!IsFailed(r))
+                               {
+                                       pIterator++;
+                                       length++;
+                               }
+                       }
+                       gpAccessoryMonitor->GetDataRouter()->Write(buffer, length);
+
+                       delete [] buffer;
+               }
+               else if(pCommand->Equals(SERIAL_COMMAND_CLOSE, true))
+               {
+                       SysLog(NID_IO, "Serial close is required");
+                       gpAccessoryMonitor->SetClientId(L"");
+               }
+               else
+               {
+                       SysLogException(NID_APP, E_SYSTEM, "Undefined command is pRequested by [%ls]", gpAccessoryMonitor->GetClientId().GetPointer());
+               }
+       }
+CATCH:
+       SetLastResult(r);
+
+       if(r == E_SUCCESS)
+               return true;
+       else
+               return false;
+}
+}//extern "C"
diff --git a/plugins/accessory-condition-handler/AccessoryMonitor.h b/plugins/accessory-condition-handler/AccessoryMonitor.h
new file mode 100644 (file)
index 0000000..7d5d203
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file       AccessoryManager.cpp
+ * @brief      This is the declaration file of the AccessoryManager class.
+ */
+
+#ifndef _ACCESSORY_MONITOR_
+#define _ACCESSORY_MONITOR_
+
+#include <FApp.h>
+#include <FBase.h>
+#include <FIo.h>
+#include <FIo_IDataRouterEventListener.h>
+#include <FIo_DataRouter.h>
+
+class AccessoryConditionHandler;
+
+class AccessoryMonitor
+       : public Osp::Base::Object
+       , public Osp::Io::_IDataRouterEventListener
+{
+private:
+       AccessoryMonitor();
+       ~AccessoryMonitor();
+
+public:
+       result Construct(AccessoryConditionHandler* pConditionHandler);
+       result SendData(char* buffer, int length);
+       Osp::App::AppId GetClientId(void) const;
+       void SetClientId(Osp::App::AppId appId);
+       void RemoveClientId(Osp::App::AppId appId);
+       Osp::Io::_DataRouter* GetDataRouter(void) const;
+       virtual void OnDataRouterDataReceivedN(const char* buffer, int length);
+       virtual void OnDataRouterStateChanged(Osp::Io::_DataRouterState state);
+
+       static AccessoryMonitor* GetInstance(void);
+       static void ReleaseInstance(void);
+
+private:
+       AccessoryConditionHandler* __pAccessoryConditionHandler;
+       Osp::Io::_DataRouter* __pDataRouter;
+       Osp::App::AppId __clientAppId;
+};
+
+#endif //AccessoryMonitor
diff --git a/plugins/accessory-condition-handler/CMakeLists.txt b/plugins/accessory-condition-handler/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..b5d3f1e
--- /dev/null
@@ -0,0 +1,36 @@
+SET (this_target osp-cond-accessory)
+
+INCLUDE_DIRECTORIES (
+       /usr/include/osp
+       /usr/include/osp/app
+       /usr/include/osp/base
+       /usr/include/osp/io
+       ../../inc
+       ./
+       )
+
+SET (${this_target}_SOURCE_FILES
+       AccessoryMonitor.cpp
+       AccessoryConditionHandler.cpp
+       )
+
+## SET EXTRA COMPILER FLAGS
+SET(EXTRA_CFLAGS  "${EXTRA_CFLAGS} -fPIC -Wall" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES})
+
+SET_TARGET_PROPERTIES(${this_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PLUGIN_INSTALL_DIR}/data")
+
+TARGET_LINK_LIBRARIES(${this_target} -L/usr/lib/osp -losp-appfw -Wl,--no-undefined -Wl,--as-needed)
+
+OSP_STRIP(${this_target})
+
+
diff --git a/plugins/alarm-condition-handler/AlarmConditionHandler.cpp b/plugins/alarm-condition-handler/AlarmConditionHandler.cpp
new file mode 100644 (file)
index 0000000..d171af7
--- /dev/null
@@ -0,0 +1,194 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        alarm_condition_candler.cpp
+ * @brief      This is the declaration file of the _AlarmConditionHandler class.
+ *
+ */
+
+#include <new>
+
+#include <FBaseInteger.h>
+#include <FSysSystemTime.h>
+#include <FBaseUtilRegularExpression.h>
+
+#include "AlarmConditionHandler.h"
+
+
+using namespace Osp::App;
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Base::Utility;
+using namespace Osp::System;
+
+
+//////////////////////////////////////////////////////////////
+//     _AlarmCondition
+//////////////////////////////////////////////////////////////
+_AlarmCondition::_AlarmCondition(const _AppLaunchCondition& op)
+       : __appLaunchCondition(op)
+{
+}
+
+const _AppLaunchCondition&
+_AlarmCondition::GetAppLaunchCondition(void) const
+{
+       return __appLaunchCondition;
+}
+
+
+//////////////////////////////////////////////////////////////
+//     _AlarmConditionHandler
+//////////////////////////////////////////////////////////////
+_AlarmConditionHandler::_AlarmConditionHandler(void)
+{
+
+}
+
+_AlarmConditionHandler::~_AlarmConditionHandler(void)
+{
+
+}
+
+
+result
+_AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
+{
+       String pattern(L"([A-Za-z]*)='([\\d\\s/:]*)'");
+       String buf(appLaunchCondition.GetConditionString());
+       ArrayList list;
+       list.Construct();
+
+       SysLog(NID_APP, "%ls", buf.GetPointer());
+
+       RegularExpression regex;
+       result r = regex.Construct(pattern);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s]", GetErrorMessage(GetLastResult()));
+
+       bool ret = regex.Consume(buf, &list);
+       SysTryReturnResult(NID_APP, ret == true, GetLastResult(), "failed to parse condition (%ls)", buf.GetPointer() );
+
+       String field = *(String *)list.GetAt(1);
+       String value = *(String *)list.GetAt(2);
+       list.RemoveAll(true);
+
+       SysLog(NID_APP, "(field:%ls), (value:%ls)", field.GetPointer(), value.GetPointer());
+
+       _AlarmCondition* pAlarmCondition = new (std::nothrow) _AlarmCondition(appLaunchCondition);
+       SysTryReturnResult(NID_APP, pAlarmCondition != null, E_OUT_OF_MEMORY , "failed to new _AlarmCondition" );
+
+       r = pAlarmCondition->Construct(*this);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] failed to pAlarmCondition->Construct", GetErrorMessage(r) );
+
+       if ( field == "DateTime")//TODO: toLowerCase
+       {
+               DateTime dueTime;
+               r = DateTime::Parse(value, dueTime);
+               if (r == E_OUT_OF_RANGE)
+               {
+                       r = E_INVALID_CONDITION;
+               }
+               SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] failed to parse value (%ls)", GetErrorMessage(r), value.GetPointer() );
+
+               r = pAlarmCondition->Set( dueTime);
+               SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] failed to pAlarmCondition->Set (%ls)", GetErrorMessage(r), value.GetPointer() );
+               SysLog(NID_APP, "alarm (%ls) added. ", value.GetPointer() );
+       }
+       else if ( field == "DueTime")//TODO: consider unordered fields
+       {
+               DateTime dueDate;
+               r = DateTime::Parse(value, dueDate);
+               if (r == E_OUT_OF_RANGE)
+               {
+                       r = E_INVALID_CONDITION;
+               }
+               SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to parse value (%ls)", value.GetPointer() );
+
+               if (String(buf[0]) == L" ")
+               {
+                       buf.Remove(0, 1);
+               }
+
+               // parse second field. (LaunchPeriod)
+               ret = regex.Consume(buf, &list);
+
+               field = *(String *)list.GetAt(1);
+               String value2 = *(String *)list.GetAt(2);
+
+               int period = 0;
+               r = Integer::Parse(value2, period);
+               SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to parse value (%ls)", value2.GetPointer() );
+               SysTryReturnResult(NID_APP, period >= 60, E_INVALID_CONDITION, "The 'LaunchPeriod' should be greater than (60) but (%ls).", value2.GetPointer() );
+
+               // fire
+               DateTime now;
+               Osp::System::SystemTime::GetCurrentTime(UTC_TIME, now);
+               r = pAlarmCondition->Set( now, period, &dueDate);
+               SysTryReturnResult(NID_APP, !IsFailed(r), r, "failed to pAlarmCondition->Set(%ls, %ls)", value.GetPointer(), value2.GetPointer() );
+               SysLog(NID_APP, "alarm (duedate:%ls), (period:%ls) added. ", value.GetPointer(), value.GetPointer() );
+       }
+       else
+       {
+               SysLog(NID_APP, "condition is invalid.", buf.GetPointer() );
+               return E_INVALID_CONDITION;
+       }
+
+
+       appLaunchCondition.SetUserData(pAlarmCondition);
+       return E_SUCCESS;
+}
+
+
+result
+_AlarmConditionHandler::Unregister( _AppLaunchCondition& appLaunchCondition)
+{
+       _AlarmCondition *pAlarmCondition = dynamic_cast<_AlarmCondition*>(appLaunchCondition.GetUserData());
+       SysTryReturnResult(NID_APP, pAlarmCondition != null, E_INVALID_STATE, "pUserData shoud NOT be null." );
+
+       result r =  pAlarmCondition->Cancel();
+       delete pAlarmCondition;
+       return r;
+}
+
+void
+_AlarmConditionHandler::OnAlarmExpired(Alarm& alarm)
+{
+       _AlarmCondition* pAlarmCondition = dynamic_cast<_AlarmCondition*>(&alarm);
+       SysTryReturnVoidResult(NID_APP, pAlarmCondition != null, E_INVALID_STATE, "pUserData shoud NOT be null." );
+
+       Fire(pAlarmCondition->GetAppLaunchCondition());
+}
+
+
+//////////////////////////////////////////////////////////////
+//     All plugins must provide both a creation and a destruction function
+//////////////////////////////////////////////////////////////
+extern "C"
+{
+_OSP_EXPORT_ _AppLaunchConditionHandlerBase*
+CreatePlugin(void)
+{
+       return new (std::nothrow) _AlarmConditionHandler;////   create and return your own class instance.
+}
+
+_OSP_EXPORT_ void
+DestroyPlugin(_AppLaunchConditionHandlerBase* p)
+{
+       delete p;
+}
+}//extern "C"
diff --git a/plugins/alarm-condition-handler/AlarmConditionHandler.h b/plugins/alarm-condition-handler/AlarmConditionHandler.h
new file mode 100644 (file)
index 0000000..57462e0
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        alarm_condition_candler.h
+ * @brief      This is the implementation file of the _AlarmConditionHandler class.
+ *
+ */
+
+#include <FSysAlarm.h>
+#include "FApp_AppLaunchConditionHandlerBase.h"
+
+/**
+ * @class      _AlarmCondition
+ * @brief      This class inherits and contains combind _AppLaunchCondition reference.
+ * @final      This class is not intended for extension.
+ */
+class _AlarmCondition:
+       public Osp::System::Alarm
+{
+public:
+
+       _AlarmCondition(const Osp::App::_AppLaunchCondition& op);
+       const Osp::App::_AppLaunchCondition& GetAppLaunchCondition(void) const;
+
+private:
+       const Osp::App::_AppLaunchCondition& __appLaunchCondition;
+};
+
+/**
+ * @class      _AlarmConditionHandler
+ * @brief      This class implements conditional app launch for alarm condition. (DateTime, DueTime)
+ * @final      This class is not intended for extension.
+ */
+class _AlarmConditionHandler:
+       public Osp::App::_AppLaunchConditionHandlerBase,
+       public Osp::System::IAlarmEventListener
+{
+
+public:
+               _AlarmConditionHandler(void);
+               virtual ~_AlarmConditionHandler(void);
+
+               virtual result Register( Osp::App::_AppLaunchCondition& appLaunchCondition);
+               virtual result Unregister( Osp::App::_AppLaunchCondition& appLaunchCondition);
+               virtual void OnAlarmExpired(Osp::System::Alarm& alarm);
+};
diff --git a/plugins/alarm-condition-handler/CMakeLists.txt b/plugins/alarm-condition-handler/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..7f37169
--- /dev/null
@@ -0,0 +1,31 @@
+SET (this_target osp-cond-alarm)
+
+INCLUDE_DIRECTORIES (
+       /usr/include/osp
+       /usr/include/osp/app
+       /usr/include/osp/base
+       )
+
+SET (${this_target}_SOURCE_FILES
+       AlarmConditionHandler.cpp
+       )
+       
+## SET EXTRA COMPILER FLAGS
+SET(EXTRA_CFLAGS  "${EXTRA_CFLAGS} -fPIC -Wall" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES})
+
+ADD_DEPENDENCIES(${this_target} osp-appfw)
+SET_TARGET_PROPERTIES(${this_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PLUGIN_INSTALL_DIR}/data")
+TARGET_LINK_LIBRARIES(${this_target} -L/usr/lib/osp -losp-appfw -Wl,--no-undefined -Wl,--as-needed)
+
+OSP_STRIP(${this_target})
+
diff --git a/plugins/nfc-condition-handler/.cproject b/plugins/nfc-condition-handler/.cproject
new file mode 100644 (file)
index 0000000..65bfddc
--- /dev/null
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?>
+
+<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+       <storageModule moduleId="org.eclipse.cdt.core.settings">
+               <cconfiguration id="0.337419437">
+                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.337419437" moduleId="org.eclipse.cdt.core.settings" name="Default">
+                               <externalSettings/>
+                               <extensions>
+                                       <extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                               </extensions>
+                       </storageModule>
+                       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+                               <configuration buildProperties="" description="" id="0.337419437" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
+                                       <folderInfo id="0.337419437." name="/" resourcePath="">
+                                               <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.888259403" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
+                                                       <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.888259403.2003055277" name=""/>
+                                                       <builder id="org.eclipse.cdt.build.core.settings.default.builder.2118925050" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
+                                                       <tool id="org.eclipse.cdt.build.core.settings.holder.libs.275589824" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
+                                                       <tool id="org.eclipse.cdt.build.core.settings.holder.1680722508" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
+                                                               <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1675042069" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+                                                       </tool>
+                                                       <tool id="org.eclipse.cdt.build.core.settings.holder.24576648" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
+                                                               <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1310280949" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+                                                       </tool>
+                                                       <tool id="org.eclipse.cdt.build.core.settings.holder.88316723" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
+                                                               <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.894902357" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+                                                       </tool>
+                                               </toolChain>
+                                       </folderInfo>
+                               </configuration>
+                       </storageModule>
+                       <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+               </cconfiguration>
+       </storageModule>
+       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+               <project id="nfc-condition-handler.null.1864129499" name="nfc-condition-handler"/>
+       </storageModule>
+       <storageModule moduleId="scannerConfiguration">
+               <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               <scannerConfigBuildInfo instanceId="0.337419437">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               </scannerConfigBuildInfo>
+       </storageModule>
+</cproject>
diff --git a/plugins/nfc-condition-handler/.project b/plugins/nfc-condition-handler/.project
new file mode 100644 (file)
index 0000000..42f82c9
--- /dev/null
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>nfc-condition-handler</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+                       <triggers>clean,full,incremental,</triggers>
+                       <arguments>
+                               <dictionary>
+                                       <key>?name?</key>
+                                       <value></value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.append_environment</key>
+                                       <value>true</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.autoBuildTarget</key>
+                                       <value>all</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.buildArguments</key>
+                                       <value></value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.buildCommand</key>
+                                       <value>make</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
+                                       <value>clean</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.contents</key>
+                                       <value>org.eclipse.cdt.make.core.activeConfigSettings</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
+                                       <value>false</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
+                                       <value>true</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.enableFullBuild</key>
+                                       <value>true</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.fullBuildTarget</key>
+                                       <value>all</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.stopOnError</key>
+                                       <value>true</value>
+                               </dictionary>
+                               <dictionary>
+                                       <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
+                                       <value>true</value>
+                               </dictionary>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+                       <triggers>full,incremental,</triggers>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.cdt.core.cnature</nature>
+               <nature>org.eclipse.cdt.core.ccnature</nature>
+               <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+               <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+       </natures>
+</projectDescription>
diff --git a/plugins/nfc-condition-handler/CMakeLists.txt b/plugins/nfc-condition-handler/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..432132c
--- /dev/null
@@ -0,0 +1,32 @@
+SET (this_target osp-cond-nfc)
+
+INCLUDE_DIRECTORIES (
+       /usr/include/osp
+       /usr/include/osp/app
+       /usr/include/osp/base
+       ../../inc
+       )
+
+SET (${this_target}_SOURCE_FILES
+       NfcConditionHandler.cpp
+       )
+       
+## SET EXTRA COMPILER FLAGS
+SET(EXTRA_CFLAGS  "${EXTRA_CFLAGS} -fPIC -Wall" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES})
+
+ADD_DEPENDENCIES(${this_target} osp-appfw)
+SET_TARGET_PROPERTIES(${this_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PLUGIN_INSTALL_DIR}/data")
+TARGET_LINK_LIBRARIES(${this_target} -L/usr/lib/osp -losp-appfw -Wl,--no-undefined -Wl,--as-needed)
+
+OSP_STRIP(${this_target})
+
diff --git a/plugins/nfc-condition-handler/NfcConditionHandler.cpp b/plugins/nfc-condition-handler/NfcConditionHandler.cpp
new file mode 100644 (file)
index 0000000..18dedae
--- /dev/null
@@ -0,0 +1,364 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file       nfc_condition_candler.cpp
+ * @brief      This is the implementation file of the _AlarmConditionHandler class.
+ *
+ */
+
+
+#include <new>
+
+#include <FBaseColHashMap.h>
+#include <FBaseUtilRegularExpression.h>
+#include <FBaseUtilUrlEncoder.h>
+
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FApp_Aul.h>
+#include <FApp_AppLaunchConditionHandlerBase.h>
+
+
+#ifdef _NfcSysTryLogReturn
+#undef _NfcSysTryLogReturn
+#endif
+
+#define _NfcSysTryLogReturn(condition, returnValue, ...) \
+       if (!(condition)) {     \
+               SetLastResult(E_INVALID_FORMAT); \
+               SysLog(NID_APP, __VA_ARGS__); \
+               return returnValue;     \
+       } \
+       else {;}
+
+using namespace Osp::App;
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Base::Utility;
+using namespace Osp::System;
+
+
+/**
+ * @class              _NfcConditionHandler
+ * @brief              This class implements conditional app launch for alarm condition. (NFC)
+ * @final
+ */
+class _NfcConditionHandler:
+       public _AppLaunchConditionHandlerBase
+{
+public:
+       _NfcConditionHandler(void) :
+               uriSchemeMap()
+       {
+               // Makes the URI scheme table which is consist of well-known URI schemes the underlying NFC system supports
+               uriSchemeMap.Construct();
+               uriSchemeMap.Add(*(new String(L"http")), *(new String(L"http")));
+               uriSchemeMap.Add(*(new String(L"https")), *(new String(L"https")));
+               uriSchemeMap.Add(*(new String(L"ftp")), *(new String(L"ftp")));
+               uriSchemeMap.Add(*(new String(L"sftp")), *(new String(L"sftp")));
+               uriSchemeMap.Add(*(new String(L"smb")), *(new String(L"smb")));
+               uriSchemeMap.Add(*(new String(L"nfs")), *(new String(L"nfs")));
+               uriSchemeMap.Add(*(new String(L"telnet")), *(new String(L"telnet")));
+               uriSchemeMap.Add(*(new String(L"file")), *(new String(L"file")));
+               uriSchemeMap.Add(*(new String(L"ssh")), *(new String(L"ssh")));
+               uriSchemeMap.Add(*(new String(L"tel")), *(new String(L"tel")));
+               uriSchemeMap.Add(*(new String(L"mailto")), *(new String(L"mailto")));
+               uriSchemeMap.Add(*(new String(L"news")), *(new String(L"news")));
+               uriSchemeMap.Add(*(new String(L"sip")), *(new String(L"sip")));
+               uriSchemeMap.Add(*(new String(L"sips")), *(new String(L"sips")));
+               uriSchemeMap.Add(*(new String(L"tftp")), *(new String(L"tftp")));
+               uriSchemeMap.Add(*(new String(L"imap")), *(new String(L"imap")));
+               uriSchemeMap.Add(*(new String(L"pop")), *(new String(L"pop")));
+               uriSchemeMap.Add(*(new String(L"market")), *(new String(L"market")));
+               uriSchemeMap.Add(*(new String(L"rtsp")), *(new String(L"rtsp")));
+       }
+
+       virtual ~_NfcConditionHandler(void)
+       {
+               uriSchemeMap.RemoveAll(true);
+       }
+
+       virtual result Register(_AppLaunchCondition& operation)
+       {
+               // TODO: The following pattern is temporary.
+               // It should be changed to cover all NFC conditions according to the NDEF specifications.
+               String pattern(L"([A-Za-z]*)='([0-9A-Za-z&=_\\-\\.\\:\\/\\\\]*)'");
+               String buf(operation.GetConditionString());
+               String field;
+               String value;
+               ArrayList list;
+               Utility::RegularExpression regex;
+               char* pOriginalCondition = null;
+               char* pTranslatedCondition = null;
+               result r = E_SUCCESS;
+               bool ret = true;
+
+               list.Construct();
+
+               r = regex.Construct(pattern);
+               SysTryReturn(NID_APP, !IsFailed(r), E_SYSTEM, E_SYSTEM, "[%s] Failed to regex.Construct(%ls).", pattern.GetPointer());
+
+               ret = regex.Consume(buf, &list);
+               r = GetLastResult();
+               SysTryReturn(NID_APP, ret == true, E_INVALID_FORMAT, E_INVALID_FORMAT, "[%s] Failed to parse the condition (%ls).", GetErrorMessage(r),
+                                       buf.GetPointer());
+
+               field = *(String*)list.GetAt(1);
+               value = *(String*)list.GetAt(2);
+               list.RemoveAll(true);
+
+               if (field == "NFC")
+               {
+                       pOriginalCondition = _StringConverter::CopyToCharArrayN(value);
+                       SysTryReturnResult(NID_APP, pOriginalCondition != null, E_SYSTEM, "Failed to parse the condition.");
+
+                       // Translates OSP condition to SLP service condition
+                       pTranslatedCondition = GetNfcAulConditionN(pOriginalCondition);
+                       delete[] pOriginalCondition;
+
+                       SysTryReturnResult(NID_APP, pTranslatedCondition != null, E_SYSTEM, "Failed to translate the condition.");
+
+                       r = _Aul::_DesktopFile::UpdateService(operation.GetAppId(), pTranslatedCondition);
+
+                       operation.SetUserData(new String(pTranslatedCondition));
+
+                       delete[] pTranslatedCondition;
+               }
+               else
+               {
+                       r = E_FAILURE;
+               }
+
+               return r;
+       }
+
+       virtual result Unregister(_AppLaunchCondition& operation)
+       {
+               String* pHandle = null;
+//             char* pOriginalCondition = null;
+               char* pTranslatedCondition = null;
+               result r = E_SUCCESS;
+
+               pHandle = dynamic_cast<String*>(operation.GetUserData());
+               SysTryReturnResult(NID_APP, pHandle != null, E_INVALID_ARG, "Invalid conditional operation.");
+
+               pTranslatedCondition = _StringConverter::CopyToCharArrayN(*pHandle);
+               SysTryReturnResult(NID_APP, pTranslatedCondition != null, E_SYSTEM, "Failed to parse the condition.");
+
+               // Translates OSP condition to SLP service condition
+//             pTranslatedCondition = GetNfcAulConditionN(pOriginalCondition);
+//             delete[] pOriginalCondition;
+//             SysTryReturnResult(NID_APP, pTranslatedCondition != null, E_SYSTEM, "Failed to translate the condition.");
+
+               r = _Aul::_DesktopFile::RemoveService(operation.GetAppId(), pTranslatedCondition); // only operation name is required to remove service.
+
+               delete[] pTranslatedCondition;
+
+               return r;
+       }
+
+private:
+       char* GetNfcAulConditionN(char* pConditionValue)
+       {
+               //-------------------------------------------------------------------------
+               // The BNF format of the OSP NFC condition is as follows:
+               //              <condition>   ::= <tnf_field>"&"<type_field>["&"<code_field>]
+               //              <tnf_field>   ::= "tnf="<tnf_value>
+               //              <tnf_value>   ::= "rtd"|"mime"|"uri"|"ext"
+               //              <type_field>  ::= "type="<type_string>
+               //              <type_string> ::= <String of US_ASCII characters>
+               //              <code_field>  ::= "code="<uri_code>
+               //              <uri_code>        ::= "0x"<hexa_digit><hexa_digit>
+               //              <hexa_digit>  ::= "0".."9"|"A".."F"
+               //
+               // AUL translation rules according to <tnf_field> are as follows:
+               //              "tnf=rtd" --> "NFC_SERVICE_WELL_KNOWN_TYPE:NULL:"<type_string>"/"{<uri_code>|"*"}
+               //              "tnf=ext" --> "NFC_SERVICE_EXTERNAL_TYPE:NULL:"<uri_scheme>"/"<type_string>
+               //              "tnf=uri" --> "NFC_SERVICE_URI_TYPE:NULL:"<uri_scheme>"/"<type_string>
+               //              "tnf=mime" --> "NFC_SERVICE_MIME_TYPE:NULL:"<type_string>
+               //              <uri_scheme> is the head part of <type_string> and delimited by colon(:) and one of the wellknown types
+               //              <type_string> of "tnf=ext" and "tnf=mime" must be decapitalized for case-insensitive matching
+               //              <type_string> of "tnf=ext" and "tnf=uri" must be percent-encoded
+               //
+               // Examples
+               //              Source(OSP):
+               //                      tnf=rtd&type=Sp
+               //                      tnf=rtd&type=U&code=0x05
+               //                      tnf=ext&type=Bordeaux_Wine:1996
+               //                      tnf=uri&type=http://www.tizen.org
+               //                      tnf=mime&type=text/x-vcard
+               //              Target(AUL):
+               //                      NFC_SERVICE_WELL_KNOWN_TYPE:NULL:Sp/*
+               //                      NFC_SERVICE_WELL_KNOWN_TYPE:NULL:U/0x05
+               //                      NFC_SERVICE_EXTERNAL_TYPE:NULL:unknown/bordeauxwine%3A1996
+               //                      NFC_SERVICE_URI_TYPE:http/http%3A%2F%2Fwww.tizen.org
+               //                      NFC_SERVICE_MIME_TYPE:NULL:text/x-vcard
+               //-------------------------------------------------------------------------
+
+               String tnfValue;        // <tnf_value>
+               String typeString;      // <type_string>
+               String uriCode(L'*');   // <uri_code>
+               int delimiterIndex = -1;
+
+               String originalCondition(pConditionValue);
+               String aulFormatCondition;
+               char* pTranslatedCondition = null;
+
+               result r = E_SUCCESS;
+               bool isOk = true;
+
+
+               // Check whether the condition includes the tnf field.
+               isOk = originalCondition.StartsWith(L"tnf=", 0);
+               _NfcSysTryLogReturn(isOk == true, null, "Illegal format (%ls) - No tnf field.", originalCondition.GetPointer() );
+
+               // Search the index of the type field.
+               r = originalCondition.IndexOf(L'&', 0, delimiterIndex);
+               _NfcSysTryLogReturn(r == E_SUCCESS, null, "Illegal format (%ls)- No type field.", originalCondition.GetPointer() );
+
+               // Read <tnf_value>.
+               // The length of <tnf_value> is (delimiterIndex - 4).
+               r = originalCondition.SubString(4, delimiterIndex - 4, tnfValue);
+               _NfcSysTryLogReturn(r == E_SUCCESS, null, "Parsing error. (%ls)", originalCondition.GetPointer() );
+
+               // Check whether the condition includes the type field.
+               isOk = originalCondition.StartsWith(L"type=", delimiterIndex + 1);
+               _NfcSysTryLogReturn(isOk == true, null, "Illegal format (%ls)- No type field.", originalCondition.GetPointer() );
+
+               // Read <type_string>.
+               r = originalCondition.SubString(delimiterIndex + 6, typeString);
+               _NfcSysTryLogReturn(r == E_SUCCESS, null, "Parsing error. (%ls)", originalCondition.GetPointer() );
+
+               if (tnfValue.CompareTo(L"rtd") == 0)
+               {
+                       // Search the index of the code field.
+                       // The code field is optional.
+                       r = typeString.IndexOf(L'&', 0, delimiterIndex);
+                       if (!IsFailed(r))
+                       {
+                               String fullTypeString(typeString);
+
+                               r = fullTypeString.SubString(0, delimiterIndex, typeString);
+                               _NfcSysTryLogReturn(r == E_SUCCESS, null, "Parsing error. (%ls)", originalCondition.GetPointer() );
+
+                               if (typeString.CompareTo(L"U") == 0)
+                               {
+                                       // Check whether the condition includes the type field.
+                                       isOk = fullTypeString.StartsWith(L"code=", delimiterIndex + 1);
+                                       _NfcSysTryLogReturn(isOk == true, null, "Illegal format (%ls)- No code field after the second '&'.", originalCondition.GetPointer() );
+
+                                       // Read <uri_code>.
+                                       r = fullTypeString.SubString(delimiterIndex + 6, uriCode);
+                                       _NfcSysTryLogReturn(r == E_SUCCESS, null, "Parsing error. (%ls)", originalCondition.GetPointer() );
+                               }
+                       }
+
+                       aulFormatCondition = L"NFC_SERVICE_WELL_KNOWN_TYPE:NULL:";
+                       aulFormatCondition.Append(typeString);
+                       aulFormatCondition.Append(L'/');
+                       aulFormatCondition.Append(uriCode);             // The default value of 'uriCode' is '*'
+                }
+                else if ((tnfValue.CompareTo(L"ext") == 0)  || (tnfValue.CompareTo(L"uri") == 0))
+                {
+                       if (tnfValue.CompareTo(L"ext") == 0)
+                       {
+                               aulFormatCondition = L"NFC_SERVICE_EXTERNAL_TYPE:NULL:";
+                               // Convert all the letters to lower case.
+                               typeString.ToLowerCase();
+                       }
+                       else
+                       {
+                               aulFormatCondition = L"NFC_SERVICE_URI_TYPE:NULL:";
+                       }
+
+                       r = typeString.IndexOf(L':', 0, delimiterIndex);
+                       if (!IsFailed(r))
+                       {
+                               String uriScheme;
+
+                               // Extract the URI scheme from <type_string>.
+                               r = typeString.SubString(0, delimiterIndex, uriScheme);
+                               _NfcSysTryLogReturn(r == E_SUCCESS, null, "Parsing error.");
+
+                               // if the URI scheme is one of the registered keywords
+                               (void) uriSchemeMap.GetValue(uriScheme);
+                               r = GetLastResult();
+                               if (!IsFailed(r))
+                               {
+                                       aulFormatCondition.Append(uriScheme);
+                               }
+                               else
+                               {
+                                       aulFormatCondition.Append(L"unknown");
+                               }
+                       }
+                       else
+                       {
+                               aulFormatCondition.Append(L"unknown");
+                       }
+
+                       String encodedTypeString;
+
+                       // Encode <type_string> using UTF-8 encoding scheme.
+                       r = UrlEncoder::Encode(typeString, L"UTF-8", encodedTypeString);
+                       _NfcSysTryLogReturn(r == E_SUCCESS, null, "Failed to UTF-8 Encoding.");
+
+                       aulFormatCondition.Append(L'/');
+                       aulFormatCondition.Append(encodedTypeString);
+               }
+               else if (tnfValue.CompareTo(L"mime") == 0)
+               {
+                       typeString.ToLowerCase();
+
+                       aulFormatCondition = L"NFC_SERVICE_MIME_TYPE:NULL:";
+                       aulFormatCondition.Append(typeString);
+               }
+               else
+               {
+                       SysLog(NID_APP, "Illegal format (%ls) - Invalid TNF value", originalCondition.GetPointer() );
+                       return null;
+               }
+
+               pTranslatedCondition = _StringConverter::CopyToCharArrayN(aulFormatCondition);
+               _NfcSysTryLogReturn(pTranslatedCondition != null, null, "String conversion error.");
+
+               return pTranslatedCondition;
+       }
+
+private:
+       HashMap uriSchemeMap;
+};     //_NfcConditionHandler
+
+
+/////////////////////////////////////////////////////////////////////////
+//     All plugins must provide both a creation and a destruction function
+/////////////////////////////////////////////////////////////////////////
+extern "C"
+{
+_OSP_EXPORT_ _AppLaunchConditionHandlerBase*
+CreatePlugin(void)
+{
+    return new (std::nothrow) _NfcConditionHandler;
+}
+
+_OSP_EXPORT_ void
+DestroyPlugin(_AppLaunchConditionHandlerBase* p)
+{
+    delete p;
+}
+}//extern "C"
diff --git a/res/etc/rc.d/init.d/osp-app-service.sh b/res/etc/rc.d/init.d/osp-app-service.sh
new file mode 100755 (executable)
index 0000000..0788e20
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+OSP_DAEMON_NAME=osp-app-service
+OSP_DAEMON_APPID=aospd00043
+
+if [ ! -e /opt/share/.ospfirstboot ]
+then
+       if [ ! -e /opt/osp/system/data/package/package.db ]
+       then
+               /usr/etc/package-manager/backend/tpk -r /opt/apps
+       fi
+       /bin/touch /opt/share/.ospfirstboot
+fi
+
+case "$1" in
+       start)
+               echo "Starting OSP app-service"
+               /opt/apps/aospd00043/bin/osp-app-service &
+               ;;
+       stop)
+               echo "Stopping OSP app-service"
+               PID=`pidof $OSP_DAEMON_NAME`
+               if [ -n "$PID" ]; then
+                       kill $PID
+               fi
+               ;;
+       *)
+               echo "Usage: osp-app-service.sh {start|stop}" >&2
+               exit 3
+               ;;
+esac
+
diff --git a/src/AppService.cpp b/src/AppService.cpp
new file mode 100755 (executable)
index 0000000..ed8ba47
--- /dev/null
@@ -0,0 +1,567 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+#include <FAppPackageManager.h>
+
+#include <FBaseSysLog.h>
+#include <FApp_Aul.h>
+#include <FIo_RegistryImpl.h>
+#include <FSys_EnvironmentImpl.h>
+#include <FBase_StringConverter.h>
+
+#include "FApp_AppInfo.h"
+#include "FApp_AppManagerImpl.h"
+#include "FApp_AppControlManager.h"
+#include "FApp_CommunicationDispatcher.h"
+#include "FApp_ContextManager.h"
+#include "FApp_AppManagerStub.h"
+#include "FApp_ConditionManagerStub.h"
+#include "FSys_DeviceManagerService.h"
+#include "FSys_SystemService.h"
+#include "FSys_AccessoryManagerService.h"
+#include "FApp_PackageManagerStub.h"
+#include "FApp_NotificationManagerStub.h"
+#include "FApp_PackageManagerImpl.h"
+#include "AppService.h"
+
+
+using namespace Osp::Base;
+using namespace Osp::Base::Runtime;
+using namespace Osp::Base::Collection;
+using namespace Osp::Io;
+using namespace Osp::System;
+using namespace Osp::App;
+
+namespace
+{
+static const RequestId HANDLER_REQUEST_INSTALL_COMPLETE = 0;
+static const RequestId HANDLER_REQUEST_UNINSTALL_COMPLETE = 1;
+}
+
+
+AppService::AppService()
+: __pCommunicationDispatcher(null)
+, __pContextMgr(null)
+, __pAppManagerStub(null)
+, __pConditionManagerStub(null)
+, __handlerThread(*this)
+, __pDeviceManagerService(null)
+, __pSystemService(null)
+, __pAccessoryManagerService(null)
+, __pPackageManagerStub(null)
+, __pNotificationManagerStub(null)
+{
+       SysLog(NID_APP, "Enter.");
+
+       InitializeServices();
+
+       SysLog(NID_APP, "Exit.");
+}
+
+AppService::~AppService()
+{
+       SysLog(NID_APP, "Enter.");
+
+       _PackageManagerImpl::GetInstance()->RemoveEventListener(this);
+
+       delete __pAppManagerStub;
+       delete __pConditionManagerStub;
+       delete __pPackageManagerStub;
+       delete __pNotificationManagerStub;
+
+       delete __pContextMgr;
+
+       SysLog(NID_APP, "Exit.");
+}
+
+Service*
+AppService::CreateInstance(void)
+{
+       static AppService* pAppService = new (std::nothrow) AppService();
+
+       return pAppService;
+}
+
+bool
+AppService::OnAppInitializing(AppRegistry& appRegistry)
+{
+       SysLog(NID_APP, "Enter.");
+
+       result r = __handlerThread.Construct(THREAD_TYPE_EVENT_DRIVEN);
+       SysTryReturn(NID_APP, IsFailed(r) == false, false, r, "[%s] Event thread creation failure.", GetErrorMessage(r));
+
+       r = __handlerThread.Start();
+       SysTryReturn(NID_APP, IsFailed(r) == false, false, r, "[%s] Event thread Start failure.", GetErrorMessage(r));
+
+       SysLog(NID_APP, "Exit.");
+       return true;
+}
+
+bool
+AppService::OnAppInitialized(void)
+{
+       SysLog(NID_APP, "Enter.");
+
+       _Aul::SetPowerOffNotiListener(OnPowerOffNotiReceived, this);
+       _AppManagerImpl::GetInstance()->AddEventListener(*this);
+
+       LaunchChannelService();
+//     LaunchSystemServices();
+//     LaunchUserServices();
+//
+       SysLog(NID_APP, "Exit.");
+       return true;
+}
+
+void
+AppService::OnPowerOffNotiReceived(void* pData)
+{
+       SysLog(NID_APP, "'power_off_start' noti received from system-server with 0x%x.", pData);
+
+       AppService* pAppService = static_cast<AppService*>(pData);
+       if (pAppService)
+       {
+               SysLog(NID_APP, "osp-app-service is terminating now.");
+               pAppService->Terminate();
+       }
+}
+
+
+bool
+AppService::InitializeServices(void)
+{
+       SysLog(NID_APP, "Enter.");
+       result r = E_SUCCESS;
+
+       __pContextMgr = new (std::nothrow) _ContextManager();
+       SysAssert(__pContextMgr != null);
+       SysTryCatch(NID_APP, __pContextMgr != null,, E_OUT_OF_MEMORY, "failed to _ContextManager creation.");
+
+       r = __pContextMgr->Construct();
+       SysAssert(!IsFailed(r));
+       SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+       __pAppManagerStub = new (std::nothrow) _AppManagerStub();
+       SysAssert(__pAppManagerStub != null);
+       SysTryCatch(NID_APP, __pAppManagerStub != null,, E_OUT_OF_MEMORY, "failed to _AppManagerStub creation.");
+
+       r = __pAppManagerStub->Construct(__pContextMgr);
+       SysAssert(!IsFailed(r));
+       SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+       __pConditionManagerStub = new (std::nothrow) _ConditionManagerStub();
+       SysAssert(__pConditionManagerStub != null);
+       SysTryCatch(NID_APP, __pConditionManagerStub != null,, E_OUT_OF_MEMORY, "failed to _ConditionManagerStub creation.");
+
+       r = __pConditionManagerStub->Construct();
+       SysAssert(!IsFailed(r));
+       SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+       __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
+       SysAssert( __pConditionManagerStub != null);
+       SysTryCatch(NID_APP, __pCommunicationDispatcher != null,, E_OUT_OF_MEMORY, "failed to _CommunicationDispatcher creation.");
+
+//     __pDeviceManagerService = _DeviceManagerService::GetInstance();
+//     SysAssert( __pDeviceManagerService != null);
+//     SysTryCatch(NID_APP, __pDeviceManagerService != null,, E_OUT_OF_MEMORY, "failed to _DeviceManagerService creation.");
+
+       __pSystemService = _SystemService::GetInstance();
+       SysAssert( __pSystemService != null);
+       SysTryCatch(NID_APP, __pSystemService != null,, E_OUT_OF_MEMORY, "failed to _SystemService creation.");
+
+       __pAccessoryManagerService = _AccessoryManagerService::GetInstance();
+       SysAssert( __pAccessoryManagerService != null);
+       SysTryCatch(NID_APP, __pAccessoryManagerService != null,, E_OUT_OF_MEMORY, "failed to _AccessoryManagerService creation.");
+
+       __pPackageManagerStub = new (std::nothrow) _PackageManagerStub();
+       SysAssert(__pPackageManagerStub != null);
+       SysTryCatch(NID_APP, __pPackageManagerStub != null,, E_OUT_OF_MEMORY, "failed to _PackageManagerStub creation.");
+
+       r = __pPackageManagerStub->Construct();
+       SysAssert(!IsFailed(r));
+       SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+       __pNotificationManagerStub = new (std::nothrow) _NotificationManagerStub();
+       SysAssert(__pNotificationManagerStub != null);
+       SysTryCatch(NID_APP, __pNotificationManagerStub != null,, E_OUT_OF_MEMORY, "failed to _pNotificationManagerStub creation.");
+
+       r = __pNotificationManagerStub->Construct();
+       SysAssert(!IsFailed(r));
+       SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+
+       SysLog(NID_APP, "Exit.");
+       return true;
+
+CATCH:
+       SysLog(NID_APP, "Catch.");
+
+       delete __pConditionManagerStub;
+
+       delete __pAppManagerStub;
+
+       delete __pContextMgr;
+
+       delete __pPackageManagerStub;
+
+       delete __pNotificationManagerStub;
+
+       SysAssertf(false, "System services initializing is failed.");
+       return false;
+}
+
+bool
+AppService::LaunchSystemServices(void)
+{
+       const String systemServiceRegPath = L"configuration/system-services.ini";
+       const String regKeyAppId = L"AppId";
+       const String regKeyExecName = L"ServiceAppName";
+       const String regKeyLaunchOnBoot = L"LaunchOnBoot";
+
+       SysLog(NID_APP, "Enter.");
+       _RegistryImpl reg;
+       const String& systemPath = _EnvironmentImpl::GetSystemPath();
+
+       result r = reg.Construct(systemPath + systemServiceRegPath, REG_OPEN_READ_ONLY, false, 0);
+       //      SysTryReturn(NID_APP, !IsFailed(r), r, r, "");
+       if (IsFailed(r))
+       {
+               SysLog(NID_APP, "failed to open registry '%ls'", (systemPath + systemServiceRegPath).GetPointer());
+               return true;
+       }
+
+       IList *pSections = null;
+       reg.GetSectionListN(&pSections);
+       SysTryReturn(NID_APP,  pSections != null, false, E_SYSTEM, "[E_SYSTEM] GetSectionListN fails (%ls) ", systemServiceRegPath.GetPointer() );
+
+       String* pSecName = null;
+       String appIdValue;
+       String executableNameValue;
+       IEnumerator* pEnum = pSections->GetEnumeratorN();
+       SysTryCatch(NID_APP, pEnum != null, , E_SYSTEM, "[E_SYSTEM] pSections->GetEnumeratorN fails (%ls)", systemServiceRegPath.GetPointer() );
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               pSecName = static_cast<String*>(pEnum->GetCurrent());
+               if( pSecName != null)
+               {
+                       reg.GetValue(*pSecName, regKeyAppId, appIdValue);
+                       reg.GetValue(*pSecName, regKeyExecName, executableNameValue);
+
+                       if ( appIdValue == _AppInfo::GetAppId())// skip osp-app-service
+                       {
+                               continue;
+                       }
+
+                       int pid = _Aul::LaunchSystemService(appIdValue, executableNameValue );
+                       if (pid != -1)
+                       {
+                               SysLog(NID_APP, "System service(%ls.%ls) is launched as pid(%d).", appIdValue.GetPointer(), executableNameValue.GetPointer(), pid);
+//                             __pContextMgr->Register(appIdValue, executableNameValue, pid, pid, true);
+                       }
+                       else
+                       {
+                               SysLog(NID_APP, "Failed to launch System service(%ls.%ls).", appIdValue.GetPointer(), executableNameValue.GetPointer());
+                       }
+               }
+       }
+
+
+       delete pEnum;
+       pSections->RemoveAll(true);
+
+       SysLog(NID_APP, "Exit.");
+       return true;
+
+CATCH:
+       if( pSections )
+       {
+               pSections->RemoveAll(true);
+               delete pSections;
+       }
+       return false;
+}
+
+bool
+AppService::LaunchChannelService(void)
+{
+       SysLog(NID_APP, "Launching channel at first...");
+       return _Aul::LaunchSystemService(L"cp7ipabg4k", L"osp-channel-service" ) == E_SUCCESS;
+}
+
+bool
+AppService::LaunchUserServices(void)
+{
+       SysLog(NID_APP, "Enter.");
+
+       IList* pAppIdList_ForLaunchOnBoot = _PackageManagerImpl::GetInstance()->GetFilteredAppIdListN(L"LaunchOnBoot", L"True");
+       if (pAppIdList_ForLaunchOnBoot == null)
+       {
+               SysLog(NID_APP, "No launch-on-boot entry.");
+               return true;
+       }
+
+       result r = E_SUCCESS;
+       String* pPackageNameStr = null;
+       char* pPackageName = null;
+
+       for (int i = 0; i < pAppIdList_ForLaunchOnBoot->GetCount(); i++)
+       {
+               pPackageNameStr = dynamic_cast<String*>(pAppIdList_ForLaunchOnBoot->GetAt(i));
+               if (pPackageNameStr != null)
+               {
+                       pPackageName = _StringConverter::CopyToCharArrayN(*pPackageNameStr);
+
+                       SysLog(NID_APP, "'%ls'", pPackageNameStr->GetPointer()) ;
+                       r = _AppControlManager::GetInstance()->LaunchPkg(pPackageName, null, null, null, null, null);
+                       delete[] pPackageName;
+
+                       if(!IsFailed(r))
+                       {
+                               SysLog(NID_APP, "'%ls'is launched", pPackageNameStr->GetPointer()) ;
+                       }
+                       else
+                       {
+                               SysLog(NID_APP, "%s", GetErrorMessage(r) );
+                       }
+               }
+       }
+
+       pAppIdList_ForLaunchOnBoot->RemoveAll(true);
+       delete pAppIdList_ForLaunchOnBoot;
+
+       SysLog(NID_APP, "Exit.");
+       return !IsFailed(r);
+}
+
+bool
+AppService::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
+{
+
+       return true;
+}
+
+void
+AppService::OnLowMemory(void)
+{
+
+}
+
+void
+AppService::OnBatteryLevelChanged(BatteryLevel batteryLevel)
+{
+
+}
+
+void
+AppService::OnUserEventReceivedN(RequestId requestId, IList *pArgs)
+{
+       if( pArgs == null)
+       {
+               return;
+       }
+
+       String* pArg = null;
+       SysLog(NID_APP, "OnUserEventReceivedN() is called. RequestId = %d \n", requestId);
+
+       for (int i = 0; (pArg = static_cast<String*>(pArgs->GetAt(i))) != null; i++)
+       {
+               SysLog(NID_APP, "%ls", pArg->GetPointer());
+       }
+
+       pArgs->RemoveAll(true);
+       delete pArgs;
+}
+
+ArrayList*
+AppService::GetPackageEventArgsN(const AppId& appId, const String& packageName)
+{
+       ArrayList* pArray = new (std::nothrow) ArrayList;
+       SysTryReturn(NID_APP, pArray != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Array allocation failure.");
+
+       pArray->Construct();
+
+
+       String tmpExecName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
+       String tmpPackageName = L"org.tizen." + appId + "#" + tmpExecName;
+
+       String* pPackageName;
+       String* pAppId;
+       String* pExecName;
+
+       pPackageName = new (std::nothrow) String(tmpPackageName);
+       SysTryCatch(NID_APP, pPackageName != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] packageName %ls allocation failure.", packageName.GetPointer());
+       pArray->Add(*pPackageName);
+
+       pAppId = new (std::nothrow) String(appId);
+       SysTryCatch(NID_APP, pAppId != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppId %ls allocation failure.", appId.GetPointer());
+       pArray->Add(*pAppId);
+
+//     pExecName = new (std::nothrow) String(_ContextManager::_Util::GetExecNameFromPackageName(packageName));
+       pExecName = new (std::nothrow) String(tmpExecName);
+       SysTryCatch(NID_APP, pExecName != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
+       pArray->Add(*pExecName);
+
+       return pArray;
+
+CATCH:
+       pArray->RemoveAll(true);
+       delete pArray;
+
+       return null;
+}
+
+void
+AppService::OnPackageInstallationCompleted(PackageType type, const AppId& appId, const String& packageName, PackageErrorType errorType)
+{
+       SysLog(NID_APP, "Enter. appId(%ls), packageName(%ls)", appId.GetPointer(), packageName.GetPointer() );
+
+       ArrayList* pArray = GetPackageEventArgsN(appId, packageName);
+       SysTryReturnVoidResult(NID_APP, pArray != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetPackageEventArgsN failure.");
+
+       result r = __handlerThread.SendUserEvent(HANDLER_REQUEST_INSTALL_COMPLETE, pArray);
+       SysTryLog(NID_APP, !IsFailed(r), "[%s] Propagated.", GetErrorMessage(r));
+
+       SysLog(NID_APP, "Exit.");
+}
+
+void
+AppService::OnPackageUninstallationCompleted(PackageType type, const AppId& appId, const String& packageName, PackageErrorType errorType)
+{
+       SysLog(NID_APP, "Enter.");
+
+       ArrayList* pArray = GetPackageEventArgsN(appId, packageName);
+       SysTryReturnVoidResult(NID_APP, pArray != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] GetPackageEventArgsN failure.");
+
+       result r = __handlerThread.SendUserEvent(HANDLER_REQUEST_UNINSTALL_COMPLETE, pArray);
+       SysTryLog(NID_APP, !IsFailed(r), "[%s] Propagated.", GetErrorMessage(r));
+
+       SysLog(NID_APP, "Exit.");
+}
+
+void
+AppService::OnPackageInstallationInProgress(PackageType type, const AppId& appId, const String& packageName, int progress)
+{
+}
+
+
+void
+AppService::OnApplicationLaunched(const AppId& appId, const Osp::Base::String& executableName, Osp::App::AppType type)
+{
+       static bool channelServiceLaunched = false;
+       static bool securityServiceLaunched = false;
+
+       const String CHANNEL_SERVICE_APPID = L"cp7ipabg4k";
+       const String SECURITY_SERVICE_APPID = L"q7097a278m";
+
+       if( appId == CHANNEL_SERVICE_APPID && !channelServiceLaunched)
+       {
+               channelServiceLaunched = true;
+
+               LaunchSystemServices();
+               _PackageManagerImpl::GetInstance()->AddEventListener(this, 0);
+
+       }
+       else if( appId == SECURITY_SERVICE_APPID && !securityServiceLaunched)
+       {
+               securityServiceLaunched = true; // do this once.
+               _AppManagerImpl::GetInstance()->RemoveEventListener(*this);
+
+               LaunchUserServices();
+       }
+}
+
+void
+AppService::OnApplicationTerminated(const AppId& appId, const Osp::Base::String& executableName, Osp::App::AppType type)
+{
+       SysLog(NID_APP, "Do nothing.");
+}
+
+
+/*
+ * AppService::_TaskHandlerThread
+ */
+
+AppService::_TaskHandlerThread::_TaskHandlerThread(AppService& mgr)
+       : __mgr(mgr)
+{
+}
+
+AppService::_TaskHandlerThread::~_TaskHandlerThread(void)
+{
+}
+
+bool
+AppService::_TaskHandlerThread::OnStart(void)
+{
+       return true;
+}
+
+void
+AppService::_TaskHandlerThread::OnStop(void)
+{
+}
+
+void
+AppService::_TaskHandlerThread::OnUserEventReceivedN(RequestId reqId, IList* pArgs)
+{
+       SysLog(NID_APP, "Enter.");
+       SysTryReturnVoidResult(NID_APP, pArgs != null && pArgs->GetCount() == 3, E_INVALID_STATE, "Wrong argument delivered for install complete event.");
+
+       String* pPackageName= dynamic_cast<String*>( pArgs->GetAt(0) );
+       SysTryReturnVoidResult(NID_APP, pPackageName != null, E_INVALID_STATE, "Invalid packageName for install complete event.");
+
+       String* pAppId = dynamic_cast<String*>( pArgs->GetAt(1) );
+       SysTryReturnVoidResult(NID_APP, pAppId != null, E_INVALID_STATE, "Invalid appId for install complete event.");
+
+       String* pExecName= dynamic_cast<String*>( pArgs->GetAt(2) );
+       SysTryReturnVoidResult(NID_APP, pExecName != null, E_INVALID_STATE, "Invalid execName for install complete event.");
+
+       switch (reqId)
+       {
+       case HANDLER_REQUEST_INSTALL_COMPLETE:
+       {
+               String isLaunchOnBoot = _ContextManager::_Util::QueryFeatureFromPackageManager(*pAppId, *pExecName, L"LaunchOnBoot" );
+               if( isLaunchOnBoot == "True")
+               {
+                       result r = _AppManagerImpl::GetInstance()->LaunchApplication(*pAppId, pExecName, null, AppManager::LAUNCH_OPTION_DEFAULT);
+                       SysTryLog(NID_APP, !IsFailed(r), "%s", GetErrorMessage(r) );
+                       SysLog(NID_APP, "'%ls'is launched", pExecName->GetPointer()) ;
+               }
+
+               SysTryReturnVoidResult(NID_APP, __mgr.__pConditionManagerStub != null, E_INVALID_STATE, "Invalid condition manager stub for install complete event.");
+               __mgr.__pConditionManagerStub->OnInstallComplete(*pAppId, *pExecName, *pPackageName);
+       }
+               break;
+
+       case HANDLER_REQUEST_UNINSTALL_COMPLETE:
+       {
+               SysTryReturnVoidResult(NID_APP, __mgr.__pConditionManagerStub != null, E_INVALID_STATE, "Invalid condition manager stub for install complete event.");
+               __mgr.__pConditionManagerStub->OnUninstallComplete(*pAppId, *pExecName );
+       }
+               break;
+
+       default:
+               SysLog(NID_APP, "Wrong request Id for handler thread : 0x%x", reqId);
+               break;
+       }
+
+       pArgs->RemoveAll(true);
+       delete pArgs;
+
+       SysLog(NID_APP, "Exit.");
+}
+
diff --git a/src/AppServiceEntry.cpp b/src/AppServiceEntry.cpp
new file mode 100644 (file)
index 0000000..e5b560e
--- /dev/null
@@ -0,0 +1,62 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+#include <new>
+
+#include <FOspConfig.h>
+#include <FApp.h>
+#include "AppService.h"
+
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+
+_OSP_EXPORT_ int OspMain(int argc, char*pArgv[]);
+
+int
+OspMain(int argc, char* pArgv[])
+{
+       result r = E_SUCCESS;
+
+       AppLog("Application started.");
+       ArrayList* pArgs = new (std::nothrow) ArrayList();
+       pArgs->Construct();
+       for (int i = 0; i < argc; i++)
+       {
+               pArgs->Add(*(new (std::nothrow) String(pArgv[i])));
+       }
+
+       r = Osp::App::Service::Execute(AppService::CreateInstance, pArgs);
+       if (IsFailed(r))
+       {
+               AppLogException("Application execution failed - [%s].", GetErrorMessage(r));
+               r &= 0x0000FFFF;
+       }
+
+       pArgs->RemoveAll(true);
+       delete pArgs;
+       AppLog("Application finished.");
+
+       return static_cast<int>(r);
+}
+#ifdef __cplusplus
+}
+#endif // __cplusplus
diff --git a/src/FApp_AppManagerService.cpp b/src/FApp_AppManagerService.cpp
new file mode 100644 (file)
index 0000000..fa72294
--- /dev/null
@@ -0,0 +1,236 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_AppManagerService.cpp
+ * @brief      This is the implementation for the _AppManagerService class.
+ */
+
+#include <FBaseSysLog.h>
+#include <FApp_AppInfo.h>
+#include <FApp_Aul.h>
+#include <FApp_AppManagerEventArg.h>
+#include <FApp_IAppManagerServiceEventListener.h>
+
+#include "FApp_PackageManagerImpl.h"
+#include "FApp_ContextManager.h"
+#include "FApp_AppManagerService.h"
+
+
+using namespace Osp::Base;
+using namespace Osp::Io;
+using namespace Osp::Text;
+
+
+namespace Osp { namespace App {
+
+
+_AppManagerService::_AppManagerService(void)
+: __pContextMgr(null)
+, __pStub(null)
+, __pProxy(null)
+{
+       SysLog(NID_APP, "");
+}
+
+_AppManagerService::~_AppManagerService(void)
+{
+       SysLog(NID_APP, "");
+}
+
+result
+_AppManagerService::Construct(_ContextManager *pContextMgr, _IAppManagerServiceEventListener* pStub)
+{
+       SysTryReturnResult(NID_APP, pContextMgr != null, E_INVALID_ARG, "pContextMgr should not be null!");
+
+       SysLog(NID_APP, "Enter\n");
+       __pContextMgr = pContextMgr;
+       __pContextMgr->SetEventListener(*this);
+       __pStub = pStub;
+       __eventListeners.Construct();
+       SysLog(NID_APP, "Exit\n");
+
+       return E_SUCCESS;
+}
+
+
+///////////////////////////////////////////
+// stub implementations
+///////////////////////////////////////////
+
+result
+_AppManagerService::LaunchApplication(const AppId& appId, const String& executableName, int req)
+{
+       SysLog(NID_APP, "(appId:%ls, serviceId:%ls)", appId.GetPointer(), executableName.GetPointer());
+       return E_SUCCESS;
+}
+
+result
+_AppManagerService::TerminateApplication(const AppId& appId, const String& executableName)
+{
+       SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
+       SysTryReturnResult(NID_APP, __pStub != null, E_INVALID_STATE, "__pStub should not be null!");
+
+       SysTryReturnResult(NID_APP, appId.IsEmpty() == false, E_INVALID_ARG, "The appId is empty.")
+       SysTryReturnResult(NID_APP, appId.GetLength() < WIDGET_APP_MAX_APPID_LENGTH, E_MAX_EXCEEDED, "The appId is too long (Maximum %d bytes).", WIDGET_APP_MAX_APPID_LENGTH)
+       SysTryReturnResult(NID_APP, appId != _AppInfo::GetAppId(), E_INVALID_ARG, "This service can't be terminated.")
+       SysTryReturnResult(NID_APP, _PackageManagerImpl::IsAppInstalled(appId) == true, E_OBJ_NOT_FOUND, "The application(%ls) is not installed.", appId.GetPointer());
+
+       const _AppContext* pAppContext = __pContextMgr->Find(appId, executableName);
+       SysTryReturnResult(NID_APP, pAppContext != null, E_OBJ_NOT_FOUND, "can't find appId(%ls, %ls).", appId.GetPointer(), executableName.GetPointer());
+
+       SysLog(NID_APP, "trying aul_terminate_pid(appId:%ls, exec:%ls, pid:%d).", appId.GetPointer(), executableName.GetPointer(), pAppContext->pId );
+
+       return _Aul::TerminateApplicationByPid( pAppContext->pId );
+//     return __pStub->OnTerminateApplicationRequested(pAppContext->ipcClientId);
+}
+
+bool
+_AppManagerService::IsRunning(const AppId& appId, const String& executableName)
+{
+       SysTryReturnResult(NID_APP, appId.IsEmpty()==false, E_INVALID_ARG, "The appId is empty.")
+       SysTryReturnResult(NID_APP, appId.GetLength() < WIDGET_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The appId is too long (Maximum %d bytes).", WIDGET_APP_MAX_APPID_LENGTH)
+
+       return _Aul::IsRunning(appId, executableName);
+}
+
+result
+_AppManagerService::GetRunningAppList(Osp::Base::Collection::ArrayList* pArray)
+{
+       SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
+
+       return __pContextMgr->GetAppListN(pArray);
+}
+
+result
+_AppManagerService::RegisterApplication(const AppId& appId, const String& executableName, AppType appType, int pid)
+{
+       return RegisterApplication(appId, executableName, appType, pid, -1);
+}
+
+result
+_AppManagerService::RegisterApplication(const AppId& appId, const String& executableName, AppType appType, int pid, int clientId)
+{
+       if (_AppInfo::GetProcessId() == pid)
+       {
+               SysLog(NID_APP, "Service itself is registered.");
+       }
+       else
+       {
+               SysLog(NID_APP, "Sending event for %ls(%d).", appId.GetPointer(), pid);
+
+               _AppManagerEventArg arg(appId, executableName, appType, _AppManagerEvent::_APP_MANAGER_EVENT_LAUNCHED);
+               SendEventToAllListeners(arg);
+       }
+
+       SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
+       return __pContextMgr->Register(appId, executableName, appType, pid, clientId, true);
+}
+
+result
+_AppManagerService::UnregisterApplication(int pid)
+{
+       SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
+       return __pContextMgr->Unregister(pid);
+}
+
+
+//const _AppContext*
+//_AppManagerService::GetAppInfoSimple(const AppId& appId, const String* pExecutableName) const
+//{
+//     SysTryReturn(NID_APP, __pContextMgr != null, null, E_INVALID_STATE, "pContextMgr should not be null!");
+//
+//     return __pContextMgr->Find(appId, pExecutableName);
+//}
+
+result
+_AppManagerService::InitEventListener( _IAppManagerServiceEventListener* pListener)
+{
+       __pProxy = pListener;
+       return E_SUCCESS;
+}
+
+
+result
+_AppManagerService::AddEventListener(int clientId)
+{
+       return __eventListeners.Add(clientId, null);
+}
+
+result
+_AppManagerService::RemoveEventListener(int clientId)
+{
+       return __eventListeners.Remove(clientId);
+}
+
+void
+_AppManagerService::OnApplicationTerminated(const _AppContext& appInfo)
+{
+       SysLog(NID_APP, "Enter");
+       if ( appInfo.pId == _AppInfo::GetProcessId() )
+       {
+               SysLog(NID_APP, "Service itself is terminated.");
+               return;
+       }
+
+       RemoveEventListener(appInfo.ipcClientId);
+
+       _AppManagerEventArg arg(appInfo.appId, appInfo.executableName, appInfo.appType, _AppManagerEvent::_APP_MANAGER_EVENT_TERMINATED);
+       SendEventToAllListeners(arg);
+}
+
+result
+_AppManagerService::SendEventToAllListeners(const _AppManagerEventArg& arg)
+{
+       _AppManagerServiceEventListenerEnum* pEnum = __eventListeners.GetMapEnumeratorN();
+
+       result r = GetLastResult();
+       SysTryReturn(NID_APP, pEnum != null, r, r, "[%s] Propagated.", GetErrorMessage(r));
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               int clientId = -1;
+               r = pEnum->GetKey(clientId);
+               SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
+
+               _IAppManagerServiceEventListener* pListener = (clientId == -1) ? __pProxy : __pStub;
+
+               if ( pListener != null )
+               {
+                       SysLog(NID_APP, "Trying to SendResponse(%d)", clientId);
+                       r = pListener->OnServiceEventReceived(clientId, arg);
+                       SysTryLog(NID_APP, !IsFailed(r), "[%s] OnServiceEventReceived fails.", GetErrorMessage(r));
+//                     SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
+               }
+       }
+
+       delete pEnum;
+       return E_SUCCESS;
+
+CATCH:
+       delete pEnum;
+       return r;
+}
+
+void
+_AppManagerService::Dump(void)
+{
+       __pContextMgr->Dump();
+}
+
+
+}}//namespace Osp { namespace App {
diff --git a/src/FApp_AppManagerStub.cpp b/src/FApp_AppManagerStub.cpp
new file mode 100644 (file)
index 0000000..1519db2
--- /dev/null
@@ -0,0 +1,278 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_AppManagerStub.cpp
+ * @brief      This is the implementation for the _AppManagerStub class.
+ */
+
+#include <FBaseSysLog.h>
+#include <FIo_IpcServer.h>
+#include <FSec_AccessController.h>
+
+#include <FApp_AppManagerProxy.h>
+#include <FApp_AppManagerIpcMessage.h>
+
+#include "FApp_AppManagerService.h"
+#include "FApp_AppManagerStub.h"
+#include "FApp_ContextManager.h"
+
+
+using namespace Osp::Base;
+using namespace Osp::Io;
+using namespace Osp::Text;
+using namespace Osp::Security;
+
+
+namespace Osp { namespace App {
+
+
+_AppManagerStub::_AppManagerStub(void)
+:__pIpcServer(null),
+ __pAppManagerService(null)
+{
+       SysLog(NID_APP, "Enter\n");
+
+       SysLog(NID_APP, "Exit\n");
+}
+
+_AppManagerStub::~_AppManagerStub(void)
+{
+       SysLog(NID_APP, "Enter\n");
+
+       if ( __pIpcServer != null)
+       {
+               __pIpcServer->Stop();
+               delete __pIpcServer;
+       }
+
+       delete __pAppManagerService;
+
+       SysLog(NID_APP, "Exit\n");
+}
+
+result
+_AppManagerStub::Construct(_ContextManager *pContextMgr)
+{
+       SysTryReturnResult(NID_APP, pContextMgr != null, E_INVALID_ARG, "pContextMgr is null.");
+
+       SysLog(NID_APP, "Enter\n");
+
+       result r = E_SUCCESS;
+
+       __pAppManagerService = new (std::nothrow) _AppManagerService();
+       SysTryReturnResult(NID_APP, __pAppManagerService != null, E_OUT_OF_MEMORY, "Not enough memory.");
+
+       r = __pAppManagerService->Construct(pContextMgr, this);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __pAppManagerService->Construct. (%s)", GetErrorMessage(r) );
+
+       _AppManagerProxy::SetService(__pAppManagerService);
+
+       r = StartIpcServer();
+
+       SysLog(NID_APP, "Exit\n");
+
+       return r;
+}
+
+result
+_AppManagerStub::StartIpcServer(void)
+{
+       __pIpcServer = new (std::nothrow) _IpcServer();
+       SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
+
+       result r = __pIpcServer->Construct( "osp.app.ipcserver.appmanager", *this);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.appmanager");
+
+       return E_SUCCESS;
+
+CATCH:
+       delete __pIpcServer;
+       __pIpcServer = null;
+       return r;
+}
+
+
+// server to client message
+result
+_AppManagerStub::OnServiceEventReceived(const int clientId, const _AppManagerEventArg& arg)
+{
+//     SysLog(NID_APP, "appId:%ls, executableName:%ls, appType:%d", arg.GetAppId().GetPointer(), arg.GetName().GetPointer(), arg.GetAppType());
+       SysTryReturnResult(NID_APP, __pIpcServer != null, E_INVALID_STATE, "__pIpcServer is null.");
+
+       result r = __pIpcServer->SendResponse(clientId, new AppManager_OnEventReceived(arg));
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+
+       return E_SUCCESS;
+}
+
+result
+_AppManagerStub::OnTerminateApplicationRequested(int clientId)
+{
+       SysTryReturnResult(NID_APP, __pIpcServer != null, E_INVALID_STATE, "__pIpcServer is null.");
+
+       result r = __pIpcServer->SendResponse(clientId, new AppManager_OnTerminateApplicationRequested());
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+
+       return E_SUCCESS;
+}
+
+
+/////////////////////////////////////////////
+// handlers
+/////////////////////////////////////////////
+
+bool
+_AppManagerStub::OnLaunchApplication(const AppId& appId, const String& execName, int req)
+{
+       SysTryCatch(NID_APP, __pAppManagerService != null, , E_INVALID_STATE, "__pAppManagerService is null!");
+
+       SysLog(NID_APP, "(appId:%ls)", appId.GetPointer());
+
+       __pAppManagerService->LaunchApplication(appId, execName, req);
+
+CATCH:
+       return true;
+}
+
+bool
+_AppManagerStub::OnTerminateApplication(const AppId& appId, const String& execName, result *pRes)
+{
+       SysTryCatch(NID_APP, __pAppManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pAppManagerService is null!");
+
+       SysLog(NID_APP, "(appId:%ls, %ls)", appId.GetPointer(), execName.GetPointer());
+
+       // APPLICATION_MANAGER
+       *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPLICATION_MANAGER);
+       SysTryReturn(NID_APP, !IsFailed(*pRes), true, *pRes, "The application does not have the privilege to call this method.");
+
+       *pRes = __pAppManagerService->TerminateApplication(appId, execName);
+
+CATCH:
+       return true;
+}
+
+bool
+_AppManagerStub::OnIsRunning(const AppId& appId, const String& execName, bool *pRes)
+{
+       SysTryCatch(NID_APP, __pAppManagerService != null, *pRes = false, E_INVALID_STATE, "__pAppManagerService is null!");
+
+       SysLog(NID_APP, "_AppManagerStub::IsRunning(%ls, %ls)", appId.GetPointer(), execName.GetPointer());
+       *pRes = __pAppManagerService->IsRunning(appId, execName);
+
+CATCH:
+       return true;
+}
+
+bool
+_AppManagerStub::OnGetRunningAppList(Osp::Base::Collection::ArrayList* pArray, result *pRes)
+{
+       SysTryReturn(NID_APP, pArray != null, E_INVALID_ARG, E_INVALID_ARG, "pArray shoud not be null!");
+       SysTryCatch(NID_APP, __pAppManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pAppManagerService is null!");
+       SysLog(NID_APP, "");
+
+       *pRes = __pAppManagerService->GetRunningAppList(pArray);
+
+CATCH:
+       return true;
+}
+
+bool
+_AppManagerStub::OnRegisterApplication(const AppId& appId, const String& executableName, int appType, int pid)
+{
+       SysTryCatch(NID_APP, __pAppManagerService != null, , E_INVALID_STATE, "__pAppManagerService is null!");
+       SysLog(NID_APP, "_AppManagerStub::RegisterApplication(appId:%ls, pid:%d)\n", appId.GetPointer(), pid);
+
+       __pAppManagerService->RegisterApplication(appId, executableName, static_cast<AppType>(appType), pid, __pIpcServer->GetClientId());
+
+CATCH:
+       return true;
+}
+
+bool
+_AppManagerStub::OnUnregisterApplication(int pid)
+{
+       SysTryCatch(NID_APP, __pAppManagerService != null, , E_INVALID_STATE, "__pAppManagerService is null!");
+       SysLog(NID_APP, "_AppManagerStub::UnregisterApplication(pid:%d)\n", pid);
+       __pAppManagerService->UnregisterApplication(pid);
+
+CATCH:
+       return true;
+}
+
+bool
+_AppManagerStub::OnAddEventListener(int pid)
+{
+       SysTryReturn(NID_APP, __pIpcServer != null, true, E_INVALID_STATE, "__pIpcServer should not be null!");
+
+       __pAppManagerService->AddEventListener(__pIpcServer->GetClientId());//, this);
+       return true;
+}
+
+bool
+_AppManagerStub::OnRemoveEventListener(int pid)
+{
+       SysTryReturn(NID_APP, __pIpcServer != null, true, E_INVALID_STATE, "__pIpcServer should not be null!");
+
+       __pAppManagerService->RemoveEventListener(__pIpcServer->GetClientId());//, this);
+       return true;
+}
+
+
+void
+_AppManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+       SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+       IPC_BEGIN_MESSAGE_MAP(_AppManagerStub, message)
+               IPC_MESSAGE_HANDLER_EX(AppManager_LaunchApplication, &server, OnLaunchApplication)
+               IPC_MESSAGE_HANDLER_EX(AppManager_TerminateApplication, &server, OnTerminateApplication)
+               IPC_MESSAGE_HANDLER_EX(AppManager_IsRunning, &server, OnIsRunning)
+               IPC_MESSAGE_HANDLER_EX(AppManager_GetRunningAppList, &server, OnGetRunningAppList)
+               IPC_MESSAGE_HANDLER_EX(AppManager_RegisterApplication, &server, OnRegisterApplication)
+               IPC_MESSAGE_HANDLER_EX(AppManager_UnregisterApplication, &server, OnUnregisterApplication)
+               IPC_MESSAGE_HANDLER_EX(AppManager_AddEventListener, &server, OnAddEventListener)
+               IPC_MESSAGE_HANDLER_EX(AppManager_RemoveEventListener, &server, OnRemoveEventListener)
+       IPC_END_MESSAGE_MAP()
+}
+
+void
+_AppManagerStub::OnIpcServerStarted(const _IpcServer& server)
+{
+//     SysLog(NID_APP, "\n");
+}
+
+void
+_AppManagerStub::OnIpcServerStopped(const _IpcServer& server)
+{
+//     SysLog(NID_APP, "\n");
+}
+
+void
+_AppManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
+{
+//     SysLog(NID_APP, "(clientId:%d)\n", clientId);
+}
+
+void
+_AppManagerStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
+{
+//     SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
+}
+
+
+}}//namespace Osp { namespace App {
diff --git a/src/FApp_CommunicationDispatcher.cpp b/src/FApp_CommunicationDispatcher.cpp
new file mode 100644 (file)
index 0000000..6f2d09d
--- /dev/null
@@ -0,0 +1,556 @@
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_CommunicationDispatcher.cpp
+ * @brief      This is the implementation file for _CommunicationDispatcher class.
+ *
+ */
+
+#include <new>
+#include <FApp_AppManagerImpl.h>
+#include <FIo_IpcServer.h>
+#include <FIo_AppServiceIpcMessages.h>
+#include "FApp_CommunicationDispatcher.h"
+
+using namespace Osp::Io;
+using namespace Osp::App;
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+
+namespace
+{
+       const String COMMUNICATION_DISPATCHER_IPC_ID = L"osp.app.ipcserver.communicationdispatcher";
+       const String COMMUNICATION_MUTEX_ID = L"osp.app.ipcserver.communicationdispatcher";
+}
+
+typedef struct communicationListener
+{
+       _ICommunicationRequestListener* requestListener;
+       struct communicationListener* prev;
+       struct communicationListener* next;
+}listener;
+
+communicationListener* gp_CommunicationListener = null;
+_CommunicationDispatcher* gp_CommunicationDispatcher = null;
+
+void
+ReleaseCommunicationListener(void)
+{
+       communicationListener* pIter = gp_CommunicationListener;
+       communicationListener* pTemp = null;
+
+       while (pIter != null)
+       {
+               pTemp = pIter;
+               pIter = pIter->next;
+               free(pTemp);
+       }
+       gp_CommunicationListener = null;
+}
+
+communicationListener*
+GetCommunicationListener(String key)
+{
+       communicationListener* pIter = gp_CommunicationListener;
+       if (pIter == null)
+       {
+               return null;
+       }
+
+       while (pIter != null)
+       {
+               if (pIter->requestListener != null)
+               {
+                       StringComparer strComparer;
+                       int cmp = 0;
+                       strComparer.Compare(pIter->requestListener->GetId(), key, cmp);
+                       if (cmp == 0)
+                       {
+                               return pIter;
+                       }
+               }
+               pIter = pIter->next;
+       }
+       return null;
+}
+
+bool
+AddCommunicationListener(_ICommunicationRequestListener* pListener)
+{
+       if (pListener == null)
+       {
+               return false;
+       }
+
+       if (GetCommunicationListener(pListener->GetId()) == null)
+       {
+               communicationListener* pTemp = (communicationListener*)malloc(sizeof(communicationListener));
+               SysTryReturn(NID_APP, pTemp != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
+
+               memset(pTemp, 0, sizeof(communicationListener));
+               pTemp->requestListener = pListener;
+
+               if (gp_CommunicationListener == null)
+               {
+                       gp_CommunicationListener = pTemp;
+               }
+               else
+               {
+                       communicationListener* pIter = gp_CommunicationListener;
+
+                       while (pIter->next != null)
+                       {
+                               pIter = pIter->next;
+                       }
+                       pIter->next = pTemp;
+                       pTemp->prev = pIter;
+               }
+               return true;
+       }
+       return false;
+}
+
+bool
+RemoveCommunicationListener(_ICommunicationRequestListener* pListener)
+{
+       if (pListener == null)
+       {
+               return false;
+       }
+       communicationListener* pIter = GetCommunicationListener(pListener->GetId());
+
+       if (pIter == null)
+       {
+               return false;
+       }
+
+       if (pIter == gp_CommunicationListener)
+       {
+               gp_CommunicationListener = pIter->next;
+               free(pIter);
+       }
+       else
+       {
+               pIter->prev->next = pIter->next;
+               pIter->next->prev = pIter->prev;
+       }
+       return true;
+}
+
+_CommunicationDispatcher::_CommunicationDispatcher()
+: __pIpcServer(null)
+, __pRegisteredAppList(null)
+, __pAppManagerImpl(null)
+{
+       result r = E_SUCCESS;
+
+       __currentAppId= "";
+       __currentClientId.value = 0;
+
+       __pIpcServer = new (std::nothrow) _IpcServer();
+       r = __pIpcServer->Construct(COMMUNICATION_DISPATCHER_IPC_ID, *this);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to IPC server initialize. [%s] Propaged.", r);
+
+       r = __pIpcServer->Start();
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to start IPC server. [%s] Propaged.", r);
+
+       __pRegisteredAppList = new (std::nothrow) ArrayList();
+       r =__pRegisteredAppList->Construct();
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to create registered app list. [%s] Propaged.", r);
+
+       r = __Mutex.Create(COMMUNICATION_MUTEX_ID);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to create mutex. [%s] Propaged.", r);
+
+       __pAppManagerImpl = _AppManagerImpl::GetInstance();
+       SysTryCatch(NID_APP, __pAppManagerImpl != null, r = E_SYSTEM, r, "Failed to get _AppManagerImpl instance");
+
+       r = __pAppManagerImpl->AddEventListener(*this);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to add event listener. [%s] Propaged.", r);
+
+CATCH:
+       SetLastResult(r);
+}
+
+_CommunicationDispatcher::~_CommunicationDispatcher()
+{
+       result r = E_SUCCESS;
+       r = __pIpcServer->Stop();
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to stop IPC server. [%s] Propaged.", r);
+
+       r = __Mutex.Release();
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to release mutex. [%s] Propaged.", r);
+
+       r = __pAppManagerImpl->RemoveEventListener(*this);
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "Failed to remove event listener. [%s] Propaged.", r);
+
+       ReleaseCommunicationListener();
+
+CATCH:
+       delete __pIpcServer;
+
+       __pRegisteredAppList->RemoveAll(true);
+       delete __pRegisteredAppList;
+
+       SetLastResult(r);
+}
+
+_CommunicationDispatcher*
+_CommunicationDispatcher::GetInstance()
+{
+       if (gp_CommunicationDispatcher == null)
+       {
+               gp_CommunicationDispatcher = new (std::nothrow) _CommunicationDispatcher();
+       }
+
+       return gp_CommunicationDispatcher;
+}
+
+Integer*
+_CommunicationDispatcher::GetClientId(const AppId& appId, const String& componentId) const
+{
+       int index = 0;
+       int numOfAppList = 0;
+       SysLog(NID_APP, "AppId: %ls, ComponentId %ls", appId.GetPointer(), componentId.GetPointer());
+       SysTryCatch(NID_APP, __pRegisteredAppList != null, , E_SYSTEM, "Registered app list is not ready");
+       numOfAppList = __pRegisteredAppList->GetCount();
+
+       while (index < numOfAppList)
+       {
+               AppId* currentAppId = null;
+               currentAppId = (AppId*)__pRegisteredAppList->GetAt(index);
+               if (currentAppId != null)
+               {
+                       StringComparer strComparer;
+                       int cmp = 0;
+
+                       strComparer.Compare(appId, *currentAppId, cmp);
+                       if (cmp == 0)
+                       {
+                               String* currentComponentId = (String*)__pRegisteredAppList->GetAt(index+1);
+                               if (currentComponentId != null)
+                               {
+                                       strComparer.Compare(componentId, *currentComponentId, cmp);
+                                       if (cmp == 0)
+                                       {
+                                               SysLog(NID_APP, "Registered information is found.");
+
+                                               Integer* pClientId = (Integer*)__pRegisteredAppList->GetAt(index+2);
+                                               if (pClientId != null)
+                                               {
+                                                       return pClientId;
+                                               }
+                                       }
+                               }
+                       }
+
+               }
+               index += 3;
+       }
+       SysLog(NID_APP, "There is no registered information.");
+CATCH:
+       return null;
+}
+
+result
+_CommunicationDispatcher::RemoveClientId(AppId appId)
+{
+       int index = 0;
+       int numOfAppList = 0;
+       SysTryCatch(NID_APP, __pRegisteredAppList != null, , E_SYSTEM, "Registered app list is not ready");
+       numOfAppList = __pRegisteredAppList->GetCount();
+
+       while (index < numOfAppList)
+       {
+               AppId* currentAppId = null;
+
+               currentAppId = (AppId*)__pRegisteredAppList->GetAt(index);
+               if (currentAppId != null)
+               {
+                       StringComparer strComparer;
+                       int cmp = 0;
+
+                       strComparer.Compare(appId, *currentAppId, cmp);
+                       if (cmp == 0)
+                       {
+                               SysLog(NID_APP, "Registered information is found.");
+                               __pRegisteredAppList->RemoveAt(index+2, true);
+                               __pRegisteredAppList->RemoveAt(index+1, true);
+                               __pRegisteredAppList->RemoveAt(index, true);
+                               index -= 3;
+                               numOfAppList -= 3;
+                       }
+
+               }
+               index += 3;
+       }
+       SysLog(NID_APP, "There is no registered information.");
+CATCH:
+       return null;
+}
+
+result
+_CommunicationDispatcher::RemoveClientId(AppId appId, String componentId)
+{
+       int index = 0;
+       int numOfAppList = 0;
+       SysTryCatch(NID_APP, __pRegisteredAppList != null, , E_SYSTEM, "Registered app list is not ready");
+       numOfAppList = __pRegisteredAppList->GetCount();
+
+       while (index < numOfAppList)
+       {
+               AppId* currentAppId = null;
+               currentAppId = (AppId*)__pRegisteredAppList->GetAt(index);
+               if (currentAppId != null)
+               {
+                       StringComparer strComparer;
+                       int cmp = 0;
+
+                       strComparer.Compare(appId, *currentAppId, cmp);
+                       if (cmp == 0)
+                       {
+                               String* currentComponentId = (String*)__pRegisteredAppList->GetAt(index+1);
+                               if (currentComponentId != null)
+                               {
+                                       strComparer.Compare(componentId, *currentComponentId, cmp);
+                                       if (cmp == 0)
+                                       {
+                                               SysLog(NID_APP, "Registered information is found.");
+                                               __pRegisteredAppList->RemoveAt(index+2, true);
+                                               __pRegisteredAppList->RemoveAt(index+1, true);
+                                               __pRegisteredAppList->RemoveAt(index, true);
+                                       }
+                               }
+                       }
+
+               }
+               index += 3;
+       }
+       SysLog(NID_APP, "There is no registered information.");
+CATCH:
+       return null;
+}
+
+result
+_CommunicationDispatcher::RemoveClientId(AppId appId, String componentId, Integer clientId)
+{
+       int index = 0;
+       int numOfAppList = 0;
+       SysTryCatch(NID_APP, __pRegisteredAppList != null, , E_SYSTEM, "Registered app list is not ready");
+       numOfAppList = __pRegisteredAppList->GetCount();
+
+       while (index < numOfAppList)
+       {
+               AppId* currentAppId = null;
+               currentAppId = (AppId*)__pRegisteredAppList->GetAt(index);
+               if (currentAppId != null)
+               {
+                       StringComparer strComparer;
+                       int cmp = 0;
+
+                       strComparer.Compare(appId, *currentAppId, cmp);
+                       if (cmp == 0)
+                       {
+                               String* currentComponentId = (String*)__pRegisteredAppList->GetAt(index+1);
+                               if (currentComponentId != null)
+                               {
+                                       strComparer.Compare(componentId, *currentComponentId, cmp);
+                                       if (cmp == 0)
+                                       {
+                                               SysLog(NID_APP, "Registered information is found.");
+                                               Integer* pClientId = (Integer*)__pRegisteredAppList->GetAt(index+2);
+                                               if (pClientId != null)
+                                               {
+                                                       if (pClientId->value == clientId.value)
+                                                       {
+                                                               __pRegisteredAppList->RemoveAt(index+2, true);
+                                                               __pRegisteredAppList->RemoveAt(index+1, true);
+                                                               __pRegisteredAppList->RemoveAt(index, true);
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+
+               }
+               index += 3;
+       }
+       SysLog(NID_APP, "There is no registered information.");
+CATCH:
+       return null;
+}
+
+result
+_CommunicationDispatcher::AddClientId(AppId appId, String componentId, Integer clientId)
+{
+       Integer* currentClientId = null;
+
+       SysTryReturnResult(NID_APP, __pRegisteredAppList != null,  E_SYSTEM, "Registered app list is not ready");
+
+       currentClientId = GetClientId(appId, componentId);
+       SysTryReturnResult(NID_APP, currentClientId == null, E_KEY_ALREADY_EXIST, "This is already registered. AppId: %ls, ComponentId: %ls, ClientId: %d", appId.GetPointer(), componentId.GetPointer(), clientId.value);
+
+       SysLog(NID_SYS, "AppId: %ls, ComponentId: %ls, ClientId: %d", appId.GetPointer(), componentId.GetPointer(), clientId.value);
+
+       AppId* pAppId = new (std::nothrow) AppId(appId);
+       String* pComponentId = new (std::nothrow) String(componentId);
+       Integer* pClientId = new (std::nothrow) Integer();
+       pClientId->value = clientId.value;
+
+       __pRegisteredAppList->Add(*pAppId);
+       __pRegisteredAppList->Add(*pComponentId);
+       __pRegisteredAppList->Add(*pClientId);
+
+       return E_SUCCESS;
+}
+
+result
+_CommunicationDispatcher::SendData(const Osp::App::AppId appId, ArrayList& data)
+{
+       Integer* clientId = null;
+       result r = E_SUCCESS;
+       String* communicationId = null;
+
+       SysTryReturnResult(NID_APP, __pRegisteredAppList != null, E_SYSTEM, "_CommunicationDispatcher is not ready");
+
+       communicationId = (String*)data.GetAt(0);
+       SysTryReturnResult(NID_APP, communicationId != null, E_SYSTEM, "There is no communicationId");
+
+       clientId = GetClientId(appId, *communicationId);
+
+       SysLog(NID_APP, "ClientId: %d", clientId->ToInt());
+
+       if (clientId!=null)
+       {
+               int client = clientId->ToInt();
+               //IpcServer Send
+               r = __pIpcServer->SendResponse(client, new (std::nothrow) IoService_Data(data));
+
+               if (r != E_SUCCESS)
+               {
+                       SysLog(NID_APP, "Send Result %s.", GetErrorMessage(r));
+                       return r;
+               }
+               return E_SUCCESS;
+       }
+       return E_OBJ_NOT_FOUND;
+}
+
+void
+_CommunicationDispatcher::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+       __Mutex.Acquire();
+       SysLog(NID_APP, "Start");
+       SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+       __currentAppId = server.GetClientAppId();
+       __currentClientId.value = server.GetClientId();
+
+       IPC_BEGIN_MESSAGE_MAP(_CommunicationDispatcher, message)
+               IPC_MESSAGE_HANDLER_EX(IoService_Request, &server, OnRequestOccured)
+       IPC_END_MESSAGE_MAP_EX()
+       SysLog(NID_APP, "End");
+       __Mutex.Release();
+}
+
+bool
+_CommunicationDispatcher::OnRequestOccured(const Osp::Base::Collection::ArrayList& request, Osp::Base::Collection::ArrayList* response)
+{
+       SysLog(NID_APP, "Application is requested by IPC, currentAppId is %ls", __currentAppId.GetPointer());
+
+       String* componentId = (String*)request.GetAt(0);
+       _ICommunicationRequestListener* plistener = null;
+
+       if (componentId == null)
+       {
+               SysLog(NID_APP, "there is no componentId");
+       }
+
+       if (componentId != null)
+       {
+               AddClientId(__currentAppId, *componentId, __currentClientId);
+               SysLog(NID_APP, "Requested componentId is %ls", componentId->GetPointer());
+
+               communicationListener* pTemp =  GetCommunicationListener(*componentId);
+
+               if (pTemp != null)
+               {
+                       plistener = pTemp->requestListener;
+
+                       if (plistener!=null)
+                       {
+                               plistener->OnRequestOccured(__currentAppId, const_cast <ArrayList*> (&request), response);
+                       }
+               }
+               else
+               {
+                       SysLog(NID_APP, "Requested module is not exist.");
+               }
+       }
+
+       return true;
+}
+
+result
+_CommunicationDispatcher::AddCommunicationEventListener(_ICommunicationRequestListener& listener)
+{
+       bool added = false;
+       added = AddCommunicationListener(&listener);
+       SysLog(NID_APP, "%ls", listener.GetId().GetPointer());
+       SysTryReturnResult(NID_APP, added == true, E_KEY_ALREADY_EXIST, "listner is already registed for key [%ld]", listener.GetId().GetPointer());
+
+       return E_SUCCESS;
+}
+
+result
+_CommunicationDispatcher::RemoveCommunicationEventListener(_ICommunicationRequestListener& listener)
+{
+       bool removed = false;
+       removed = RemoveCommunicationListener(&listener);
+       SysTryReturnResult(NID_APP, removed == true, E_KEY_NOT_FOUND, "listner is already registed for key [%ld]", listener.GetId().GetPointer());
+
+       return E_SUCCESS;
+}
+
+void
+_CommunicationDispatcher::OnApplicationLaunched(const AppId& appId, const String& executableName, AppType type)
+{
+}
+
+void
+_CommunicationDispatcher::OnApplicationTerminated(const AppId& appId, const String& executableName, AppType type)
+{
+       SysLog(NID_APP, "App[%ls, %ls] terminate event is forwarded", appId.GetPointer(), executableName.GetPointer());
+
+       __Mutex.Acquire();
+       communicationListener* pIter = gp_CommunicationListener;
+       SysLog(NID_APP, "App[%ls, %ls] terminate event is forwarded", appId.GetPointer(), executableName.GetPointer());
+
+       RemoveClientId(appId);
+
+       while (pIter != null)
+       {
+               if (pIter->requestListener != null)
+               {
+                       SysLog(NID_APP, "listener is [%ls]", pIter->requestListener->GetId().GetPointer());
+                       pIter->requestListener->OnApplicationTerminated(appId, executableName, type);
+               }
+               pIter = pIter->next;
+       }
+       __Mutex.Release();
+}
+
+
diff --git a/src/FApp_ConditionHandler.cpp b/src/FApp_ConditionHandler.cpp
new file mode 100644 (file)
index 0000000..ce7b917
--- /dev/null
@@ -0,0 +1,323 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+//
+// 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.
+//
+
+/**
+ * @file        FApp_ConditionHandler.cpp
+ * @brief      This is the implementation for the _ConditionHandler class.
+ */
+
+#include <unistd.h>
+#include <cstdio>
+
+#include <FBaseRtLibrary.h>
+#include <FAppApp.h>
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FIo_DirectoryImpl.h>
+#include <FApp_AppManagerImpl.h>
+#include <FApp_AppControlManager.h>
+
+#include "FApp_ConditionHandler.h"
+
+namespace Osp { namespace App {
+
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Io;
+
+_ConditionHandler::_ConditionHandler(const String& fileName, const String& types)
+: __typesString(types)
+, __pluginFileName(fileName)
+, __pPluginInstance(null)
+, __pLib(null)
+, __pfDestroyPlugin(null)
+{
+       SysLog(NID_APP, "%ls, %ls", fileName.GetPointer(), types.GetPointer() );
+}
+
+_ConditionHandler::~_ConditionHandler()
+{
+       SysLog(NID_APP, "Enter");
+       if (__pfDestroyPlugin != null && __pPluginInstance != null)
+       {
+               __pfDestroyPlugin(__pPluginInstance);
+               __pfDestroyPlugin = null;
+               __pPluginInstance = null;
+       }
+
+       delete __pLib;
+
+       SysLog(NID_APP, "Exit");
+}
+//#define FILENAME_MAX 2048
+
+result
+_ConditionHandler::Construct()
+{
+       SysLog(NID_APP, "Enter");
+
+       result r = LoadPlugin();
+    __conditionalOperations.Construct( 16, 0.75f, __strHashMapProvider, __strComparer);
+
+    SysLog(NID_APP, "Exit");
+    return r;
+}
+
+result
+_ConditionHandler::LoadPlugin(void)
+{
+       char filePath[FILENAME_MAX];
+       char* pFileName = _StringConverter::CopyToCharArrayN(__pluginFileName);
+       create_plugin pfCreatePlugin = null;
+       result r = E_SUCCESS;
+
+       String dataPath = App::GetInstance()->GetAppRootPath() + L"data";
+       snprintf( filePath, FILENAME_MAX, "%ls/%s", dataPath.GetPointer(), pFileName);
+       delete[] pFileName;
+
+       if (access(filePath, F_OK) != 0) // for uts-app
+       {
+               dataPath.Clear();
+               pFileName = _StringConverter::CopyToCharArrayN(__pluginFileName);
+               r = _AppManagerImpl::GetAppRootPath(L"aospd00043", dataPath);
+               snprintf(filePath, FILENAME_MAX, "%ls/%s", dataPath.GetPointer(), pFileName);
+               delete[] pFileName;
+               SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM,
+                               "[E_SYSTEM] osp-app-service should be installed.");
+
+               dataPath.Append(L"data");
+       }
+
+       __pLib = new (std::nothrow) Runtime::Library();
+       r = __pLib->Construct(filePath);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "dlopen fails (%s)", GetErrorMessage(r) );
+
+       pfCreatePlugin = (create_plugin)__pLib->GetProcAddress(L"CreatePlugin");
+       __pfDestroyPlugin = (destroy_plugin)__pLib->GetProcAddress(L"DestroyPlugin");
+       SysTryCatch(NID_APP, pfCreatePlugin != null && __pfDestroyPlugin != null, r = E_FAILURE, E_FAILURE, "failed to get symbols," );
+
+       __pPluginInstance = pfCreatePlugin();
+       SysTryCatch(NID_APP, __pPluginInstance != null, r = E_FAILURE, E_FAILURE, "pfCreatePlugin fails" );
+
+       __pPluginInstance->SetEventListener(*this);
+
+       return E_SUCCESS;
+
+CATCH:
+       SysLog(NID_APP, "CATCH:");
+       delete __pLib;
+       __pLib = null;
+       __pfDestroyPlugin = null;
+       return r;
+}
+
+result
+_ConditionHandler::CreateUniqueId(String& uniqueId)
+{
+       int index = 0;//TODO: improve algorithm
+       String candidateSectionName(__pluginFileName);
+       while( index < Integer::VALUE_MAX)
+       {
+               candidateSectionName.Format(1024, L"%ls_%d",__pluginFileName.GetPointer(), index );
+               if (FindItemBySectionName(candidateSectionName) == null)
+               {
+                       uniqueId.Clear();
+                       uniqueId.Append(candidateSectionName);
+                       return E_SUCCESS;
+               }
+               index++;
+       }
+
+       return E_OVERFLOW;
+}
+
+result
+_ConditionHandler::AddCondition( _AppLaunchCondition& operation)
+{
+       SysTryReturnResult(NID_APP, __pPluginInstance != null, E_INVALID_STATE, "" );
+
+       //TODO
+       String condition = operation.GetConditionString();
+       if (HasCondition(operation.GetAppId(), operation.GetExecutableName(), &condition))
+               return E_OBJ_ALREADY_EXIST;
+
+       result r = __pPluginInstance->Register(operation);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] failed to register", GetErrorMessage(r) );
+
+       String uniqueId;
+       if (operation.__regSectionName.IsEmpty())
+       {
+               CreateUniqueId(uniqueId);
+               operation.__regSectionName = uniqueId;
+               _ConditionRegistryHelper::AddToRegistry(uniqueId, operation.GetAppId(), operation.GetExecutableName(), operation.GetConditionString(), operation.__pArguments );
+       }
+       else
+       {
+               // from registry conditional-operations.ini
+               uniqueId = operation.__regSectionName;
+       }
+
+       __conditionalOperations.Add(operation.GetConditionString(), &operation);
+       SysLog(NID_APP, "AppLaunchCondition item count (%d)", __conditionalOperations.GetCount());
+
+       return E_SUCCESS;
+}
+
+result
+_ConditionHandler::RemoveCondition(const AppId& appId, const String& executableName, const String* pCondition)
+{
+//     SysLog(NID_APP,"appId(%ls), executableName(%ls), condition(%ls)", appId.GetPointer(), executableName.GetPointer(), (pCondition) ? pCondition->GetPointer() : L"" );
+
+       SysTryReturnResult(NID_APP, __pPluginInstance != null, E_INVALID_STATE, "" );
+
+       bool found = false;
+
+       IListT<_AppLaunchCondition*>* pValues = __conditionalOperations.GetValuesN();
+       SysTryReturn(NID_APP, pValues != null, GetLastResult(), GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
+
+       result r = E_SUCCESS;
+       for (int i = 0; i< pValues->GetCount(); i++)
+       {
+               String uniqueId;
+
+               _AppLaunchCondition *pOperation = null;
+               r = pValues->GetAt(i, pOperation);
+               SysTryCatch(NID_APP, pOperation != null, , r, "[%s] Propagated.", GetErrorMessage(r) );
+
+               if ( pOperation->GetAppId() == appId && pOperation->GetExecutableName() == executableName &&
+                               (pCondition == null || *pCondition == pOperation->GetConditionString()) )
+               {
+                       SysLog(NID_APP,"Trying to unregister appId(%ls), executableName(%ls), condition(%ls)", appId.GetPointer(), executableName.GetPointer(), pOperation->GetConditionString().GetPointer() );
+                       r = __pPluginInstance->Unregister(*pOperation);//, const_cast<Object*>(pOperation->pHandle));
+                       SysTryCatch(NID_APP, !IsFailed(r), delete pOperation, r, "[%s] failed to Unregister(%ls, %ls)", GetErrorMessage(r), appId.GetPointer(), pOperation->GetConditionString().GetPointer() );//TBC
+//                     SysTryLog(NID_APP, !IsFailed(r), "[%s] failed to Unregister(%ls, %ls)", GetErrorMessage(r), appId.GetPointer(), pOperation->GetCondition().GetPointer() );//TBC
+                       _ConditionRegistryHelper::RemoveFromRegistry(pOperation->__regSectionName);
+
+                       r = __conditionalOperations.Remove(pOperation->GetConditionString(), pOperation);
+                       SysLogException(NID_APP, !IsFailed(r), "[%s]", GetErrorMessage(r));
+
+                       delete pOperation;
+                       if ( pCondition != null)
+                       {
+                               pValues->RemoveAll();
+                               delete pValues;
+                               return E_SUCCESS;
+                       }
+                       else
+                       {
+                               found = true;
+                               // loop next
+                       }
+               }
+       }
+
+       return (found) ? E_SUCCESS : E_OBJ_NOT_FOUND;
+
+CATCH:
+       pValues->RemoveAll();
+       delete pValues;
+       return r;
+}
+
+
+//TODO: argument?
+bool
+_ConditionHandler::HasCondition(const AppId& appId, const String& executableName, const String *pCondition) const
+{
+       IListT<_AppLaunchCondition*>* pList = __conditionalOperations.GetValuesN();
+       SysTryReturn(NID_APP, pList != null, false, GetLastResult(), "[%s] Propagated. ", GetLastResult());
+
+       result r = E_SUCCESS;
+       for (int i = 0; i < pList->GetCount(); i++)
+       {
+               _AppLaunchCondition *pOperation = null;
+               r = pList->GetAt(i, pOperation);
+               SysTryCatch(NID_APP, pOperation != null, , r, "[%s] Propagated.", GetErrorMessage(r));
+
+               if (pOperation->GetAppId() == appId && pOperation->GetExecutableName() == executableName
+                               && ( pCondition == null || pOperation->GetConditionString() == *pCondition) )
+               {
+                       return true;
+               }
+       }
+
+CATCH:
+       delete pList;
+       return false;
+}
+
+bool
+_ConditionHandler::CanHandleType(const String& type ) const
+{
+       return __typesString.Contains(type);
+}
+
+_AppLaunchCondition*
+_ConditionHandler::FindItemBySectionName(const String& sectionName) const
+{
+       IListT<_AppLaunchCondition*>* pValues = __conditionalOperations.GetValuesN();
+       SysTryReturn(NID_APP, pValues != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
+
+       result r = E_SUCCESS;
+       for (int i = 0; i< pValues->GetCount(); i++)
+       {
+               _AppLaunchCondition *pOperation = null;
+               r = pValues->GetAt(i, pOperation);
+               if ( !IsFailed(r) && pOperation->__regSectionName == sectionName)
+               {
+                       return pOperation;
+               }
+       }
+       return null;
+}
+
+void
+_ConditionHandler::OnAppLaunchConditionMet(const _AppLaunchCondition& operation)
+{
+       SysLog(NID_APP, "Enter");
+
+       result r  = _AppControlManager::GetInstance()->LaunchAppWithCondition(operation.GetAppId(), operation.GetExecutableName(), operation.GetConditionString(), operation.__pArguments );
+       SysTryLog(NID_APP, !IsFailed(r), "[%ls] LaunchApplication failed.", GetErrorMessage(r));
+
+       SysLog(NID_APP, "Exit");
+}
+
+void
+_ConditionHandler::Dump(void) const
+{
+       SysLog(NID_APP, "[%ls]", this->__pluginFileName.GetPointer() );
+
+//     result r = E_SUCCESS;
+//     _AppLaunchConditionEnumerator* pEnum =__conditionalOperations.GetMapEnumeratorN();
+//     SysTryReturnVoidResult(NID_APP, pEnum != null, GetLastResult(), "[%s]", GetErrorMessage(GetLastResult()));
+//
+//     while( pEnum->MoveNext() == E_SUCCESS )
+//     {
+//             _AppLaunchCondition *pOperation = null;
+//             r = pEnum->GetValue(pOperation);
+//             SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
+//             SysTryCatch(NID_APP, pOperation != null, , r, "[%s] Propagated.", GetErrorMessage(r));
+//
+//             SysLog(NID_APP, "appId:%ls, condition:%ls, uniqueId:%ls", pOperation->__appId.GetPointer(), pOperation->GetConditionString().GetPointer(), pOperation->__regSectionName.GetPointer() );
+//     }
+//
+//CATCH:
+//     delete pEnum;
+}
+
+
+}} // Osp::App
diff --git a/src/FApp_ConditionManagerService.cpp b/src/FApp_ConditionManagerService.cpp
new file mode 100644 (file)
index 0000000..8b8bf09
--- /dev/null
@@ -0,0 +1,609 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+//
+// 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.
+//
+
+/**
+ * @file        FApp_ConditionManagerService.cpp
+ * @brief      This is the implementation for the _ConditionManagerService class.
+ */
+#include <cstdio>
+
+#include <FIoDirectory.h>
+#include <FIoRegistry.h>
+#include <FAppApp.h>
+
+#include <FBaseSysLog.h>
+#include <FIo_RegistryImpl.h>
+
+#include "FApp_Types.h"
+#include "FApp_PackageManagerImpl.h"
+#include "FApp_ConditionHandler.h"
+#include "FApp_ConditionManagerService.h"
+
+
+namespace Osp { namespace App {
+
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Io;
+
+namespace
+{
+       const String REGISTRY_FILE_PLUGIN = L"data/app-launch-condition-handlers.ini";
+       const String REG_KEY_KEY = L"Key";
+       const String REG_KEY_FILENAME = L"Filename";
+
+       const String REGISTRY_FILE_OPERATIONS = L"data/app-launch-conditions.ini";
+       const String REG_KEY_APPID = L"AppId";
+       const String REG_KEY_EXENAME = L"ExecutableName";
+       const String REG_KEY_CONDTION = L"Condition";
+       const String REG_KEY_LAUNCH_TYPE = L"LaunchType";
+       const String REG_KEY_ARG_COUNT = L"ArgCount";
+       const String REG_KEY_ARG = L"Arg";
+
+       const int MAX_LEN_ARG = 1024;
+       const int MAX_LEN_CONDITION = 400;
+}
+
+
+_ConditionManagerService::_ConditionManagerService()
+{
+       SysLog(NID_APP, "Enter");
+       SysLog(NID_APP, "Exit");
+}
+
+_ConditionManagerService::~_ConditionManagerService()
+{
+       SysLog(NID_APP, "Enter");
+       result r = E_SUCCESS;
+
+       _ConditionHandler* pHandler = null;
+       for (int i =0; i < __handlers.GetCount(); i ++)
+       {
+               pHandler = null;
+               r = __handlers.GetAt(i, pHandler);
+               delete pHandler;
+       }
+       __handlers.RemoveAll();
+
+       SysLog(NID_APP, "Exit");
+}
+
+result
+_ConditionManagerService::Construct(void)
+{
+       SysLog(NID_APP,"Enter.");
+
+       result r = E_SUCCESS;
+
+       r = __handlers.Construct();
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __handlers.Construct.(%s)", GetErrorMessage(r) );
+
+       r = __handlerLookupTable.Construct( 16, 0.75f, __strHashMapProvider, __strComparer);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __handlerLookupTable.Construct.(%s)", GetErrorMessage(r) );
+
+       r = InitializePlugins();
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to InitializePlugins.(%s)", GetErrorMessage(r) );
+
+       r = InitializeConditionalOperations();
+       SysTryLog(NID_APP, !IsFailed(r), "failed to InitializeLaunchConditions.(%s)", GetErrorMessage(r) );
+
+       SysLog(NID_APP,"Exit.");
+       return E_SUCCESS;
+}
+
+result
+_ConditionManagerService::InitializePlugins(void)
+{
+       SysLog(NID_APP,"Enter.");
+       _RegistryImpl reg;
+       const String& homePath = App::GetInstance()->GetAppRootPath();
+
+       result r = reg.Construct(homePath + REGISTRY_FILE_PLUGIN, REG_OPEN_READ_ONLY , false, 0);
+       if (IsFailed(r))
+       {
+               SysLog(NID_APP, "failed to open registry '%ls' (%s)", (homePath + REGISTRY_FILE_PLUGIN).GetPointer(), GetErrorMessage(r) );
+               return E_SUCCESS;
+       }
+
+       IList *pSections = null;
+       r = reg.GetSectionListN(&pSections);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to GetSectionListN. (%s)", GetErrorMessage(r) );
+
+       IEnumerator* pEnum = pSections->GetEnumeratorN();
+       String* pSecName = null;
+
+       IMap* pMap = null;
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               pSecName = static_cast<String*>(pEnum->GetCurrent());
+               pSecName->Trim();
+
+               pMap = reg.GetAllEntriesN(*pSecName);
+               SysTryCatch(NID_APP, pMap != null, , E_SYSTEM, "");// try next
+
+               r = InitializePluginEntry(*pMap);
+               if ( r == E_OBJ_NOT_FOUND)
+               {
+                       // empty statement
+               }
+               else
+               {
+                       SysTryCatch(NID_APP, !IsFailed(r), , r, "");
+               }
+
+               pMap->RemoveAll(true);
+               delete pMap;
+       }
+
+       pSections->RemoveAll(true);
+
+       SysLog(NID_APP,"Exit.");
+       return E_SUCCESS;
+
+CATCH:
+       SysLog(NID_APP,"Catch.");
+       pSections->RemoveAll(true);
+
+       return r;
+}
+
+result
+_ConditionManagerService::InitializePluginEntry(IMap& map)
+{
+       result r = E_SUCCESS;
+
+       const String* pTypes = static_cast<const String*>(map.GetValue(REG_KEY_KEY));
+       const String* pFilename = static_cast<const String*>(map.GetValue(REG_KEY_FILENAME));
+       _ConditionHandler * pHandler = null;
+
+       SysTryReturn(NID_APP, pTypes != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pTypes is null");
+       SysTryReturn(NID_APP, pFilename != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pFilename is null");
+
+       Utility::StringTokenizer strTok(*pTypes, L',');
+       String type;
+
+       pHandler = new (std::nothrow) _ConditionHandler(*pFilename, *pTypes);
+       SysTryReturn(NID_APP, pHandler != null, E_FAILURE, E_FAILURE, "failed to new _ConditionHandler(%ls, %ls).", pFilename->GetPointer(), pTypes->GetPointer() );
+
+       r = pHandler->Construct();
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "failed to pHandler->Construct. (%s)", GetErrorMessage(r) );
+
+       __handlers.Add(pHandler);
+
+
+       if ( strTok.GetTokenCount() == 0)
+       {
+               __handlerLookupTable.Add(*pTypes, pHandler);
+       }
+       else
+       {
+               while ( strTok.GetNextToken(type) == E_SUCCESS)
+               {
+                       type.Trim();
+                       __handlerLookupTable.Add(type, pHandler);
+               }
+       }
+
+       SysLog(NID_APP, "%ls is loaded.", pFilename->GetPointer() );
+
+       return E_SUCCESS;
+
+CATCH:
+       SysLog(NID_APP, "CATCH:");
+       delete pHandler;
+       return r;
+}
+
+// condinfo.ini
+result
+_ConditionManagerService::InitializeConditionalOperations(void)
+{
+       SysLog(NID_APP,"Enter.");
+       _RegistryImpl reg;
+       String homePath = App::GetInstance()->GetAppRootPath();
+
+       result r = reg.Construct(homePath + REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_ONLY, false, 0);
+//     SysTryReturn(NID_APP, !IsFailed(r), r, r, "");
+       if ( IsFailed(r))
+       {
+               SysLog(NID_APP, "failed to open registry '%ls'", (homePath + REGISTRY_FILE_OPERATIONS).GetPointer());
+               return E_SUCCESS;
+       }
+
+       IList *pSections = null;
+       reg.GetSectionListN(&pSections );
+
+       IEnumerator*    pEnum = pSections->GetEnumeratorN();
+       String* pSecName = null;
+
+       IMap* pMap = null;
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               pSecName = static_cast<String*>(pEnum->GetCurrent());
+               pSecName->Trim();
+
+               pMap = reg.GetAllEntriesN(*pSecName);
+               SysTryCatch(NID_APP, pMap != null, r = E_INVALID_FORMAT, E_INVALID_FORMAT, "failed to GetAllEntryNamesN(%ls)", pSecName->GetPointer() );
+
+               r = InitializeConditionalOperationEntry(*pSecName, *pMap);
+               SysTryLog(NID_APP, !IsFailed(r), "failed to InitializeConditionalOperationEntry(%ls), but ignored.", pSecName->GetPointer() );
+
+               pMap->RemoveAll(true);
+               delete pMap;
+
+               pMap = null;
+       }
+
+       r = E_SUCCESS;
+
+CATCH:
+       delete pEnum;
+
+       pSections->RemoveAll(true);
+       delete pSections;
+
+       SysLog(NID_APP,"Exit.");
+       return r;
+}
+
+result
+_ConditionManagerService::InitializeConditionalOperationEntry(const String& sectionName, const IMap& map)
+{
+       String appId;
+       String executableName;
+       String condition;
+       ArrayList* pArgs = null;
+
+       result r =      _ConditionRegistryHelper::GetAllParamsN(map, appId, executableName, condition, pArgs);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] appId(%ls), condition(%ls) is failed to register.", GetErrorMessage(r), appId.GetPointer(), condition.GetPointer() );
+
+       r = RegisterAppLaunch( appId, executableName, condition, pArgs, AppManager::LAUNCH_OPTION_DEFAULT, &sectionName);
+       SysTryLog(NID_APP, !IsFailed(r), "[%s] appId(%ls), condition(%ls) is failed to register.", GetErrorMessage(r), appId.GetPointer(), condition.GetPointer() );
+
+       if (pArgs != null)
+       {
+               pArgs->RemoveAll(true);
+               delete pArgs;
+       }
+       return r;
+
+//CATCH:
+//     // remove invalid conditions.
+//     _ConditionRegistryHelper::RemoveFromRegistry(sectionName);
+//     return r;
+}
+
+_ConditionHandler*
+_ConditionManagerService::GetHandlerByCondition(const String& condition)
+{
+       Osp::Base::Utility::StringTokenizer strTok(condition, L"=");
+       SysTryReturn(NID_APP, strTok.GetTokenCount() > 0, null, E_INVALID_ARG, "Condition string is invalid.(%ls)", condition.GetPointer() );
+
+       String key;
+       result r = strTok.GetNextToken(key);
+       SysTryReturn(NID_APP, !IsFailed(r), null, E_INVALID_ARG, "[%s](%ls)", GetErrorMessage(r), condition.GetPointer() );
+
+       _ConditionHandler* pHandler = null;
+       r = __handlerLookupTable.GetValue(key, pHandler);
+       SysTryReturn(NID_APP, !IsFailed(r), null, E_INVALID_ARG, "[%s](%ls)", GetErrorMessage(r), key.GetPointer() );
+
+       return pHandler;
+}
+
+///////////////////////////////////////////
+// stub implementations
+///////////////////////////////////////////
+
+void
+_ConditionManagerService::DumpArguments(const IList* pArguments)
+{
+       if (pArguments != null)
+       {
+               const String* pArg = null;
+               for(int i = 0; i < pArguments->GetCount(); i ++)
+               {
+                       pArg = dynamic_cast<const String*>(pArguments->GetAt(i));
+                       if (pArg != null)
+                       {
+                               SysLog(NID_APP, "argument%d :  %ls", i, pArg->GetPointer());
+                       }
+               }
+       }
+}
+
+result
+_ConditionManagerService::RegisterAppLaunch(const AppId& appId, const String& executableName, const Osp::Base::String& condition, const Osp::Base::Collection::IList* pArguments, AppManager::LaunchOption option, const String* pRegSectionName)
+{
+       SysTryReturnResult(NID_APP, appId.IsEmpty()==false, E_INVALID_ARG, "The appId is empty.");
+
+       const String& exeName = (executableName.IsEmpty()) ? _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId) : executableName;
+
+       result r = E_SUCCESS;
+       SysTryReturnResult(NID_APP, exeName.IsEmpty()==false, E_INVALID_ARG, "The appId is empty.");
+       SysTryReturnResult(NID_APP, appId.GetLength() < WIDGET_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The appId is too long (Maximum %d bytes).", WIDGET_APP_MAX_APPID_LENGTH);
+       SysTryReturnResult(NID_APP, condition.IsEmpty()==false, E_INVALID_ARG, "The launch condition is empty or too long (Maximum %d bytes).", MAX_LEN_CONDITION);
+       SysTryReturnResult(NID_APP, condition.GetLength() < MAX_LEN_CONDITION, E_INVALID_ARG, "The launch condition is empty or too long (Maximum %d bytes).", MAX_LEN_CONDITION);
+       //SysTryReturnResult(NID_APP, _PackageManagerImpl::IsAppInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer()); client side due to negative test.
+       SysTryReturn(NID_APP, pArguments == null || (r = ValidateArguments(pArguments)) == E_SUCCESS, r, r, "[%s]", GetErrorMessage(r));
+
+       SysLog(NID_APP,"appId(%ls), executableName(%ls), condition(%ls)", appId.GetPointer(), executableName.GetPointer(), condition.GetPointer() );
+       if (pArguments != null)
+       {
+               DumpArguments(pArguments);
+       }
+
+       _ConditionHandler* pHandler = this->GetHandlerByCondition(condition);
+       SysTryReturnResult(NID_APP, pHandler != null, E_INVALID_ARG, "failed to GetHandlerByCondition(%ls)", condition.GetPointer() );
+
+       _AppLaunchCondition* pAppLaunchCondition = new (std::nothrow) _AppLaunchCondition();
+       SysTryReturnResult(NID_APP, pAppLaunchCondition != null, E_OUT_OF_MEMORY, "failed to create pAppLaunchCondition");
+
+       r = pAppLaunchCondition->Construct(appId, exeName, condition, pArguments, option, pRegSectionName );
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "failed to pAppLaunchCondition->Constructor");
+
+       r = pHandler->AddCondition(*pAppLaunchCondition);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s]", GetErrorMessage(r));
+
+       SysLog(NID_APP, "SUCCESSED.");
+       return E_SUCCESS;
+
+CATCH:
+       delete pAppLaunchCondition;
+       if ( r == E_OBJ_ALREADY_EXIST )
+       {
+               SysLog(NID_APP, "[E_OBJ_ALREADY_EXIST] AddCondition failed but, it's ignored.");
+               return E_SUCCESS;
+       }
+       return r;
+}
+
+result
+_ConditionManagerService::ValidateArguments(const IList* pArguments) const
+{
+       int totalArgumentsLen = 0;
+       for (int i = 0; i< pArguments->GetCount(); i ++)
+       {
+               const String* pArg = dynamic_cast<const String*>(pArguments->GetAt(i));
+               SysTryReturnResult(NID_APP, pArg != null, E_SYSTEM , "A system error has occurred.");
+
+               totalArgumentsLen += pArg->GetLength();
+       }
+       SysTryReturnResult(NID_APP, totalArgumentsLen < MAX_LEN_ARG, E_MAX_EXCEEDED, "The size of pArguments(%d) has exceeded the maximum limit(%d).", totalArgumentsLen, MAX_LEN_ARG);
+       return E_SUCCESS;
+}
+
+
+result
+_ConditionManagerService::UnregisterAppLaunch(const AppId& appId, const String& executableName, const Osp::Base::String* pCondition)
+{
+       SysTryReturnResult(NID_APP, _PackageManagerImpl::IsAppInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
+       String exeName = ( executableName.IsEmpty())? _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId) : executableName;
+
+       SysLog(NID_APP,"appId(%ls), executableName(%ls), condition(%ls)", appId.GetPointer(), exeName.GetPointer(), (pCondition) ? pCondition->GetPointer() : L"" );
+
+       if ( pCondition == null)
+       {
+               if (__handlers.GetCount() == 0) return E_OBJ_NOT_FOUND;
+
+               result r = E_SUCCESS;
+               _ConditionHandler* pHandler = null;
+               for (int i =0; i < __handlers.GetCount(); i ++)
+               {
+                       pHandler = null;
+                       r = __handlers.GetAt(i, pHandler);
+                       SysTryReturn(NID_APP, pHandler != null, r, r, "[%s]", GetErrorMessage(r) );
+                       pHandler->RemoveCondition(appId, exeName, null);
+               }
+
+               return E_SUCCESS;
+       }
+       else
+       {
+               _ConditionHandler* pHandler = GetHandlerByCondition(*pCondition);
+               SysTryReturnResult(NID_APP, pHandler != null, E_OBJ_NOT_FOUND, "");
+
+               return pHandler->RemoveCondition(appId, exeName, pCondition);
+       }
+
+       SysLog(NID_APP, "FAILED.");
+       return E_FAILURE;// NEVER_GET_HERE
+}
+
+bool
+_ConditionManagerService::IsAppLaunchRegistered(const AppId& appId, const String& executableName, const Osp::Base::String* pCondition)
+{
+//     SysTryReturnResult(NID_APP, _PackageManagerImpl::IsAppInstalled(appId) == true, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
+
+       ClearLastResult();
+       String exeName = ( executableName.IsEmpty())? _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId) : executableName;
+
+       if (pCondition == null)
+       {
+               result r = E_SUCCESS;
+               _ConditionHandler* pHandler = null;
+               for (int i =0; i < __handlers.GetCount(); i ++)
+               {
+                       pHandler = null;
+                       r = __handlers.GetAt(i, pHandler);
+                       SysTryReturn(NID_APP, pHandler != null, r, r, "[%s]", GetErrorMessage(r) );
+                       if ( pHandler->HasCondition(appId, exeName, null) == true)
+                       {
+                               return true;
+                       }
+               }
+       }
+       else
+       {
+               _ConditionHandler* pHandler = GetHandlerByCondition(*pCondition);
+               SysTryReturn(NID_APP, pHandler != null, false, E_INVALID_ARG, "[E_INVALID_ARG]");
+
+               return pHandler->HasCondition(appId, exeName, pCondition);
+       }
+
+       return false;
+}
+
+
+///////////////////////////////////////////
+// internal helper
+///////////////////////////////////////////
+//TODO: save arguments
+result
+_ConditionRegistryHelper::AddToRegistry(const String& sectionName, const AppId& appId, const String& executableName, const String& condition, const IList *pArg)
+{
+       _RegistryImpl reg;
+
+       result r = reg.Construct(App::GetInstance()->GetAppRootPath() + REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_WRITE | REG_OPEN_CREATE, false, 0);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "%s", GetErrorMessage(r) );
+
+//     String name = String(appId) + String(condition);
+       r = reg.AddSection(sectionName);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] sectionName : %ls", GetErrorMessage(r), sectionName.GetPointer() );
+
+       r = reg.AddValue(sectionName, REG_KEY_APPID, appId);
+       r = reg.AddValue(sectionName, REG_KEY_EXENAME, executableName);
+       r = reg.AddValue(sectionName, REG_KEY_CONDTION, condition);
+       r = reg.AddValue(sectionName, REG_KEY_LAUNCH_TYPE, L"");
+
+       if (pArg != null)
+       {
+               String value = Integer::ToString(pArg->GetCount());
+               r = reg.AddValue(sectionName, REG_KEY_ARG_COUNT, value );
+
+               const String* pCurArg = null;
+               String key;
+               for( int i = 0; i< pArg->GetCount(); i ++)
+               {
+                       pCurArg = dynamic_cast<const String*>(pArg->GetAt(i));
+                       if (pCurArg != null)
+                       {
+                               key = REG_KEY_ARG + Integer::ToString(i);
+                               r = reg.AddValue(sectionName, key, *pCurArg);
+                       }
+               }
+       }
+
+       r = reg.Flush();
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "%s", GetErrorMessage(r) );
+
+       SysLog(NID_APP, "ConditionInfo is added to registry. [%ls] appid=%ls, condition=%ls, lunchType=none", sectionName.GetPointer(), appId.GetPointer(), condition.GetPointer() );
+
+       return E_SUCCESS;
+
+CATCH:
+       return r;
+}
+
+result
+_ConditionRegistryHelper::RemoveFromRegistry(const String &section)
+{
+       _RegistryImpl reg;
+       result r = reg.Construct(App::GetInstance()->GetAppRootPath() + REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_WRITE, false, 0);
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "%s", GetErrorMessage(r) );
+
+       r = reg.RemoveSection(section);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "%s", GetErrorMessage(r) );
+
+       r = reg.Flush();
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "%s", GetErrorMessage(r) );
+
+       SysLog(NID_APP, "Removed. [%ls]", section.GetPointer() );
+       return E_SUCCESS;
+
+CATCH:
+       return r;
+}
+
+result
+_ConditionRegistryHelper::GetAllParamsN(const IMap& map, String& appId, String& executableName, String& condition, ArrayList*& pArgs)
+{
+       const String*   pAppId = static_cast<const String*>(map.GetValue(REG_KEY_APPID));
+       const String*   pExeName = static_cast<const String*>(map.GetValue(REG_KEY_EXENAME));
+       const String*   pCondition = static_cast<const String*>(map.GetValue(REG_KEY_CONDTION));
+       //      const String*   pLaunchMode = static_cast<const String*>(map.GetValue(REG_KEY_LAUNCH_TYPE));
+       SysTryReturn(NID_APP, pAppId != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pAppId is null");
+       SysTryReturn(NID_APP, pCondition != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "registry value is invalid. pCondition is null");
+
+       const String*   pArgCount = static_cast<const String*>(map.GetValue(REG_KEY_ARG_COUNT));
+       if (pArgCount != null)
+       {
+               int argCount;
+               Integer::Parse(*pArgCount, argCount);
+               if (argCount > 0)
+               {
+                       String key;
+                       const String*   pValue = null;
+                       pArgs = new ArrayList();
+                       pArgs->Construct();
+                       for (int i = 0; i< argCount; i++)
+                       {
+                               key = REG_KEY_ARG + Integer::ToString(i);
+                               pValue = dynamic_cast<const String*>(map.GetValue(key));
+                               SysTryCatch(NID_APP,  pValue != null, , GetLastResult(), "failed to get '%ls'.", key.GetPointer() );
+                               pArgs->Add(*new String(*pValue));
+                       }
+               }
+       }
+
+       appId = *pAppId;
+       condition = *pCondition;
+       if (pExeName)
+       {
+               executableName = *pExeName;
+       }
+       return E_SUCCESS;
+
+CATCH:
+       if (pArgs != null)
+       {
+               pArgs->RemoveAll(true);
+       }
+       delete pArgs;
+       pArgs = null;
+
+       return E_FAILURE;
+}
+
+
+//bool
+//_ConditionRegistryHelper::ContainsSectionName(const String& sectionName)
+//{
+//     _RegistryImpl reg;
+//
+//     result r = reg.Construct(REGISTRY_FILE_OPERATIONS, REG_OPEN_READ_ONLY, false, 0);
+//     SysTryReturn(NID_APP, !IsFailed(r), r, r, "%s", GetErrorMessage(r) );
+//     return ( reg.GetSectionIndex(sectionName) >= 0);
+//}
+
+void
+_ConditionManagerService::Dump(void) const
+{
+//     result r = E_SUCCESS;
+//     _ConditionHandler* pHandler = null;
+//     for (int i =0; i < __handlers.GetCount(); i ++)
+//     {
+//             pHandler = null;
+//             r = __handlers.GetAt(i, pHandler);
+//             SysTryReturnVoidResult(NID_APP, pHandler != null, r, "[%s]", GetErrorMessage(r) );
+//             pHandler->Dump();
+//     }
+}
+
+
+}} //namespace Osp { namespace App {
diff --git a/src/FApp_ConditionManagerStub.cpp b/src/FApp_ConditionManagerStub.cpp
new file mode 100644 (file)
index 0000000..b6c79fd
--- /dev/null
@@ -0,0 +1,328 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+//
+// 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.
+//
+
+/**
+ * @file        FApp_ConditionManagerStub.cpp
+ * @brief      This is the implementation for the _ConditionManagerStub class.
+ */
+#include <cstdio>
+#include <dlfcn.h>
+
+#include <FSec_AccessController.h>
+
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FIo_IpcServer.h>
+#include <FApp_PackageManagerImpl.h>
+#include <FApp_ConditionManagerIpcMessages.h>
+#include "FApp_ConditionManagerService.h"
+#include "FApp_ConditionManagerStub.h"
+
+
+namespace Osp { namespace App {
+
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Io;
+using namespace Osp::Security;
+
+
+///////////////////////////////////////////
+// _ConditionManagerStub
+///////////////////////////////////////////
+
+_ConditionManagerStub::_ConditionManagerStub()
+       :__pIpcServer(null)
+       ,__pConditionManagerService(null)
+{
+       SysLog(NID_APP, "Enter\n");
+       SysLog(NID_APP, "Exit\n");
+}
+
+_ConditionManagerStub::~_ConditionManagerStub()
+{
+       SysLog(NID_APP, "Enter\n");
+
+       if ( __pIpcServer != null)
+       {
+               __pIpcServer->Stop();
+               delete __pIpcServer;
+       }
+
+       SysLog(NID_APP, "Exit\n");
+}
+
+result
+_ConditionManagerStub::Construct(void)
+{
+       SysLog(NID_APP, "Enter.");
+
+       __pConditionManagerService = new (std::nothrow) _ConditionManagerService();
+
+       result r = E_SUCCESS;
+       r = __pConditionManagerService->Construct();
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __pConditionManagerService->Construct.(%s)", GetErrorMessage(r) );
+
+       r = StartIpcServer();
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to StartIpcServer.(%s)", GetErrorMessage(r) );
+
+       SysLog(NID_APP, "Exit.");
+       return E_SUCCESS;
+}
+
+result
+_ConditionManagerStub::StartIpcServer(void)
+{
+       SysLog(NID_APP, "");
+
+       __pIpcServer = new (std::nothrow) _IpcServer();
+       SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
+
+       result r = __pIpcServer->Construct( "osp.app.ipcserver.conditionmanager", *this);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.appmanager");
+
+       return E_SUCCESS;
+
+CATCH:
+       delete __pIpcServer;
+       __pIpcServer = null;
+       return r;
+}
+
+//
+//  from XML : <Condition Name="DueTime">07/24/2012 22:52:33 60m</Condition>
+//     from API : "DueTime='12/31/2020 21:24:59' LaunchPeriod='60'"
+//
+result
+_ConditionManagerStub::ExtractDueAndPeriod(const String& src, String& dueTime, String& period)
+{
+       DateTime tmpDate;
+       const int dateTimeLen = 19;
+
+       result r = src.SubString(0, dateTimeLen, dueTime);
+       SysTryReturn(NID_APP, IsFailed(r) == false, E_INVALID_FORMAT, E_INVALID_FORMAT, "invalid DueTime value.(%ls)", src.GetPointer());
+
+       r = DateTime::Parse(dueTime, tmpDate);
+       SysTryReturn(NID_APP, IsFailed(r) == false, E_INVALID_FORMAT, E_INVALID_FORMAT, "invalid DueTime value.(%ls)", dueTime.GetPointer());
+
+       r = src.SubString(dateTimeLen + 1, src.GetLength() -(dateTimeLen + 1) -1, period);//60
+       SysTryReturn(NID_APP, IsFailed(r) == false, E_INVALID_FORMAT, E_INVALID_FORMAT, "invalid DueTime value.(%ls)", dueTime.GetPointer());
+
+       return E_SUCCESS;
+}
+
+void
+_ConditionManagerStub::OnInstallComplete(const AppId& appId, const String& executableName, const String& packageName )
+{
+       SysTryReturnVoidResult(NID_APP, __pConditionManagerService != null, E_INVALID_STATE, "Invalid condition manager service state.");
+       SysLog(NID_APP, "Enter");
+
+       ArrayList* pArray = _PackageManagerImpl::GetInstance()->GetAppLaunchConditionListN(packageName);
+       SysTryReturnVoidResult(NID_APP, pArray != null, E_INVALID_STATE, "failed to GetAppLaunchConditionListN(%ls)", packageName.GetPointer());
+
+       _LaunchConditionInfoImpl* pCondition = null;
+       String condition;
+       String name;
+       String value;
+       result r = E_SUCCESS;
+
+       for ( int i = 0; i < pArray->GetCount(); i++)
+       {
+               pCondition = dynamic_cast<_LaunchConditionInfoImpl*>(pArray->GetAt(i));
+               if ( pCondition == null)
+               {
+                       continue;
+               }
+
+               name = pCondition->GetName();
+               value = pCondition->GetValue();
+
+               if ( name == L"DueTime")
+               {
+                       String dueTime;
+                       String period;
+
+                       r = ExtractDueAndPeriod(value, dueTime, period);
+                       if( IsFailed(r))
+                       {
+                               continue;
+                       }
+
+                       condition.Format( 1024, L"DueTime='%ls' LaunchPeriod='%ls'", dueTime.GetPointer(), period.GetPointer());
+               }
+               else
+               {
+                       condition = name + "='" + value + "'";
+               }
+
+               SysLog(NID_APP, "condition(%ls)", condition.GetPointer());
+               __pConditionManagerService->RegisterAppLaunch(appId, executableName, condition, null, AppManager::LAUNCH_OPTION_DEFAULT, null);
+       }
+       SysLog(NID_APP, "Exit");
+}
+
+void
+_ConditionManagerStub::OnUninstallComplete(const AppId& appId, const String& executableName)
+{
+       SysTryReturnVoidResult(NID_APP, __pConditionManagerService != null, E_INVALID_STATE, "Invalid condition manager service state.");
+
+       __pConditionManagerService->UnregisterAppLaunch(appId, executableName, null);
+}
+
+///////////////////////////////////////////
+// ipc handlers
+///////////////////////////////////////////
+
+bool
+_ConditionManagerStub::OnRegisterAppLaunch(const AppId& appId, const String& executableName, const String& cond, const Osp::Base::Collection::ArrayList& args , int flag, result *pRes)
+{
+       SysLog(NID_APP, "(appId:%ls, executableName:%ls, cond:%ls, flag:%x)\n", appId.GetPointer(), executableName.GetPointer(), cond.GetPointer(), flag);
+//     SysTryCatch(NID_APP, __pConditionManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pConditionManagerService is null!");
+       if ( __pConditionManagerService == null )
+       {
+               SysLog(NID_APP, "__pConditionManagerService is null!");
+               *pRes = E_INVALID_STATE;
+               return true;
+       }
+
+       String targetAppId;
+       if ( appId.IsEmpty() == true )
+       {
+               // APPLICATION_SERVICE
+               targetAppId = __pIpcServer->GetClientAppId();
+       }
+       else
+       {
+               // APPLICATION_MANAGER
+               *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPLICATION_MANAGER);
+               SysTryReturn(NID_APP, !IsFailed(*pRes), true, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+               targetAppId = appId;
+       }
+
+       *pRes = __pConditionManagerService->RegisterAppLaunch(targetAppId, executableName, cond, (args.GetCount()>0)? &args : null, AppManager::LAUNCH_OPTION_DEFAULT);
+
+//CATCH:
+       return true;
+}
+
+bool
+_ConditionManagerStub::OnUnregisterAppLaunch(const AppId& appId, const String& executableName, const String& cond, result *pRes)
+{
+       SysLog(NID_APP, "(appId:%ls, executableName:%ls, cond:%ls)\n", appId.GetPointer(), executableName.GetPointer(), cond.GetPointer());
+//     SysTryCatch(NID_APP, __pConditionManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pConditionManagerService is null!");
+       if ( __pConditionManagerService == null )
+       {
+               SysLog(NID_APP, "__pConditionManagerService is null!");
+               *pRes = E_INVALID_STATE;
+               return true;
+       }
+
+       String targetAppId;
+       if ( appId.IsEmpty() == true )
+       {
+               // APPLICATION_SERVICE
+               targetAppId = __pIpcServer->GetClientAppId();
+       }
+       else
+       {
+               // APPLICATION_MANAGER
+               *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPLICATION_MANAGER);
+               SysTryReturn(NID_APP, !IsFailed(*pRes), true, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+               targetAppId = appId;
+       }
+
+       *pRes = __pConditionManagerService->UnregisterAppLaunch(targetAppId, executableName, (cond.IsEmpty() == true) ? null : (String*)&cond);
+
+//CATCH:
+       return true;
+}
+
+bool
+_ConditionManagerStub::OnIsAppLaunchRegistered(const AppId& appId, const String& executableName, const String& cond, bool *pIsAppLaunchRegistered, result *pException)
+{
+       if ( __pConditionManagerService == null )
+       {
+               SysLog(NID_APP, "__pConditionManagerService is null!");
+               *pException = E_SYSTEM;
+               return true;
+       }
+
+       String targetAppId;
+       if ( appId.IsEmpty() == true )
+       {
+               // NP
+               targetAppId = __pIpcServer->GetClientAppId();
+       }
+       else
+       {
+               // APPLICATION_MANAGER
+               result r = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPLICATION_MANAGER);
+               if(IsFailed(r))
+               {
+                       *pException = E_PRIVILEGE_DENIED;
+                       SysTryReturn(NID_APP, !IsFailed(r), true, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+               }
+
+               targetAppId = appId;
+       }
+
+       *pIsAppLaunchRegistered = __pConditionManagerService->IsAppLaunchRegistered( targetAppId, executableName, (cond.IsEmpty() == true) ? null : &cond);
+       *pException = GetLastResult();
+       SysLog(NID_APP, "(appId:%s, executableName:%ls, cond:%s) is registered = (%s)\n", appId.GetPointer(), executableName.GetPointer(), cond.GetPointer(), (*pIsAppLaunchRegistered)? "true":"false");
+
+       return true;
+}
+
+void
+_ConditionManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+       SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+       IPC_BEGIN_MESSAGE_MAP(_ConditionManagerStub, message)
+               IPC_MESSAGE_HANDLER_EX(ConditionManager_RegisterAppLaunch, &server, OnRegisterAppLaunch)
+               IPC_MESSAGE_HANDLER_EX(ConditionManager_UnregisterAppLaunch, &server, OnUnregisterAppLaunch)
+               IPC_MESSAGE_HANDLER_EX(ConditionManager_IsAppLaunchRegistered, &server, OnIsAppLaunchRegistered)
+       IPC_END_MESSAGE_MAP()
+}
+
+void
+_ConditionManagerStub::OnIpcServerStarted(const _IpcServer& server)
+{
+       SysLog(NID_APP, "\n");
+}
+
+void
+_ConditionManagerStub::OnIpcServerStopped(const _IpcServer& server)
+{
+       SysLog(NID_APP, "\n");
+}
+
+void
+_ConditionManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
+{
+       SysLog(NID_APP, "(clientId:%d)\n", clientId);
+}
+
+void
+_ConditionManagerStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
+{
+       SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
+}
+
+}} //namespace Osp { namespace App {
diff --git a/src/FApp_ContextManager.cpp b/src/FApp_ContextManager.cpp
new file mode 100644 (file)
index 0000000..0e472c8
--- /dev/null
@@ -0,0 +1,359 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_ContextManager.cpp
+ * @brief      This is the implementation for the _ContextManager.cpp class.
+ */
+
+#include <cstdio>
+#include <cerrno>
+#include <dlfcn.h>
+
+#include <FBaseColArrayList.h>
+
+#include <FBaseSysLog.h>
+#include <FApp_Aul.h>
+#include <FApp_AppManagerImpl.h>
+#include <FApp_PackageManagerImpl.h>
+
+#include "FApp_ContextManager.h"
+
+
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+
+
+namespace Osp { namespace App {
+
+const unsigned long CONTEXT_MANAGER_MAGIC = 0x585443;  // 'C' 'T' 'X'
+
+///////////////////////////////////////////////////
+// _AppContext
+///////////////////////////////////////////////////
+_AppContext::_AppContext(const String& appId, const String& executableName, AppType appType, int pid, int ipcClientId, bool isSystemService)
+: appId(appId)
+, executableName(executableName)
+, appType(appType)
+, pId(pid)
+, ipcClientId(ipcClientId)
+, uiState(APP_UI_STATE_BACKGROUND)
+, isRegistered(true)
+, isSystemService(isSystemService)
+{
+}
+
+String
+_AppContext::ToString(void) const
+{
+       Osp::Base::String ret;
+       ret.Format(1024, L"%ls#%ls(pid:%d)", appId.GetPointer(), executableName.GetPointer(), pId);
+       return ret;
+}
+
+
+///////////////////////////////////////////////////
+// _ContextManager
+///////////////////////////////////////////////////
+_ContextManager::_ContextManager()
+       : __magic(CONTEXT_MANAGER_MAGIC)
+       , __pEventListener(null)
+{
+       //
+}
+
+_ContextManager::~_ContextManager()
+{
+}
+
+result
+_ContextManager::Construct(void)
+{
+       result r = E_SUCCESS;
+       __errorProneAppIds.Construct();
+       _Aul::SetOnAppTerminatedCb(OnAppTerminate, this);
+
+       return r;
+}
+
+void
+_ContextManager::SetEventListener(_IContextManagerEventListener& listener)
+{
+       __pEventListener = &listener;
+}
+
+result
+_ContextManager::Register(const AppId& appId, const String& executableName, AppType appType, int pid, int ipcClientId, bool isSystemService )
+{
+       if( __appContexts[pid] != null)
+       {
+               SysAssertf( isSystemService == true, "The application (appid:%ls, pid:%d) is registered twice.", appId.GetPointer(), pid);
+               return E_SUCCESS;
+       }
+
+       _AppContext* pAppContext = new (std::nothrow) _AppContext(appId, executableName, appType, pid, ipcClientId, isSystemService);
+
+       __appContexts[pid] = pAppContext;
+
+       // ==== set oom policy for ServiceApp
+       result r = E_SUCCESS;
+       switch (GetOomAppType(appId, pid))
+       {
+       case OOM_APP_TYPE_SYSTEM:
+               break;
+       case OOM_APP_TYPE_LAUNCHING:
+               break;
+       case OOM_APP_TYPE_FOREGROUND_HIGH:
+               break;
+       case OOM_APP_TYPE_SERVICE_HIGH:
+               break;
+       case OOM_APP_TYPE_FOREGROUND:
+               break;
+       case OOM_APP_TYPE_SERVICE_MID:
+               r = _Aul::SetOomAdj(pid, -7);
+               break;
+       case OOM_APP_TYPE_BACKGROUND_HIGH:
+               break;
+       case OOM_APP_TYPE_SERVICE_LOW:
+               r = _Aul::SetOomAdj(pid, -3);
+               break;
+       case OOM_APP_TYPE_BACKGROUND:
+               break;
+       }
+       SysLog(NID_APP, "Set OOM : result is %s", GetErrorMessage(r));
+
+       SysLog(NID_APP, "The %s (appid:%ls, pid:%d) Registered.", isSystemService ? "application":"system service", appId.GetPointer(), pid);
+       Dump();
+       return E_SUCCESS;
+}
+
+// see also    OnAppTerminate
+result
+_ContextManager::Unregister(int pid)
+{
+       _AppContext* pAppContext = __appContexts[pid];
+       SysTryReturn(NID_APP, pAppContext != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "Unknown pid(%d).", pid);
+
+       pAppContext->isRegistered = false;
+       SysLog(NID_APP, "(appid:%ls, pid:%d) Unregistered.", pAppContext->appId.GetPointer(), pid);
+       return E_SUCCESS;
+}
+
+
+// event handler for _Aul::SetOnAppTerminatedCb
+int
+_ContextManager::OnAppTerminate(int pid, void *pData)
+{
+       SysTryReturn(NID_APP, pData != null, -1, E_INVALID_STATE, "");
+
+       _ContextManager* pContextMgr = static_cast<_ContextManager*>(pData);
+       SysTryReturn(NID_APP, pContextMgr->__magic == CONTEXT_MANAGER_MAGIC, -1, E_INVALID_STATE, "Wrong magic number %x(%x)", pContextMgr->__magic, CONTEXT_MANAGER_MAGIC);
+
+       _AppContext* pAppContext = pContextMgr->__appContexts[pid];
+
+       if ( pAppContext == null)
+       {
+//             SysLog(NID_APP, "Not registered pid(%d), It means this process isn't osp app.", pid);
+               return 0;
+       }
+
+       if (pAppContext->isRegistered)
+       {
+               SysLog(NID_APP, "This app is terminated abnormally.");
+               pContextMgr->AbonormalAppTerminationHanlder( pAppContext->pId, pAppContext->appId, pAppContext->executableName );
+       }
+
+       if (pContextMgr->__pEventListener != null )
+       {
+               pContextMgr->__pEventListener->OnApplicationTerminated(*pAppContext);
+       }
+
+       int res = pContextMgr->__appContexts.erase(pid);
+       SysTryCatch(NID_APP, res == 1, , E_INVALID_STATE, "[E_INVALID_STATE] __appContexts.erase(%d) returns (%d). It seems to be invalid.", pid, res);
+
+       SysLog(NID_APP, "app info is removed (%ls, %d)", pAppContext->executableName.GetPointer(), pid);
+
+       pContextMgr->Dump();
+
+CATCH:
+       delete pAppContext;
+       return 0;
+}
+
+void
+_ContextManager::AbonormalAppTerminationHanlder(int pid, const AppId& appId, const String& execName)
+{
+       this->Unregister(pid);
+
+       const String& needToAutoRestartOnFailure = _Util::QueryFeatureFromPackageManager(appId, execName, L"AutoRestart");
+       if (needToAutoRestartOnFailure == "True")
+       {
+               if(!IsErrorProneApp(appId))// prevent error prone app being restarted over and over again..
+               {
+                       SysLog(NID_APP, "The app is configured as AutoRestart, so It will be restarted.");
+
+                       __errorProneAppIds.Add(appId);
+
+                       _AppManagerImpl::GetInstance()->LaunchApplication(appId, &execName, null, AppManager::LAUNCH_OPTION_DEFAULT);
+
+               }
+               else
+               {
+                       SysLog(NID_APP, "The app is configured as AutoRestart, but It won't be restarted. because it was already restarted, and terminated unexpectedly again. ");
+               }
+       }
+}
+
+bool
+_ContextManager::IsErrorProneApp(const AppId& appId) const
+{
+       const int count = __errorProneAppIds.GetCount();
+       String errorProneAppId;
+
+       for (int i = 0; i < count; i ++)
+       {
+               __errorProneAppIds.GetAt(i, errorProneAppId);
+               if(errorProneAppId == appId)
+               {
+                       return true;
+               }
+       }
+       return false;
+}
+
+
+const _AppContext*
+_ContextManager::Find(const AppId& appId, const Osp::Base::String& executableName) const
+{
+       AppContexts::const_iterator it;
+
+       for (it = __appContexts.begin(); it != __appContexts.end(); it++)
+       {
+               const _AppContext* const pAppContext = (*it).second;
+
+               if (pAppContext != null && pAppContext->appId == appId && pAppContext->executableName == executableName)
+               {
+                       return pAppContext;
+               }
+       }
+
+       return null;
+}
+
+const _AppContext*
+_ContextManager::Find(int pid)
+{
+       return __appContexts[pid];
+}
+
+result
+_ContextManager::GetAppListN(Osp::Base::Collection::ArrayList* pArray) const
+{
+       AppContexts::const_iterator it;
+       String logText;
+
+       for (it = __appContexts.begin(); it != __appContexts.end(); it++)
+       {
+               const _AppContext* const pAppContext = (*it).second;
+
+               if (pAppContext != null)
+               {
+                       if ( pArray != null)
+                       {
+                               pArray->Add(pAppContext->appId);
+                       }
+
+                       logText.Append(pAppContext->appId);
+                       logText.Append(L", ");
+               }
+       }
+       SysLog(NID_APP, "Total %d apps : %ls", __appContexts.size(), logText.GetPointer() );
+
+       return E_SUCCESS;
+}
+
+_OomAppType
+_ContextManager::GetOomAppType(const AppId& appId, const int pid) const
+{
+       _OomAppType appType = OOM_APP_TYPE_FOREGROUND;
+
+       // FIX_ME : will be implemented for type checking
+
+       return appType;
+}
+
+void
+_ContextManager::Dump(void) const
+{
+       AppContexts::const_iterator it;
+
+       SysLog(NID_APP, "registered app count : %d", __appContexts.size());
+
+       for (it = __appContexts.begin(); it != __appContexts.end(); it++)
+       {
+               const _AppContext* const pAppContext = (*it).second;
+               if (pAppContext != null)
+               {
+                       SysLog(NID_APP, "%ls", pAppContext->ToString().GetPointer());
+               }
+       }
+}
+
+
+
+/*
+ * _ContextManager::Util
+ */
+
+/*String
+_ContextManager::_Util::GetExecNameFromPackageName(const String& packageName)
+{
+       String execName;
+       const String prefix(L"org.tizen.1234567890");
+       const int prefixLen = prefix.GetLength();
+       packageName.SubString(prefixLen, execName);
+
+       return execName;
+}*/
+
+String
+_ContextManager::_Util::QueryFeatureFromPackageManager(const String& appId, const String& execName, const String& feature)
+{
+       ArrayList* pFeatureList = _PackageManagerImpl::GetInstance()->GetPackageAppFeatureListN(appId, execName);
+       SysTryReturn(NID_APP, pFeatureList != null, L"", E_SYSTEM, "Cannot acquire feature list.");
+
+       String ret = L"";
+
+       for (int i = 0; i < pFeatureList->GetCount(); i++)
+       {
+               const _AppFeatureInfoImpl* pInfo = static_cast<const _AppFeatureInfoImpl*>(pFeatureList->GetAt(i));
+               SysLog(NID_APP, "%ls, %ls", pInfo->GetName().GetPointer(), pInfo->GetValue().GetPointer());
+               if (pInfo == null && pInfo->GetName() == feature)
+               {
+                       ret = pInfo->GetValue();
+                       break;
+               }
+       }
+
+       pFeatureList->RemoveAll(true);
+       delete pFeatureList;
+
+       return ret;
+}
+
+} } // Osp::App
+
diff --git a/src/FApp_NotificationManagerService.cpp b/src/FApp_NotificationManagerService.cpp
new file mode 100755 (executable)
index 0000000..fd8b2b5
--- /dev/null
@@ -0,0 +1,279 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+//
+// 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.
+//
+
+/**
+ * @file        FApp_NotificationManagerService.cpp
+ * @brief      This is the implementation for the _NotificationManagerService class.
+ */
+
+#include <FAppNotificationManager.h>
+#include <FAppNotificationMessage.h>
+
+#include <FBaseSysLog.h>
+#include <FBaseInternalTypes.h>
+#include <FBase_StringConverter.h>
+#include <FApp_AppArg.h>
+#include "FApp_AppInfo.h"
+#include "FApp_Aul.h"
+#include "FApp_NotificationManagerImpl.h"
+#include "FApp_NotificationManagerService.h"
+#include "FApp_PackageManagerImpl.h"
+
+using namespace Osp::App;
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Io;
+
+extern "C" int service_create_request(bundle *data, service_h *service);
+
+namespace
+{
+
+result
+ConvertNotificationResult(int error)
+{
+       switch (error)
+       {
+       case UI_NOTIFICATION_ERROR_NONE:
+               return E_SUCCESS;
+       case UI_NOTIFICATION_ERROR_INVALID_PARAMETER:
+               return E_INVALID_ARG;
+       case UI_NOTIFICATION_ERROR_OUT_OF_MEMORY:
+               return E_OUT_OF_MEMORY;
+       case UI_NOTIFICATION_ERROR_DB_FAILED:
+               return E_DATABASE;
+       case UI_NOTIFICATION_ERROR_NO_SUCH_FILE:
+               return E_SYSTEM;
+       case UI_NOTIFICATION_ERROR_INVALID_STATE:
+               return E_SYSTEM;
+       default:
+               return E_SYSTEM;
+       }
+}
+
+static int
+GetMessageLength()
+{
+       static int length = (_AppInfo::GetApiVersion() < _API_VERSION_3_0) ? 127 : MAX_NOTIFICATION_MESSAGE_LENGTH;
+
+       return length;
+}
+
+ui_notification_progress_type_e
+ConvertToNotificationProgressType(int progressType)
+{
+       switch (progressType)
+       {
+       case ONGOING_ACTIVITY_TYPE_TEXT:
+               return UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
+       case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
+               return UI_NOTIFICATION_PROGRESS_TYPE_SIZE;
+       case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
+               return UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
+       default:
+               return UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
+       }
+}
+}
+
+namespace Osp { namespace App {
+
+_NotificationManagerService::_NotificationManagerService()
+
+{
+}
+
+_NotificationManagerService::~_NotificationManagerService()
+{
+}
+
+result
+_NotificationManagerService::Construct(void)
+{
+       return E_SUCCESS;
+}
+
+result
+_NotificationManagerService::NotifyMessage(const AppId& appId,const NotificationMessage& notiMessage, bool isOngoing)
+{
+       result r = E_SUCCESS;
+       int retcode = 0;
+       int progress = -1;
+       char* pMsg = null;
+       ui_notification_h core = NULL;
+       char* pTitleText = NULL;
+       char* pIconPath = NULL;
+       char* pSoundPath = NULL;
+
+       char buffer[256];
+       memset(buffer, 0, 256);
+
+       const String& messageText = notiMessage.GetAlertText();
+       const String& launchArguments = notiMessage.GetAppMessage();
+       const String& titleText = notiMessage.GetTitleText();
+       const String& iconPath = notiMessage.GetIconFilePath();
+       const String& soundPath = notiMessage.GetSoundFilePath();
+
+       bool isAppInstalled = _PackageManagerImpl::IsAppInstalled(appId);
+       SysTryReturnResult(NID_APP, isAppInstalled == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
+
+       if (!messageText.IsEmpty())
+       {
+               SysTryReturnResult(NID_APP,
+                                         messageText.GetLength() <=  GetMessageLength(), E_INVALID_ARG,
+                                         "MessageText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
+
+               retcode = ui_notification_create(isOngoing, &core);
+               SysTryReturnResult(NID_APP, retcode == UI_NOTIFICATION_ERROR_NONE, E_SYSTEM, "Notification creation error : 0x%x.", retcode);
+
+               pMsg = _StringConverter::CopyToCharArrayN(messageText);
+
+               int ret = ui_notification_set_content(core, pMsg);
+               SysTryLog(NID_APP, ret == UI_NOTIFICATION_ERROR_NONE, "Setting notification content failure : %d.", ret);
+
+               r = _PackageManagerImpl::GetInstance()->GetPackageName(appId, null, buffer, 256);
+               SysTryCatch(NID_APP, r == E_SUCCESS, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Cannot acquire package name for %ls.",
+                                  appId.GetPointer());
+
+
+               if (!titleText.IsEmpty())
+               {
+                       pTitleText = _StringConverter::CopyToCharArrayN(titleText);
+                       ui_notification_set_title(core, pTitleText);
+               }
+               else
+               {
+                       app_manager_get_app_name(buffer, &pTitleText);
+                       ui_notification_set_title(core, pTitleText);
+               }
+               if (!iconPath.IsEmpty())
+               {
+                       pIconPath = _StringConverter::CopyToCharArrayN(iconPath);
+                       ui_notification_set_icon(core, pIconPath);
+               }
+               else
+               {
+                       app_manager_get_app_icon_path(buffer, &pIconPath);
+                       ui_notification_set_icon(core, pIconPath);
+               }
+               if (!soundPath.IsEmpty())
+               {
+                       pSoundPath = _StringConverter::CopyToCharArrayN(soundPath);
+                       ui_notification_set_sound(core, pSoundPath);
+               }
+               if (isOngoing)
+               {
+                       OngoingActivityType activityType =  notiMessage.GetOngoingActivityType();
+                       progress = notiMessage.GetOngoingActivityProgressValue();
+                       switch (activityType)
+                       {
+                       case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
+                               ui_notification_update_progress(core, ConvertToNotificationProgressType(activityType), progress/100);
+                               break;
+                       case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
+                               ui_notification_update_progress(core, ConvertToNotificationProgressType(activityType), progress);
+                               break;
+                       default:
+                               // ui_notification_set_content() is done already
+                       break;
+                       }
+               }
+
+               bundle* kb = NULL;
+               service_h svc = NULL;
+               _AppArg arg;
+
+               r = arg.Construct(launchArguments);
+               SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
+
+               kb = arg.GetBundle();
+               service_create_request(kb, &svc);
+               service_set_package(svc, buffer);
+
+               ui_notification_set_service(core, svc);
+               SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), buffer);
+
+               r = ConvertNotificationResult(ui_notification_post(core));
+               SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
+
+       }
+
+       else
+       {
+               SysTryReturnResult(NID_APP, 0, E_INVALID_ARG, "MessageText is Empty");
+       }
+
+       if (notiMessage.GetBadgeNumber() >= 0)
+       {
+               notification_set_badge(NULL, NOTIFICATION_GROUP_ID_NONE, notiMessage.GetBadgeNumber());
+       }
+
+CATCH:
+       delete[] pMsg;
+       delete[] pIconPath;
+       delete[] pTitleText;
+       delete[] pSoundPath;
+
+       if (core)
+       {
+               ui_notification_destroy(core);
+       }
+
+       return r;
+}
+
+result
+_NotificationManagerService::RemoveNotification(const AppId& appId, bool isOngoing)
+{
+       int retCode = 0;
+       char* pAppid = NULL;
+       bool b = _PackageManagerImpl::IsAppInstalled(appId);
+       SysTryReturnResult(NID_APP, b == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
+
+       char buffer[256];
+       memset(buffer, 0, 256);
+       result r = _PackageManagerImpl::GetInstance()->GetPackageName(appId, null, buffer, 256);
+       SysTryReturnResult(NID_APP, r == E_SUCCESS, E_OBJ_NOT_FOUND, "Cannot acquire package name for %ls.", appId.GetPointer());
+
+       pAppid = _StringConverter::CopyToCharArrayN(appId);
+
+       if (isOngoing)
+       {
+               retCode = ui_notification_cancel_all_by_app_id(pAppid, true);
+       }
+       else
+       {
+               retCode = ui_notification_cancel_all_by_app_id(pAppid, false);
+       }
+
+       switch (retCode)
+       {
+       case UI_NOTIFICATION_ERROR_NONE:
+               r = E_SUCCESS;
+               break;
+
+       case UI_NOTIFICATION_ERROR_INVALID_PARAMETER:
+               r = E_INVALID_ARG;
+               break;
+
+       default:
+               r = E_SYSTEM;
+               break;
+       }
+       return r;
+}
+}} //namespace Osp { namespace App {
diff --git a/src/FApp_NotificationManagerStub.cpp b/src/FApp_NotificationManagerStub.cpp
new file mode 100755 (executable)
index 0000000..6cd65e0
--- /dev/null
@@ -0,0 +1,165 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_NotificationManagerStub.cpp
+ * @brief      This is the implementation for the _NotificationManagerStub class.
+ */
+#include <cstdio>
+#include <dlfcn.h>
+
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FIo_IpcServer.h>
+#include <FSec_AccessController.h>
+#include <FApp_NotificationManagerIpcMessages.h>
+
+#include "FApp_NotificationManagerService.h"
+#include "FApp_NotificationManagerStub.h"
+
+
+namespace Osp { namespace App {
+
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Io;
+using namespace Osp::Security;
+
+
+///////////////////////////////////////////
+// _NotificationManagerStub
+///////////////////////////////////////////
+
+_NotificationManagerStub::_NotificationManagerStub()
+       :__pIpcServer(null)
+       ,__pNotificationManagerService(null)
+{
+       SysLog(NID_APP, "_NotificationManagerStub - Enter\n");
+}
+
+_NotificationManagerStub::~_NotificationManagerStub()
+{
+       if ( __pIpcServer != null)
+       {
+               __pIpcServer->Stop();
+               delete __pIpcServer;
+       }
+
+       SysLog(NID_APP, "_NotificationManagerStub - Exit\n");
+}
+
+result
+_NotificationManagerStub::Construct(void)
+{
+       SysLog(NID_APP, "Enter.");
+
+       __pNotificationManagerService = new (std::nothrow) _NotificationManagerService();
+
+       result r = E_SUCCESS;
+       r = __pNotificationManagerService->Construct();
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __pNotificationManagerService->Construct.(%s)", GetErrorMessage(r) );
+
+       r = StartIpcServer();
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to StartIpcServer.(%s)", GetErrorMessage(r) );
+
+       SysLog(NID_APP, "Exit.");
+       return E_SUCCESS;
+}
+
+result
+_NotificationManagerStub::StartIpcServer(void)
+{
+       SysLog(NID_APP, "_NotificationManagerStub - StartIpcServer");
+
+       __pIpcServer = new (std::nothrow) _IpcServer();
+       SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
+
+       result r = __pIpcServer->Construct( "osp.app.ipcserver.notificationmanager", *this);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.notificationmanager");
+
+       r = __pIpcServer->Start();
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to Start IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.notificationmanager");
+
+       return E_SUCCESS;
+
+CATCH:
+       delete __pIpcServer;
+       __pIpcServer = null;
+       return r;
+}
+
+void
+_NotificationManagerStub::OnNotifyMessage(const AppId& appId, const NotificationMessage& notiMessage,bool Ongoing, result* pRes)
+{
+       SysTryReturnVoidResult(NID_APP, __pNotificationManagerService != null, E_INVALID_STATE, "Invalid Notification manager state.");
+
+       *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_NOTIFICATION_SERVICE);
+       SysTryReturnVoidResult(NID_APP, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       *pRes = __pNotificationManagerService->NotifyMessage(appId, notiMessage,Ongoing);
+}
+
+void
+_NotificationManagerStub::OnRemoveNotification(const AppId& appId, bool Ongoing, result* pRes)
+{
+       SysTryReturnVoidResult(NID_APP, __pNotificationManagerService != null, E_INVALID_STATE, "Invalid Notification manager state.");
+
+       *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_NOTIFICATION_SERVICE);
+       SysTryReturnVoidResult(NID_APP, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       *pRes = __pNotificationManagerService->RemoveNotification(appId, Ongoing);
+}
+
+///////////////////////////////////////////
+// ipc handlers
+///////////////////////////////////////////
+void
+_NotificationManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+       SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+       IPC_BEGIN_MESSAGE_MAP(_NotificationManagerStub, message)
+               IPC_MESSAGE_HANDLER_EX(NotificationManager_NotifyMessage, &server, OnNotifyMessage)
+               IPC_MESSAGE_HANDLER_EX(NotificationManager_RemoveNotification, &server, OnRemoveNotification)
+       IPC_END_MESSAGE_MAP()
+}
+
+void
+_NotificationManagerStub::OnIpcServerStarted(const _IpcServer& server)
+{
+       SysLog(NID_APP, "_NotificationManagerStub::OnIpcServerStarted \n");
+}
+
+void
+_NotificationManagerStub::OnIpcServerStopped(const _IpcServer& server)
+{
+       SysLog(NID_APP, "_NotificationManagerStub::OnIpcServerStopped \n");
+}
+
+void
+_NotificationManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
+{
+       SysLog(NID_APP, "_NotificationManagerStub::OnIpcClientConnected (clientId:%d)\n", clientId);
+}
+
+void
+_NotificationManagerStub::OnIpcClientDisconnected(const _IpcServer&server, int clientId)
+{
+       SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
+}
+
+}} //namespace Osp { namespace App {
diff --git a/src/FApp_PackageManagerStub.cpp b/src/FApp_PackageManagerStub.cpp
new file mode 100644 (file)
index 0000000..537029d
--- /dev/null
@@ -0,0 +1,162 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file        FApp_PackageManagerStub.cpp
+ * @brief      This is the implementation for the _PackageManagerStub class.
+ */
+#include <cstdio>
+#include <dlfcn.h>
+
+#include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
+#include <FIo_IpcServer.h>
+#include <FSec_AccessController.h>
+#include <FApp_PackageManagerIpcMessages.h>
+
+#include "FApp_PackageManagerImpl.h"
+#include "FApp_PackageManagerStub.h"
+
+
+namespace Osp { namespace App {
+
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Io;
+using namespace Osp::Security;
+
+
+///////////////////////////////////////////
+// _PackageManagerStub
+///////////////////////////////////////////
+
+_PackageManagerStub::_PackageManagerStub()
+       :__pIpcServer(null)
+       ,__pPackageManagerImpl(null)
+{
+       SysLog(NID_APP, "_PackageManagerStub - Enter\n");
+}
+
+_PackageManagerStub::~_PackageManagerStub()
+{
+       if ( __pIpcServer != null)
+       {
+               __pIpcServer->Stop();
+               delete __pIpcServer;
+       }
+
+       SysLog(NID_APP, "_PackageManagerStub - Exit\n");
+}
+
+result
+_PackageManagerStub::Construct(void)
+{
+       SysLog(NID_APP, "_PackageManagerStub - Construct.");
+
+       __pPackageManagerImpl = _PackageManagerImpl::GetInstance();
+
+       result r = E_SUCCESS;
+       r = StartIpcServer();
+       SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to StartIpcServer.(%s)", GetErrorMessage(r));
+
+       return E_SUCCESS;
+}
+
+result
+_PackageManagerStub::StartIpcServer(void)
+{
+       SysLog(NID_APP, "_PackageManagerStub - StartIpcServer");
+
+       __pIpcServer = new (std::nothrow) _IpcServer();
+       SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
+
+       result r = __pIpcServer->Construct( "osp.app.ipcserver.packagemanager", *this);
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.packagemanager");
+
+       r = __pIpcServer->Start();
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to Start IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.packagemanager");
+
+       return E_SUCCESS;
+
+CATCH:
+       delete __pIpcServer;
+       __pIpcServer = null;
+       return r;
+}
+
+void
+_PackageManagerStub::OnInstallPackage(const String& packagePath, const String& licensePath, result* pRes)
+{
+       SysTryReturnVoidResult(NID_APP, __pPackageManagerImpl != null, E_INVALID_STATE, "Invalid package manager state.");
+
+       *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_INSTALLATION);
+       SysTryReturnVoidResult(NID_APP, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       String appId;
+       *pRes = __pPackageManagerImpl->InstallApp(PACKAGE_TYPE_OSP, appId, packagePath, &licensePath, PACKAGE_ATTRIBUTE_DOWNLOADED, false);
+}
+
+void
+_PackageManagerStub::OnUninstallPackage(const AppId& appId, result* pRes)
+{
+       SysTryReturnVoidResult(NID_APP, __pPackageManagerImpl != null, E_INVALID_STATE, "Invalid package manager state.");
+
+       *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_UNINSTALLATION);
+       SysTryReturnVoidResult(NID_APP, !IsFailed(*pRes), *pRes = E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
+
+       *pRes = __pPackageManagerImpl->UninstallApp(appId);
+}
+
+///////////////////////////////////////////
+// ipc handlers
+///////////////////////////////////////////
+void
+_PackageManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+       SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
+
+       IPC_BEGIN_MESSAGE_MAP(_PackageManagerStub, message)
+               IPC_MESSAGE_HANDLER_EX(PackageManager_InstallPackage, &server, OnInstallPackage)
+               IPC_MESSAGE_HANDLER_EX(PackageManager_UninstallPackage, &server, OnUninstallPackage)
+       IPC_END_MESSAGE_MAP()
+}
+
+void
+_PackageManagerStub::OnIpcServerStarted(const _IpcServer& server)
+{
+       SysLog(NID_APP, "_PackageManagerStub::OnIpcServerStarted \n");
+}
+
+void
+_PackageManagerStub::OnIpcServerStopped(const _IpcServer& server)
+{
+       SysLog(NID_APP, "_PackageManagerStub::OnIpcServerStopped \n");
+}
+
+void
+_PackageManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
+{
+       SysLog(NID_APP, "_PackageManagerStub::OnIpcClientConnected (clientId:%d)\n", clientId);
+}
+
+void
+_PackageManagerStub::OnIpcClientDisconnected(const _IpcServer&server, int clientId)
+{
+       SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
+}
+
+}} //namespace Osp { namespace App {
diff --git a/src/FSys_AccessoryManagerService.cpp b/src/FSys_AccessoryManagerService.cpp
new file mode 100644 (file)
index 0000000..e3f0ff8
--- /dev/null
@@ -0,0 +1,151 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+//
+// 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.
+//
+
+/**
+ * @file               FSys_AccessoryManagerService.cpp
+ * @brief              This is the implementation file for _AccessoryManagerService class.
+ */
+
+#include <new>
+#include <FBaseSysLog.h>
+#include <FBaseRtLibrary.h>
+
+#include "FSys_AccessoryManagerService.h"
+#include "FApp_CommunicationDispatcher.h"
+
+using namespace Osp::App;
+using namespace Osp::Io;
+using namespace Osp::System;
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Base::Runtime;
+
+namespace {
+       const String ACCESSORY_MANAGER_SERVICE_ID = L"osp.accessorymanager.service";
+       const String ACCESSORY_PLUGIN_LIBRARY_PATH = L"/opt/apps/aospd00043/data/libosp-cond-accessory.so";
+}
+
+typedef result (*SendDataFunction)(Osp::App::AppId appId, Osp::Base::Collection::ArrayList* data);
+typedef void (*RegisterSendDataFunction)(SendDataFunction function);
+
+_AccessoryManagerService* gpAccessoryManagerService = null;
+
+result
+SendDataFunc(AppId appId, ArrayList* data)
+{
+       SysLog(NID_SYS, "Request to send data");
+       SysTryReturnResult(NID_SYS, gpAccessoryManagerService != null, E_SYSTEM, "AccessoryManagerService is not ready");
+       return gpAccessoryManagerService->SendData(appId, data);
+}
+
+_AccessoryManagerService*
+_AccessoryManagerService::GetInstance()
+{
+       if(gpAccessoryManagerService == null)
+       {
+               gpAccessoryManagerService = new (std::nothrow) _AccessoryManagerService();
+       }
+       return gpAccessoryManagerService;
+}
+
+_AccessoryManagerService::_AccessoryManagerService()
+       : _ICommunicationRequestListener()
+       , __pLib(null)
+       , __pCommunicationDispatcher(null)
+       , __pOnRequestOccuredFunction(null)
+       , __pRemoveOwnerApplicationFunction(null)
+{
+       result r = E_SUCCESS;
+       RegisterSendDataFunction pRegisterSendDataFunction;
+
+       __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
+       SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "Failed to get _CommunicationDispatcher");
+
+       r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
+       SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to add event listener on _CommunicationDispatcher");
+
+       __pLib = new Library();
+       r = __pLib->Construct(ACCESSORY_PLUGIN_LIBRARY_PATH);
+       SysTryCatch(NID_APP, !IsFailed(r),, r, "dlopen fails (%s)", GetErrorMessage(r));
+
+       pRegisterSendDataFunction = (RegisterSendDataFunction)__pLib->GetProcAddress(L"RegisterSendData");
+       SysTryCatch(NID_APP, pRegisterSendDataFunction != null, r = E_SYSTEM, E_SYSTEM, "Failed to find RegisterSendDataFunction");
+
+       __pOnRequestOccuredFunction = (OnRequestOccuredFunction)__pLib->GetProcAddress(L"OnRequestOccured");
+       SysTryCatch(NID_APP, __pOnRequestOccuredFunction != null, r = E_SYSTEM, E_SYSTEM, "Failed to find OnRequestOccuredFunction");
+
+       __pRemoveOwnerApplicationFunction = (RemoveOwnerApplicationFunction)__pLib->GetProcAddress(L"RemoveOwnerApplication");
+       SysTryCatch(NID_APP, __pRemoveOwnerApplicationFunction != null, r = E_SYSTEM, E_SYSTEM, "Failed to find OnRequestOccuredFunction");
+
+       pRegisterSendDataFunction(SendDataFunc);
+
+CATCH:
+       SetLastResult(r);
+}
+
+_AccessoryManagerService::~_AccessoryManagerService()
+{
+       result r = E_SUCCESS;
+
+       SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher is not initiated.");
+
+       r = __pCommunicationDispatcher->RemoveCommunicationEventListener(*this);
+       SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to remove event listener on _CommunicationDispatcher");
+
+CATCH:
+       SetLastResult(r);
+
+}
+
+result
+_AccessoryManagerService::SendData(AppId appId, ArrayList* data)
+{
+       SysTryReturnResult(NID_SYS, __pCommunicationDispatcher != null, E_SYSTEM, "_CommunicationDispatcher is not initiated.");
+
+       return __pCommunicationDispatcher->SendData(appId, *data);
+}
+
+String
+_AccessoryManagerService::GetId(void)
+{
+       return ACCESSORY_MANAGER_SERVICE_ID;
+}
+
+void
+_AccessoryManagerService::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
+{
+       result r = E_SUCCESS;
+       SysTryCatch(NID_SYS, __pOnRequestOccuredFunction != null, r = E_SYSTEM, E_SYSTEM, "There is no OnRequestOccuredFunction");
+
+       SysLog(NID_SYS, "AppId is [%ls]", appId.GetPointer());
+       __pOnRequestOccuredFunction(appId, request, response);
+
+CATCH:
+       SetLastResult(r);
+}
+
+void
+_AccessoryManagerService::OnApplicationTerminated(const AppId& appId, const String& executableName, AppType type)
+{
+       result r = E_SUCCESS;
+       SysTryCatch(NID_SYS, __pRemoveOwnerApplicationFunction != null, r = E_SYSTEM, E_SYSTEM, "There is no RemoveOwnerApplicationFunction");
+
+       __pRemoveOwnerApplicationFunction(appId, executableName);
+CATCH:
+       SetLastResult(r);
+}
+
diff --git a/src/FSys_DeviceManagerService.cpp b/src/FSys_DeviceManagerService.cpp
new file mode 100644 (file)
index 0000000..547c06d
--- /dev/null
@@ -0,0 +1,405 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file               FSys_DeviceManagerService.cpp
+ * @brief              This is the implementation file for _DeviceManagerService class.
+ */
+
+#include <new>
+#include <system/media_key.h>
+#include <bluetooth.h>
+
+#include <FBaseSysLog.h>
+#include <FSys_DeviceManagerEventProvider.h>
+
+#include "FApp_CommunicationDispatcher.h"
+#include "FSys_DeviceManagerService.h"
+
+using namespace Osp::App;
+using namespace Osp::Io;
+using namespace Osp::System;
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+
+namespace {
+       const String DEVICE_MANAGER_SERVICE_ID = L"osp.devicemanager.service";
+       const String DEVICE_MANAGER_COMMAND_OPEN = L"osp.devicemanager.command.open";
+       const String DEVICE_MANAGER_COMMAND_CLOSE = L"osp.devicemanager.command.close";
+       const String DEVICE_MANAGER_COMMAND_STATUS= L"osp.devicemanager.command.status";
+       const String DEVICE_MANAGER_COMMAND_EVENT = L"osp.devicemanager.command.event";
+       const String DEVICE_MANAGER_BLUETOOTH = L"osp.devicemanager.bluetooth";
+
+       const String BLUETOOTH_A2DP_CONNECTED = L"Connected";
+       const String BLUETOOTH_A2DP_DISCONNECTED = L"Disconnected";
+       const String BLUETOOTH_A2DP_PLAY = L"Play";
+       const String BLUETOOTH_A2DP_STOP = L"Stop";
+       const String BLUETOOTH_A2DP_PAUSE = L"Pause";
+       const String BLUETOOTH_A2DP_RESUME = L"Resume";
+       const String BLUETOOTH_A2DP_FORWARD = L"Forward";
+       const String BLUETOOTH_A2DP_FASTFORWARD = L"FastForward";
+       const String BLUETOOTH_A2DP_BACKWARD = L"Backward";
+       const String BLUETOOTH_A2DP_REWIND = L"Rewind";
+}
+
+Osp::System::_DeviceManagerService* Osp::System::_DeviceManagerService::__pDeviceManagerService = null;
+
+void bluetooth_connection_state_changed(int result, bool connected, const char* remote_address, bt_audio_profile_type_e type, void* user_data)
+{
+       SysLog(NID_SYS, "Bluetooth headset connection event, %s,%d", remote_address, connected);
+       String bt_event;
+       _DeviceManagerService* pDeviceManagerService = _DeviceManagerService::GetInstance();
+
+       if(pDeviceManagerService != null)
+       {
+               if(pDeviceManagerService->GetBluetoothStatus() != connected)
+               {
+                       pDeviceManagerService->SendEvent(bt_event);
+               }
+               pDeviceManagerService->SetBluetoothStatus(connected);
+       }
+}
+
+void app_media_key_handler(media_key_e key, media_key_event_e status, void* pUserData)
+{
+       String event;
+       SysLog(NID_SYS, "Bluetooth headset event is occured %d, %d", (int)key, (int)status);
+       _DeviceManagerService* pDeviceManagerService = _DeviceManagerService::GetInstance();
+       if(pDeviceManagerService != null)
+       {
+               if(status == MEDIA_KEY_STATUS_RELEASED)
+               {
+                       switch(key)
+                       {
+                       case MEDIA_KEY_PLAY:
+                               event = BLUETOOTH_A2DP_PLAY;
+                               break;
+                       case MEDIA_KEY_STOP:
+                               event = BLUETOOTH_A2DP_STOP;
+                               break;
+                       case MEDIA_KEY_PAUSE:
+                               event = BLUETOOTH_A2DP_PAUSE;
+                               break;
+                       case MEDIA_KEY_PREVIOUS:
+                               event = BLUETOOTH_A2DP_BACKWARD;
+                               break;
+                       case MEDIA_KEY_NEXT:
+                               event = BLUETOOTH_A2DP_FORWARD;
+                               break;
+                       case MEDIA_KEY_FASTFORWARD:
+                               event = BLUETOOTH_A2DP_FASTFORWARD;
+                               break;
+                       case MEDIA_KEY_REWIND:
+                               event = BLUETOOTH_A2DP_REWIND;
+                               break;
+                       case MEDIA_KEY_UNKNOWN:
+                               break;
+                       default:
+                               SysLog(NID_SYS, "default");
+                       }
+                       pDeviceManagerService->SendEvent(event);
+               }
+       }
+}
+
+_DeviceManagerService::_DeviceManagerService()
+       : _ICommunicationRequestListener()
+       , __pCommunicationDispatcher(null)
+       , isBluetoothHeadSetConnected(false)
+{
+       result r = E_SUCCESS;
+       int btResult = 0;
+
+       __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
+       SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher initiate is failed");
+
+       r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
+       SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to add event listener");
+
+       btResult = bt_audio_initialize();
+       SysTryCatch(NID_SYS, btResult == BT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to init bluetooth headset event");
+
+       btResult = bt_audio_set_connection_state_changed_cb(bluetooth_connection_state_changed, null);
+       SysTryCatch(NID_SYS, btResult == BT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to register bluetooth headset event");
+
+       r = __interestedAppList.Construct();
+       SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to initiate bluetooth headset application list");
+CATCH:
+       SetLastResult(r);
+}
+
+_DeviceManagerService::~_DeviceManagerService()
+{
+       result r = E_SUCCESS;
+       int btResult = 0;
+
+       SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher is not ready");
+
+       r = __pCommunicationDispatcher->RemoveCommunicationEventListener(*this);
+       SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to remove event listener");
+
+       btResult = bt_audio_unset_connection_state_changed_cb();
+       SysTryCatch(NID_SYS, btResult == BT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to unregister bluetooth headset connection event");
+
+       btResult = bt_audio_deinitialize();
+       SysTryCatch(NID_SYS, btResult == BT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Failed to close bluetooth");
+CATCH:
+       SetLastResult(r);
+}
+
+_DeviceManagerService*
+_DeviceManagerService::GetInstance(void)
+{
+       if(__pDeviceManagerService == null)
+       {
+               __pDeviceManagerService = new (std::nothrow) _DeviceManagerService();
+       }
+       return __pDeviceManagerService;
+}
+
+String
+_DeviceManagerService::GetId(void)
+{
+       return DEVICE_MANAGER_SERVICE_ID;
+}
+
+void
+_DeviceManagerService::SendEvent(String event)
+{
+       if(__interestedAppList.GetCount() > 0)
+       {
+               int count = 0;
+               AppId* pAppId = null;
+               ArrayList data;
+               String serviceId(DEVICE_MANAGER_SERVICE_ID);
+               String commandId(DEVICE_MANAGER_COMMAND_EVENT);
+               String deviceId(DEVICE_MANAGER_BLUETOOTH);
+               String eventId(event);
+
+               data.Construct();
+               data.Add(serviceId);
+               data.Add(commandId);
+               data.Add(deviceId);
+               data.Add(eventId);
+
+               for(count = 0 ; count < __interestedAppList.GetCount() ; count++)
+               {
+                       pAppId = (AppId*)__interestedAppList.GetAt(count);
+                       if(pAppId == null)
+                       {
+                               SysLogException(NID_SYS, E_SYSTEM, "fail to get appid from bluetooth headset app list");
+                               return;
+                       }
+
+                       __pCommunicationDispatcher->SendData(*pAppId, data);
+                       SysLog(NID_SYS, "Bluetooth headset event is sended to %ls", pAppId->GetPointer());
+               }
+
+       }
+       else
+       {
+               SysLog(NID_SYS, "Bluetooth Headset Event is not required by any application");
+       }
+}
+
+void
+_DeviceManagerService::OnBluetoothEventOccured(int code)
+{
+       int count = 0;
+       AppId* pAppId = null;
+
+       String command = DEVICE_MANAGER_COMMAND_EVENT;
+       String device = DEVICE_MANAGER_BLUETOOTH;
+       String event = L"event test";
+
+       result r = E_SUCCESS;
+
+       if(__interestedAppList.GetCount() == 0)
+       {
+               SysLog(NID_SYS, "Bluetooth Headset Event is not required by any application");
+               return;
+       }
+
+       ArrayList eventData;
+       r = eventData.Construct();
+       SysTryCatch(NID_SYS, r == E_SUCCESS, , E_SYSTEM, "fail to create eventData, [%s] Propagated.", GetErrorMessage(r));
+
+       eventData.Add(command);
+       eventData.Add(device);
+       eventData.Add(event);
+
+       for(count = 0 ; count < __interestedAppList.GetCount() ; count++)
+       {
+               pAppId = (AppId*)__interestedAppList.GetAt(count);
+               if(pAppId == null)
+               {
+                       SysLogException(NID_SYS, E_SYSTEM, "fail to get appid from bluetooth headset app list");
+                       return;
+               }
+
+               r = __pCommunicationDispatcher->SendData(*pAppId, eventData);
+               if(r != E_SUCCESS)
+               {
+                       SysLogException(NID_SYS, E_SYSTEM, "fail to send bluetooth event data");
+               }
+       }
+
+CATCH:
+       SetLastResult(r);
+}
+
+void
+_DeviceManagerService::AddInterestedApp(AppId appId)
+{
+       int count = 0;
+       for(count = 0; count < __interestedAppList.GetCount(); count++)
+       {
+               AppId* pAppId = null;
+
+               pAppId = (AppId*)__interestedAppList.GetAt(count);
+               if(*pAppId == appId)
+               {
+                       return;
+               }
+       }
+
+       if(__interestedAppList.GetCount() == 0)
+       {
+               SysLog(NID_SYS, "Bluetooth headset event is reserved.");
+               media_key_reserve(app_media_key_handler, null);
+       }
+
+       AppId* pNewAppId = new AppId(appId);
+       __interestedAppList.Add(*pNewAppId);
+
+}
+
+void
+_DeviceManagerService::RemoveInterestedApp(AppId appId)
+{
+       int count = 0;
+       for(count = 0; count < __interestedAppList.GetCount(); count++)
+       {
+               AppId* pAppId = null;
+
+               pAppId = (AppId*)__interestedAppList.GetAt(count);
+               if(*pAppId == appId)
+               {
+                       __interestedAppList.RemoveAt(count, true);
+
+                       if(__interestedAppList.GetCount() == 0)
+                       {
+                               SysLog(NID_SYS, "Bluetooth headset event is released.");
+                               media_key_release();
+                       }
+
+                       return;
+               }
+       }
+
+}
+
+void
+_DeviceManagerService::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
+{
+       StringComparer strComparer;
+       int cmp = 0;
+       result r = E_SUCCESS;
+       String* command = null;
+       String* device = null;
+
+       SysLog(NID_APP, "Request is forwarded to _DeviceManagerService");
+       SysTryCatch(NID_SYS, request != null && response != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters are null");
+
+       command = (String*)request->GetAt(1);
+       device = (String*)request->GetAt(2);
+       SysTryCatch(NID_SYS, command!= null && device != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters has no command %x, %x", command, device);
+
+       SysLog(NID_SYS, "command is %ls, device is %ls", command->GetPointer(), device->GetPointer());
+
+       strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_OPEN, cmp);
+       if(cmp == 0)
+       {
+               strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
+               if(cmp == 0)
+               {
+                       SysLog(NID_SYS, "Bluetooth headset event is required");
+                       AddInterestedApp(appId);
+               }
+       }
+
+       strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_CLOSE, cmp);
+       if(cmp == 0)
+       {
+               strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
+               if(cmp == 0)
+               {
+                       RemoveInterestedApp(appId);
+               }
+       }
+
+       strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_STATUS, cmp);
+       if(cmp == 0)
+       {
+               strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
+               if(cmp == 0)
+               {
+
+                       SysLog(NID_SYS, "Bluetooth headset status is %d", isBluetoothHeadSetConnected);
+                       if(response != null)
+                       {
+                               String* serviceId = new (std::nothrow) String(DEVICE_MANAGER_SERVICE_ID);
+                               String* commandId = new (std::nothrow) String(DEVICE_MANAGER_COMMAND_STATUS);
+                               String* deviceId = new (std::nothrow) String(DEVICE_MANAGER_BLUETOOTH);
+                               String* status = null;
+                               if(isBluetoothHeadSetConnected == true)
+                               {
+                                       status = new (std::nothrow) String(BLUETOOTH_A2DP_CONNECTED);
+                               }
+                               else
+                               {
+                                       status = new (std::nothrow) String(BLUETOOTH_A2DP_DISCONNECTED);
+                               }
+                               response->Add(*serviceId);
+                               response->Add(*commandId);
+                               response->Add(*deviceId);
+                               response->Add(*status);
+                       }
+               }
+       }
+
+CATCH:
+       SetLastResult(r);
+}
+
+void
+_DeviceManagerService::OnApplicationTerminated(const AppId& appId, const String& executableName, AppType type)
+{
+       RemoveInterestedApp(appId);
+}
+
+bool
+_DeviceManagerService::GetBluetoothStatus(void)
+{
+       return isBluetoothHeadSetConnected;
+}
+void
+_DeviceManagerService::SetBluetoothStatus(bool status)
+{
+       isBluetoothHeadSetConnected = status;
+}
+
diff --git a/src/FSys_SystemService.cpp b/src/FSys_SystemService.cpp
new file mode 100644 (file)
index 0000000..149cc77
--- /dev/null
@@ -0,0 +1,156 @@
+//
+// Open Service Platform
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// 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.
+//
+
+/**
+ * @file               FSys_SystemService.cpp
+ * @brief              This is the implementation file for _SystemService class.
+ */
+
+#include <new>
+
+#include <FBaseSysLog.h>
+
+#include <FSec_AccessController.h>
+
+#include "FApp_CommunicationDispatcher.h"
+#include "FSys_SystemService.h"
+
+using namespace Osp::App;
+using namespace Osp::Io;
+using namespace Osp::System;
+using namespace Osp::Base;
+using namespace Osp::Base::Collection;
+using namespace Osp::Security;
+
+namespace {
+       const String SYSTEM_SERVICE_ID = L"osp.system.service";
+       const String SYSTEM_COMMAND_CHECK_PRIVILEGE = L"osp.system.command.check.privilege";
+       const String SYSTEM_RESULT_OK = L"osp.system.result.ok";
+       const String SYSTEM_RESULT_ERROR = L"osp.system.result.error";
+       const String SYSTEM_COMMAND_PRIVILEGE_USER_IDENTITY = L"user.identity";
+       const String SYSTEM_COMMAND_PRIVILEGE_INSTALLATION = L"installation";
+}
+
+Osp::System::_SystemService* Osp::System::_SystemService::__pSystemService = null;
+
+_SystemService::_SystemService()
+       : _ICommunicationRequestListener()
+       , __pCommunicationDispatcher(null)
+{
+       result r = E_SUCCESS;
+
+       __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
+       SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher initiate is failed");
+
+       r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
+       SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to add event listener");
+
+CATCH:
+       SetLastResult(r);
+}
+
+_SystemService::~_SystemService()
+{
+       result r = E_SUCCESS;
+
+       SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher is not ready");
+
+       r = __pCommunicationDispatcher->RemoveCommunicationEventListener(*this);
+       SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "fail to remove event listener");
+
+CATCH:
+       SetLastResult(r);
+}
+
+_SystemService*
+_SystemService::GetInstance(void)
+{
+       if(__pSystemService == null)
+       {
+               __pSystemService = new (std::nothrow) _SystemService();
+       }
+       return __pSystemService;
+}
+
+String
+_SystemService::GetId(void)
+{
+       return SYSTEM_SERVICE_ID;
+}
+
+void
+_SystemService::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
+{
+       result r = E_SUCCESS;
+       StringComparer strComparer;
+       int cmp = 0;
+       String* command = null;
+       String* privilegeId = null;
+
+       SysLog(NID_APP, "Request is forwarded to _DeviceManagerService");
+       SysTryCatch(NID_SYS, request != null && response != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters are null");
+
+       command = (String*)request->GetAt(1);
+       SysTryCatch(NID_SYS, command!= null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters has no command %x, %x", command);
+
+       strComparer.Compare(*command, SYSTEM_COMMAND_CHECK_PRIVILEGE, cmp);
+       if(cmp == 0)
+       {
+               SysLog(NID_SYS, "Check System level privilege");
+               if(response != null)
+               {
+                       String* serviceId = new (std::nothrow) String(SYSTEM_SERVICE_ID);
+                       String* commandId = new (std::nothrow) String(SYSTEM_COMMAND_CHECK_PRIVILEGE);
+                       String* result = null;
+
+                       privilegeId = (String*)request->GetAt(2);
+
+                       strComparer.Compare(*privilegeId, SYSTEM_COMMAND_PRIVILEGE_USER_IDENTITY, cmp);
+                       if(cmp == 0)
+                       {
+                               r = _AccessController::CheckSystemPrivilege(appId, _PRV_USER_IDENTITY);
+                       }
+
+                       strComparer.Compare(*privilegeId, SYSTEM_COMMAND_PRIVILEGE_INSTALLATION, cmp);
+                       if(cmp == 0)
+                       {
+                               r = _AccessController::CheckSystemPrivilege(appId, _PRV_INSTALLATION);
+                       }
+
+                       if(r == E_SUCCESS)
+                       {
+                               result = new (std::nothrow) String(SYSTEM_RESULT_OK);
+                       }
+                       else
+                       {
+                               result = new (std::nothrow) String(SYSTEM_RESULT_ERROR);
+                       }
+
+                       response->Add(*serviceId);
+                       response->Add(*commandId);
+                       response->Add(*result);
+               }
+       }
+CATCH:
+       SetLastResult(r);
+}
+
+void
+_SystemService::OnApplicationTerminated(const AppId& appId, const String& executableName, AppType type)
+{      
+}
+
diff --git a/system-service-export.ver b/system-service-export.ver
new file mode 100755 (executable)
index 0000000..68c06a8
--- /dev/null
@@ -0,0 +1,6 @@
+{
+global:
+       OspMain;
+local:
+       *;
+};