sync with tizen_2.2
authorsungmin82.ha <sungmin82.ha@samsung.com>
Tue, 30 Jul 2013 06:11:46 +0000 (15:11 +0900)
committersungmin82.ha <sungmin82.ha@samsung.com>
Tue, 30 Jul 2013 06:11:46 +0000 (15:11 +0900)
Change-Id: I9dc01bae0fec5a8e7a0596b07f519cae0f854ef8
Signed-off-by: Sungmin Ha <sungmin82.ha@samsung.com>
200 files changed:
AUTHORS [new file with mode: 0644]
LICENSE.APLv2 [new file with mode: 0644]
NOTICE [new file with mode: 0644]
ei-library/.classpath [new file with mode: 0644]
ei-library/.project [new file with mode: 0644]
ei-library/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
ei-library/build.xml [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/ConnectionToEmulator.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/Emulator.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/EmulatorList.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/EventReceiver.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/EventSocket.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/IEmulatorChangeListener.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/SDKInstallPathConfig.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/message/ActionID.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/message/EventHeader.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/message/EventMessage.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/message/EventType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/connection/message/GroupID.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/AbstractEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/BatteryEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/CallEvent.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/CallEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/CallItem.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/EarJackEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/EventInjectorCreator.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/LocationEvent.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/LocationEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/NfcEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/NfcEventType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/RSSIEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/SDCardEvent.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/SDCardEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/SMSEvent.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/SMSEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/SensorEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/USBEventInjector.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/listener/EventListenerList.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/listener/ICallEventListener.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/listener/IEventListener.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/listener/ISDcardEventListener.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/listener/ISMSEventListener.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/receiver/AbstractEventReceiver.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/receiver/EventReceiver.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/receiver/StatusEventReceiver.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/sender/AbstractEventSender.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/sender/DeviceEventSender.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/sender/LocationEventSender.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/sender/ModemEventSender.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/sender/NfcEventSender.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/sender/SDCardEventSender.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/sender/SDCardStatusCheckSender.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/sender/SensorEventSender.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/BatteryCharger.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/CallErrorCode.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/CallEventType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/CallStatus.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/CallType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/EarJackStatus.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/LocationEventMode.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/MMSStatus.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/MimeTypeList.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/MobileType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/MotionEventType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/NDEFFormat.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/NDEFRecord.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/NfcTagType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/ProximityStatus.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/SDCardEventType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/SMSEventType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/SMSStatus.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/SensorEventType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/events/type/USBStatus.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/exception/CallEventException.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/exception/ConnectionException.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/exception/DeviceEventException.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/exception/EILibError.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/exception/InjectorLibraryException.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/exception/InvalidTypeException.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/exception/NfcEventException.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/exception/SMSEventException.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/exception/SensorEventException.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/encription/DecodeMsg.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/encription/EncodeMsg.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/encription/EnumConstants.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/encription/SMS_USERDATA.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/encription/SmsAddressInfo.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_DELIVER.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_SUBMIT.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextCodingScheme.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextVP.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/encription/TmDateTime.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/AbstractGA.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/AbstractItem.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/ByteArrayItem.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/ByteUtil.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G01A07.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G01A21MO.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G01A21MT.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G01A22.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G01A22End.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G01A23.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G01A26.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G01A29.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G01A62.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G02A31.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G04A01.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/G04A05.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/IntItem.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/ItemType.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/StringUtil.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/modem/protocol/StructureGA.java [new file with mode: 0644]
ei-library/src/org/tizen/eilib/tools/EILogger.java [new file with mode: 0644]
eventinjector-cli/.classpath [new file with mode: 0644]
eventinjector-cli/.project [new file with mode: 0644]
eventinjector-cli/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
eventinjector-cli/build.xml [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/DeviceList.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/EventInjector.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/EventRecorder.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/GlobalOption.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/StringResource.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/Argument.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/Command.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/Device.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/EmulatorDevice.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/ExitDevice.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/HelpDevice.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/Option.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/Record.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/RecordPlay.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/RecordStart.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/ArgBatteryCharger.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/ArgBatteryLevel.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/Battery.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/BatteryLevel.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/BatterySetCharger.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/EarJack.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/EarJackSet.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/RSSI.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/RssiSet.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/SDCard.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/SDCardMount.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/SDCardStatus.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/SDCardUnmount.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/USBDevice.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/device/USBDeviceSet.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/location/Location.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/location/LocationCoordinate.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/location/LocationLogFile.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/location/LocationStop.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/ArgCallNumber.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/Call.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/CallAlert.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/CallConnect.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/CallDial.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/CallDisconnect.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/CallHidden.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/MmsSetStatus.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/SMS.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/SmsSend.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/modem/SmsSetStatus.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/nfc/ArgMessageEventType.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/nfc/ArgMessageIndex.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/nfc/ArgNDEFMessage.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/nfc/ArgNfcTagEvent.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/nfc/Nfc.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/nfc/NfcMessage.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/nfc/NfcP2P.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/nfc/NfcTag.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/ArgAccelValue.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/ArgGyroValue.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/ArgLightValue.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/ArgMagneticValue.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/ArgProxiValue.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorFilePath.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorName.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorValue.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/Motion.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/MotionSet.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/Sensor.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/SensorFile.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/SensorGet.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/device/sensor/SensorSet.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/exception/ConsoleError.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/exception/ConsoleException.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/parser/ArgCompletor.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/parser/Args.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/parser/CommandCompletor.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/parser/CommandParser.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/parser/DeviceCompletor.java [new file with mode: 0644]
eventinjector-cli/src/org/tizen/injector/parser/HelpMessage.java [new file with mode: 0644]
library/COPYING.BSD [new file with mode: 0644]
library/jline-1.0.jar [new file with mode: 0644]
package/build.linux [new file with mode: 0644]
package/changelog [new file with mode: 0644]
package/pkginfo.manifest [new file with mode: 0644]
supplement/eventinjector-cli-mac.sh [new file with mode: 0644]
supplement/eventinjector-cli.bat [new file with mode: 0644]
supplement/eventinjector-cli.sh [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..1722483
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,12 @@
+YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+DaiYoung Kim <daiyoung777.kim@samsung.com>
+SeokYeon Hwang <syeon.hwang@samsung.com>
+SangJin Kim <sangjin3.kim@samsung.com>
+KiTae Kim <kt920.kim@samsung.com>
+JinHyung Jo <jinhyung.jo@samsung.com>
+SungMin Ha <sungmin82.ha@samsung.com>
+MunKyu Im <munkyu.im@samsung.com>
+JiHye Kim <jihye1128.kim@samsung.com>
+GiWoong Kim <giwoong.kim@samsung.com>
+SooYoung Ha <yoosah.ha@samsnung.com>
+HyunGoo Kang <hyungoo1.kang@samsung.com>
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100644 (file)
index 0000000..1d4a865
--- /dev/null
@@ -0,0 +1,206 @@
+Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
+
+
+
diff --git a/NOTICE b/NOTICE
new file mode 100644 (file)
index 0000000..04c1aec
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,3 @@
+Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE.APLv2 file for Apache License Version 2, terms and conditions.
diff --git a/ei-library/.classpath b/ei-library/.classpath
new file mode 100644 (file)
index 0000000..0825831
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="lib" path="lib/sdblib.jar"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/ei-library/.project b/ei-library/.project
new file mode 100644 (file)
index 0000000..d326e1d
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>EILibrary</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/ei-library/.settings/org.eclipse.jdt.core.prefs b/ei-library/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..e5232dd
--- /dev/null
@@ -0,0 +1,12 @@
+#Mon Sep 24 13:49:36 KST 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/ei-library/build.xml b/ei-library/build.xml
new file mode 100644 (file)
index 0000000..c716c21
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0" standalone="yes"?>
+<project name="eilib" basedir="." default="make-jar">
+
+       <property name="jar.file" value="../eilib.jar" />
+       <property name="sdb.file" value="sdblib.jar" />
+
+       <path id="classpath">
+               <fileset dir="lib" includes="${sdb.file}" />
+       </path>
+
+       <target name="clean">
+               <echo message="cleaning..." />
+               <delete dir="build" />
+               <delete file="${jar.file}" />
+       </target>
+
+       <target name="prepare-compile">
+               <echo message="prepare for compile..." />
+               <delete dir="build" />
+               <mkdir dir="build" />
+       </target>
+
+       <target name="compile" depends="prepare-compile">
+               <echo message="compiling..." />
+               <javac encoding="UTF-8" fork="true" srcdir="src" destdir="build" debug="on" memorymaximumsize="128m">
+                       <classpath refid="classpath" />
+               </javac>
+       </target>
+
+       <target name="create-jar">
+               <echo message="creating jar..." />
+               <jar jarfile="${jar.file}" basedir="build" duplicate="add">
+                       <manifest>
+                               <attribute name="Class-path" value="${sdb.file}" />
+                       </manifest>
+               </jar>
+               <delete dir="build" />
+       </target>
+
+       <target name="make-jar" depends="compile, create-jar" />
+
+       <!-- for dibs system... -->
+       <path id="classpath-dibs">
+               <fileset dir="${classpath.dibs}" includes="${sdb.file}" />
+       </path>
+
+       <target name="compile-dibs" depends="prepare-compile">
+               <echo message="compiling..." />
+               <javac encoding="UTF-8" fork="true" srcdir="src" destdir="build" debug="on" memorymaximumsize="128m">
+                       <classpath refid="classpath-dibs" />
+               </javac>
+       </target>
+
+       <target name="create-dibs-jar">
+               <echo message="creating dibs jar..." />
+               <jar jarfile="${jar.file}" basedir="build" duplicate="add">
+                       <manifest>
+                               <attribute name="Class-path" value="../../ide/lib/${sdb.file}" />
+                       </manifest>
+               </jar>
+               <delete dir="build" />
+       </target>
+
+
+       <target name="make-jar-dibs" depends="compile-dibs, create-dibs-jar" />
+
+</project>
diff --git a/ei-library/src/org/tizen/eilib/connection/ConnectionToEmulator.java b/ei-library/src/org/tizen/eilib/connection/ConnectionToEmulator.java
new file mode 100644 (file)
index 0000000..e2c229c
--- /dev/null
@@ -0,0 +1,404 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.connection;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.EventType;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.connection.EmulatorList;
+import org.tizen.eilib.events.EventInjectorCreator;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.receiver.StatusEventReceiver;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.tools.EILogger;
+import org.tizen.sdblib.exception.SdbCommandRejectedException;
+import org.tizen.sdblib.exception.ShellCommandUnresponsiveException;
+import org.tizen.sdblib.exception.TimeoutException;
+import org.tizen.sdblib.receiver.MultiLineReceiver;
+/**
+ * Instances of this class manages communication with emulator and event injector .
+ * 
+ */
+public class ConnectionToEmulator {
+       /**
+        * Socket to connect with emulator.
+        */
+       private EventSocket socket = null;
+
+       /**
+        * Receiver of event from the emulator.
+        */
+       private HashMap<Integer, AbstractEventReceiver> receiverMap;
+
+       /**
+        * Running emulator list.
+        */
+       private EmulatorList emList;
+
+       /**
+        * Current connecting emulator.
+        */
+       private Emulator currentEmulator = null;
+
+
+       private static String EMULD_VERSION = "0.2.23";
+
+       /**
+        * Constructs a new instance of this class make event map and create socket
+        */
+       public ConnectionToEmulator() {
+               receiverMap = new HashMap<Integer, AbstractEventReceiver>();
+               addEventReceiver(GroupID.STATUS, new StatusEventReceiver());
+
+               socket = new EventSocket(receiverMap);
+
+               emList = EmulatorList.getInstance();
+       }
+
+       /**
+        * Add event receiver.
+        * You can register the event receiver that can receive the message from the emulator.
+        * @param gID GroupID value,
+        * @param receiver
+        */
+       public void addEventReceiver(int gID, AbstractEventReceiver receiver) {
+               receiverMap.put((Integer)gID, receiver);
+       }
+
+       /**
+        * Remove event receiver
+        * 
+        * @param gID GroupID value
+        */
+       public void removeEventReceiver(int gID) {
+               receiverMap.remove((Integer)gID);
+       }
+
+       /**
+        * Find event receiver
+        * @param gID GroupID value
+        * @return event receiver
+        */
+       public AbstractEventReceiver findEventReceiver(int gID) {
+               return receiverMap.get(gID);
+       }
+
+       /**
+        * Set IP address.
+        * Default value is local host (127.0.0.1)
+        * 
+        * @param ip ip address of emulator (Format : xxx.xxx.xxx.xxx)
+        */
+       public void setIPAdderss(String ip) {
+               socket.setIP(ip);
+       }
+
+       /**
+        * Set port number
+        * 
+        * Note : Before connect to emulator, set port number.
+        * If port number is 0 (default), to connect to emulator is failed.
+        * 
+        * @param port
+        */
+       public void setPort(int port) {
+               socket.setPort(port);
+       }
+
+       /**
+        * Connect to emulator
+        * 
+        * @exception IOException <ul>
+        *      <li>If failed to open socket </li>
+        * @exception UnknownHostException <ul>
+        *      <li>If port number is not initialized.</li>
+        * @exception InjectorLibraryException
+        * 
+        * @return result of connect to emulator. 
+        * @throws InjectorLibraryException 
+        */
+       public boolean connect() throws IOException, InjectorLibraryException {
+               return connect(0);
+       }
+
+       /**
+        * Connect to emulator
+        * 
+        * @exception IOException <ul>
+        *      <li>If failed to open socket </li>
+        * @exception UnknownHostException <ul>
+        *      <li>If port number is not initialized.</li>
+        * @exception InjectorLibraryException
+        * 
+        * @param   port
+        * @return result of connect to emulator. 
+        * @throws InjectorLibraryException 
+        */
+       public boolean connect(int port) throws IOException, InjectorLibraryException {
+               if (socket.isConnected()) {
+                       socket.disconnect();
+               }
+
+               boolean result = false;
+               if (port == 0) {
+                       if (socket.getPort() == 0) {
+                               ArrayList<Emulator> list = emList.getEmulatorList();
+                               if(list.size() == 0) {
+                                       throw new InjectorLibraryException(EILibError.EmulatorNotExist);
+                               } else if (list.size() > 1) {
+                                       throw new InjectorLibraryException(EILibError.EmulatorNotOne);
+                               } else {
+                                       socket.setPort(list.get(0).getPort());
+                               }
+                       }
+                       result = socket.connect();
+               } else {
+                       result = socket.connect(port);
+               }
+
+               if (result) {
+                       //sendModemInitialize();
+                       //sendInitializeMessage();
+
+                       int socketPort = socket.getPort();
+                       ArrayList<Emulator> emulators = emList.getEmulatorList();
+                       for (Emulator e : emulators) {
+                               if (e.getPort() == socketPort) {
+                                       currentEmulator = e;
+                               }
+                       }
+
+                       if (currentEmulator != null) {
+                               checkEmuldVersion();
+                       }
+               }
+
+               if (creator != null) {
+                       creator.intializeConnectToEmulator();
+               }
+
+               return result;
+       }
+
+       private final static String shellCmd = "rpm -q emuld";
+       private String shellResult      = null;
+       private void checkEmuldVersion() throws InjectorLibraryException {
+               shellResult     = null;
+               String errorMessage     = null;
+
+               try {
+                       currentEmulator.getDevice().executeShellCommand(shellCmd, new MultiLineReceiver() {
+                               @Override
+                               public void processNewLines(String[] lines) {
+                                       shellResult = lines[0];
+                               }
+                       });
+               } catch (TimeoutException e) {
+                       errorMessage = e.getMessage();
+               } catch (SdbCommandRejectedException e) {
+                       errorMessage = e.getMessage();
+               } catch (ShellCommandUnresponsiveException e) {
+                       errorMessage = e.getMessage();
+               } catch (IOException e) {
+                       errorMessage = e.getMessage();
+               }
+
+               if (errorMessage == null && shellResult != null) {
+                       //emuld-0.2.20-1.1.i586
+                       String[] vals = shellResult.split("-");
+                       if (vals.length == 3) {
+                               String version = vals[1];
+                               if (version.compareTo(EMULD_VERSION) < 0) {
+                                       throw new InjectorLibraryException(EILibError.EmuldVersionOld);
+                               }
+                       } else {
+                               EILogger.getLogger().warning("Emuld does not installed normal path.");
+                       }
+               } else {
+                       EILogger.getLogger().warning(errorMessage);
+               }
+       }
+
+       public String getEmuldVersion() {
+               return EMULD_VERSION;
+       }
+
+       /**
+        * Disconnect to emulator
+        * 
+        * @return result
+        */
+       public boolean disconnect() {
+               return socket.disconnect();
+       }
+
+       /**
+        * Return current state of connection to emulator.
+        * @return
+        */
+       public boolean isConnect() {
+               return socket.isConnected();
+       }
+
+       public void terminate() {
+               if (socket.isConnected()) {
+                       socket.disconnect();
+               }
+       }
+
+       private EventInjectorCreator creator = null;
+
+       /**
+        * Setting the relationship between the 'EventInjectorCreator' and 'ConnectionToEmualtor'
+        * 
+        * @param creator EventInjectorCreator's instance
+        */
+       public void setEventInjectorCreator(EventInjectorCreator creator) {
+               this.creator = creator;
+       }
+
+       /**
+        * Send message to emulator
+        * @param message
+        * @return
+        * @throws IOException 
+        * @throws ConnectionException 
+        */
+       public boolean sendMessage(EventMessage message) throws IOException, ConnectionException {
+               return socket.sendMessage(message);
+       }
+
+       private EventMessage initMessage = null;
+       private byte[] initMsgHeader1   = {0x04, 0x00, 0x40, 0x41};
+       private byte[] initMsgData1     = {0x16, 0x00, 0x00, 0x00};
+       private byte[] initMsgHeader2   = {0x00, 0x00, 0x40, 0x47};
+       private byte[] initMsgData2     = {0x00, 0x00, 0x40, 0x42};
+
+       private byte[] initAskData      = {0x00, 0x00, 0x11, 0x5b};
+
+       /**
+        * Send initialize message. Receive call list message from the vmodem.
+        * 
+        * @throws IOException
+        * @throws InjectorLibraryException
+        * @throws ConnectionException 
+        */
+       public void sendInitializeMessage() throws IOException, ConnectionException {
+               if (!socket.isConnected()) {
+                       // TODO : error
+                       EILogger.getLogger().warning("Socket is disconnected..");
+                       return;
+               }
+
+               if (initMessage == null) {
+                       initMessage = new EventMessage(128);
+                       initMessage.setEventTypeBuffer(EventType.TELEPHONY);
+               }
+
+               // #1
+               initMessage.clear();
+               initMessage.getHeaderBuffer().put(initAskData);
+               sendMessage(initMessage);
+       }
+
+       /**
+        * Send message that initialize the vmodem.
+        * 
+        * @throws IOException
+        * @throws InjectorLibraryException
+        * @throws ConnectionException 
+        */
+       public void sendModemInitialize() throws IOException, ConnectionException {
+               if (!socket.isConnected()) {
+                       // TODO : error
+                       EILogger.getLogger().warning("Socket is disconnected..");
+               }
+               
+               if (initMessage == null) {
+                       initMessage = new EventMessage(128);
+                       initMessage.setEventTypeBuffer(EventType.TELEPHONY);
+               }
+
+               // #1
+               initMessage.clear();
+               initMessage.getHeaderBuffer().put(initMsgHeader1);
+               initMessage.getDataBuffer().put(initMsgData1);
+               sendMessage(initMessage);
+
+               // #2
+               initMessage.clear();
+               initMessage.getHeaderBuffer().put(initMsgHeader2);
+               initMessage.getDataBuffer().put(initMsgData2);
+               sendMessage(initMessage);
+       }
+
+       /**
+        * Return running emulator list
+        * @return array of emulator.
+        */
+       public  ArrayList<Emulator> getEmulatorList() {
+               return emList.getEmulatorList();
+       }
+
+       /**
+        * Return current connection emulator.
+        * @return emulator If running emulator does not exist, null is returned.
+        */
+       public Emulator getCurrentEmulator() {
+               if (!isConnect()) {
+                       return null;
+               }
+               if (emList == null) {
+                       return null;
+               }
+
+               /*
+               int socketPort = socket.getPort();
+               ArrayList<Emulator> emulators = emList.getEmulatorList();
+               for (Emulator e : emulators) {
+                       if (e.getPort() == socketPort) {
+                               return e;
+                       }
+               }
+               */
+               return currentEmulator;
+       }
+
+       /**
+        * 
+        * @param listener
+        */
+       public void addDeviceChangeListener(IEmulatorChangeListener listener) {
+               emList.setChangeListener(listener);
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/connection/Emulator.java b/ei-library/src/org/tizen/eilib/connection/Emulator.java
new file mode 100644 (file)
index 0000000..5c78178
--- /dev/null
@@ -0,0 +1,341 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.connection;
+
+import java.io.IOException;
+
+import org.tizen.sdblib.DeviceState;
+import org.tizen.sdblib.IDevice;
+import org.tizen.sdblib.IShellOutputReceiver;
+import org.tizen.sdblib.exception.SdbCommandRejectedException;
+import org.tizen.sdblib.exception.ShellCommandUnresponsiveException;
+import org.tizen.sdblib.exception.TimeoutException;
+import org.tizen.sdblib.receiver.NullOutputReceiver;
+import org.tizen.sdblib.service.SyncService;
+import org.tizen.sdblib.util.DeviceUtil;
+import org.tizen.sdblib.util.SdbShellProcess;
+
+/**
+ * This class have IDevice and additional feather.
+ *
+ */
+public class Emulator {
+       private final static int INSTALL_TIMEOUT = 2 * 60 * 1000; 
+       
+       private IDevice device;
+       private int port;
+       private boolean isMounted;
+       private String SDCardName;
+
+       /**
+        * 
+        * @param device
+        */
+       public Emulator(IDevice device) {
+               this.device = device;
+               setPort(Integer.parseInt(device.getSerialNumber().substring(9)) + 3);
+               isMounted       = false;
+               SDCardName      = "";
+       }
+
+       /**
+        * Return emulator's description
+        * emulator name + serial number + port number
+        */
+       @Override
+       public String toString() {
+               return device.getDeviceName() + " " + device.getSerialNumber() + " " + Integer.toString(port);
+       }
+
+       /**
+        * If two emulators have the same names, determines that they are same.
+        */
+       @Override
+       public boolean equals(Object obj) {
+               if (!(obj instanceof Emulator)) {
+                       return false;
+               }
+
+               if (((Emulator)obj).getDeviceName().equals(getDeviceName())) {
+                       return true;
+               }
+               return false;
+       }
+
+       /**
+        * Return IDevice object
+        * @return
+        */
+       public IDevice getDevice() {
+               return device;
+       }
+
+       /**
+        * 
+        * @param device
+        */
+       public void setDevice(IDevice device) {
+               this.device = device;
+               setPort(Integer.parseInt(device.getSerialNumber().substring(9)) + 3);
+       }
+
+       /**
+        * Return emulator's emulator daemon port
+        * @return
+        */
+       public int getPort() {
+               return port;
+       }
+
+       /**
+        * 
+        * @param port emulator daemon port
+        */
+       public void setPort(int port) {
+               this.port = port;
+       }
+
+       /**
+        * Return SD card mount status
+        * @return
+        */
+       public boolean isMounted() {
+               return isMounted;
+       }
+
+       /**
+        * 
+        * @param isMounted true : mount, false : unmount
+        */
+       public void setMounted(boolean isMounted) {
+               this.isMounted = isMounted;
+       }
+
+       /**
+        * Return mounted SD card name
+        * @return 
+        */
+       public String getSDCardName() {
+               return SDCardName;
+       }
+
+       public void setSDCardName(String SDCardName) {
+               this.SDCardName = SDCardName;
+       }
+
+
+    /**
+     * Returns the serial number of the device.
+     */
+    public String getSerialNumber() {
+       return device.getSerialNumber();
+    }
+
+    /**
+     * Returns the name of the device.
+     */
+    public String getDeviceName(){
+       return device.getDeviceName();
+    }
+
+    /**
+     * Returns the state of the device.
+     * @return
+     */
+    public DeviceState getState() {
+       return device.getState();
+    }
+
+    /**
+     * Returns if the device is ready.
+     *
+     * @return <code>true</code> if {@link #getState()} returns {@link DeviceState#ONLINE}.
+     */
+    public boolean isOnline() {
+       return DeviceUtil.isOnline( device );
+    }
+
+    /**
+     * Returns <code>true</code> if the device is an emulator.
+     */
+    public boolean isEmulator() {
+       return device.isEmulator();
+    }
+
+    /**
+     * Returns if the device is offline.
+     *
+     * @return <code>true</code> if {@link #getState()} returns {@link DeviceState#OFFLINE}.
+     */
+    public boolean isOffline() {
+       return !DeviceUtil.isOnline( device );
+    }
+
+    /**
+     * Returns a {@link SyncService} object to push / pull files to and from the device.
+     *
+     * @return <code>null</code> if the SyncService couldn't be created. This can happen if sdb
+     *            refuse to open the connection because the {@link IDevice} is invalid
+     *            (or got disconnected).
+     * @throws TimeoutException in case of timeout on the connection.
+     * @throws SdbCommandRejectedException if sdb rejects the command
+     * @throws IOException if the connection with sdb failed.
+     */
+    public SyncService getSyncService()
+            throws TimeoutException, SdbCommandRejectedException, IOException {
+       return device.getSyncService();
+    }
+
+    /**
+     * Executes a shell command on the device and return SdbShellProcess
+     *
+     * @param command the shell command to execute
+     * @throws IOException in case of I/O error on the connection.
+     *
+     * @see SdbShellProcess
+     */
+    public SdbShellProcess executeShellCommand(String command) throws IOException {
+       return device.executeShellCommand(command);
+    }
+
+    /**
+     * Executes a shell command on the device, and sends the result to a <var>receiver</var>
+     * <p/>This is similar to calling
+     * <code>executeShellCommand(command, receiver, SdbPreferences.getTimeOut())</code>.
+     *
+     * @param command the shell command to execute
+     * @param receiver the {@link IShellOutputReceiver} that will receives the output of the shell
+     *            command
+     * @throws TimeoutException in case of timeout on the connection.
+     * @throws SdbCommandRejectedException if sdb rejects the command
+     * @throws ShellCommandUnresponsiveException in case the shell command doesn't send output
+     *            for a given time.
+     * @throws IOException in case of I/O error on the connection.
+     *
+     * @see #executeShellCommand(String, IShellOutputReceiver, int)
+     * @see SdbPreferences#getTimeOut()
+     */
+    public void executeShellCommand(String command, IShellOutputReceiver receiver)
+            throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException,
+            IOException {
+       device.executeShellCommand(command, receiver);
+    }
+
+    /**
+     * Executes a shell command on the device, and sends the result to a <var>receiver</var>.
+     * <p/><var>maxTimeToOutputResponse</var> is used as a maximum waiting time when expecting the
+     * command output from the device.<br>
+     * At any time, if the shell command does not output anything for a period longer than
+     * <var>maxTimeToOutputResponse</var>, then the method will throw
+     * {@link ShellCommandUnresponsiveException}.
+     * <p/>For commands like log output, a <var>maxTimeToOutputResponse</var> value of 0, meaning
+     * that the method will never throw and will block until the receiver's
+     * {@link IShellOutputReceiver#isCancelled()} returns <code>true</code>, should be
+     * used.
+     *
+     * @param command the shell command to execute
+     * @param receiver the {@link IShellOutputReceiver} that will receives the output of the shell
+     *            command
+     * @param maxTimeToOutputResponse the maximum amount of time during which the command is allowed
+     *            to not output any response. A value of 0 means the method will wait forever
+     *            (until the <var>receiver</var> cancels the execution) for command output and
+     *            never throw.
+     * @throws TimeoutException in case of timeout on the connection when sending the command.
+     * @throws SdbCommandRejectedException if sdb rejects the command.
+     * @throws ShellCommandUnresponsiveException in case the shell command doesn't send any output
+     *            for a period longer than <var>maxTimeToOutputResponse</var>.
+     * @throws IOException in case of I/O error on the connection.
+     *
+     * @see SdbPreferences#getTimeOut()
+     */
+    public void executeShellCommand(String command, IShellOutputReceiver receiver,
+            int maxTimeToOutputResponse)
+            throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException,
+            IOException {
+       device.executeShellCommand(command, receiver, maxTimeToOutputResponse);
+    }
+
+    /**
+     * Creates a port forwarding between a local and a remote port.
+     *
+     * @param localPort the local port to forward
+     * @param remotePort the remote port.
+     * @return <code>true</code> if success.
+     * @throws TimeoutException in case of timeout on the connection.
+     * @throws SdbCommandRejectedException if sdb rejects the command
+     * @throws IOException in case of I/O error on the connection.
+     */
+    public void createForward(int localPort, int remotePort)
+            throws TimeoutException, SdbCommandRejectedException, IOException {
+       device.createForward(localPort, remotePort);
+    }
+
+    /**
+     * Removes a port forwarding between a local and a remote port.
+     *
+     * @param localPort the local port to forward
+     * @param remotePort the remote port.
+     * @return <code>true</code> if success.
+     * @throws TimeoutException in case of timeout on the connection.
+     * @throws SdbCommandRejectedException if sdb rejects the command
+     * @throws IOException in case of I/O error on the connection.
+     */
+    public void removeForward(int localPort, int remotePort)
+            throws TimeoutException, SdbCommandRejectedException, IOException {
+       device.removeForward(localPort, remotePort);
+    }
+
+    /**
+     * Pushes a file to device
+     *
+     * @param localFilePath the absolute path to file on local host
+     * @return {@link String} destination path on device for file
+     * @throws TimeoutException in case of timeout on the connection.
+     * @throws SdbCommandRejectedException if sdb rejects the command
+     * @throws IOException in case of I/O error on the connection.
+     */
+    public String syncPackageToDevice(String localFilePath)
+            throws TimeoutException, SdbCommandRejectedException, IOException {
+       return DeviceUtil.uploadPackage( localFilePath, device );
+    }
+
+    /**
+     * Removes a file from device.
+     *
+     * @param remoteFilePath path on device of file to remove
+     * @throws TimeoutException in case of timeout on the connection.
+     * @throws SdbCommandRejectedException if sdb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device didn't respond for long time when
+     *            performing the action.
+     * @throws IOException if file removal failed
+     */
+    public void removeRemotePackage(String remoteFilePath)
+            throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException,
+            IOException {
+       device.executeShellCommand( "rm " + remoteFilePath, NullOutputReceiver.getInstance(), INSTALL_TIMEOUT );
+    }
+}
diff --git a/ei-library/src/org/tizen/eilib/connection/EmulatorList.java b/ei-library/src/org/tizen/eilib/connection/EmulatorList.java
new file mode 100644 (file)
index 0000000..3b01248
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.connection;
+
+import static org.tizen.sdblib.util.DeviceUtil.isOnline;
+
+import java.util.ArrayList;
+
+import org.tizen.sdblib.IDevice;
+import org.tizen.sdblib.IDeviceChangeListener;
+import org.tizen.sdblib.SmartDevelopmentBridge;
+
+/**
+ * Control running emulator list
+ * 
+ */
+public class EmulatorList implements IDeviceChangeListener {
+       private static EmulatorList instance = null;
+       private final ArrayList<Emulator> emulatorList = new ArrayList<Emulator>();
+
+       /**
+        * Return instance of EmulatorList.
+        * To generate 'EmualtorList' instance is impossible.
+        * @return
+        */
+       public static EmulatorList getInstance() {
+               if (instance == null) {
+                       instance = new EmulatorList();
+               }
+
+               return instance;
+       }
+
+       /**
+        * 
+        * @throws InterruptedException 
+        */
+       private EmulatorList() {
+               /*
+               IDevice[] devices = null;
+               if (sdbBridge != null) {
+                       devices = sdbBridge.getDevices();
+                       
+                       if (devices != null && devices.length != 0) {
+                               for (IDevice device : devices) {
+                                       this.deviceConnected(device);
+                               }
+                       }
+               }
+               */
+       }
+
+       private boolean init = false;
+       /**
+        * Return list of running emulators.
+        * @return
+        */
+       public ArrayList<Emulator> getEmulatorList() {
+               if (!init) {
+                       SmartDevelopmentBridge.createBridge(SDKInstallPathConfig.getSDBPath(), true);
+
+                       SmartDevelopmentBridge sdbBridge = SmartDevelopmentBridge.getBridge();
+                       SmartDevelopmentBridge.addDeviceChangeListener(this);
+
+                       while (!sdbBridge.isDeviceListInitialized()) {
+                               synchronized(this) {
+                                       try {
+                                               this.wait(1000);
+                                       } catch (InterruptedException e) {
+                                               // TODO Auto-generated catch block
+                                               e.printStackTrace();
+                                       }
+                               }
+                       }
+                       init = true;
+               }
+               return emulatorList;
+       }
+
+       private IEmulatorChangeListener listener = null;
+       public void setChangeListener(IEmulatorChangeListener listener) {
+               this.listener = listener;
+       }
+
+       /**
+        * 
+        */
+       @Override
+       public void onConnected(IDevice device) {
+               if ( !isOnline( device ) )
+               {
+                       return;
+               }
+
+               if ( !device.isEmulator() )
+               {
+                       return;
+               }
+
+               Emulator em = new Emulator(device);
+               emulatorList.add(em);
+
+               if (listener != null) {
+                       listener.deviceConnected(em);
+               }
+       }
+
+       /**
+        * 
+        */
+       @Override
+       public void onDisconnected(IDevice device) {
+               for (Emulator e : emulatorList) {
+                       if (e.getDevice().equals(device)) {
+                               if (listener != null) {
+                                       listener.deviceDisconnected(e);
+                               }
+
+                               emulatorList.remove(e);
+                               break;
+                       }
+               }
+       }
+
+       /**
+        * 
+        */
+       @Override
+       public void onChanged(IDevice device, int changeMask) {
+               if (changeMask == 1)
+        {
+            onConnected(device);
+        }
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/connection/EventReceiver.java b/ei-library/src/org/tizen/eilib/connection/EventReceiver.java
new file mode 100644 (file)
index 0000000..4544476
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.connection;
+
+import java.io.IOException;
+import java.nio.channels.SocketChannel;
+import java.util.HashMap;
+
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.tools.EILogger;
+
+class EventReceiver extends Thread {
+       private SocketChannel socket;
+       private HashMap<Integer, AbstractEventReceiver> receiverMap;
+       public EventReceiver(SocketChannel socket, HashMap<Integer, AbstractEventReceiver> receiverMap) {
+               this.socket      = socket;
+               this.receiverMap = receiverMap;
+               this.setDaemon(true);
+               this.setName("EventReceiver");
+       }
+
+       public void run() {
+               while (socket.isConnected() && this.isAlive() && !this.isInterrupted()) {
+                       EventMessage msg = new EventMessage(1024);
+                       try {
+                               socket.read(msg.getHeaderBuffer());
+                       } catch (IOException e) {
+                               if (!socket.isConnected()) {
+                                       EILogger.getLogger().info("Connection is broken.");
+                               } else {
+                                       EILogger.getLogger().warning(e.getMessage());
+                               }
+                               continue;
+                       }
+
+                       msg.setEventHeader();
+
+                       if (msg.getEventHeader().getLength() != 0) {
+                               msg.getDataBuffer().limit(msg.getEventHeader().getLength());
+                               try {
+                                       socket.read(msg.getDataBuffer());
+                               } catch (IOException e) {
+                                       if (!socket.isConnected()) {
+                                               EILogger.getLogger().info("Connection is broken");
+                                       } else {
+                                               EILogger.getLogger().warning(e.getMessage());
+                                       }
+                                       continue;
+                               }
+                       }
+
+                       forwardingMessage(msg);
+               }
+       }
+
+       private AbstractEventReceiver receiver;
+       private void forwardingMessage(final EventMessage msg) {
+               switch(msg.getEventHeader().getGroupID()) {
+               case GroupID.CALL:
+               case GroupID.SUPS:
+               case GroupID.SMS:
+               case GroupID.SDCARD:
+               case GroupID.STATUS:
+                       receiver = receiverMap.get(msg.getEventHeader().getGroupID());
+                       break;
+               default:
+                       EILogger.getLogger().info("GroupID( " + msg.getEventHeader().getGroupID()
+                                                                                       + " ) of message does not exist.");
+                       return; 
+               }
+
+               if (receiver != null) {
+                       synchronized(receiver) {
+                               new ExecutorThread(receiver, msg).start();
+                       }
+               } else {
+                       EILogger.getLogger().info("Receiver does not exist. Add Recevier this groupID :"
+                                       + msg.getEventHeader().getGroupID());
+               }
+       }
+}
+
+class ExecutorThread extends Thread {
+       private EventMessage message = null;
+       private AbstractEventReceiver receiver = null;
+
+       ExecutorThread(AbstractEventReceiver receiver, EventMessage msg) {
+               this.receiver = receiver;
+               this.message = msg;
+               this.setDaemon(true);
+               this.setName(receiver.getName() + " receiver");
+       }
+
+       public void run() {
+               receiver.run(message);
+       }
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/connection/EventSocket.java b/ei-library/src/org/tizen/eilib/connection/EventSocket.java
new file mode 100644 (file)
index 0000000..5808c67
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.connection;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+import java.nio.channels.SocketChannel;
+import java.util.HashMap;
+
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.tools.EILogger;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.EILibError;
+
+public class EventSocket {
+       private static final String LocalHost = "127.0.0.1";
+       private int port        = 0;
+       private String ip       = LocalHost;
+       private SocketChannel socket;
+
+       private EventReceiver receiver = null;
+       private HashMap<Integer, AbstractEventReceiver> receiverMap = null;
+       public EventSocket(HashMap<Integer, AbstractEventReceiver> receiverMap) {
+               this.receiverMap = receiverMap;
+       }
+
+       public boolean connect() throws IOException {
+               return connect(this.port);
+       }
+
+       public boolean connect(int port) throws IOException {
+               if (port <= 0) {
+                       throw new UnknownHostException("Port number is " + Integer.toString(port) + ".\n" +
+                                       "Please set port number.");
+               } else {
+                       this.port = port;
+               }
+
+               if (socket != null) {
+                       disconnect();
+               }
+
+               SocketAddress addr = new InetSocketAddress(ip, port);
+               try {
+                       socket = SocketChannel.open(addr);
+               } catch (IOException e) {
+                       e.printStackTrace();
+                       return false;
+               }
+
+               // Start Receiver Thread
+               receiver = new EventReceiver(socket, receiverMap);
+               receiver.start();
+
+               return true;
+       }
+
+       public boolean disconnect() {
+               if (socket.isConnected()) {
+                       try {
+                               socket.close();
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                               return false;
+                       } finally {
+                               receiver.interrupt();
+                       }
+               }
+
+               return true;
+       }
+
+       public void setPort(int port) {
+               this.port = port;
+       }
+
+       public void setIP(String ip) {
+               this.ip = ip;
+       }
+
+       public int getPort() {
+               return port;
+       }
+
+       public String getIP() {
+               return ip;
+       }
+
+       SocketChannel getSocket() {
+               return socket;
+       }
+
+       public boolean isConnected() {
+               if (socket == null) {
+                       return false;
+               }
+               return socket.isConnected();
+       }
+
+       public synchronized boolean sendMessage(EventMessage message) throws IOException, ConnectionException {
+               if (!socket.isConnected()) {
+                       return false;
+               }
+
+               try {
+                       socket.write(message.getMessage());
+               } catch (IOException e) {
+                       if (!socket.isConnected()) {
+                               EILogger.getLogger().info("Connection is broken.");
+                       } else if (e.getMessage().equals("Broken pipe")) {
+                               throw new ConnectionException(EILibError.EmuldTerminated);
+                       } else {
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+                       throw e;
+               }
+
+               return true;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/connection/IEmulatorChangeListener.java b/ei-library/src/org/tizen/eilib/connection/IEmulatorChangeListener.java
new file mode 100644 (file)
index 0000000..005073a
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.connection;
+
+public abstract class IEmulatorChangeListener  {
+       public abstract void deviceChanged(Emulator arg0, int arg1);
+
+       public abstract void deviceConnected(Emulator arg0);
+
+       public abstract void deviceDisconnected(Emulator arg0);
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/connection/SDKInstallPathConfig.java b/ei-library/src/org/tizen/eilib/connection/SDKInstallPathConfig.java
new file mode 100644 (file)
index 0000000..c06490b
--- /dev/null
@@ -0,0 +1,186 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.connection;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import org.tizen.eilib.tools.EILogger;
+
+enum OSType {
+       WINDOWS, LINUX, MAC;
+}
+
+final class SDKInstallPathConfig {
+
+    private static String defaultHomePath      = null;
+    private static String sdkInstallPath       = null;
+    private static String sdbPath                      = null;
+
+    private static final String DIR_TOOLS       = "tools";
+    private static final String DIR_SDK_DATA = "tizen-sdk-data";
+
+    private final static String SDKSUFFIX = DIR_SDK_DATA + File.separatorChar + "tizensdkpath";
+
+    // Registry Key
+    private static final String REGISTRY_PATH_OF_SHELL_FOLDER = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
+    private static final String REGISTRY_LOCAL_APP_DATA_OF_SHELL_FOLDER = "\"Local AppData\"";
+    // Value Column
+    private static final String REG_SZ = "REG_SZ";
+
+    private static OSType osType;
+    static {
+       String os = System.getProperty("os.name").toLowerCase();
+       if (os.indexOf("windows") > -1) {
+               osType = OSType.WINDOWS;
+       } else if (os.indexOf("linux") > -1) {
+               osType = OSType.LINUX;
+       } else if (os.indexOf("mac") > -1) {
+               osType = OSType.MAC;
+       }
+
+       switch(osType) {
+       case WINDOWS:
+               defaultHomePath = getRegistryValue(REGISTRY_PATH_OF_SHELL_FOLDER,REGISTRY_LOCAL_APP_DATA_OF_SHELL_FOLDER) ;
+               break;
+       case LINUX:
+       case MAC:
+               defaultHomePath = System.getProperty("user.home");
+               break;
+       default:
+               // TODO : error System.getProperty("os.name") + " is not supported currently."
+               EILogger.getLogger().warning(System.getProperty("os.name") + " is not supported currently.");
+               break;
+       }
+        loadSdkPath();
+    }
+
+    private static void loadSdkPath() {
+       boolean status = false;
+       if (defaultHomePath != null) {
+               String sdkPath = defaultHomePath + File.separatorChar + SDKSUFFIX;
+               File sdk = new File(sdkPath);
+               if (sdk.exists()) {
+                   String[] fileContent = getContents(sdkPath).split("=");
+                   if (fileContent != null && new File(fileContent[1]).exists()) {
+                       sdkInstallPath = fileContent[1];
+                       status = true;
+                   }
+               }
+       }
+
+        if (!status) {
+            EILogger.getLogger().warning("Tizen SDK is not installed properly.");
+            // System.exit(0);
+        }
+    }
+
+    private static String getContents(String filePath) {
+        BufferedReader input   = null;
+        StringBuilder contents         = new StringBuilder();
+        String line                    = null;
+        
+        try {
+            input = new BufferedReader(new FileReader(filePath));
+            while((line=input.readLine()) != null){
+                contents.append(line);
+                contents.append(System.getProperty("line.separator"));
+            }
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+            return null;
+               } catch (IOException e) {
+                       e.printStackTrace();
+                       return null;
+               }finally{
+            if (input != null) {
+               try {
+                                       input.close();
+                               } catch (IOException e) {
+                                       e.printStackTrace();
+                               }
+            }
+        }
+
+        return (contents != null ? contents.toString().trim() : null);
+    }
+
+    private static String getRegistryValue(String node, String key) {
+        if (osType != OSType.WINDOWS) {
+            return null;
+        }
+
+        BufferedReader br      = null;
+        String value           = "";
+
+        String query = "reg query " + "\"" + node + "\" /v " + key;
+        try {
+            Process process = Runtime.getRuntime().exec(query);
+            String encoding = System.getProperty("sun.jnu.encoding");
+            br = new BufferedReader(new InputStreamReader(process.getInputStream(), encoding));
+
+            String line = null;
+            while ((line = br.readLine()) != null) {
+                int index = line.indexOf(REG_SZ);
+                if (index >= 0) {
+                    value = line.substring(index + REG_SZ.length()).trim();
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (br != null) {
+                try {
+                    br.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+
+        return value;
+    }
+
+    public static String getSDKPath() {
+        return sdkInstallPath;
+    }
+   
+    public static String getSDBPath() {
+       if (sdbPath == null && sdkInstallPath != null) {
+               sdbPath = getSDKPath() + File.separator + DIR_TOOLS
+                               + File.separator + (osType == OSType.WINDOWS ? "sdb.exe" : "sdb");
+       }
+
+       return sdbPath;
+    }
+
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/connection/message/ActionID.java b/ei-library/src/org/tizen/eilib/connection/message/ActionID.java
new file mode 100644 (file)
index 0000000..1ae67bf
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.connection.message;
+
+public enum ActionID {
+
+       // DEVICE 100 ~
+       BATTERY_LEVEL(100), BATTERY_CHARGER(101), USB_STATUS(102),
+       EARJACK_STATUS(103), RSSI_LEVEL(104),
+       // SENSOR 110 ~
+       ACCEL_VALUE(110), GYRO_VALUE(111), MAG_VALUE(112),
+       LIGHT_VALUE(113), PROXI_VALUE(114), MOTION_VALUE(115),
+
+       // ETC 120 ~
+       LOCATION_STATUS(120), NFC_STATUS(121);
+       
+       int id;
+       
+       ActionID(int id) {
+               this.id = id;
+       }
+
+       public int getId() {
+               return id;
+       }
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/connection/message/EventHeader.java b/ei-library/src/org/tizen/eilib/connection/message/EventHeader.java
new file mode 100644 (file)
index 0000000..fb0f275
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.connection.message;
+
+
+/**
+ * This class is EventMessage's header.
+ * 
+ */
+public class EventHeader {
+       private short length    = 0;
+       private int groupID             = 0;
+       private int actionID    = 0;
+
+       /**
+        * Return event data's length
+        * @return
+        */
+       public short getLength() {
+               return length;
+       }
+
+       /**
+        * Set event data's length
+        * 
+        * @param length
+        */
+       public void setLength(short length) {
+               this.length = length;
+       }
+
+       /**
+        * Return event's group ID
+        *
+        * @return
+        * 
+        * @see GroupID
+        */
+       public int getGroupID() {
+               return groupID;
+       }
+
+       /**
+        * Set event's group ID
+        * 
+        * @param groupID
+        * 
+        * @see GroupID
+        */
+       public void setGroupID(int groupID) {
+               this.groupID = groupID;
+       }
+
+       /**
+        * Return event's action ID
+        *
+        * @return
+        * 
+        * @see ActionID
+        */
+       public int getActionID() {
+               return actionID;
+       }
+
+       /**
+        * Set event's action ID
+        * 
+        * @param actionID
+        * 
+        * @see ActionID
+        */
+       public void setActionID(int actionID) {
+               this.actionID = actionID;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/connection/message/EventMessage.java b/ei-library/src/org/tizen/eilib/connection/message/EventMessage.java
new file mode 100644 (file)
index 0000000..c2cc621
--- /dev/null
@@ -0,0 +1,241 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.connection.message;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+
+/**
+ * This class is used to communicate with emulator.
+ * 
+ */
+public class EventMessage {
+       private static final int HEADER_SIZE = 4;
+       private static final int MAX_DATA_SIZE = 4096;
+       private int maxDataLength = MAX_DATA_SIZE;
+
+       private EventHeader eventHeader = null;
+
+       private ByteBuffer message      = null;
+       private ByteBuffer type         = null;
+       private ByteBuffer header   = null;
+       private ByteBuffer data         = null;
+
+       private int messageLength = 0;
+
+       /**
+        * Data size is set default max size.
+        * 
+        */
+       public EventMessage() {
+               this(MAX_DATA_SIZE);
+       }
+
+       /**
+        * 
+        * @param size Max size of data
+        */
+       public EventMessage(int size) {
+               eventHeader = new EventHeader();
+
+               initEventMessage(size);
+       }
+
+       /**
+        * Set EventHeader (length, groupID, actionID) using header buffer
+        * 
+        * @see EventHeader
+        */
+       // receiver
+       public void setEventHeader() {
+               header.clear();
+               eventHeader.setLength(header.getShort());
+               eventHeader.setGroupID(header.get() & 0xff);
+               eventHeader.setActionID(header.get() & 0xff);
+       }
+
+       /**
+        * Return event header.
+        * 
+        * @return
+        * 
+        * @see EventHeader
+        */
+       public EventHeader getEventHeader() {
+               return eventHeader;
+       }
+
+
+       /**
+        * Return event type buffer.
+        * TODO : This buffer is used only while sending message.
+        * @return
+        */
+       public ByteBuffer getEventTypeBuffer() {
+               return type;
+       }
+
+       /**
+        * Return header buffer.
+        * This buffer size is 4
+        * Note : Check buffer's position before using buffer.
+        * 
+        * @return header buffer
+        */
+       public ByteBuffer getHeaderBuffer() {
+               return header;
+       }
+
+       /**
+        * Return data buffer
+        * This buffer is main message data.
+        * Length variable of EventHeader is this buffer's size.
+        * Note : Check buffer's position before using buffer.
+        * 
+        * @return data buffer
+        */
+       public ByteBuffer getDataBuffer() {
+               return data;
+       }
+
+       /**
+        * Return data buffer's capacity.
+        * You can change buffer capacity using initEventMessage().
+        * @return
+        */
+       public int getMaxDataBufferSize() {
+               return maxDataLength;
+       }
+
+       /**
+        * Return data buffer's start position
+        * @return
+        */
+       public int getDataBufferOffset() {
+               return EventType.ID_LENGH + HEADER_SIZE;
+       }
+
+       /**
+        * 
+        * @param id
+        * 
+        * @see EventType
+        */
+       public void setEventTypeBuffer(EventType id) {
+               type.position(0);
+               type.put(id.getType());
+       }
+
+       /**
+        * 
+        * @param h
+        * 
+        * @see EventHeader
+        */
+       public void setHeaderBuffer(EventHeader h) {
+               header.clear();
+               header.putShort(h.getLength());
+               header.put(((Integer)h.getGroupID()).byteValue());
+               header.put(((Integer)h.getActionID()).byteValue());
+       }
+
+       /**
+        * Return message buffer
+        * This buffer is event type buffer + header buffer + data buffer
+        * The position of this buffer is always zero whenever the function is called.
+        * This buffer is used wnen sending the message to the emulator.
+        * When you write data to the buffer, use each buffer(type, header, data).
+        * 
+        * @return message buffer
+        */
+       public ByteBuffer getMessage() {
+               setMessageLength();
+               message.position(messageLength);
+               message.flip();
+               message.position(0);
+               return message;
+       }
+
+       /**
+        * Determine the length of a message before sending the message.
+        * Message length : event type buffer size + header buffer size + data buffer size
+        */
+       public void setMessageLength() {
+               messageLength = EventType.ID_LENGH + HEADER_SIZE + data.position();
+       }
+
+       /**
+        * 
+        * @return message buffer's length
+        */
+       public int getMessageLength() {
+               setMessageLength();
+               return messageLength;
+       }
+
+       /**
+        * Message buffer clear.
+        * Initialize message buffer prior to use, when reusing 'EventMessage'
+        * Note : 'Event Type' buffer is not initialized.
+        */
+       public void clear() {
+               message.clear();
+               header.clear();
+               data.clear();
+       }
+
+       /**
+        * This class initialize EventMessage class.
+        * Previously used memory space is discarded and a new memory space is alloacted.
+        * 
+        * @param size Max size of data
+        */
+       public void     initEventMessage(int size) {
+               if (size >= 0) {
+                       maxDataLength = size;
+               }
+               message = ByteBuffer.allocate(EventType.ID_LENGH + HEADER_SIZE + maxDataLength);
+               message.order(ByteOrder.LITTLE_ENDIAN);
+
+               // sender only use this buffer.
+               message.limit(EventType.ID_LENGH);
+               type = message.slice();
+
+               message.position(message.limit());
+               message.limit(message.position() + HEADER_SIZE);
+               header = message.slice();
+               header.order(ByteOrder.LITTLE_ENDIAN);
+
+               message.position(message.limit());
+               message.limit(message.capacity());
+               data = message.slice();
+               data.order(ByteOrder.LITTLE_ENDIAN);
+       }
+
+}
diff --git a/ei-library/src/org/tizen/eilib/connection/message/EventType.java b/ei-library/src/org/tizen/eilib/connection/message/EventType.java
new file mode 100644 (file)
index 0000000..9a9b366
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.connection.message;
+
+import java.nio.ByteBuffer;
+
+public enum EventType {
+       TELEPHONY("telephony\n"), SENSOR("sensor\n"), NFC("nfc\n"),
+       LOCATION("location\n"), SDCARD("sdcard\n");
+
+       public static int ID_LENGH      = 10;
+       private ByteBuffer type         = null;
+
+       EventType(String type) {
+               // ID_LENGTH = 10;
+               this.type = ByteBuffer.allocate(10);
+               for (byte c : type.getBytes()) {
+                       this.type.put(c);
+               }
+       }
+
+       public ByteBuffer getType() {
+               this.type.clear();
+               return type;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/connection/message/GroupID.java b/ei-library/src/org/tizen/eilib/connection/message/GroupID.java
new file mode 100644 (file)
index 0000000..c72089e
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.connection.message;
+
+public class GroupID {
+               public static final int CALL            = 1;
+               public static final int SUPS            = 3; // GSM_SUPS (CALL)
+               public static final int SMS                     = 4;
+               public static final int SDCARD          = 11;
+               public static final int STATUS          = 15;
+}
diff --git a/ei-library/src/org/tizen/eilib/events/AbstractEventInjector.java b/ei-library/src/org/tizen/eilib/events/AbstractEventInjector.java
new file mode 100644 (file)
index 0000000..a0e0eeb
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events;
+
+public abstract class AbstractEventInjector {
+       /**
+        * This method is called when connecting emulator.
+        * If need initialize variable, use this method.
+        */
+       public abstract void initEventInjector();
+}
diff --git a/ei-library/src/org/tizen/eilib/events/BatteryEventInjector.java b/ei-library/src/org/tizen/eilib/events/BatteryEventInjector.java
new file mode 100644 (file)
index 0000000..21290ed
--- /dev/null
@@ -0,0 +1,270 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events;
+
+import java.io.IOException;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.receiver.EventReceiver;
+import org.tizen.eilib.events.receiver.StatusEventReceiver;
+import org.tizen.eilib.events.sender.DeviceEventSender;
+import org.tizen.eilib.events.type.BatteryCharger;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.eilib.modem.protocol.ByteUtil;
+import org.tizen.eilib.tools.EILogger;
+
+
+/**
+ * Instances of this class send battery event to the emulator.
+ * <dl>
+ * <dt><b>Send Events : </b></dt>
+ * <dd>Battery Level, Battery Charger State</dd>
+ * </dl>
+ * <p>
+ */
+public class BatteryEventInjector  extends AbstractEventInjector {
+       private BatteryEventSender sender = null;
+       static final int MIN_VALUE = 1;
+       static final int MAX_VALUE = 100;
+
+       BatteryEventInjector(ConnectionToEmulator connector) {
+               sender = new BatteryEventSender(connector);
+               EventReceiver receiver = new EventReceiver("BatteryReceiver", sender);
+
+               AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS);
+               if (abReceiver != null && abReceiver instanceof StatusEventReceiver) {
+                       StatusEventReceiver re = (StatusEventReceiver)abReceiver;
+                       re.addStatusEventReceiver(ActionID.BATTERY_LEVEL, receiver);
+                       re.addStatusEventReceiver(ActionID.BATTERY_CHARGER, receiver);
+               }
+       }
+
+       /**
+        * Return max level of battery
+        * @return
+        */
+       public int getMaxBatteryLevel() {
+               return MAX_VALUE;
+       }
+
+       /**
+        * Return min level of battery
+        * @return
+        */
+       public int getMinBatteryLevel() {
+               return MIN_VALUE;
+       }
+
+       /**
+        * Change battery level of emulator.
+        *
+        * @param level battery level(0 ~ 100)
+        * @return result
+        * @throws IOException 
+        * @throws DeviceEventException 
+        * @throws ConnectionException 
+        */
+       public boolean setLevel(int level) throws IOException, DeviceEventException, ConnectionException{
+               if (level < MIN_VALUE || level > MAX_VALUE) {
+                       throw new DeviceEventException(EILibError.InvalidValue);
+               }
+
+               return sender.setLevel(level);
+       }
+
+       /**
+        * Change charger state of emulator.
+        *
+        * @param isCharger battery's charger state
+        * @return result
+        * @throws IOException 
+        * @throws DeviceEventException 
+        * @throws ConnectionException 
+        */
+       public boolean setChargerState(BatteryCharger charger) throws IOException, DeviceEventException, ConnectionException {
+               if (charger == null) {
+                       throw new DeviceEventException(EILibError.InvalidValue);
+               }
+               return sender.setChargerState(charger);
+       }
+
+       /**
+        * Change battery level of emulator.
+        *
+        * @return level of battery (0 ~ 100)
+        * @throws IOException 
+        * @throws ConnectionException 
+        * 
+        */
+       public int getLevel() throws IOException, DeviceEventException, ConnectionException {
+               int level = sender.getLevel();
+               
+               if (level == -1) { // throw error
+                       throw new DeviceEventException(EILibError.FailedGetValue);
+               }
+
+               return level;
+       }
+
+       /**
+        * Change charger state of emulator.
+        *
+        * @return battery's charger state. true : charging, false : non charging
+        * @throws IOException 
+        * @throws ConnectionException 
+        * @throws DeviceEventException 
+        * 
+        */
+       public BatteryCharger getChargerState() throws IOException, ConnectionException, DeviceEventException {
+               BatteryCharger charger = sender.getChargerState();
+               if (charger == null) {
+                       throw new DeviceEventException(EILibError.FailedGetValue);
+               }
+
+               return charger;
+       }
+
+       @Override
+       public void initEventInjector() {
+               // TODO Auto-generated method stub
+               
+       }
+
+}
+
+class BatteryEventSender extends DeviceEventSender {
+       private static String BatteryID = "8\n";
+       private static final int SET_LEVEL       = 1;
+       private static final int SET_CHARGER = 2;
+
+       private double params[] = new double[2];
+
+       private EventMessage returnMsg = null;
+
+       BatteryEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+
+       public synchronized boolean setLevel(int level) throws IOException, ConnectionException {
+               params[0] = SET_LEVEL;
+               params[1] = level;
+               makeMessage(BatteryID, params);
+               return sendMessage(null);
+       }
+
+       public int getLevel() throws IOException, ConnectionException {
+               // empty message
+               makeMessage(BatteryID, null);
+               sendMessage(ActionID.BATTERY_LEVEL);
+
+               synchronized(this) {
+                       // wait 5 second
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+
+               int level = -1;
+               if (returnMsg != null) {
+                       if (returnMsg.getEventHeader().getActionID()
+                                       != ActionID.BATTERY_LEVEL.getId()) {
+                               // TODO : error
+                               EILogger.getLogger().warning("An unexpected event occurs.");
+                       } else {
+                               level = ByteUtil.byte2int
+                                               (returnMsg.getDataBuffer().array(), 14);
+       
+                               if (level < BatteryEventInjector.MIN_VALUE
+                                               || level > BatteryEventInjector.MAX_VALUE) {
+                                       level = -1;
+                               }
+                       }
+                       returnMsg = null;
+               }
+
+               return level;           
+       }
+
+       public synchronized boolean setChargerState(BatteryCharger charger) throws IOException, ConnectionException {
+               params[0] = SET_CHARGER;
+               params[1] = charger.getValue();
+               makeMessage(BatteryID, params);
+               return sendMessage(null);
+       }
+
+       public BatteryCharger getChargerState() throws IOException, ConnectionException {
+               // empty message
+               makeMessage(BatteryID, null);
+               sendMessage(ActionID.BATTERY_CHARGER);
+
+               synchronized(this) {
+                       // wait 5 second
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+
+               if (returnMsg != null) {
+                       if (returnMsg.getEventHeader().getActionID()
+                                       != ActionID.BATTERY_CHARGER.getId()) {
+                               // TODO : error
+                               EILogger.getLogger().warning("An unexpected event occurs.");
+                       } else {
+                               int i = ByteUtil.byte2int
+                                               (returnMsg.getDataBuffer().array(), 14);
+                               if (BatteryCharger.CONNECT.getValue() == i) {
+                                       return BatteryCharger.CONNECT;
+                               } else if (BatteryCharger.DISCONNECT.getValue() == i) {
+                                       return BatteryCharger.DISCONNECT;
+                               }
+                       }
+                       returnMsg = null;
+               }
+
+               return null;
+       }
+
+       public void fireEvent(EventMessage message) {
+               synchronized(this) {
+                       this.returnMsg = message;
+                       this.notifyAll();
+               }
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/CallEvent.java b/ei-library/src/org/tizen/eilib/events/CallEvent.java
new file mode 100644 (file)
index 0000000..f64fa52
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events;
+
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.type.CallEventType;
+import org.tizen.eilib.events.type.CallStatus;
+import org.tizen.eilib.events.type.CallType;
+
+
+public class CallEvent {
+       private CallEventType eventType;
+       private int callID;
+       private CallType callType;
+       private CallStatus callStatus;
+       private String callNumber;
+       private ArrayList<CallItem> callItemList;
+
+       public String toString() {
+               String str = "ID: " + callID +
+                               "\nType: " + callType +
+                               "\nStatus: " + callStatus +
+                               "\nNumber: " + callNumber + "\n";
+               if (callItemList != null) {
+                       for (CallItem item : callItemList) {
+                               str += item.toString();
+                       }
+               }
+               return str;
+       }
+       public CallEvent() {
+               eventType = CallEventType.NONE;
+               callID = 0;
+               callType = CallType.NONE;
+               callStatus = CallStatus.NONE;
+               callNumber = "";
+               callItemList = null;
+       }
+
+       public CallEventType getEventType() {
+               return eventType;
+       }
+
+       void setEventType(CallEventType eventType) {
+               this.eventType = eventType;
+       }
+
+       public int getCallID() {
+               return callID;
+       }
+
+       void setCallID(int callID) {
+               this.callID = callID;
+       }
+
+       public CallType getCallType() {
+               return callType;
+       }
+
+       void setCallType(CallType callType) {
+               this.callType = callType;
+       }
+
+       public String getCallNumber() {
+               return callNumber;
+       }
+
+       void setCallNumber(String callNumber) {
+               this.callNumber = callNumber;
+       }
+
+       public ArrayList<CallItem> getCallItemList() {
+               return callItemList;
+       }
+
+       void setCallItemList(ArrayList<CallItem> callItemList) {
+               this.callItemList = callItemList;
+       }
+
+       public CallStatus getCallStatus() {
+               return callStatus;
+       }
+
+       void setCallStatus(CallStatus callStatus) {
+               this.callStatus = callStatus;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/CallEventInjector.java b/ei-library/src/org/tizen/eilib/events/CallEventInjector.java
new file mode 100644 (file)
index 0000000..7d19594
--- /dev/null
@@ -0,0 +1,597 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.listener.EventListenerList;
+import org.tizen.eilib.events.listener.ICallEventListener;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.sender.ModemEventSender;
+import org.tizen.eilib.events.type.CallEventType;
+import org.tizen.eilib.events.type.CallStatus;
+import org.tizen.eilib.events.type.CallType;
+import org.tizen.eilib.events.type.MobileType;
+import org.tizen.eilib.events.type.CallErrorCode;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.CallEventException;
+import org.tizen.eilib.modem.protocol.AbstractGA;
+import org.tizen.eilib.modem.protocol.G01A07;
+import org.tizen.eilib.modem.protocol.G01A21MO;
+import org.tizen.eilib.modem.protocol.G01A21MT;
+import org.tizen.eilib.modem.protocol.G01A22;
+import org.tizen.eilib.modem.protocol.G01A22End;
+import org.tizen.eilib.modem.protocol.G01A23;
+import org.tizen.eilib.modem.protocol.G01A26;
+import org.tizen.eilib.modem.protocol.G01A29;
+import org.tizen.eilib.modem.protocol.G01A62;
+import org.tizen.eilib.modem.protocol.StructureGA;
+import org.tizen.eilib.tools.EILogger;
+
+/**
+ * Instance of this class send call event to the emulator.
+ *
+ */
+public class CallEventInjector extends AbstractEventInjector {
+       private CallEventSender sender          = null;
+       private CallEventReceiver receiver      = null;
+       private EventListenerList listeners = new EventListenerList();
+
+       private CallEvent callEvent     = null;
+       private boolean isCallWaiting   = true;
+       private boolean isIncomingCall = false;
+       private boolean isCalling = false;
+
+       private boolean isDialing = false;
+
+       private boolean isListFull = false;
+
+       CallEventInjector(ConnectionToEmulator connector) {
+               sender   = new CallEventSender(connector);
+               receiver = new CallEventReceiver(this);
+
+               connector.addEventReceiver(GroupID.CALL, receiver);
+               connector.addEventReceiver(GroupID.SUPS, receiver);
+       }
+
+       private RSSIEventInjector rssi;
+       void setRssiEventInjector(RSSIEventInjector rssi) {
+               this.rssi = rssi;
+       }
+
+       /**
+        * Send call event to the emulator.
+        * This call is always non hidden call. (????)
+        * @param number phone number
+        * @return
+        * @throws IOException 
+        * @throws ConnectionException 
+        * @throws CallEventException 
+        */
+       public boolean calling(String number) throws IOException, ConnectionException, CallEventException {
+               return calling(number, false);
+       }
+
+       /**
+        * Send call event to the emulator
+        * @param number phone number
+        * @param isHidden if this value is true, number does not display in window(LCD) of the emulator.
+        * @return
+        * @throws IOException 
+        * @throws ConnectionException 
+        * @throws CallEventException 
+        */
+       public boolean calling(String number, boolean isHidden) throws IOException, ConnectionException, CallEventException {
+               // TODO : check rssi Status ??
+               if (rssi.isLevelZero()) {
+                       throw new CallEventException(EILibError.RSSIIsZero);
+               }
+
+               if (isListFull == true) {
+                       throw new CallEventException(EILibError.ListFull);
+               }
+
+               if (isIncomingCall || isDialing) {
+                       throw new CallEventException(EILibError.IncomingCall);
+               }
+
+               if (isCalling && !isCallWaiting) {
+                       throw new CallEventException(EILibError.NowBusy);
+               }
+
+               // throw CallEventException
+               if (!checkNumber(number)) {
+                       throw new CallEventException(EILibError.NumberFormatError);
+               }
+
+               G01A21MT ga = new G01A21MT();
+               ga.intialize();
+               
+               StructureGA sga = ga.getBody();
+               sga.setInt("CALL_TYPE", 0x01);  // voice
+               sga.setInt("FORWARDED_STATUS", 0);
+               sga.setInt("CLIR_STATUS", isHidden ? 0x01 : 0x00);
+               sga.setInt("NUM_LEN",number.getBytes().length);
+               sga.setInt("NUM_TYPE", 0x01);
+               sga.setInt("CLI_PRESENT_ID", 0x01);
+               sga.setInt("NO_CLI_CAUSE", 0x00);
+               sga.setByteArray("CALL_NUMBER", number.getBytes());
+
+               boolean re = sender.send(ga);
+
+               synchronized(this) {
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               EILogger.getLogger().info(e.getMessage());
+                       }
+               }
+
+               return re;
+       }
+
+       /**
+        * End call event to the emulator.
+        * @param number
+        * @return
+        * @throws IOException 
+        * @throws CallEventException 
+        * @throws ConnectionException 
+        */
+       public boolean disconnectCall(String number) throws IOException, CallEventException, ConnectionException {
+               if (!checkNumber(number)) {
+                       throw new CallEventException(EILibError.NumberFormatError);
+               }
+
+               // for getting call item list
+               synchronized(this) {
+                       try {
+                               this.wait(500);
+                       } catch (InterruptedException e) {
+                               EILogger.getLogger().info(e.getMessage());
+                       }
+               }
+
+               if (callEvent != null && callEvent.getCallItemList() != null) {
+                       for (CallItem item : callEvent.getCallItemList()) {
+                               if (item.getNumber().equals(number)) {
+                                       return disconnectCall(item.getId());
+                               }
+                       }
+               }
+               // TODO : error item dose not exist..
+               throw new CallEventException(EILibError.NumberNotFound);
+       }
+
+       /**
+        * End call event to the emulator.
+        * @param callID
+        * @return
+        * @throws IOException 
+        * @throws ConnectionException 
+        * @throws CallEventException 
+        */
+       public boolean disconnectCall(int callID) throws IOException, CallEventException, ConnectionException {
+               return disconnectCall(callID, CallErrorCode.Success);
+       }
+
+       /** 
+        * End call event to the emulator
+        * @param callID
+        * @param code
+        * @return
+        * @throws IOException 
+        * @throws ConnectionException 
+        * @throws CallEventException 
+        */
+       public boolean disconnectCall(int callID, CallErrorCode code) throws IOException, ConnectionException, CallEventException {
+               // for getting call item list
+               synchronized(this) {
+                       try {
+                               this.wait(500);
+                       } catch (InterruptedException e) {
+                               EILogger.getLogger().info(e.getMessage());
+                       }
+               }
+
+               boolean isFindID = false;
+               if (callEvent != null && callEvent.getCallItemList() != null) {
+                       for (CallItem item : callEvent.getCallItemList()) {
+                               if (item.getId() == callID) {
+                                       isFindID = true;
+                                       break;
+                               }
+                       }
+               }
+               if (!isFindID) {
+                       throw new CallEventException(EILibError.NumberNotFound);
+               }
+
+               // send error code
+               G01A07 ga1 = new G01A07();
+               ga1.intialize();
+
+               StructureGA sga1 = ga1.getBody();
+               sga1.setInt("ERROR_CAUSE_0", code.value() & 0x00ff);
+               sga1.setInt("ERROR_CAUSE_1", (code.value()>>8) & 0x00ff);
+               
+               G01A22End ga2 = new G01A22End();
+               ga2.intialize();
+               
+               StructureGA sga2 = ga2.getBody();
+               sga2.setInt("CALL_ID", callID);
+
+               sender.send(ga1);
+               sender.send(ga2);
+
+               isDialing = false;
+
+               synchronized(this) {
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               EILogger.getLogger().info(e.getMessage());
+                       }
+               }
+               return true;
+       }
+
+       /**
+        * Alter call status.
+        * 
+        * @return
+        * @throws IOException 
+        * @throws CallEventException 
+        * @throws ConnectionException 
+        * @throws InjectorLibraryException 
+        */
+       public boolean alterCall() throws IOException, CallEventException, ConnectionException {
+               // for getting call item list
+               synchronized(this) {
+                       try {
+                               this.wait(500);
+                       } catch (InterruptedException e) {
+                               EILogger.getLogger().info(e.getMessage());
+                       }
+               }
+
+               if (callEvent != null 
+                               && callEvent.getCallItemList() != null && !callEvent.getCallItemList().isEmpty()) {
+                       G01A62 ga = new G01A62();
+                       ga.intialize();
+       
+                       boolean re =  sender.send(ga);
+
+                       synchronized(this) {
+                               try {
+                                       this.wait(5000);
+                               } catch (InterruptedException e) {
+                                       EILogger.getLogger().info(e.getMessage());
+                               }
+                       }
+
+                       return re;
+               } else {
+                       throw new CallEventException(EILibError.NotExistCall);
+               }
+       }
+
+       /**
+        * Get the phone
+        * 
+        * @return
+        * @throws IOException 
+        * @throws ConnectionException 
+        * @throws CallEventException 
+        */
+       public boolean connectCall() throws IOException, ConnectionException, CallEventException {
+               // for getting call item list
+               synchronized(this) {
+                       try {
+                               this.wait(500);
+                       } catch (InterruptedException e) {
+                               EILogger.getLogger().info(e.getMessage());
+                       }
+               }
+
+               if (callEvent != null 
+                               && callEvent.getCallItemList() != null && !callEvent.getCallItemList().isEmpty()) {
+                       G01A23 ga = new G01A23();
+                       ga.intialize();
+       
+                       boolean re = sender.send(ga);
+
+                       isDialing = false;
+
+                       synchronized(this) {
+                               try {
+                                       this.wait(5000);
+                               } catch (InterruptedException e) {
+                                       EILogger.getLogger().info(e.getMessage());
+                               }
+                       }
+                       return re;
+               } else {
+                       throw new CallEventException(EILibError.NotExistCall);
+               }
+       }
+
+       /**
+        * Last call item list..
+        * Call item list received from emulator(vmodem) the most recently .
+        * 
+        * @return call item list
+        */
+       public ArrayList<CallItem> getCallItemList() {
+               // for getting call item list
+               synchronized(this) {
+                       try {
+                               this.wait(500);
+                       } catch (InterruptedException e) {
+                               EILogger.getLogger().info(e.getMessage());
+                       }
+               }
+
+               if (callEvent != null) {
+                       return callEvent.getCallItemList();
+               }
+               return null;
+       }
+
+       /**
+        * Add call event listener.
+        * Note: You can receive incoming calls from emulator.
+        * Note: You can receive current call list from emulator.
+        * 
+        * @param listener
+        */
+       public void addCallEventListener(ICallEventListener listener) {
+               listeners.add(listener);
+       }
+
+       /**
+        * Remove call event listener.
+        * 
+        * @param listener
+        */
+       public void removeCallEventListener(ICallEventListener listener) {
+               listeners.remove(listener);
+       }
+
+       /**
+        * 
+        * @return
+        */
+       public boolean isCallWaiting() {
+               return isCallWaiting;
+       }
+
+       /**
+        * 
+        * @param isCallWaiting
+        */
+       void setCallWaiting(boolean isCallWaiting) {
+               this.isCallWaiting = isCallWaiting;
+       }
+
+       private boolean checkNumber(String number) throws CallEventException {
+               if (number == null /*|| number.length() == 0*/) {
+                       throw new CallEventException(EILibError.NumberIsEmpty);
+               }
+
+               if (number.length() > 15) {
+                       throw new CallEventException(EILibError.NumberIsTooLong);
+               }
+
+               Pattern tellPattern = Pattern.compile( "[^0-9++]");
+               Matcher matcher = tellPattern.matcher(number);
+               return !matcher.find();
+       }
+
+       private CallStatus findCallStatus(int id) {
+               for (CallStatus status : CallStatus.values()) {
+                       if (status.getID() == id) {
+                               return status;
+                       }
+               }
+               return null;
+       }
+
+       private CallType findCallType(int id) {
+               for (CallType type : CallType.values()) {
+                       if (type.getID() == id) {
+                               return type;
+                       }
+               }
+               return null;
+       }
+
+       private MobileType findMobileType(int id) {
+               for (MobileType type : MobileType.values()) {
+                       if (type.getID() == id) {
+                               return type;
+                       }
+               }
+               
+               return null;
+       }
+
+       void fireCallEvent(G01A21MO ga) {
+               StructureGA sga = ga.getBody();
+               CallEvent event = new CallEvent();
+               event.setEventType(CallEventType.INCOMING);
+               event.setCallID(sga.getInt("CALL_ID"));
+               event.setCallType(findCallType(sga.getInt("CALL_TYPE")));
+
+               byte[] temp = sga.getByteArray("CALL_NUMBER");
+               event.setCallNumber(new String(temp).trim());
+               int s = temp[0];
+               event.setCallStatus(findCallStatus(s));
+
+               isDialing = true;
+
+               this.callEvent = event;
+
+               for (int i = 0 ; i < listeners.size() ; i++) {
+                       final ICallEventListener listener = (ICallEventListener)listeners.getListeners().get(i);
+                       listener.incomingCall(event);
+               }
+       }
+
+       void fireCallListEvent(AbstractGA ga, CallEventType eventType) {
+               StructureGA header = ga.getHeader();
+               StructureGA body   = ga.getBody();
+
+               int loopCount = header.getInt("COUNT");
+               CallEvent event = new CallEvent();
+               event.setEventType(eventType);
+               event.setCallItemList(new ArrayList<CallItem>());
+               isIncomingCall = false;
+               for (int i = 0; i < loopCount; i++) {
+                       CallItem item = new CallItem();
+                       item.setId(body.getInt("IDX", i));
+                       item.setStatus(findCallStatus(body.getInt("STAT", i)));
+                       // TODO
+                       item.setMultiParty((body.getInt("MULTIPARTY", i) == 1 ? true : false));
+                       item.setMobileType(findMobileType(body.getInt("DIR", i)));
+                       item.setNumber(new String(body.getByteArray("NUMBER", i)).trim());
+                       if(item.getStatus() == null || item.getStatus() == CallStatus.NONE) {
+                               loopCount++;
+                               continue;
+                       } else if (item.getStatus() == CallStatus.INCOMING
+                                       || item.getStatus() == CallStatus.WAITING) {
+                               // TODO
+                               isIncomingCall = true;
+                       }
+                       event.getCallItemList().add(item);
+                       isCalling = true;
+               }
+
+               if (event.getCallItemList().isEmpty()) {
+                       isIncomingCall = false;
+                       isCalling = false;
+                       isListFull = false;
+               } else if (event.getCallItemList().size() == 6) {
+                       isListFull = true;
+               } else {
+                       isListFull = false;
+               }
+
+               this.callEvent = event;
+
+               synchronized(this) {
+                       this.notifyAll();
+               }
+
+               for (int i = 0 ; i < listeners.size() ; i++) {
+                       final ICallEventListener listener = (ICallEventListener)listeners.getListeners().get(i);
+                       listener.receivingCallList(event);
+               }
+       }
+
+       @Override
+       public void initEventInjector() {
+               // TODO Auto-generated method stub
+               
+       }
+}
+
+class CallEventSender extends ModemEventSender {
+       public CallEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+}
+
+class CallEventReceiver extends AbstractEventReceiver {
+       private CallEventInjector injector;
+       public CallEventReceiver(CallEventInjector injector) {
+               super("Call event");
+               this.injector = injector;
+       }
+
+       public void run(EventMessage msg) {
+               synchronized(this) {
+                       // groupid 3: GSM_SUPS, actionid 73: GSM_SUPS_SET_CW_REQ
+                       if (msg.getEventHeader().getGroupID() == GroupID.SUPS
+                                       && msg.getEventHeader().getActionID() == 73) {
+                               ByteBuffer buf = msg.getDataBuffer();
+                               for (int i = 0; i < msg.getDataBuffer().position(); i++) {
+                                       if (buf.get(i) == -1) {                                 // -1 : class id 255
+                                               if (buf.get(i+4) == 3) {                        // 3 : cw on
+                                                       injector.setCallWaiting(true);
+                                               } else if (buf.get(i+4) == 4) {         // 4 : cw off
+                                                       injector.setCallWaiting(false);
+                                               }
+                                       }
+                               }
+                               return;
+                       }
+
+                       switch(msg.getEventHeader().getActionID()) {
+                       case 0x21: //mo call
+                       {
+                               G01A21MO ga = new G01A21MO();
+                               ga.intialize(msg.getDataBuffer());
+                               injector.fireCallEvent(ga);
+                       }
+                               break;
+                       case 0x22: // disconnect
+                       {
+                               G01A22 ga = new G01A22();
+                               ga.intialize(msg.getDataBuffer());
+                               injector.fireCallListEvent(ga, CallEventType.LIST22);
+                       }
+                               break;
+                       case 0x26: // connect
+                       {
+                               G01A26 ga = new G01A26();
+                               ga.intialize(msg.getDataBuffer());
+                               injector.fireCallListEvent(ga, CallEventType.LIST26);
+                       }
+                               break;
+                       case 0x29: // ring
+                       {
+                               G01A29 ga = new G01A29();
+                               ga.intialize(msg.getDataBuffer());
+                               injector.fireCallListEvent(ga, CallEventType.LIST29);
+                       }
+                               break;
+                       default:
+                               break;
+                       }
+               }
+       }
+
+}
diff --git a/ei-library/src/org/tizen/eilib/events/CallItem.java b/ei-library/src/org/tizen/eilib/events/CallItem.java
new file mode 100644 (file)
index 0000000..aa3f0dd
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events;
+
+import org.tizen.eilib.events.type.CallStatus;
+import org.tizen.eilib.events.type.MobileType;
+
+
+public class CallItem {
+       private int id;
+       private CallStatus status;
+       private boolean isMultiParty;
+       private MobileType mType; // MT / MO
+       private String number;
+
+       public String toString() {
+               String str = "ID: " + id +
+                               "\nMO-MT: "  + mType + 
+                               "\nStatus: " + status +
+                               "\nNumber: " + number + "\n";
+               return str;
+       }
+       public int getId() {
+               return id;
+       }
+
+       void setId(int id) {
+               this.id = id;
+       }
+
+       public CallStatus getStatus() {
+               return status;
+       }
+
+       void setStatus(CallStatus status) {
+               this.status = status;
+       }
+
+       public boolean isMultiParty() {
+               return isMultiParty;
+       }
+
+       void setMultiParty(boolean isMultiParty) {
+               this.isMultiParty = isMultiParty;
+       }
+
+       public MobileType getMobileType() {
+               return mType;
+       }
+
+       void setMobileType(MobileType mt) {
+               this.mType = mt;
+       }
+
+       public String getNumber() {
+               return number;
+       }
+
+       void setNumber(String number) {
+               this.number = number;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/EarJackEventInjector.java b/ei-library/src/org/tizen/eilib/events/EarJackEventInjector.java
new file mode 100644 (file)
index 0000000..311c8e2
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events;
+
+import java.io.IOException;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.receiver.EventReceiver;
+import org.tizen.eilib.events.receiver.StatusEventReceiver;
+import org.tizen.eilib.events.sender.DeviceEventSender;
+import org.tizen.eilib.events.type.EarJackStatus;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.modem.protocol.ByteUtil;
+import org.tizen.eilib.tools.EILogger;
+
+/**
+ * Instances of this class send ear jack event to the emulator.
+ * <dl>
+ * <dt><b>Send Events : </b></dt>
+ * <dd>EarJack's status</dd>
+ * </dl>
+ * <p>
+ */
+public class EarJackEventInjector  extends AbstractEventInjector {
+       private EarJackEventSender sender = null;
+
+       EarJackEventInjector(ConnectionToEmulator connector) {
+               sender = new EarJackEventSender(connector);
+               EventReceiver receiver = new EventReceiver("EarJackReceiver", sender);
+
+               AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS);
+               if (abReceiver != null && abReceiver instanceof StatusEventReceiver) {
+                       StatusEventReceiver re = (StatusEventReceiver)abReceiver;
+                       re.addStatusEventReceiver(ActionID.EARJACK_STATUS, receiver);
+               }
+       }
+
+       /**
+        * Change ear jack status of emulator.
+        *
+        * @param status EarJackStatus.DISCONNECT,
+        *                               EarJackStatus.WIRE3_CONNECT, EarJackSTatus.WIRE4_CONNECT
+        * @throws IOException 
+        * @throws ConnectionException 
+        * 
+        */
+       public boolean setStatus(EarJackStatus status) throws IOException, ConnectionException {
+               return sender.sendEarJackstatus(status);
+       }
+
+       /**
+        * Get ear jack status of emulator.
+        *
+        * @return status of ear jack
+        *                               EarJackStatus.DISCONNECT,
+        *                               EarJackStatus.WIRE3_CONNECT, EarJackSTatus.WIRE4_CONNECT
+        * @throws IOException 
+        * @throws ConnectionException 
+        * 
+        */
+       public EarJackStatus getStatus() throws IOException, DeviceEventException, ConnectionException {
+               EarJackStatus status = sender.getStatus();
+               if (status == null) {
+                       throw new DeviceEventException(EILibError.FailedGetValue);
+               }
+               return status;
+       }
+
+       @Override
+       public void initEventInjector() {
+               // TODO Auto-generated method stub
+               
+       }
+       
+}
+
+class EarJackEventSender extends DeviceEventSender {
+       private static String EarJackID = "9\n";
+       private EventMessage returnMsg = null;
+
+       public EarJackEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+
+       public synchronized boolean sendEarJackstatus(EarJackStatus status) throws IOException, ConnectionException {
+               double params[] = new double[1];
+               params[0] = status.getValue();
+               makeMessage(EarJackID, params);
+               return sendMessage(null);
+       }
+
+       public synchronized EarJackStatus getStatus() throws IOException, ConnectionException {
+               // empty message
+               makeMessage(EarJackID, null);
+               sendMessage(ActionID.EARJACK_STATUS);
+
+               synchronized(this) {
+                       // wait 5 second
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+
+               EarJackStatus status = null;
+               if (returnMsg != null) {
+                       if (returnMsg.getEventHeader().getActionID()
+                                       != ActionID.EARJACK_STATUS.getId()) {
+                               // TODO : error
+                               EILogger.getLogger().warning("An unexpected event occurs.");
+                       } else {
+                               int state = ByteUtil.byte2int
+                                               (returnMsg.getDataBuffer().array(), 14);
+                               for (EarJackStatus s : EarJackStatus.values()) {
+                                       if (s.getValue() == state) {
+                                               status = s;
+                                               break;
+                                       }
+                               }
+                       }
+                       returnMsg = null;
+               }
+
+               return status;
+       }
+
+       @Override
+       public void fireEvent(EventMessage message) {
+               synchronized(this) {
+                       this.returnMsg = message;
+                       this.notifyAll();
+               }
+       }
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/events/EventInjectorCreator.java b/ei-library/src/org/tizen/eilib/events/EventInjectorCreator.java
new file mode 100644 (file)
index 0000000..53ab499
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.eilib.tools.EILogger;
+
+public class EventInjectorCreator {
+       private ConnectionToEmulator connector = null;
+       private ArrayList<AbstractEventInjector> injectors = null;
+
+       public EventInjectorCreator(ConnectionToEmulator connector) {
+               assert connector == null;
+
+               this.connector = connector;
+               if (this.connector != null) {
+                       this.connector.setEventInjectorCreator(this);
+               }
+
+               injectors = new ArrayList<AbstractEventInjector>();
+       }
+
+       public void intializeConnectToEmulator() {
+               for (AbstractEventInjector i : injectors) {
+                       if (i != null) {
+                               i.initEventInjector();
+                       }
+               }
+       }
+
+       private BatteryEventInjector batteryInjector = null;
+       public BatteryEventInjector getBatteryEventInjector() {
+               if (batteryInjector == null) {
+                       batteryInjector = new BatteryEventInjector(connector);
+                       injectors.add(batteryInjector);
+               }
+               return batteryInjector;
+       }
+
+       private USBEventInjector USBInjector = null;
+       public USBEventInjector getUSBEventInjector() {
+               if (USBInjector == null) {
+                       USBInjector = new USBEventInjector(connector);
+                       injectors.add(USBInjector);
+               }
+               return USBInjector;
+       }
+
+       private EarJackEventInjector earJackInjector = null;
+       public EarJackEventInjector getEarJackInjector() {
+               if (earJackInjector == null) {
+                       earJackInjector = new EarJackEventInjector(connector);
+                       injectors.add(earJackInjector);
+               }
+               return earJackInjector;
+       }
+
+       private boolean isInitModem = false;
+       private CallEventInjector callInjector = null;
+       public CallEventInjector getCallEventInjector() throws ConnectionException {
+               if (callInjector == null) {
+                       try {
+                               connector.sendInitializeMessage();
+                       } catch (IOException e) {
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+                       callInjector = new CallEventInjector(connector);
+                       callInjector.setRssiEventInjector(getRssiEventInjector());
+                       injectors.add(callInjector);
+               }
+
+               if (!isInitModem) {
+                       try {
+                               connector.sendModemInitialize();
+                       } catch (IOException e) {
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+                       isInitModem = true;
+               }
+
+               synchronized(this) {
+                       try {
+                               this.wait(500);
+                       } catch (InterruptedException e) {
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+               return callInjector;
+       }
+
+       private SMSEventInjector smsInjector = null;
+       public SMSEventInjector getSMSEventInjector() throws ConnectionException {
+               if (smsInjector == null) {
+                       try {
+                               connector.sendInitializeMessage();
+                       } catch (IOException e) {
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+                       smsInjector = new SMSEventInjector(connector);
+                       smsInjector.setRssiEventInjector(getRssiEventInjector());
+                       injectors.add(smsInjector);
+               }
+               if (!isInitModem) {
+                       try {
+                               connector.sendModemInitialize();
+                       } catch (IOException e) {
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+                       isInitModem = true;
+               }
+               return smsInjector;
+       }
+
+       private RSSIEventInjector rssiInjector = null;
+       public RSSIEventInjector getRssiEventInjector() {
+               if (rssiInjector == null) {
+                       rssiInjector = new RSSIEventInjector(connector);
+                       injectors.add(rssiInjector);
+               }
+               return rssiInjector;
+       }
+
+       private LocationEventInjector locationInjector = null;
+       public LocationEventInjector getLocationInjector() {
+               if (locationInjector == null) {
+                       locationInjector = new LocationEventInjector(connector);
+                       injectors.add(locationInjector);
+               }
+               return locationInjector;
+       }
+
+       private SensorEventInjector sensorInjector = null;
+       public SensorEventInjector getSensorInjector() {
+               if (sensorInjector == null) {
+                       sensorInjector = new SensorEventInjector(connector);
+                       injectors.add(sensorInjector);
+               }
+               return sensorInjector;
+       }
+
+       private SDCardEventInjector SDCardInjector = null;
+       public SDCardEventInjector getSDCardInjector() throws IOException, DeviceEventException, ConnectionException {
+               if (SDCardInjector == null) {
+                       SDCardInjector = new SDCardEventInjector(connector);
+                       injectors.add(SDCardInjector);
+               }
+               return SDCardInjector;
+       }
+
+       private NfcEventInjector nfcEventInjector = null;
+       public NfcEventInjector getNfcEventInjector() throws IOException, ConnectionException {
+               if (nfcEventInjector == null) {
+                       nfcEventInjector = new NfcEventInjector(connector);
+                       injectors.add(SDCardInjector);
+               }
+               return nfcEventInjector;
+       }
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/events/LocationEvent.java b/ei-library/src/org/tizen/eilib/events/LocationEvent.java
new file mode 100644 (file)
index 0000000..f3436d1
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.eilib.events;
+
+import org.tizen.eilib.events.type.LocationEventMode;
+
+public class LocationEvent {
+       private LocationEventMode mode;
+       private double latitude;
+       private double logitude;
+       private String fileName;
+
+       public LocationEvent() {
+               mode = null;
+               latitude = 0.0;
+               logitude = 0.0;
+               fileName = null;
+       }
+
+       public LocationEventMode getMode() {
+               return mode;
+       }
+
+       void setMode(LocationEventMode mode) {
+               this.mode = mode;
+       }
+
+       public double getLatitude() {
+               return latitude;
+       }
+
+       void setLatitude(double latitude) {
+               this.latitude = latitude;
+       }
+
+       public double getLogitude() {
+               return logitude;
+       }
+
+       void setLogitude(double logitude) {
+               this.logitude = logitude;
+       }
+
+       public String getFileName() {
+               return fileName;
+       }
+
+       void setFileName(String fileName) {
+               this.fileName = fileName;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/LocationEventInjector.java b/ei-library/src/org/tizen/eilib/events/LocationEventInjector.java
new file mode 100644 (file)
index 0000000..ed4efa3
--- /dev/null
@@ -0,0 +1,274 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events;
+
+import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_OK;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.Emulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.receiver.EventReceiver;
+import org.tizen.eilib.events.receiver.StatusEventReceiver;
+import org.tizen.eilib.events.sender.LocationEventSender;
+import org.tizen.eilib.events.type.LocationEventMode;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.sdblib.service.SyncResult;
+import org.tizen.sdblib.service.SyncService;
+
+// TODO RECEIVER
+public class LocationEventInjector extends AbstractEventInjector {
+       private LocationEventSender sender = null;
+       private LocationEventMode currentMode;
+       private ConnectionToEmulator connector;
+
+       private static final String logFileName         = "nmea_replay.log";
+       private static final String remoteFilePath = "/opt/media/gps-manager/replay/" + logFileName;
+
+       LocationEventInjector(ConnectionToEmulator connector) {
+               sender = new LocationEventSender(connector);
+               AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS);
+               if (abReceiver != null && abReceiver instanceof StatusEventReceiver) {
+                       StatusEventReceiver re = (StatusEventReceiver)abReceiver;
+                       re.addStatusEventReceiver(ActionID.LOCATION_STATUS,
+                                       new EventReceiver("LocationReceiver", sender));
+               }
+
+               this.connector = connector;
+               initEventInjector();
+       }
+
+       /**
+        * This is set stop mode to the emulator's location mode. Emulator does not read location value after setting stop mode.
+        * If you no longer need to raise the location event, call this function.
+        * Otherwise unnecessary work occurs that emulator consistently read the location value.
+        * @return
+        * @throws IOException 
+        * @throws ConnectionException 
+        */
+       public boolean setStopMode() throws IOException, ConnectionException {
+               if (currentMode != LocationEventMode.STOPMODE) {
+                       currentMode = LocationEventMode.STOPMODE;
+                       return sender.sendMessage(LocationEventMode.STOPMODE.toString());
+               }
+               return true;
+       }
+
+       /**
+        * 
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        */
+       public boolean setManualMode() throws IOException, ConnectionException {
+               if (currentMode != LocationEventMode.MANUALMODE) {
+                       currentMode = LocationEventMode.MANUALMODE;
+                       return sender.sendMessage(LocationEventMode.MANUALMODE.toString());
+               }
+               return true;
+       }
+
+       /**
+        * Return current event mode
+        * 
+        * @see LocationEventMode
+        * @return
+        */
+       public LocationEventMode getEventMode() {
+               return currentMode;
+       }
+
+       /**
+        * Set location information.
+        * @param latitude -90 ~ 90
+        * @param longitude -180 ~ 180
+        * @return
+        * @throws IOException 
+        * @throws InjectorLibraryException 
+        * @throws ConnectionException 
+        */
+       public boolean sendLocation(double latitude, double longitude) throws IOException, InjectorLibraryException, ConnectionException {
+               if (!checkValues(latitude, longitude)) {
+                       throw new InjectorLibraryException(EILibError.InvalidLocationValue);
+               }
+
+               setManualMode();
+
+               String msg = currentMode.toString() + "," + latitude + "," + longitude;
+               return sender.sendMessage(msg);
+       }
+
+       /**
+        * Send location log file.
+        * File format is NMEA
+        * @param filePath
+        * @return
+        * @throws IOException
+        * @throws InjectorLibraryException 
+        * @throws ConnectionException 
+        */
+       public boolean sendLocationFile(String filePath) throws IOException, InjectorLibraryException, ConnectionException {
+               return sendLocationFile(new File(filePath));
+       }
+
+       /**
+        * Send location log file.
+        * File format is NMEA
+        * @param filePath
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        * @throws InjectorLibraryException 
+        */
+       public boolean sendLocationFile(File file) throws IOException, ConnectionException, InjectorLibraryException {
+               file = file.getCanonicalFile();
+
+               if (!file.exists()) {
+                       throw new InjectorLibraryException(EILibError.NotExistLogFile);
+               }
+
+               // TODO : PUSH FILE TO EMULATOR
+               // USING SDB
+               //sync.pushFile(file.getCanonicalPath(), remoteFilePath..);
+               Emulator emulator = connector.getCurrentEmulator();
+               if (emulator == null) {
+                       // TODO : exception
+                       return false;
+               }
+
+               SyncService sync = emulator.getSyncService();
+               if (sync != null) {
+                       SyncResult result = sync.push(file.getPath(), emulator.getDevice().getFileEntry(remoteFilePath));
+                       if (result.getCode() != RESULT_OK) {
+                               // TODO
+                               return false;
+                       }
+               }
+
+               currentMode = LocationEventMode.LOGMODE;
+               return sender.sendMessage(currentMode.toString() + "," + logFileName);
+       }
+
+       public LocationEvent getLocationStatus() throws IOException, ConnectionException, InjectorLibraryException {
+               String value = sender.getLocationStatus();
+               LocationEvent event = null;
+               if (value != null) {
+                       event = new LocationEvent();
+                       String[] vals = value.split(",");
+                       for (LocationEventMode m : LocationEventMode.values()) {
+                               if (m.toString().equals(vals[0])) {
+                                       event.setMode(m);
+                                       break;
+                               }
+                       }
+
+                       if (event.getMode() != null) {
+                               switch (event.getMode()) {
+                               case STOPMODE:
+                                       break;
+                               case LOGMODE:
+                                       event.setFileName(vals[1]);
+                                       break;
+                               case MANUALMODE:
+                                       event.setLatitude(Double.valueOf(vals[1]));
+                                       event.setLogitude(Double.valueOf(vals[2]));
+                                       break;
+                               default:
+                                       throw new InjectorLibraryException(EILibError.FailedGetValue);
+                               }
+                       } else {
+                               throw new InjectorLibraryException(EILibError.FailedGetValue);
+                       }
+               } else {
+                       throw new InjectorLibraryException(EILibError.FailedGetValue);
+               }
+
+               return event;
+       }
+       /**
+        * Initialize event injector local variable.
+        */
+       @Override
+       public void initEventInjector() {
+               currentMode = LocationEventMode.NONE;
+       }
+
+       private int minLatitude = -90;
+       private int maxLatitude = 90;
+       private int minLongitude = -180;
+       private int maxLongitude = 180;
+       private boolean checkValues(double latitude, double longitude) {
+               if (latitude > maxLatitude || latitude < minLatitude) {
+                       return false;
+               }
+
+               if (longitude > maxLongitude || longitude < minLongitude) {
+                       return false;
+               }
+       
+               return true;
+       }
+
+       /**
+        * Return minimum latitude value
+        * @return
+        */
+       public int getMinLatitude() {
+               return minLatitude;
+       }
+
+       /**
+        * Return maximum latitude value
+        * @return
+        */
+       public int getMaxLatitude() {
+               return maxLatitude;
+       }
+
+       /**
+        * Return minimum longitude value
+        * @return
+        */
+       public int getMinLongitude() {
+               return minLongitude;
+       }
+
+       /**
+        * Return maximum longitude value
+        * @return
+        */
+       public int getMaxLongitude() {
+               return maxLongitude;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/NfcEventInjector.java b/ei-library/src/org/tizen/eilib/events/NfcEventInjector.java
new file mode 100644 (file)
index 0000000..e30e14b
--- /dev/null
@@ -0,0 +1,482 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.Emulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.receiver.EventReceiver;
+import org.tizen.eilib.events.receiver.StatusEventReceiver;
+import org.tizen.eilib.events.sender.NfcEventSender;
+import org.tizen.eilib.events.type.NDEFFormat;
+import org.tizen.eilib.events.type.NDEFRecord;
+import org.tizen.eilib.events.type.NfcTagType;
+import org.tizen.eilib.events.type.MimeTypeList;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.NfcEventException;
+import org.tizen.eilib.tools.EILogger;
+import org.tizen.sdblib.exception.SdbCommandRejectedException;
+import org.tizen.sdblib.exception.ShellCommandUnresponsiveException;
+import org.tizen.sdblib.exception.TimeoutException;
+import org.tizen.sdblib.receiver.MultiLineReceiver;
+
+/**
+ * Instance of this class send nfc event to the emulator
+ *
+ */
+public class NfcEventInjector extends AbstractEventInjector {
+       private NfcEventSender sender = null;
+       private ArrayList<NDEFRecord> recordList;
+       private ArrayList<NDEFRecord> attachedList;
+       private ConnectionToEmulator connector;
+       private static final int MaxRecordListLength = 4096;
+       private static final int MaxRecordCount = 5;
+       private static NfcEventType currentEventType = NfcEventType.NONE;
+
+       private int recordListLength = 0;
+
+       NfcEventInjector(ConnectionToEmulator connector) throws IOException, ConnectionException {
+               sender = new NfcEventSender(connector);
+               recordList = new ArrayList<NDEFRecord>();
+               attachedList = new ArrayList<NDEFRecord>();
+               AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS);
+               if (abReceiver != null && abReceiver instanceof StatusEventReceiver) {
+                       StatusEventReceiver re = (StatusEventReceiver)abReceiver;
+                       re.addStatusEventReceiver(ActionID.NFC_STATUS,
+                                               new EventReceiver("NfcReceiver", sender));
+               }
+
+               this.connector = connector;
+
+               // get current status
+               try {
+                       getNfcStatus();
+               } catch (NfcEventException e) {
+                       EILogger.getLogger().info(e.getMessage());
+               }
+       }
+
+       public NfcEventType getCurrentEventType() {
+               return currentEventType;
+       }
+
+       private int checkRecordListMaxLength() {
+               int lenList = 0;
+               for (NDEFRecord record : recordList) {
+                       lenList += 1 + record.toString().length() + 4;
+               }
+
+               if (lenList > MaxRecordListLength) {
+                       return -1;
+               }
+
+               return lenList;
+       }
+
+       public ArrayList<NDEFRecord> getRecordList() {
+               return recordList;
+       }
+
+       public int getRecordListLength() {
+               return recordListLength;
+       }
+
+       public void addNDEFRecord(NDEFRecord record) throws NfcEventException {
+               if (record == null) {
+                       throw new NfcEventException(EILibError.NullRecord);
+               }
+               if (recordList.size() >= MaxRecordCount) {
+                       throw new NfcEventException(EILibError.RecordCountIsMax);
+               }
+
+               checkRecordFormat(record);
+
+               recordList.add(record);
+
+               int temp = checkRecordListMaxLength();
+               if (temp == -1) {
+                       recordList.remove(record);
+                       throw new NfcEventException(EILibError.NDEFMessageLenIsMax);
+               } else {
+                       recordListLength = temp;
+               }
+       }
+
+       private void checkRecordFormat(NDEFRecord record) throws NfcEventException {
+               checkInvaildCharacters(record.getId());
+               checkInvaildCharacters(record.getTypeName());
+               checkInvaildCharacters(record.getPayload());
+
+               if (record.getFormat() == NDEFFormat.WELL_KNOWN) {
+                       if (!record.getTypeName().equals("U")
+                                       && !record.getTypeName().equals("T")) {
+                               throw new NfcEventException(EILibError.InvalidWellKnownType);
+                       }
+               } else if (record.getFormat() == NDEFFormat.MEDIA) {
+                       if (checkFileTpye(record.getPayload()) == null) {
+                               throw new NfcEventException(EILibError.NotMimeType);
+                       }
+                       if (checktFileSize(record.getPayload()) == false) {
+                               throw new NfcEventException(EILibError.BigSizeFile);
+                       }
+               }
+       }
+
+       private boolean checktFileSize(String filePath) throws NfcEventException {
+               boolean result = false;
+               shellCmd    = "du " + filePath;
+               try {
+                       connector.getCurrentEmulator().executeShellCommand(shellCmd, new MultiLineReceiver() {
+                               @Override
+                               public void processNewLines(String[] lines) {
+                                       shellResult = lines[0];
+                               }
+                               
+                       });
+               } catch (TimeoutException e) {
+                       throw new NfcEventException(EILibError.CheckMediaFileException);
+               } catch (SdbCommandRejectedException e) {
+                       throw new NfcEventException(EILibError.CheckMediaFileException);
+               } catch (ShellCommandUnresponsiveException e) {
+                       throw new NfcEventException(EILibError.CheckMediaFileException);
+               } catch (IOException e) {
+                       throw new NfcEventException(EILibError.CheckMediaFileException);
+               }
+               if (shellResult != null) {
+                       int index = shellResult.indexOf('\t');
+                       if (index != -1) {
+                               shellResult = shellResult.substring(0, index);
+                               
+                               if (Integer.valueOf(shellResult) <= 10) {
+                                       result = true;
+                               }
+                       }
+               }
+
+               return result;
+       }
+
+       private String checkFileTpye(String payload) {
+               int index   = payload.lastIndexOf('.');
+               String type = null;
+               if (index != -1) {
+                       String ex = payload.substring(index + 1);
+                       MimeTypeList typelist = MimeTypeList.getInstance();
+
+                       type = typelist.findMimeType(ex);
+               }
+
+               return type;
+       }
+
+       private void checkInvaildCharacters(String text) throws NfcEventException {
+               for (char c : text.toCharArray()) {
+                       if (c == '\n') {
+                               throw new NfcEventException(EILibError.InvalidCharNewLine);
+                       }
+                       
+                       if (c == ',') {
+                               throw new NfcEventException(EILibError.InvalidChar);
+                       }
+
+                       if (c >= 0x80) {
+                               throw new NfcEventException(EILibError.InvalidCharAscii);
+                       }
+               }
+       }
+
+       public void removeNDEFRecord(NDEFRecord record) throws NfcEventException {
+               if (record == null) {
+                       throw new NfcEventException(EILibError.NullRecord);
+               }
+
+               if (!recordList.remove(record)) {
+                       throw new NfcEventException(EILibError.FailedRemoveRecord);
+               }
+               checkRecordListMaxLength();
+       }
+
+       public void removeNDEFRecord(int index) throws NfcEventException {
+               try {
+                       recordList.remove(index);
+               } catch (IndexOutOfBoundsException e) {
+                       throw new NfcEventException(EILibError.FailedRemoveRecord);
+               }
+               checkRecordListMaxLength();
+       }
+
+       public NDEFRecord getNDEFRecord(NDEFRecord record) {
+               for (NDEFRecord r : recordList) {
+                       if (r.equals(record)) {
+                               return r;
+                       }
+               }
+               return null;
+       }
+
+       public NDEFRecord getNDEFRecorde(int index) {
+               return recordList.get(index);
+       }
+
+       public boolean sendTagDiscovered(NfcTagType tag) throws IOException, NfcEventException, ConnectionException {
+               if (currentEventType == NfcEventType.TAG_DISCOVERED) {
+                       throw new NfcEventException(EILibError.TagAttachState);
+               } else if (currentEventType == NfcEventType.P2P_DISCOVERED
+                               || currentEventType == NfcEventType.P2P_SEND) {
+                       throw new NfcEventException(EILibError.P2PAttachState);
+               }
+
+               if (!avaliableNfc()) {
+                       throw new NfcEventException(EILibError.NFCIsDisable);
+               }
+
+               if (recordList.size() == 0) {
+                       throw new NfcEventException(EILibError.RecordCountIsZero);
+               }
+
+               if (tag == null || tag == NfcTagType.P2P) {
+                       throw new NfcEventException(EILibError.SelecTagType);
+               }
+
+               String message = NfcEventType.TAG_DISCOVERED.getType() + ":"
+                               + tag.getType() + "," + recordList.size();
+               for (NDEFRecord record : recordList) {
+                       message += "," + record.getMessage();
+               }
+
+               sender.sendMessage(message + "\n");
+
+               currentEventType = NfcEventType.TAG_DISCOVERED;
+
+               return true;
+       }
+
+       
+       public boolean sendTagDetached() throws IOException, NfcEventException, ConnectionException {
+               if (currentEventType != NfcEventType.TAG_DISCOVERED) {
+                       throw new NfcEventException(EILibError.CanNotDettach);
+               }
+
+               if (!avaliableNfc()) {
+                       throw new NfcEventException(EILibError.NFCIsDisable);
+               }
+
+               sender.sendMessage(NfcEventType.TAG_DETACHED.getType() + ":" + "\n");
+
+               currentEventType = NfcEventType.TAG_DETACHED;
+
+               return true;
+       }
+
+       public boolean sendP2PDiscovered() throws IOException, NfcEventException, ConnectionException {
+               if (currentEventType == NfcEventType.TAG_DISCOVERED) {
+                       throw new NfcEventException(EILibError.TagAttachState);
+               } else if (currentEventType == NfcEventType.P2P_DISCOVERED
+                               || currentEventType == NfcEventType.P2P_SEND) {
+                       throw new NfcEventException(EILibError.P2PAttachState);
+               }
+
+               if (!avaliableNfc()) {
+                       throw new NfcEventException(EILibError.NFCIsDisable);
+               }
+
+               sender.sendMessage(NfcEventType.P2P_DISCOVERED.getType() + ":" + "\n");
+
+               currentEventType = NfcEventType.P2P_DISCOVERED;
+
+               return true;
+       }
+
+       public boolean sendP2PSend() throws IOException, NfcEventException, ConnectionException {
+               if (currentEventType != NfcEventType.P2P_DISCOVERED
+                               && currentEventType != NfcEventType.P2P_SEND) {
+                       throw new NfcEventException(EILibError.CanNotSend);
+               }
+
+               if (!avaliableNfc()) {
+                       throw new NfcEventException(EILibError.NFCIsDisable);
+               }
+
+               if (recordList.size() == 0) {
+                       throw new NfcEventException(EILibError.RecordCountIsZero);
+               }
+
+               String message = NfcEventType.P2P_SEND.getType() + ":"
+                               + NfcTagType.P2P.getType() + "," + recordList.size();
+
+               for (NDEFRecord record : recordList) {
+                       message += "," + record.getMessage();
+               }
+
+               sender.sendMessage(message + "\n");
+
+               currentEventType = NfcEventType.P2P_SEND;
+
+               return true;
+       }
+
+       public boolean sendP2PDetached() throws IOException, NfcEventException, ConnectionException {
+               if (currentEventType != NfcEventType.P2P_DISCOVERED
+                               && currentEventType != NfcEventType.P2P_SEND) {
+                       throw new NfcEventException(EILibError.CanNotDettach);
+               }
+
+               if (!avaliableNfc()) {
+                       throw new NfcEventException(EILibError.NFCIsDisable);
+               }
+
+               sender.sendMessage(NfcEventType.P2P_DETACHED.getType() + ":" + "\n");
+
+               currentEventType = NfcEventType.P2P_DETACHED;
+
+               return true;
+       }
+
+       public ArrayList<NDEFRecord> getAttachedRecordList() {
+               return attachedList;
+       }
+
+       public NfcEventType getNfcStatus() throws IOException, ConnectionException, NfcEventException {
+               if (!avaliableNfc()) {
+                       throw new NfcEventException(EILibError.NFCIsDisable);
+               }
+
+               String value = sender.getNfcStatus();
+
+               NfcEventType type = null;
+               if (value != null) {
+                       String[] vals = value.split(":");
+                       int temp = Integer.valueOf(vals[0]);
+                       for (NfcEventType t : NfcEventType.values()) {
+                               if (temp == t.getType()) {
+                                       currentEventType = type = t;
+                                       break;
+                               }
+                       }
+
+                       attachedList.clear();
+                       if (type != null
+                                       && (type == NfcEventType.TAG_DISCOVERED
+                                           || type == NfcEventType.P2P_SEND)) {
+                               makeNDEFMessage(vals[1]);
+                       }
+               }
+
+               return type == null ? NfcEventType.NONE : type;
+       }
+
+       private void makeNDEFMessage(String value) {
+               if (value.endsWith("\n")) {
+                       value = value.substring(0, value.length() - 1);
+               }
+               String[] vals = value.split(",");
+
+               int count = Integer.valueOf(vals[1]);
+               for (int i = 0; i < count; i++) {
+                       String temp = vals[2 + (4*i)];
+                       NDEFFormat format = null;
+                       for (NDEFFormat f : NDEFFormat.values()) {
+                               if (f.getFormat().equals(temp)) {
+                                       format = f;
+                                       break;
+                               }
+                       }
+                       if (format == null) {
+                               continue;
+                       }
+                       attachedList.add
+                       (new NDEFRecord(format, vals[3 + (4*i)], vals[4 + (4*i)], vals[5 + (4*i)]));
+               }
+       }
+
+       private String shellCmd = "vconftool get db/nfc/enable";
+       private String errorMessage = null;
+       private String shellResult      = null;
+       public boolean avaliableNfc() throws ConnectionException {
+               boolean result  = true;
+               shellResult     = null;
+               errorMessage    = null;
+               Emulator emualtor = connector.getCurrentEmulator();
+               
+               try {
+                       emualtor.getDevice().executeShellCommand(shellCmd, new MultiLineReceiver() {
+                               @Override
+                               public void processNewLines(String[] lines) {
+                                       shellResult = lines[0];
+                               }
+                       });
+               } catch (TimeoutException e) {
+                       errorMessage = e.getMessage();
+                       result = false;
+               } catch (SdbCommandRejectedException e) {
+                       errorMessage = e.getMessage();
+                       result = false;
+               } catch (ShellCommandUnresponsiveException e) {
+                       errorMessage = e.getMessage();
+                       result = false;
+               } catch (IOException e) {
+                       errorMessage = e.getMessage();
+                       result = false;
+               }
+               if (result && shellResult != null) {
+                       if (shellResult.indexOf('1') != -1) {
+                               result = true;
+                       } else {
+                               result = false;
+                       }
+               } else {
+                       EILogger.getLogger().info(errorMessage);
+               }
+
+               if (!result) {
+                       currentEventType = NfcEventType.NONE;
+                       try {
+                               sender.sendMessage(NfcEventType.TAG_DETACHED.getType() + ":" + "\n");
+                       } catch (IOException e) {
+                               EILogger.getLogger().info(e.getMessage());
+                       }
+               }
+
+               return result;
+       }
+
+       @Override
+       public void initEventInjector() {
+               // TODO Auto-generated method stub
+
+       }
+
+}
diff --git a/ei-library/src/org/tizen/eilib/events/NfcEventType.java b/ei-library/src/org/tizen/eilib/events/NfcEventType.java
new file mode 100644 (file)
index 0000000..410faee
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events;
+
+public enum NfcEventType
+{
+       NONE("NFC_NONE", 0),
+       TAG_DISCOVERED("NFC_TAG_DISCOVERED", 100),
+       TAG_DETACHED("NFC_TAG_DETACHED", 101),
+       P2P_DISCOVERED("NFC_P2P_DISCOVERED", 102),
+       P2P_DETACHED("NFC_P2P_DETACHED", 103),
+       P2P_SEND("NFC_P2P_SEND", 104);
+
+       int type;
+       String name;
+
+       NfcEventType(String n, int t) {
+               type = t;
+               name = n;
+       }
+
+       public int getType() {
+               return type;
+       }
+
+       @Override
+       public String toString() {
+               return name;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/RSSIEventInjector.java b/ei-library/src/org/tizen/eilib/events/RSSIEventInjector.java
new file mode 100644 (file)
index 0000000..dffa850
--- /dev/null
@@ -0,0 +1,258 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events;
+
+import java.io.IOException;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.receiver.EventReceiver;
+import org.tizen.eilib.events.receiver.StatusEventReceiver;
+import org.tizen.eilib.events.sender.DeviceEventSender;
+import org.tizen.eilib.events.sender.ModemEventSender;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.eilib.modem.protocol.ByteUtil;
+import org.tizen.eilib.modem.protocol.G02A31;
+import org.tizen.eilib.modem.protocol.StructureGA;
+import org.tizen.eilib.tools.EILogger;
+
+/**
+ * Instance of this class to control rssi status of emulator.
+ *
+ */
+public class RSSIEventInjector extends AbstractEventInjector {
+       private RSSIEventSender sender           = null;
+       private ModemEventSender modemSender = null;
+       static final int MIN_VALUE = 0;
+       static final int MAX_VALUE = 5;
+       private boolean isLevelZero = false;
+
+       RSSIEventInjector(ConnectionToEmulator connector) {
+               sender          = new RSSIEventSender(connector);
+               modemSender = new ModemEventSender(connector);
+               EventReceiver receiver = new EventReceiver("RSSIReceiver", sender);
+               AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS);
+               if (abReceiver != null && abReceiver instanceof StatusEventReceiver) {
+                       StatusEventReceiver re = (StatusEventReceiver)abReceiver;
+                       re.addStatusEventReceiver(ActionID.RSSI_LEVEL, receiver);
+               }
+       }
+
+       /**
+        * Return maximum level of rssi
+        * @return
+        */
+       public int getMaxLevel() {
+               return MAX_VALUE;
+       }
+
+       /**
+        * Return minimim level of rssi
+        * @return
+        */
+       public int getMinLevel() {
+               return MIN_VALUE;
+       }
+
+       /**
+        * 
+        * @param level
+        * @return
+        * @throws IOException 
+        * @throws DeviceEventException 
+        * @throws ConnectionException 
+        */
+       public boolean setLevel(int level) throws IOException, DeviceEventException, ConnectionException {
+               if (level < MIN_VALUE || level > MAX_VALUE) {
+                       throw new DeviceEventException(EILibError.InvalidValue);
+               }
+
+               if (sender.setLevel(level)) {
+                       if (level == MIN_VALUE) {
+                               if (!isLevelZero) {
+                                       sendRssiStatus();
+                                       isLevelZero = true;
+                               }
+                       } else {
+                               if (isLevelZero) {
+                                       sendRssiStatus();
+                                       isLevelZero = false;
+                               }
+                       }
+               }
+               return sender.setLevel(level);
+       }
+
+       /**
+        * 
+        * @return
+        * @throws IOException 
+        * @throws ConnectionException 
+        * @throws DeviceEventException 
+        */
+       public int getLevel() throws IOException, ConnectionException, DeviceEventException {
+               int level = sender.getLevel();
+
+               if (level == -1) {
+                       throw new DeviceEventException(EILibError.FailedGetValue);
+               }
+
+               return level;
+       }
+
+       /**
+        * 
+        * @return if this value is true, rssi level is zero.
+        * If rssi value is 0, the emulator's network does not work.
+        * So, call ant sms events do not work.
+        */
+       private boolean isInit = false;
+       public boolean isLevelZero() {
+               if (!isInit){
+                       try {
+                               if (getLevel() == 0) {
+                                       isLevelZero = true;
+                               }
+                       } catch (DeviceEventException e) {
+                               // TODO Auto-generated catch block
+                               EILogger.getLogger().warning(e.getMessage());
+                       } catch (IOException e) {
+                               // TODO Auto-generated catch block
+                               EILogger.getLogger().warning(e.getMessage());
+                       } catch (ConnectionException e) {
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+                       isInit = true;
+               }
+               return isLevelZero;
+       }
+
+       private void sendRssiStatus() throws IOException, ConnectionException {
+               int netType = 0x02;     // UMTS
+               int netServiceDomain = 0x01;    // Combined(CS + PS) Mode
+               int netRegStatus = isLevelZero ? 0x01 : 0x00;   
+               int netEdgeSupport = 0x00;              // GSM_NET_EDGE_NOTSUPPORT
+               int lac0 = 0x11;
+               int lac1 = 0x20;
+               int id0 = 0x00;
+               int id1 = 0x00;
+               int id2 = 0x00;
+               int id3 = 0x0A;
+               int rejCause = 0x00;
+               
+               G02A31 ga = new G02A31();
+               ga.intialize();
+               
+               StructureGA sga = ga.getBody();
+               sga.setInt("NET_ACT_TYPE", netType);
+               sga.setInt("NET_SVC_DOMAIN", netServiceDomain);
+               sga.setInt("NET_REG_STATUS", netRegStatus);
+               sga.setInt("NET_EDGE_SUPPORT", netEdgeSupport);
+               sga.setInt("LAC0", lac0);
+               sga.setInt("LAC1", lac1);
+               sga.setInt("CELL_ID0", id0);
+               sga.setInt("CELL_ID1", id1);
+               sga.setInt("CELL_ID2", id2);
+               sga.setInt("CELL_ID3", id3);
+               sga.setInt("REJ_CAUSE", rejCause);
+
+               modemSender.send(ga);
+       }
+
+       @Override
+       public void initEventInjector() {
+               // TODO Auto-generated method stub
+               
+       }
+}
+
+class RSSIEventSender extends DeviceEventSender {
+       private EventMessage returnMsg = null;
+
+       public RSSIEventSender(ConnectionToEmulator connector) {
+               super(connector);
+               // TODO Auto-generated constructor stub
+       }
+
+       private static String RSSIID    = "11\n";
+       private double params[] = new double[1];
+
+       public synchronized boolean setLevel(int level) throws IOException, ConnectionException {
+               params[0] = level;
+               makeMessage(RSSIID, params);
+               return sendMessage(null);
+       }
+
+       public synchronized int getLevel() throws IOException, ConnectionException {
+               // empty message
+               makeMessage(RSSIID, null);
+               sendMessage(ActionID.RSSI_LEVEL);
+
+               synchronized(this) {
+                       // wait 5 second
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+               
+               int level = -1;
+               if (returnMsg != null) {
+                       if (returnMsg.getEventHeader().getActionID()
+                                       != ActionID.RSSI_LEVEL.getId()) {
+                               // TODO : error
+                               EILogger.getLogger().warning("An unexpected event occurs.");
+                       } else {
+                               level = ByteUtil.byte2int
+                                               (returnMsg.getDataBuffer().array(), 14);
+                               if (level < RSSIEventInjector.MIN_VALUE 
+                                               || level > RSSIEventInjector.MAX_VALUE) {
+                                       level = -1;
+                               }
+                       }
+                       returnMsg = null;
+               }
+
+               return level;
+       }
+
+       @Override
+       public void fireEvent(EventMessage message) {
+               synchronized(this) {
+                       this.returnMsg = message;
+                       this.notifyAll();
+               }
+       }
+       
+}
diff --git a/ei-library/src/org/tizen/eilib/events/SDCardEvent.java b/ei-library/src/org/tizen/eilib/events/SDCardEvent.java
new file mode 100644 (file)
index 0000000..64db39c
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events;
+
+public class SDCardEvent {
+       private boolean isSucces;
+       private boolean isMount;
+       private String SDCardName;
+
+       public boolean isMount() {
+               return isMount;
+       }
+
+       void setMount(boolean isMount) {
+               this.isMount = isMount;
+       }
+
+       public String getSDCardName() {
+               return SDCardName;
+       }
+
+       void setSDCardName(String sDCardName) {
+               SDCardName = sDCardName;
+       }
+
+       public boolean isSucces() {
+               return isSucces;
+       }
+
+       void setSucces(boolean isSucces) {
+               this.isSucces = isSucces;
+       }
+
+}
diff --git a/ei-library/src/org/tizen/eilib/events/SDCardEventInjector.java b/ei-library/src/org/tizen/eilib/events/SDCardEventInjector.java
new file mode 100644 (file)
index 0000000..afee48d
--- /dev/null
@@ -0,0 +1,433 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.Emulator;
+import org.tizen.eilib.connection.EmulatorList;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.listener.EventListenerList;
+import org.tizen.eilib.events.listener.ISDcardEventListener;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.sender.SDCardEventSender;
+import org.tizen.eilib.events.sender.SDCardStatusCheckSender;
+import org.tizen.eilib.events.type.SDCardEventType;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.eilib.tools.EILogger;
+
+/**
+ * This class send SD card event to the emulator.
+ * Using this class, you can mount sdcard or umount sdcard
+ *
+ */
+public class SDCardEventInjector extends AbstractEventInjector {
+       private SDCardStatusCheckSender statusCheckSender        = null;
+       private SDCardEventReceiver receiver = null;
+       private SDCardEventSender       sender   = null;
+       private ConnectionToEmulator connector;
+       private EventListenerList listeners  = new EventListenerList();
+
+       private boolean isDataWaiting           = false;
+       private boolean isUnmountSuccess        = false;
+
+       SDCardEventInjector(ConnectionToEmulator connector) throws IOException, DeviceEventException, ConnectionException {
+               sender   = new SDCardEventSender(connector);
+               receiver = new SDCardEventReceiver(this);
+               statusCheckSender = new SDCardStatusCheckSender(connector);
+               connector.addEventReceiver(GroupID.SDCARD, receiver);
+               this.connector = connector;
+
+               queryMountStatus();
+               //getCurrentMountStatus(true);
+       }
+
+       @Override
+       public void initEventInjector() {
+               try {
+                       queryMountStatus();
+                       //getCurrentMountStatus(true);
+               } catch (IOException e) {
+                       EILogger.getLogger().warning(e.getMessage());
+               } catch (DeviceEventException e) {
+                       EILogger.getLogger().warning(e.getMessage());
+               }  catch (ConnectionException e) {
+                       EILogger.getLogger().warning(e.getMessage());
+               }
+       }
+
+       /**
+        * Find out status sdcard of all running emulator.
+        * @throws IOException
+        * @throws ConnectionException 
+        * @throws DeviceEventException 
+        * @throws InjectorLibraryException 
+        */
+       public void queryMountStatus() throws IOException, DeviceEventException, ConnectionException {
+               ArrayList<Emulator> emulators = EmulatorList.getInstance().getEmulatorList();
+               for (Emulator emulator : emulators) {
+                       statusCheckSender.sendMountCheck(emulator, true);
+               }
+       }
+
+       /**
+        * Return mount status.
+        * @return true - mount, false - umount
+        */
+       public boolean isMounted() {
+               return connector.getCurrentEmulator().isMounted();
+       }
+
+       /**
+        * Return name of sdcard
+        * @return
+        */
+       public String getMountSDCardName() {
+               return connector.getCurrentEmulator().getSDCardName();
+       }
+
+       /**
+        * Return whether the operation is success
+        * @return
+        */
+       public boolean isUnmountSuccess() {
+               return isUnmountSuccess;
+       }
+
+       /**
+        *  Return mount status of current emulator.
+        *  This function refresh mount status.
+        * @param isWait if this value false, this function returns immediately (asynchronous)
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        * @throws DeviceEventException 
+        */
+       public boolean getCurrentMountStatus(boolean isWait) throws IOException, ConnectionException, DeviceEventException {
+               isDataWaiting = true;
+               if (!sender.getMountStatus()) {
+                       // TODO : exception
+                       return false;
+               }
+
+               if (isWait) {
+                       synchronized(this) {
+                               try {
+                                       this.wait(2000);
+                               } catch (InterruptedException e1) {
+                                       EILogger.getLogger().warning(e1.getMessage());
+                               }
+                       }
+                       if (isDataWaiting) {
+                               throw new DeviceEventException(EILibError.FailedGetValue);
+                       }
+               }
+               return true;
+       }
+
+       /**
+        * 
+        * @param isWait if this value false, this function returns immediately (asynchronous)
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        */
+       public boolean unmount(boolean isWait) throws IOException, ConnectionException {
+               isUnmountSuccess = false;
+
+               //getCurrentMountStatus(true);
+
+               if (!isMounted()) {
+                       return true;
+               }
+
+               if (!sender.sendUnmount()) {
+                       // TODO :exception
+                       return false;
+               }
+
+               if (isWait) {
+                       synchronized(this) {
+                               try {
+                                       this.wait();
+                               } catch (InterruptedException e1) {
+                                       EILogger.getLogger().warning(e1.getMessage());
+                               }
+                       }
+                       
+                       if (isMounted()) {
+                               return false;
+                       }
+
+                       if (!isUnmountSuccess()) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       /**
+        * 
+        * @param SDCardName
+        * @param isWait if this value false, this function returns immediately (asynchronous)
+        * @return
+        * @throws IOException
+        * @throws InjectorLibraryException
+        * @throws ConnectionException 
+        */
+       public boolean mount(String SDCardName, boolean isWait)
+                       throws IOException, ConnectionException, InjectorLibraryException {
+
+               queryMountStatus();
+               //getCurrentMountStatus(true);
+
+               if (isMounted()) {
+                       throw new InjectorLibraryException(EILibError.EmulatorIsMounted);
+               }
+
+               for (Emulator e : EmulatorList.getInstance().getEmulatorList()) {
+                       if (e.isMounted()) {
+                               if (e.getSDCardName().equals(SDCardName)) {
+                                       throw new InjectorLibraryException(EILibError.SDCardIsMounted);
+                               }
+                       }
+               }
+
+               if (!sender.sendMount(SDCardName)) {
+                       // TODO : exception
+                       return false;
+               }
+
+               if (isWait) {
+                       synchronized(this) {
+                               try {
+                                       this.wait();
+                               } catch (InterruptedException e1) {
+                                       EILogger.getLogger().warning(e1.getMessage());
+                               }
+                       }
+                       if (!isMounted()) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       /**
+        * Add SDCard event listener.
+        * 
+        * @param listener
+        */
+       public void addSDCardEventListener(ISDcardEventListener listener) {
+               listeners.add(listener);
+       }
+
+       /**
+        * Remove SDCard event listener.
+        * 
+        * @param listener
+        */
+       public void removeSDCardEventListener(ISDcardEventListener listener) {
+               listeners.remove(listener);
+       }
+
+       private Emulator emulator = null;
+       synchronized void  fireUnmountSuccess(String name) {
+               emulator = connector.getCurrentEmulator();
+               emulator.setMounted(false);
+               emulator.setSDCardName("");
+               isUnmountSuccess = true;
+               
+               synchronized(this) {
+                       this.notifyAll();
+               }
+
+               // TODO
+               SDCardEvent event = new SDCardEvent();
+               event.setMount(false);
+               event.setSucces(true);
+               event.setSDCardName(name);
+
+               for (int i = 0 ; i < listeners.size() ; i++) {
+                       final ISDcardEventListener listener = (ISDcardEventListener)listeners.getListeners().get(i);
+                       listener.completeUnmount(event);
+               }
+       }
+
+       synchronized void fireMountSuccess(String name) {
+               emulator = connector.getCurrentEmulator();
+               emulator.setMounted(true);
+               emulator.setSDCardName(name);
+
+               synchronized(this) {
+                       this.notifyAll();
+               }
+
+               // TODO
+               SDCardEvent event = new SDCardEvent();
+               event.setMount(true);
+               event.setSucces(true);
+               event.setSDCardName(name);
+
+               for (int i = 0 ; i < listeners.size() ; i++) {
+                       final ISDcardEventListener listener = (ISDcardEventListener)listeners.getListeners().get(i);
+                       listener.completeMount(event);
+               }
+       }
+
+       synchronized void fireUnmountStatus(String name) {
+               emulator = connector.getCurrentEmulator();
+               emulator.setMounted(false);
+               emulator.setSDCardName("");
+               isDataWaiting = false;
+
+               synchronized(this) {
+                       this.notifyAll();
+               }
+
+               // TODO
+               SDCardEvent event = new SDCardEvent();
+               event.setMount(false);
+               event.setSucces(true);
+               event.setSDCardName(name);
+
+               for (int i = 0 ; i < listeners.size() ; i++) {
+                       final ISDcardEventListener listener = (ISDcardEventListener)listeners.getListeners().get(i);
+                       listener.completeQeueryStatus(event);
+               }
+       }
+
+       synchronized void fireMountStatus(String name) {
+               emulator = connector.getCurrentEmulator();
+               emulator.setMounted(true);
+               emulator.setSDCardName(name);
+               isDataWaiting = false;
+
+               synchronized(this) {
+                       this.notifyAll();
+               }
+               // TODO
+               SDCardEvent event = new SDCardEvent();
+               event.setMount(true);
+               event.setSucces(true);
+               event.setSDCardName(name);
+
+               for (int i = 0 ; i < listeners.size() ; i++) {
+                       final ISDcardEventListener listener = (ISDcardEventListener)listeners.getListeners().get(i);
+                       listener.completeQeueryStatus(event);
+               }
+       }
+
+       synchronized void fireUnmountFailed(String name) {
+               isUnmountSuccess = false;
+
+               synchronized(this) {
+                       this.notifyAll();
+               }
+               
+               // TODO
+               SDCardEvent event = new SDCardEvent();
+               event.setMount(false);
+               event.setSucces(false);
+               event.setSDCardName(name);
+
+               for (int i = 0 ; i < listeners.size() ; i++) {
+                       final ISDcardEventListener listener = (ISDcardEventListener)listeners.getListeners().get(i);
+                       listener.completeUnmount(event);
+               }
+       }
+
+       synchronized void fireMountFailed(String name) {
+               EILogger.getLogger().warning("Fire mount failed :" + name);
+
+               // empty..
+               synchronized(this) {
+                       this.notifyAll();
+               }
+       }
+
+       /**
+        * 
+        * @return
+        */
+       public boolean isDataWaiting() {
+               return isDataWaiting;
+       }
+}
+
+class SDCardEventReceiver extends AbstractEventReceiver {
+       private SDCardEventInjector injector;
+       public SDCardEventReceiver(SDCardEventInjector injector) {
+               super("SD card event");
+               this.injector = injector;
+       }
+
+       @Override
+       public void run(EventMessage message) {
+               int len = message.getDataBuffer().position();
+               String name = "";
+               if (len != 0) {
+                       try {
+                               name = new String(message.getDataBuffer().array(),
+                                               message.getDataBufferOffset(), len, "US-ASCII");
+                       } catch (UnsupportedEncodingException e) {
+                               EILogger.getLogger().warning(e.getMessage());
+                               name = "";
+                       }
+               }
+               switch(message.getEventHeader().getActionID()) {
+               case SDCardEventType.Action_Unmount:
+                       injector.fireUnmountSuccess(name);
+                       break;
+               case SDCardEventType.Action_Mount:
+                       injector.fireMountSuccess(name);
+                       break;
+               case SDCardEventType.Status_Unmount:
+                       injector.fireUnmountStatus(name);
+                       break;
+               case SDCardEventType.Status_Mount:
+                       injector.fireMountStatus(name);
+                       break;
+               case SDCardEventType.Fail_Unmount:
+                       injector.fireUnmountFailed(name);
+                       break;
+               case SDCardEventType.Fail_Mount:
+                       injector.fireMountFailed(name);
+                       break;
+               default:
+                       // TODO
+               }
+       }
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/events/SMSEvent.java b/ei-library/src/org/tizen/eilib/events/SMSEvent.java
new file mode 100644 (file)
index 0000000..2322c51
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events;
+
+import org.tizen.eilib.events.type.SMSEventType;
+
+public class SMSEvent {
+       private SMSEventType type;
+       private String number;
+       private String message;
+       public SMSEventType getType() {
+               return type;
+       }
+
+       void setType(SMSEventType type) {
+               this.type = type;
+       }
+
+       public String getNumber() {
+               return number;
+       }
+
+       void setNumber(String number) {
+               this.number = number;
+       }
+
+       public String getMessage() {
+               return message;
+       }
+
+       void setMessage(String message) {
+               this.message = message;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/SMSEventInjector.java b/ei-library/src/org/tizen/eilib/events/SMSEventInjector.java
new file mode 100644 (file)
index 0000000..946f8b8
--- /dev/null
@@ -0,0 +1,564 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.listener.EventListenerList;
+import org.tizen.eilib.events.listener.ISMSEventListener;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.sender.ModemEventSender;
+import org.tizen.eilib.events.type.MMSStatus;
+import org.tizen.eilib.events.type.SMSStatus;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.SMSEventException;
+import org.tizen.eilib.modem.encription.DecodeMsg;
+import org.tizen.eilib.modem.encription.EncodeMsg;
+import org.tizen.eilib.modem.encription.EnumConstants;
+import org.tizen.eilib.modem.encription.SMS_USERDATA;
+import org.tizen.eilib.modem.encription.SmsAddressInfo;
+import org.tizen.eilib.modem.encription.TPDU_SMS_DELIVER;
+import org.tizen.eilib.modem.encription.TPDU_SMS_SUBMIT;
+import org.tizen.eilib.modem.encription.TapiNetTextCodingScheme;
+import org.tizen.eilib.modem.encription.TmDateTime;
+import org.tizen.eilib.modem.protocol.AbstractGA;
+import org.tizen.eilib.modem.protocol.G04A01;
+import org.tizen.eilib.modem.protocol.G04A05;
+import org.tizen.eilib.modem.protocol.StructureGA;
+import org.tizen.eilib.tools.EILogger;
+
+/**
+ * Instances of this class send sms event to the emulator.
+ *
+ */
+public class SMSEventInjector extends AbstractEventInjector {
+       private SMSEventSender sender           = null;
+       private SMSEventReceiver receiver       = null;
+       private EventListenerList listeners = new EventListenerList();
+       private boolean isMsgReceived = false;
+
+       SMSEventInjector(ConnectionToEmulator connector) {
+               sender   = new SMSEventSender(connector);
+               receiver = new SMSEventReceiver(this);
+
+               connector.addEventReceiver(GroupID.SMS, receiver);
+       }
+
+       private RSSIEventInjector rssi;
+       void setRssiEventInjector(RSSIEventInjector rssi) {
+               this.rssi = rssi;
+       }
+
+       /**
+        * Set sms send status in the emulator.
+        * If status value is error, to transfer sms from emulator will be failed.
+        *
+        * @param status success or fail
+        * @return result
+        * @throws IOException
+        * @throws ConnectionException
+        */
+       public boolean sendStatus(SMSStatus status) throws IOException, ConnectionException {
+               G04A05 ga = new G04A05();
+               ga.intialize();
+
+               StructureGA sga = ga.getBody();
+               sga.setInt("DATA1", status.getValue() & 0x00ff);
+               sga.setInt("DATA2", (status.getValue() >> 8) & 0x00ff);
+
+               sender.send(ga);
+
+               return true;
+       }
+
+       /**
+        * Set mms send status in the emulator.
+        * If status value is error, to transfer mms from emulator will be failed.
+        *
+        * @param status success or fail
+        * @return result
+        * @throws IOException
+        * @throws ConnectionException
+        */
+       public boolean sendStatus(MMSStatus status) throws IOException, ConnectionException {
+               G04A05 ga = new G04A05();
+               ga.intialize();
+
+               StructureGA sga = ga.getBody();
+               sga.setInt("DATA1", status.getValue() & 0x00ff);
+               sga.setInt("DATA2", (status.getValue() >> 8) & 0x00ff);
+
+               sender.send(ga);
+
+               return true;
+       }
+
+
+       /**
+        * Send SMS to the emulator.
+        * This function return immediately after sends the message, does not check result of sending message.
+        * You can check the result to transfer message using 'isMsgReceived()' function.
+        * 
+        * @param number phone number (sender)
+        * @param message text message (limit of length is 80)
+        * @return
+        * @throws IOException 
+        * @throws SMSEventException 
+        * @throws ConnectionException 
+        */
+       public boolean sendMessage(String number, String message) throws IOException, SMSEventException, ConnectionException {
+               return sendMessage(number, message, false);
+       }
+
+       /**
+        * Send SMS to the emulator
+        * @param number phone number
+        * @param message text message
+        * @param isWait if this value is true, wait until arrive return message.
+        * 
+        * @return
+        * @throws IOException 
+        * @throws SMSEventException 
+        * @throws ConnectionException 
+        */
+       public boolean sendMessage(String number, String message, boolean isWait) throws IOException, SMSEventException, ConnectionException {
+               // TODO : check rssi Status ??
+               if (rssi.isLevelZero()) {
+                       throw new SMSEventException(EILibError.RSSIIsZero);
+               }
+
+               // throw SMSEventException();
+               if (!checkNumber(number)) {
+                       throw new SMSEventException(EILibError.NumberFormatError);
+               }
+
+               if (message.length() > 80) {
+                       throw new SMSEventException(EILibError.MessageIsTooLong);
+               }
+
+               char[] packet = new char[500];
+               int pid = 0;
+               int dcs = 0xF0;
+
+               EncodeMsg encode = new EncodeMsg();
+
+               TPDU_SMS_DELIVER tpdu_deliver = new TPDU_SMS_DELIVER();
+               tpdu_deliver.msgType = 0;
+               tpdu_deliver.mms         = false;
+               tpdu_deliver.rp          = false;
+               tpdu_deliver.udhi        = false;
+               tpdu_deliver.sri         = false;
+
+               SmsAddressInfo orgAddr  = new SmsAddressInfo();
+               orgAddr.diallingNum     = number.toCharArray();
+               orgAddr.dialnumlen              = orgAddr.diallingNum.length;
+
+               tpdu_deliver.orgAddr = orgAddr;
+               tpdu_deliver.pId         = 0;
+               tpdu_deliver.scts        = getDateTime();
+               tpdu_deliver.dcs         = getScheme();
+               tpdu_deliver.udl         = 0;
+
+               ArrayList<SMS_USERDATA> dataArray = getUserData(message);
+               if (dataArray.size() > 1) {
+                       tpdu_deliver.udhi = true;
+               }
+
+               for (SMS_USERDATA userData : dataArray) {
+                       tpdu_deliver.userData = userData;
+                       int packet_len = encode.EncodeSmsDeliverTpdu(getSCA(),
+                                       tpdu_deliver, packet, pid, dcs);
+                       final byte[] data = convertToByte(packet, packet_len);
+
+                       G04A01 ga = new G04A01() {
+                               protected void makeBody() {
+                                       StructureGA ga = getBody();
+                                       ga.addByteArrayItem("DATA", data.length);
+                               }
+                       };
+                       ga.intialize();
+
+                       StructureGA sga = ga.getBody();
+                       sga.setByteArray("DATA", data);
+
+                       // message 전송이 성공하기 전에 여러번 메시지를 보내면 어떻게 되는가???
+                       // 하나의 message가 전송 완료되기 전에 다음 메시지를 받으면 안될 것 같음...
+                       setMsgReceived(false);
+
+                       // SEND DATA                    
+                       sender.send(ga);
+               }
+
+               if (isWait) {
+                       synchronized(this) {
+                               try {
+                                       // wait 10 second
+                                       this.wait(10000);
+                               } catch (InterruptedException e) {
+                                       e.printStackTrace();
+                                       EILogger.getLogger().warning(e.getMessage());
+                               }
+                       }
+                       
+                       if (!isMsgReceived()) {
+                               throw new SMSEventException(EILibError.SendMessageFailed);
+                       }
+               }
+
+               return true;
+       }
+
+       /**
+        * Return sending message status
+        * 
+        * @return if this value is true, sending message success.
+        */
+       public boolean isMsgReceived() {
+               return isMsgReceived;
+       }
+
+       void setMsgReceived(boolean isMsgReceived) {
+               this.isMsgReceived = isMsgReceived;
+       }
+
+       /**
+        * Add sms event listener.
+        * TODO : You can receive SMS from emulator.
+        * 
+        * @param listener
+        */
+       public void addSMSEventListener(ISMSEventListener listener) {
+               listeners.add(listener);
+       }
+
+       /**
+        * Remove sms event listener.
+        * 
+        * @param listener
+        */
+       public void removeSMSEventListener(ISMSEventListener listener) {
+               listeners.remove(listener);
+       }
+
+       private SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
+       private SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
+       private SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
+       private SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
+       private SimpleDateFormat minuteFormat = new SimpleDateFormat("mm");
+       private SimpleDateFormat secondFormat = new SimpleDateFormat("ss");
+       private TmDateTime getDateTime() {
+               Date date = new Date();
+               TmDateTime tm = new TmDateTime();
+               tm.year         = Integer.parseInt(yearFormat.format(date).trim());
+               tm.month        = Integer.parseInt(monthFormat.format(date).trim());
+               tm.day          = Integer.parseInt(dayFormat.format(date).trim());
+               tm.hour         = Integer.parseInt(hourFormat.format(date).trim());
+               tm.minute       = Integer.parseInt(minuteFormat.format(date).trim());
+               tm.second       = Integer.parseInt(secondFormat.format(date).trim());
+               return tm;
+       }
+
+       private TapiNetTextCodingScheme getScheme() {
+               TapiNetTextCodingScheme scheme = new TapiNetTextCodingScheme();
+               scheme.bCompressed = false;
+               scheme.bMsgClassSet = false;
+               scheme.bMsgIndActive = false;
+               scheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS;
+               scheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_VOICE_MSG;
+               scheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2;
+//             scheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT;
+//             scheme.classType = cmbMobileTerminateClassType.getSelectionIndex();
+               scheme.classType = 0;
+               scheme.codingGroup = 0;
+               scheme.code = 0;
+               
+               return scheme;
+       }
+
+       private SmsAddressInfo SCA = null;
+       private final char[] SMSC_NUM = {+8, 2, 1, 0, 9, 1, 1, 1, 1};
+       private SmsAddressInfo getSCA() {
+               if (SCA == null) {
+                       SCA = new SmsAddressInfo();
+                       //SCA.diallingNum = String.format(cmbMobileTerminateUseSMSC.getText()).toCharArray();
+                       SCA.diallingNum = SMSC_NUM;
+                       SCA.dialnumlen  = SCA.diallingNum.length;
+               }
+               return SCA;
+       }
+
+       private void sendDeliveryReport() throws IOException, ConnectionException {
+               char[] packet = new char[500];
+               int pid = 0;
+               int dcs = 0xF0;
+
+               EncodeMsg encode = new EncodeMsg();
+               
+               TPDU_SMS_DELIVER tpdu_deliver = new TPDU_SMS_DELIVER();
+               tpdu_deliver.msgType = 0;
+               tpdu_deliver.mms         = false;
+               tpdu_deliver.rp          = false;
+               tpdu_deliver.udhi        = false;
+               tpdu_deliver.sri         = false;
+
+               SmsAddressInfo orgAddr  = new SmsAddressInfo();
+               String dstnum                   = DecodeMsg.deliveryReportNum_set.iterator().next();
+               DecodeMsg.deliveryReportNum_set.remove(dstnum);
+               orgAddr.diallingNum     = String.format(dstnum).toCharArray();
+//             orgAddr.diallingNum     = String.format(
+//             txtMobileTerminateReceivedNumber.getText()).toCharArray();
+               orgAddr.dialnumlen              = orgAddr.diallingNum.length;
+
+               tpdu_deliver.orgAddr = orgAddr;
+               tpdu_deliver.pId         = 0;
+               tpdu_deliver.scts        = getDateTime();
+               tpdu_deliver.dcs         = getScheme();
+               tpdu_deliver.udl         = 0;
+               String msg = "Message delivered.";
+               SMS_USERDATA userData1 = new SMS_USERDATA();
+               try {
+                       userData1.data   = msg.getBytes("ISO-10646-UCS-2");
+                       userData1.length = userData1.data.length;
+                       userData1.headerCnt = 0;
+                       userData1.setSMSUDH((char)0x00, (short)0x0000, (char)2, (char)1);
+                       tpdu_deliver.userData = userData1;
+               } catch (UnsupportedEncodingException e1) {
+                       // TODO Auto-generated catch block
+                       e1.printStackTrace();
+               }
+               int packet_len = encode.EncodeSmsDeliverTpdu(getSCA(),
+                               tpdu_deliver, packet, pid, dcs);
+               final byte[] data = convertToByte(packet, packet_len);
+
+               G04A01 ga = new G04A01() {
+                       protected void makeBody() {
+                               StructureGA ga = getBody();
+                               ga.addByteArrayItem("DATA", data.length); //$NON-NLS-1$
+                       }
+               };
+               ga.intialize();
+
+               StructureGA sga = ga.getBody();
+               sga.setByteArray("DATA", data); //$NON-NLS-1$
+
+               // SEND DATA
+               sender.send(ga);
+       }
+
+       private boolean checkNumber(String number) throws SMSEventException {
+               if (number == null || number.length() == 0) {
+                       throw new SMSEventException(EILibError.NumberIsEmpty);
+               }
+
+               if (number.length() > 15) {
+                       throw new SMSEventException(EILibError.NumberIsTooLong);
+               }
+
+               Pattern tellPattern = Pattern.compile( "[^0-9++]");
+               Matcher matcher = tellPattern.matcher(number);
+               return !matcher.find();
+       }
+
+       private ArrayList<SMS_USERDATA> getUserData(String message) {
+               ArrayList<SMS_USERDATA> list = new ArrayList<SMS_USERDATA>();
+               int length = 60; //temp length
+               int count = message.length() / length; 
+               count = count + 1;
+               int index = 0;
+               SMS_USERDATA userData;
+
+               for (int i = 0; i < count; i++) {
+                       userData = new SMS_USERDATA();
+                       try {
+                               int len = index+length > (message.length() - index) ? (message.length() - index)
+                                                 : index + length;
+                               userData.data = message.substring(index, index + len).getBytes("ISO-10646-UCS-2");
+                               userData.length = userData.data.length;
+                               userData.headerCnt = 1;
+                               userData.setSMSUDH((char)0x00, (short)0x0000, (char)count, (char)(i+1));
+                       } catch (UnsupportedEncodingException e) {
+                               e.printStackTrace();
+                               continue;
+                       }
+                       if (count == 1) {
+                               userData.headerCnt = 0;
+                       }
+                       list.add(userData);
+                       index = index + length;
+               }
+               return list;
+       }
+
+       private byte[] convertToByte(char[] buf, int length) {
+               byte[] result = new byte[length];
+               for (int i = 0; i < length; i++) {
+                       result[i] = (byte) buf[i];
+               }
+               return result;
+       }
+
+       private char[] convertToChar(byte[] buf, int start, int length) {
+               char[] result = new char[length];
+               int idx = 0;
+               for (int i = 0; i < buf.length; i++) {
+                       if (i >= start) {
+                               result[idx++] = (char) buf[i];
+                               if (idx >= length) {
+                                       break;
+                               }
+                       }
+               }
+               return result;
+       }
+
+       void fireSMSEvent(AbstractGA ga) throws IOException, ConnectionException {
+               StructureGA sga = ga.getBody();
+
+               TPDU_SMS_SUBMIT tpdu_submit = new TPDU_SMS_SUBMIT();
+               byte[] buf              = sga.getByteArray("DATA");
+               char[] rawdata  = convertToChar(buf, 3, buf.length - 3); // new
+                                                                                                                               // change
+                                                                                                                               // May 6
+
+               // System.out.println();
+               // for(int i = 0; i <rawdata.length; i++ ) {
+               // System.out.print("[0x" + Integer.toHexString(rawdata[i]) + "]");
+               // if(i%10 == 9)
+               // System.out.println();
+               // }
+               DecodeMsg decode = new DecodeMsg();
+               
+               decode.DecodeSmsSubmitTpdu(tpdu_submit, 500, rawdata);
+
+               // char[] data = tpdu_submit.userData;
+               // for(int i = 0; i <data.length; i++ ) {
+               // System.out.print("[0x" + Integer.toHexString(data[i]) + "]");
+               // if(i%10 == 9)
+               // System.out.println();
+               // }
+//             String str = Messages.SMS_21
+//                             + String.valueOf(tpdu_submit.destAddr.diallingNum).trim()
+//                             + Messages.SMS_14
+//                             + String.valueOf(tpdu_submit.userData).trim();
+
+//             lblMobileTerminateReceivedMessage.setText(str);
+               
+               SMSEvent event = new SMSEvent();
+               event.setNumber(String.valueOf(tpdu_submit.destAddr.diallingNum).trim());
+               if(DecodeMsg.relayedsms) {
+                       event.setMessage(String.valueOf(DecodeMsg.smsbuffer).trim());
+                       DecodeMsg.relay_cnt--;
+                       if(DecodeMsg.relay_cnt == 0) {
+                               for(int i = 0; i < DecodeMsg.smsbuffer_index; i++) {
+                                       DecodeMsg.smsbuffer[i] = '\0';
+                               }
+
+                               DecodeMsg.smsbuffer_index = 0;
+                               DecodeMsg.relayedsms      = false;
+                       }
+               } else {
+                       event.setMessage(String.valueOf(tpdu_submit.userData).trim());
+               }
+
+               if(DecodeMsg.deliveryReport) {
+                       if(DecodeMsg.relayedsms) {
+                               if(tpdu_submit.udl < 255) {
+                                       sendDeliveryReport();
+                               }
+                       } else {
+                               sendDeliveryReport();
+                       }
+               }
+       }
+
+       void fireMsgReceived(boolean b) {
+               setMsgReceived(b);
+               synchronized(this) {
+                       this.notifyAll();
+               }
+       }
+
+       @Override
+       public void initEventInjector() {
+               // TODO Auto-generated method stub
+               
+       }
+}
+
+class SMSEventSender extends ModemEventSender {
+       public SMSEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+}
+
+class SMSEventReceiver extends AbstractEventReceiver {
+       private SMSEventInjector injector;
+       public SMSEventReceiver(SMSEventInjector injector) {
+               super("SMS event");
+               this.injector = injector;
+       }
+
+       public void run(EventMessage msg) {
+               synchronized(this) {
+                       try {
+                               switch(msg.getEventHeader().getActionID()) {
+                               case 0x01 : // receive message
+                               {
+                                       G04A01 ga = new G04A01();
+                                       ga.intialize(msg.getDataBuffer());
+                                       injector.fireSMSEvent(ga);
+                               }
+                                       break;
+                               case 12: // GSM_SMS_RECEIVER_RES
+                                       injector.fireMsgReceived(true);
+                                       break;
+                               default:
+                                       break;
+                               }
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       } catch (ConnectionException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+
+       }
+
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/events/SensorEventInjector.java b/ei-library/src/org/tizen/eilib/events/SensorEventInjector.java
new file mode 100644 (file)
index 0000000..04fe92b
--- /dev/null
@@ -0,0 +1,500 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events;
+
+import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_OK;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.Emulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.receiver.EventReceiver;
+import org.tizen.eilib.events.receiver.StatusEventReceiver;
+import org.tizen.eilib.events.sender.SensorEventSender;
+import org.tizen.eilib.events.type.MotionEventType;
+import org.tizen.eilib.events.type.ProximityStatus;
+import org.tizen.eilib.events.type.SensorEventType;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.eilib.exception.SensorEventException;
+import org.tizen.eilib.tools.EILogger;
+import org.tizen.sdblib.service.SyncResult;
+import org.tizen.sdblib.service.SyncService;
+
+/**
+ * Manual sensor event
+ *
+ */
+public class SensorEventInjector extends AbstractEventInjector {
+       private SensorEventSender sender = null;
+       private ConnectionToEmulator connector;
+       private ArrayList<String> logFiles;
+
+       SensorEventInjector(ConnectionToEmulator connector) {
+               sender = new SensorEventSender(connector);
+
+               EventReceiver receiver = new EventReceiver("SensorReceiver", sender);
+
+               AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS);
+               if (abReceiver != null && abReceiver instanceof StatusEventReceiver) {
+                       StatusEventReceiver re = (StatusEventReceiver)abReceiver;
+                       re.addStatusEventReceiver(ActionID.ACCEL_VALUE, receiver);
+                       re.addStatusEventReceiver(ActionID.GYRO_VALUE, receiver);
+                       re.addStatusEventReceiver(ActionID.MAG_VALUE, receiver);
+                       re.addStatusEventReceiver(ActionID.LIGHT_VALUE, receiver);
+                       re.addStatusEventReceiver(ActionID.PROXI_VALUE, receiver);
+                       re.addStatusEventReceiver(ActionID.MOTION_VALUE, receiver);
+               }
+
+               this.connector = connector;
+               logFiles = new ArrayList<String>();
+       }
+
+       private double G = 9.80665;
+       private double MAX_ACCEL = 2.00;
+       private double MIN_ACCEL = -2.00;
+
+       /**
+        * Return minimum acceleration value.
+        * @return
+        */
+       public double getMinAccelValue() {
+               return MIN_ACCEL;
+       }
+
+       /**
+        * Return maximum acceleration value.
+        * @return
+        */
+       public double getMaxAccelValue() {
+               return MAX_ACCEL;
+       }
+
+       /**
+        * Send acceleration event to emulator.
+        * Min value : -2.00
+        * Max value : 2.00
+        * @param x
+        * @param y
+        * @param z
+        * @return
+        * @throws IOException 
+        * @throws SensorEventException 
+        * @throws ConnectionException 
+        * @throws InjectorLibraryException 
+        */
+       public boolean accelEvent(double x, double y, double z) throws IOException, SensorEventException, ConnectionException {
+               if (x > MAX_ACCEL || x < MIN_ACCEL) {
+                       throw new SensorEventException(EILibError.InvalidSensorValue);
+               }
+               if (y > MAX_ACCEL || y < MIN_ACCEL) {
+                       throw new SensorEventException(EILibError.InvalidSensorValue);
+               }
+               if (z > MAX_ACCEL || z < MIN_ACCEL) {
+                       throw new SensorEventException(EILibError.InvalidSensorValue);
+               }
+
+               return sender.sendManualEvent(SensorEventType.ACCEL, x * G, y * G, z * G);
+       }
+
+       public double[] getAccelValue() throws IOException, ConnectionException, SensorEventException {
+               String value = sender.getSensorValue(SensorEventType.ACCEL);
+               double[] values  = null;
+               if (value != null) {
+                       String[] str = value.split(",");
+                       values = new double[3];
+                       int i = 0;
+                       try {
+                       for (String v : str) {
+                               double t = Double.valueOf(v);
+                               values[i++] = t / G / 100000;
+                       }
+                       } catch(NumberFormatException t) {
+                               throw new SensorEventException(EILibError.FailedGetValue);
+                       }
+               } else {
+                       throw new SensorEventException(EILibError.FailedGetValue);
+               }
+
+               return values;
+       }
+
+       private double MAX_GYRO = 10.00;
+       private double MIN_GYRO = -10.00;
+       private int GYRO_VALUE = 1000;
+
+       /**
+        * Return minimum gyroscope value
+        * @return
+        */
+       public double getMinGyroValue() {
+               return MIN_GYRO;
+       }
+
+       /**
+        * Return maximum gyroscope value
+        * @return
+        */
+       public double getMaxGyroValue() {
+               return MAX_GYRO;
+       }
+
+       /**
+        * Send gyroscope sensor event to emulator
+        * Min value : -10.00
+        * Max value : 10.00 
+        * @param x
+        * @param y
+        * @param z
+        * @return
+        * @throws IOException 
+        * @throws ConnectionException 
+        * @throws SensorEventException 
+        */
+       public boolean gyroEvent(double x, double y, double z) throws IOException, ConnectionException, SensorEventException {
+               if (x > MAX_GYRO || x < MIN_GYRO) {
+                       throw new SensorEventException(EILibError.InvalidSensorValue);
+               }
+               if (y > MAX_GYRO || y < MIN_GYRO) {
+                       throw new SensorEventException(EILibError.InvalidSensorValue);
+               }
+               if (z > MAX_GYRO || z < MIN_GYRO) {
+                       throw new SensorEventException(EILibError.InvalidSensorValue);
+               }
+
+               return sender.sendManualEvent(SensorEventType.GYRO, x * GYRO_VALUE, y * GYRO_VALUE, z * GYRO_VALUE);
+       }
+
+
+       public double[] getGyroValue() throws IOException, ConnectionException, SensorEventException {
+               String value = sender.getSensorValue(SensorEventType.GYRO);
+               double[] values  = null;
+               if (value != null) {
+                       String[] str = value.split(",");
+                       values = new double[3];
+                       int i = 0;
+                       try {
+                       for (String v : str) {
+                               double t = Double.valueOf(v);
+                               values[i++] = (t * 17.50) / GYRO_VALUE;
+                       }
+                       } catch(NumberFormatException t) {
+                               throw new SensorEventException(EILibError.FailedGetValue);
+                       }
+               } else {
+                       throw new SensorEventException(EILibError.FailedGetValue);
+               }
+
+               return values;
+       }
+
+       private int MAX_MAGNETIC = 2000;
+       private int MIN_MAGNETIC = -2000;
+
+       /**
+        * Return minimum magnetic value
+        * @return
+        */
+       public int getMinMagneticValue() {
+               return MIN_MAGNETIC;
+       }
+
+       /**
+        * Return maximum magnetic value
+        * @return
+        */
+       public int getMaxMagneticValue() {
+               return MAX_MAGNETIC;
+       }
+
+       /**
+        * Send magnetic sensor event to emulator
+        * @param x
+        * @param y
+        * @param z
+        * @return
+        * @throws IOException 
+        * @throws ConnectionException 
+        * @throws SensorEventException 
+        */
+       public boolean magneticEvent(int x, int y, int z) throws IOException, ConnectionException, SensorEventException {
+               if (x > MAX_MAGNETIC || x < MIN_MAGNETIC) {
+                       throw new SensorEventException(EILibError.InvalidSensorValue);
+               }
+               if (y > MAX_MAGNETIC || y < MIN_MAGNETIC) {
+                       throw new SensorEventException(EILibError.InvalidSensorValue);
+               }
+               if (z > MAX_MAGNETIC || z < MIN_MAGNETIC) {
+                       throw new SensorEventException(EILibError.InvalidSensorValue);
+               }
+
+               return sender.sendManualEvent(SensorEventType.MAGNETIC, x, y, z);
+       }
+
+       public int[] getMagneticValue() throws IOException, ConnectionException, SensorEventException{
+               String value = sender.getSensorValue(SensorEventType.MAGNETIC);
+               int[] values  = null;
+               if (value != null) {
+                       String[] str = value.split(" ");
+                       values = new int[3];
+                       int i = 0;
+                       try {
+                       for (String v : str) {
+                               if (v.endsWith("\n")) {
+                                       v = v.substring(0, v.length() - 1);
+                               }
+                               int t = Integer.valueOf(v);
+                               values[i++] = t;
+                       }
+                       } catch(NumberFormatException t) {
+                               throw new SensorEventException(EILibError.FailedGetValue);
+                       }
+               } else {
+                       throw new SensorEventException(EILibError.FailedGetValue);
+               }
+
+               return values;
+       }
+
+       /**
+        * Send sensor event to emulator using log file.
+        * @param type
+        * @param filePath
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        * @throws InjectorLibraryException
+        */
+       public boolean sendLogFileEvent(SensorEventType type, String filePath) throws IOException, ConnectionException {
+               return sendLogFileEvent(type, filePath, 1);
+       }
+
+       /**
+        * Send sensor event to emulator using log file.
+        * @param type
+        * @param filePath
+        * @param repeatCount
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        * @throws InjectorLibraryException
+        */
+       public boolean sendLogFileEvent(SensorEventType type, String filePath, int repeatCount) throws IOException, ConnectionException {
+               List<String> files = new ArrayList<String>();
+               files.add(filePath);
+               return logFileEvent(type, files, repeatCount);
+       }
+
+       /**
+        * Send sensor event to emulator using log file.
+        * @param type
+        * @param files
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        * @throws InjectorLibraryException
+        */
+       public boolean sendLogFileEvent(SensorEventType type, List<String> files) throws IOException, ConnectionException {
+               return sendLogFileEvent(type, files, 1);
+       }
+
+       /**
+        * Send sensor event to emulator using log file.
+        * @param type
+        * @param files
+        * @param repeatCount
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        */
+       public boolean sendLogFileEvent(SensorEventType type, List<String> files, int repeatCount) throws IOException, ConnectionException {
+               return logFileEvent(type, files, repeatCount);
+       }
+
+       private String remoteAccelFilePath              = "/opt/sensor/accel/InputFiles/";
+       private String remoteGyroFilePath               = "/opt/sensor/gyro/InputFiles/";
+       private String remoteMagneticFilePath   = "/opt/sensor/geo/InputFiles/";
+       private boolean logFileEvent(SensorEventType type, List<String> files, int repeatCount) throws IOException, ConnectionException {
+               logFiles.clear();
+               String remoteFilePath = "";
+               switch(type) {
+               case FILE_ACCEL:
+                       remoteFilePath = remoteAccelFilePath;
+                       break;
+               case FILE_GYRO:
+                       remoteFilePath = remoteGyroFilePath;
+                       break;
+               case FILE_MAGNETIC:
+                       remoteFilePath = remoteMagneticFilePath;
+                       break;
+               default:
+                       // TODO : error
+                       return false;
+               }
+
+               File file = null;
+               Emulator emulator = connector.getCurrentEmulator();
+               if (emulator == null) {
+                       // TODO :exception
+                       return false;
+               }
+
+               for(String f : files) {
+                       file = new File(f);
+                       if(!file.exists()) {
+                               EILogger.getLogger().warning("File Not Found : " + file.getAbsolutePath());
+                               continue;
+                       }
+
+                       SyncService sync = emulator.getSyncService();
+                       if (sync != null) {
+                               SyncResult result = sync.push(file.getPath(), emulator.getDevice().getFileEntry( remoteFilePath + file.getName() ) );
+                               if (result.getCode() != RESULT_OK) {
+                                       // TODO
+                                       continue;
+                               }
+                       }
+                       logFiles.add(file.getName());
+               }
+
+               if (logFiles.isEmpty()) {
+                       // TODO : exception
+                       return false;
+               }
+
+               return sender.sendLogEvent(type, repeatCount, logFiles);
+       }
+
+       private int MIN_LUX_DATA = 1;
+       private int MAX_LUX_DATA = 65535;
+       private int level        = 10;
+
+       /**
+        * 
+        * @param luxData
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        * @throws InjectorLibraryException 
+        */
+       public boolean ligthEvent(int luxData) throws IOException, ConnectionException, InjectorLibraryException {
+               if (luxData < MIN_LUX_DATA || luxData > MAX_LUX_DATA) {
+                       throw new InjectorLibraryException(EILibError.InvalidSensorValue);
+               }
+
+               return sender.sendLightEvent(luxData, getLevelData(luxData));
+       }
+
+       /**
+        * 
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        * @throws SensorEventException 
+        */
+       public int getLightValue() throws IOException, ConnectionException, SensorEventException {
+               int level = sender.getLightValue();
+
+               if (level < MIN_LUX_DATA || level > MAX_LUX_DATA) {
+                       throw new SensorEventException(EILibError.FailedGetValue);
+               }
+
+               return level;
+       }
+
+       /**
+        * Return minimum light value
+        * @return
+        */
+       public int getMinLightValue() {
+               return MIN_LUX_DATA;
+       }
+
+       /**
+        * Return maximum light value
+        * @return
+        */
+       public int getMaxLightValue() {
+               return MAX_LUX_DATA;
+       }
+
+       private int getLevelData(int luxData) {
+               return (luxData / 6554) % level + 1; // TODO
+       }
+
+       /**
+        * 
+        * @param event
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        */
+       public boolean motionEvent(MotionEventType event) throws IOException, ConnectionException {
+               return sender.sendMotionEvent(event);
+       }
+
+       /**
+        * 
+        * @param status
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        * @throws InjectorLibraryException
+        */
+       public boolean proximityEvent(ProximityStatus status) throws IOException, ConnectionException {
+               return sender.sendProximityEvent(status);
+       }
+
+       /**
+        * 
+        * @return
+        * @throws IOException
+        * @throws ConnectionException 
+        * @throws SensorEventException 
+        */
+       public ProximityStatus getProximityStatus() throws IOException, ConnectionException, SensorEventException {
+               ProximityStatus status = sender.getProxiStatus();
+
+               if (status == null) {
+                       throw new SensorEventException(EILibError.FailedGetValue);
+               }
+
+               return status;
+       }
+
+       @Override
+       public void initEventInjector() {
+       }       
+}
diff --git a/ei-library/src/org/tizen/eilib/events/USBEventInjector.java b/ei-library/src/org/tizen/eilib/events/USBEventInjector.java
new file mode 100644 (file)
index 0000000..c17f125
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events;
+
+import java.io.IOException;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.receiver.EventReceiver;
+import org.tizen.eilib.events.receiver.StatusEventReceiver;
+import org.tizen.eilib.events.sender.DeviceEventSender;
+import org.tizen.eilib.events.type.USBStatus;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.modem.protocol.ByteUtil;
+import org.tizen.eilib.tools.EILogger;
+
+/**
+ * Instances of this class send status of usb event to the emulator.
+ * <dl>
+ * <dt><b>Send Events : </b></dt>
+ * <dd>USB's status</dd>
+ * </dl>
+ * <p>
+ */
+public class USBEventInjector extends AbstractEventInjector {
+       private USBEventSender sender = null;
+
+       USBEventInjector(ConnectionToEmulator connector) {
+               sender = new USBEventSender(connector);
+               EventReceiver receiver = new EventReceiver("USBReceiver", sender);
+
+               AbstractEventReceiver abReceiver = connector.findEventReceiver(GroupID.STATUS);
+               if (abReceiver != null && abReceiver instanceof StatusEventReceiver) {
+                       StatusEventReceiver re = (StatusEventReceiver)abReceiver;
+                       re.addStatusEventReceiver(ActionID.USB_STATUS, receiver);
+               }
+       }
+
+       /**
+        * Change usb status of emulator.
+        *
+        * @param status USBStatus.DISCONNECT,
+        *                               USBStatus.CONNECT
+        * @throws IOException 
+        * @throws ConnectionException 
+        * 
+        */
+       public boolean setStatus(USBStatus status) throws IOException, ConnectionException {
+               return sender.setStatus(status);
+       }
+
+       /**
+        * Get usb status of emulator.
+        *
+        * @return status of USB connection
+        *                               USBStatus.DISCONNECT,
+        *                               USBStatus.CONNECT
+        * @throws DeviceEventException 
+        * @throws IOException 
+        * @throws ConnectionException 
+        * 
+        */
+       public USBStatus getStatus() throws IOException, DeviceEventException, ConnectionException {
+               USBStatus status = sender.getStatus();
+               if (status == null) {
+                       throw new DeviceEventException(EILibError.FailedGetValue);
+               }
+               return status;
+       }
+
+       @Override
+       public void initEventInjector() {
+               // TODO Auto-generated method stub
+               
+       }
+}
+
+class USBEventSender extends DeviceEventSender {
+       USBEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+
+       private static String USBID             = "10\n";
+       private EventMessage returnMsg = null;
+
+       public synchronized USBStatus getStatus() throws IOException, ConnectionException {
+               // empty message
+               makeMessage(USBID, null);
+               sendMessage(ActionID.USB_STATUS);
+
+               synchronized(this) {
+                       // wait 5 second
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+
+               USBStatus status = null;
+               if (returnMsg != null) {
+                       if (returnMsg.getEventHeader().getActionID()
+                                       != ActionID.USB_STATUS.getId()) {
+                               // TODO : error
+                               EILogger.getLogger().warning("An unexpected event occurs.");
+                       } else {
+                               int state = ByteUtil.byte2int
+                                               (returnMsg.getDataBuffer().array(), 14);
+                               for (USBStatus s : USBStatus.values()) {
+                                       if (s.getValue() == state) {
+                                               status = s;
+                                               break;
+                                       }
+                               }
+                       }
+                       returnMsg = null;
+               }
+
+               return status;
+       }
+
+       public synchronized boolean setStatus(USBStatus status) throws IOException, ConnectionException {
+               double params[] = new double[1];
+               params[0] = status.getValue();
+
+               makeMessage(USBID, params);
+               return sendMessage(null);
+       }
+
+       @Override
+       public void fireEvent(EventMessage message) {
+               synchronized(this) {
+                       this.returnMsg = message;
+                       this.notifyAll();
+               }
+       }
+
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/events/listener/EventListenerList.java b/ei-library/src/org/tizen/eilib/events/listener/EventListenerList.java
new file mode 100644 (file)
index 0000000..b4a45c9
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.listener;
+
+import java.util.ArrayList;
+
+public class EventListenerList {
+       /**
+        * The list of listeners. 
+        */
+       private volatile ArrayList<IEventListener> listeners = new ArrayList<IEventListener>();
+
+       /**
+        * Adds a listener to this list. This method has no effect if the same listener is already registered.
+        * 
+        * @param listener the non-<code>null</code> listener to add
+        */
+       public synchronized void add(IEventListener listener) {
+               // This method is synchronized to protect against multiple threads adding 
+               // or removing listeners concurrently. This does not block concurrent readers.
+               if (listener == null) {
+                       throw new IllegalArgumentException();
+               }
+               // check for duplicates
+               if (listeners.contains(listener)) {
+                       return;
+               }
+               listeners.add(listener);
+       }
+
+       /**
+        * Returns an array containing all the registered listeners.
+        * <p>
+        * Note: Callers of this method <b>must not</b> modify the returned array. 
+        *
+        * @return the list of registered listeners
+        */
+       public ArrayList<IEventListener> getListeners() {
+               return listeners;
+       }
+
+       /**
+        * Returns whether this listener list is empty.
+        *
+        * @return <code>true</code> if there are no registered listeners, and
+        *   <code>false</code> otherwise
+        */
+       public boolean isEmpty() {
+               return listeners.isEmpty();
+       }
+
+       /**
+        * Removes a listener from this list. Has no effect if the same listener was not already registered.
+        *
+        * @param listener the non-<code>null</code> listener to remove
+        */
+       public synchronized void remove(Object listener) {
+               // This method is synchronized to protect against multiple threads adding 
+               // or removing listeners concurrently. This does not block concurrent readers.
+               if (listener == null) {
+                       throw new IllegalArgumentException();
+               }
+
+               listeners.remove(listener);
+       }
+
+       /**
+        * Returns the number of registered listeners.
+        *
+        * @return the number of registered listeners
+        */
+       public int size() {
+               return listeners.size();
+       }
+
+       /**
+        * Removes all listeners from this list.
+        */
+       public synchronized void clear() {
+               listeners.clear();
+       }
+}
+
diff --git a/ei-library/src/org/tizen/eilib/events/listener/ICallEventListener.java b/ei-library/src/org/tizen/eilib/events/listener/ICallEventListener.java
new file mode 100644 (file)
index 0000000..8340af7
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events.listener;
+
+import org.tizen.eilib.events.CallEvent;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the events that are generated
+ * when call event occurs from emulator.
+ *
+ */
+public interface ICallEventListener extends IEventListener {
+       /**
+        * Sent when arrived call from emulator.
+        * @param event an event containing information about call.
+        * 
+        * @see CallEvent
+        */
+       public void incomingCall(CallEvent event);
+       
+       /**
+        * Sent when arrived call list from emulator.
+        * @param event an event containing information about call list.
+        * 
+        * @see CallEvent
+        */
+       public void receivingCallList(CallEvent event);
+}
diff --git a/ei-library/src/org/tizen/eilib/events/listener/IEventListener.java b/ei-library/src/org/tizen/eilib/events/listener/IEventListener.java
new file mode 100644 (file)
index 0000000..2fc6693
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events.listener;
+
+public interface IEventListener {
+
+}
diff --git a/ei-library/src/org/tizen/eilib/events/listener/ISDcardEventListener.java b/ei-library/src/org/tizen/eilib/events/listener/ISDcardEventListener.java
new file mode 100644 (file)
index 0000000..38dfc52
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events.listener;
+
+import org.tizen.eilib.events.SDCardEvent;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the events that are generated
+ * when sdcard event occurs from emulator
+ */
+public interface ISDcardEventListener extends IEventListener {
+
+       /**
+        * Sent when complete mount sd card
+        * @param event
+        */
+       public void completeMount(SDCardEvent event);
+
+       /**
+        * Sent when complete unmount sd card.
+        * @param event
+        */
+       public void completeUnmount(SDCardEvent event);
+
+       /** Send when complete qeuery sd card status.
+        * 
+        * @param event
+        */
+       public void completeQeueryStatus(SDCardEvent event);
+}
diff --git a/ei-library/src/org/tizen/eilib/events/listener/ISMSEventListener.java b/ei-library/src/org/tizen/eilib/events/listener/ISMSEventListener.java
new file mode 100644 (file)
index 0000000..df66ea3
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events.listener;
+
+import org.tizen.eilib.events.SMSEvent;
+
+/**
+ * Classes which implement this interface provide methods
+ * that deal with the events that are generated
+ * when SMS event occurs from emulator.
+ *
+ */
+public interface ISMSEventListener extends IEventListener {
+       /**
+        * Sent when arrived SMS from emulator.
+        * @param event an event containing information about sms.
+        * 
+        * @see SMSEvent
+        */
+       public void incomingSMS(SMSEvent event);
+}
diff --git a/ei-library/src/org/tizen/eilib/events/receiver/AbstractEventReceiver.java b/ei-library/src/org/tizen/eilib/events/receiver/AbstractEventReceiver.java
new file mode 100644 (file)
index 0000000..f6a2047
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events.receiver;
+
+import org.tizen.eilib.connection.message.EventMessage;
+
+public abstract class AbstractEventReceiver{
+       private String name;
+
+       public AbstractEventReceiver(String name) {
+               this.name = name;
+       }
+
+       public abstract void run(final EventMessage message);
+
+       public String getName() {
+               return name;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/receiver/EventReceiver.java b/ei-library/src/org/tizen/eilib/events/receiver/EventReceiver.java
new file mode 100644 (file)
index 0000000..dce30cd
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.receiver;
+
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.events.sender.AbstractEventSender;
+
+public class EventReceiver extends AbstractEventReceiver {
+       private AbstractEventSender sender;
+
+       public EventReceiver(String name, AbstractEventSender sender) {
+               super(name);
+               this.sender = sender;
+       }
+
+       @Override
+       public void run(EventMessage message) {
+               sender.fireEvent(message);
+       }
+
+}
diff --git a/ei-library/src/org/tizen/eilib/events/receiver/StatusEventReceiver.java b/ei-library/src/org/tizen/eilib/events/receiver/StatusEventReceiver.java
new file mode 100644 (file)
index 0000000..972a8f2
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.receiver;
+
+import java.util.HashMap;
+
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.EventMessage;
+
+public class StatusEventReceiver extends AbstractEventReceiver {
+       public StatusEventReceiver() {
+               super("Status event");
+       }
+
+       private HashMap<Integer, AbstractEventReceiver> receiverMap = new HashMap<Integer, AbstractEventReceiver>();;
+
+       public void addStatusEventReceiver(ActionID id, AbstractEventReceiver receiver) {
+               receiverMap.put((Integer)id.getId(), receiver);
+       }
+
+       public void run(EventMessage message) {
+               AbstractEventReceiver receiver = null;
+               int actionID = message.getEventHeader().getActionID();
+               for (ActionID id : ActionID.values()) {
+                       if (id.getId() == actionID) {
+                               receiver = receiverMap.get(actionID);
+                               break;
+                       }
+               }
+
+               if (receiver != null) {
+                       synchronized(receiver) {
+                               receiver.run(message);
+                       }
+               }
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/sender/AbstractEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/AbstractEventSender.java
new file mode 100644 (file)
index 0000000..187aab5
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events.sender;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.EventMessage;
+
+public abstract class AbstractEventSender {
+       private ConnectionToEmulator connector = null;
+       protected EventMessage message = null;
+
+       public AbstractEventSender(ConnectionToEmulator connector) {
+               this.connector = connector;
+               initializeEventMessage();
+       }
+
+       abstract void initializeEventMessage();
+
+       public ConnectionToEmulator getConnector() {
+               return connector;
+       }
+
+       public void setConnector(ConnectionToEmulator connector) {
+               this.connector = connector;
+       }
+
+       public abstract void fireEvent(EventMessage messate);
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/events/sender/DeviceEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/DeviceEventSender.java
new file mode 100644 (file)
index 0000000..1f85ebd
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.sender;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.EventType;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.exception.ConnectionException;
+
+public abstract class DeviceEventSender extends AbstractEventSender {
+       public DeviceEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+
+       private String msg = "";
+       private Integer msgLength = new Integer(0);
+
+       protected void makeMessage(String id, double params[]) {
+               message.clear();
+               
+               if(params == null) {
+                       msgLength = 0;
+                       return;
+               }
+
+               msg = id + params.length + "\n";
+               for( int i = 0 ; i < params.length ; i++) {
+                       msg += (Double.toString(params[i]) + "\n");
+               }
+               
+               byte[] tmp = msg.getBytes();
+               msgLength = tmp.length;
+               ((ByteBuffer) message.getDataBuffer().clear()).put(tmp);
+       }
+
+       protected boolean sendMessage(ActionID id)
+                               throws IOException, ConnectionException {
+               // make header
+               ByteBuffer header = message.getHeaderBuffer();
+               header.clear();
+
+               if (id != null) {
+                       header.put(msgLength.byteValue());
+                       header.put((byte)0x00);
+                       header.put(((Integer)GroupID.STATUS).byteValue());
+                       header.put(((Integer)id.getId()).byteValue());
+               } else {
+                       header.put(msgLength.byteValue());
+                       header.put((byte)0x00);
+                       header.put((byte)0x00);
+                       header.put((byte)0x00);
+               }
+
+               getConnector().sendMessage(message);
+
+               return true;
+       }
+
+       @Override
+       void initializeEventMessage() {
+               message = new EventMessage(1024);
+               message.setEventTypeBuffer(EventType.SENSOR);
+       }
+
+       public abstract void fireEvent(EventMessage message);
+}
diff --git a/ei-library/src/org/tizen/eilib/events/sender/LocationEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/LocationEventSender.java
new file mode 100644 (file)
index 0000000..4b77679
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.sender;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.EventType;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.tools.EILogger;
+
+public class LocationEventSender extends AbstractEventSender {
+       private EventMessage returnMsg = null;
+
+       public LocationEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+
+       public boolean sendMessage(String msg) throws IOException, ConnectionException {
+               message.clear();
+
+               ByteBuffer data = message.getDataBuffer();
+               data.put(msg.getBytes());
+
+               ByteBuffer header = message.getHeaderBuffer();
+               header.put(((Integer)data.position()).byteValue());
+               header.put((byte)0x00);
+               header.put((byte)0x00);
+               header.put((byte)0x00);
+
+               return getConnector().sendMessage(message);
+       }
+
+       public String getLocationStatus() throws IOException, ConnectionException {
+               message.clear();
+               ByteBuffer header = message.getHeaderBuffer();
+               header.put((byte)0x00);
+               header.put((byte)0x00);
+               header.put(((Integer)GroupID.STATUS).byteValue());
+               header.put(((Integer)ActionID.LOCATION_STATUS.getId()).byteValue());
+
+               getConnector().sendMessage(message);
+
+               synchronized(this) {
+                       // wait 5 second
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+
+               String event = null;
+               if (returnMsg != null) {
+                       if (returnMsg.getDataBuffer().position() != 0) {
+                               event = new String(returnMsg.getDataBuffer().array(),
+                                               14, returnMsg.getDataBuffer().limit());
+                       }
+                       returnMsg = null;
+               }
+
+               return event;
+       }
+
+       public void fireEvent(EventMessage message) {
+               synchronized(this) {
+                       this.returnMsg = message;
+                       this.notifyAll();
+               }
+       }
+
+       @Override
+       void initializeEventMessage() {
+               message = new EventMessage(1024);
+               message.setEventTypeBuffer(EventType.LOCATION);
+       }
+
+}
diff --git a/ei-library/src/org/tizen/eilib/events/sender/ModemEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/ModemEventSender.java
new file mode 100644 (file)
index 0000000..ff58f6b
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.sender;
+
+import java.io.IOException;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.EventType;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.modem.protocol.AbstractGA;
+
+public class ModemEventSender extends AbstractEventSender {
+       public ModemEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+
+       protected void makeMessage(AbstractGA sendObj) {
+               message.clear();
+               sendObj.makeStarterPacket(message);
+               sendObj.makePacket(message);
+       }
+
+
+       public boolean send(AbstractGA ga) throws IOException, ConnectionException {
+               makeMessage(ga);
+               return sendMessage();
+       }
+
+       protected boolean sendMessage() throws IOException, ConnectionException {
+               getConnector().sendMessage(message);
+
+               return true;
+       }
+
+       @Override
+       void initializeEventMessage() {
+               message = new EventMessage();
+               message.setEventTypeBuffer(EventType.TELEPHONY);
+       }
+
+       @Override
+       public void fireEvent(EventMessage messate) {
+               // TODO Auto-generated method stub
+               
+       }
+
+}
diff --git a/ei-library/src/org/tizen/eilib/events/sender/NfcEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/NfcEventSender.java
new file mode 100644 (file)
index 0000000..d6346c7
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.sender;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.EventType;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.tools.EILogger;
+public class NfcEventSender extends AbstractEventSender {
+       private EventMessage returnMsg = null;
+
+       public NfcEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+
+       public boolean sendMessage(String msg) throws IOException, ConnectionException {
+               message.clear();
+
+               byte[] buf = msg.getBytes();
+
+               message.getDataBuffer().put(buf);
+
+               ByteBuffer header = message.getHeaderBuffer();
+               header.putShort((short)buf.length);
+               header.put((byte)0x00);
+               header.put((byte)0x00);
+
+               return getConnector().sendMessage(message);
+       }
+
+       public String getNfcStatus() throws IOException, ConnectionException {
+               message.clear();
+
+               ByteBuffer header = message.getHeaderBuffer();
+               header.put((byte)0x00);
+               header.put((byte)0x00);
+               header.put(((Integer)GroupID.STATUS).byteValue());
+               header.put(((Integer)ActionID.NFC_STATUS.getId()).byteValue());
+
+               getConnector().sendMessage(message);
+
+               synchronized(this) {
+                       // wait 5 second
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+
+               String event = null;
+               if (returnMsg != null) {
+                       if (returnMsg.getDataBuffer().position() != 0) {
+                               event = new String(returnMsg.getDataBuffer().array(),
+                                               14, returnMsg.getDataBuffer().limit());
+                       }
+                       returnMsg = null;
+               }
+
+               return event;
+       }
+
+       @Override
+       void initializeEventMessage() {
+               message = new EventMessage();
+               message.setEventTypeBuffer(EventType.NFC);
+       }
+
+       public void fireEvent(EventMessage message) {
+               synchronized(this) {
+                       this.returnMsg = message;
+                       this.notifyAll();
+               }
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/sender/SDCardEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/SDCardEventSender.java
new file mode 100644 (file)
index 0000000..e9fae3a
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.sender;
+
+import java.io.IOException;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.EventType;
+import org.tizen.eilib.events.type.SDCardEventType;
+import org.tizen.eilib.exception.ConnectionException;
+
+public class SDCardEventSender extends AbstractEventSender {
+
+       public SDCardEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+
+       public boolean getMountStatus() throws IOException, ConnectionException {
+               message.clear();
+               String msg = SDCardEventType.Status_Unmount + "\n";
+               byte[] buf = msg.getBytes();
+               message.getDataBuffer().put(buf);
+               message.getHeaderBuffer().put((byte)buf.length);
+
+               return getConnector().sendMessage(message);
+       }
+
+       public boolean sendMount(String path) throws IOException, ConnectionException {
+               message.clear();
+               String msg = SDCardEventType.Action_Mount + "\n" + path + "\n";
+               byte[] buf = msg.getBytes();
+               message.getDataBuffer().put(buf);
+               message.getHeaderBuffer().put((byte)buf.length);
+
+               return getConnector().sendMessage(message);
+       }
+
+       public boolean sendUnmount() throws IOException, ConnectionException {
+               message.clear();
+               String msg = SDCardEventType.Action_Unmount + "\n";
+               byte[] buf = msg.getBytes();
+               message.getDataBuffer().put(buf);
+               message.getHeaderBuffer().put((byte)buf.length);
+
+               return getConnector().sendMessage(message);
+       }
+
+       @Override
+       void initializeEventMessage() {
+               message = new EventMessage(1024);
+               message.setEventTypeBuffer(EventType.SDCARD);
+       }
+
+       @Override
+       public void fireEvent(EventMessage messate) {
+               // TODO Auto-generated method stub
+               
+       }
+
+}
diff --git a/ei-library/src/org/tizen/eilib/events/sender/SDCardStatusCheckSender.java b/ei-library/src/org/tizen/eilib/events/sender/SDCardStatusCheckSender.java
new file mode 100644 (file)
index 0000000..8d54ab9
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.sender;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.Emulator;
+import org.tizen.eilib.connection.EventSocket;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.EventType;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.receiver.AbstractEventReceiver;
+import org.tizen.eilib.events.type.SDCardEventType;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.eilib.exception.EILibError;
+
+public class SDCardStatusCheckSender extends AbstractEventSender {
+
+       private HashMap<Integer, AbstractEventReceiver> receiverMap = new HashMap<Integer, AbstractEventReceiver>();
+       private SDCardStatusCheckReceiver receiver;
+       private EventSocket socket;
+
+       public SDCardStatusCheckSender(ConnectionToEmulator connector) {
+               super(connector);
+               receiver = new SDCardStatusCheckReceiver(this);
+               receiverMap.put(GroupID.SDCARD, receiver);
+               socket = new EventSocket(receiverMap);
+       }
+       
+       public void sendMountCheck(Emulator emulator, boolean isWait) throws IOException, ConnectionException, DeviceEventException {
+               receiver.setEmulator(emulator);
+
+               int port = emulator.getPort();
+               try {
+                       socket.connect(port);
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+
+               message.clear();
+
+               String sdcardMsg = SDCardEventType.Status_Unmount + "\n";               // query mount status
+               byte[] buf = sdcardMsg.getBytes();
+               message.getDataBuffer().put(buf);
+               message.getHeaderBuffer().put((byte)buf.length);
+
+               socket.sendMessage(message);
+
+               synchronized(this) {
+                       try {
+                               this.wait(2000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                       }
+               }
+
+               socket.disconnect();
+               if (receiver.isWait()) {
+                       throw new DeviceEventException(EILibError.FailedGetValue);
+               }
+
+       }
+
+       @Override
+       void initializeEventMessage() {
+               message = new EventMessage();
+               message.setEventTypeBuffer(EventType.SDCARD);
+       }
+
+       @Override
+       public void fireEvent(EventMessage messate) {
+               synchronized(this) {
+                       this.notifyAll();
+               }
+       }
+}
+
+class SDCardStatusCheckReceiver extends AbstractEventReceiver {
+       private Emulator emulator;
+       private SDCardStatusCheckSender sender;
+       private boolean isWait = false;
+       public SDCardStatusCheckReceiver(SDCardStatusCheckSender sender) {
+               super("SD card check");
+               this.sender = sender;
+       }
+       public void setEmulator(Emulator emulator) {
+               this.emulator = emulator;
+       }
+
+       @Override
+       public void run(EventMessage message) {
+               isWait = true;
+
+               int actionID = message.getEventHeader().getActionID();
+               if (actionID == SDCardEventType.Status_Unmount) { // unmounted status
+                       emulator.setMounted(false);
+               } else if (actionID == SDCardEventType.Status_Mount) { // mounted status
+                       emulator.setMounted(true);
+                       int len = message.getDataBuffer().position();
+                       String name = null;
+                       if (len != 0) {
+                               try {
+                                       name = new String(message.getDataBuffer().array(),
+                                                       message.getDataBufferOffset(), len, "US-ASCII");
+                               } catch (UnsupportedEncodingException e) {
+                                       e.printStackTrace();
+                               }
+                       }
+                       if (name != null) {
+                               emulator.setSDCardName(name);
+                       }
+               }
+
+               isWait = false;
+               sender.fireEvent(null);
+       }
+
+       public boolean isWait() {
+               return isWait;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/sender/SensorEventSender.java b/ei-library/src/org/tizen/eilib/events/sender/SensorEventSender.java
new file mode 100644 (file)
index 0000000..5f26685
--- /dev/null
@@ -0,0 +1,294 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.sender;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.message.ActionID;
+import org.tizen.eilib.connection.message.EventMessage;
+import org.tizen.eilib.connection.message.EventType;
+import org.tizen.eilib.connection.message.GroupID;
+import org.tizen.eilib.events.type.MotionEventType;
+import org.tizen.eilib.events.type.ProximityStatus;
+import org.tizen.eilib.events.type.SensorEventType;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.modem.protocol.ByteUtil;
+import org.tizen.eilib.tools.EILogger;
+
+public class SensorEventSender extends AbstractEventSender {
+       private String msg = "";
+       private Integer msgLength = new Integer(0);
+       private EventMessage returnMsg = null;
+
+       public SensorEventSender(ConnectionToEmulator connector) {
+               super(connector);
+       }
+
+       public boolean sendManualEvent(SensorEventType type,
+                                                               double x, double y, double z) throws IOException, ConnectionException {
+               message.clear();
+
+               msg = type.getType()
+                       + 3 + "\n" // count of value
+                       + Double.toString(x) + "\n"
+                       + Double.toString(y) + "\n"
+                       + Double.toString(z) + "\n";
+
+               byte[] tmp = msg.getBytes();
+               msgLength = tmp.length;
+               ((ByteBuffer)message.getDataBuffer().clear()).put(tmp);
+
+               return sendMessage(null);
+       }
+
+       public boolean sendLogEvent(SensorEventType type,
+                                                               int repeatCount, ArrayList<String> files) throws IOException, ConnectionException {
+               message.clear();
+
+               msg = type.getType() + repeatCount + "\n" + files.size() + "\n";
+               for (String name : files) {
+                       msg = msg + name + "\n";
+               }
+
+               byte[] tmp = msg.getBytes();
+               msgLength = tmp.length;
+               ((ByteBuffer)message.getDataBuffer().clear()).put(tmp);
+               
+               return sendMessage(null);
+       }
+
+       public boolean sendLightEvent(int luxData, int levelData) throws IOException, ConnectionException {
+               message.clear();
+
+               // set level data
+               msg = SensorEventType.LIGHT.getType()
+                               + 2 + "\n" // count of value
+                               + Integer.toString(1) +"\n"
+                               + Integer.toString(levelData) + "\n";
+               
+               byte[] tmp = msg.getBytes();
+               msgLength = tmp.length;
+               ((ByteBuffer)message.getDataBuffer().clear()).put(tmp);
+               
+               if (!sendMessage(null)) {
+                       // TODO
+                       return false;
+               }
+
+               message.clear();
+
+               // set lux data
+               msg = SensorEventType.LIGHT.getType()
+                               + 2 + "\n" // count of value
+                               + Integer.toString(2) +"\n"
+                               + Integer.toString(luxData) + "\n";
+               
+               tmp = msg.getBytes();
+               msgLength = tmp.length;
+               ((ByteBuffer)message.getDataBuffer().clear()).put(tmp);
+               
+               return sendMessage(null);
+       }
+
+       public boolean sendMotionEvent(MotionEventType event) throws IOException, ConnectionException {
+               message.clear();
+
+               msg = SensorEventType.MOTION.getType()
+                               + 1 + "\n" // count of value
+                               + Integer.toString(event.getType()) + "\n";
+
+               byte[] tmp = msg.getBytes();
+               msgLength = tmp.length;
+               ((ByteBuffer)message.getDataBuffer().clear()).put(tmp);
+
+               return sendMessage(null);
+       }
+
+
+       public boolean sendProximityEvent(ProximityStatus status) throws IOException, ConnectionException {
+               message.clear();
+
+               msg = SensorEventType.PROXI.getType()
+                               + 1 + "\n" // count of value
+                               + Integer.toString(status.getValue()) + "\n";
+
+               byte[] tmp = msg.getBytes();
+               msgLength = tmp.length;
+               ((ByteBuffer)message.getDataBuffer().clear()).put(tmp);
+
+               return sendMessage(null);
+       }
+
+       protected synchronized boolean sendMessage(ActionID id)
+                               throws IOException, ConnectionException {
+               // make header
+               ByteBuffer header = message.getHeaderBuffer();
+       
+               header.clear();
+               if (id != null) {
+                       header.put(msgLength.byteValue());
+                       header.put((byte)0x00);
+                       header.put(((Integer)GroupID.STATUS).byteValue());
+                       header.put(((Integer)id.getId()).byteValue());
+               } else {
+                       header.put(msgLength.byteValue());
+                       header.put((byte)0x00);
+                       header.put((byte)0x00);
+                       header.put((byte)0x00);
+               }
+
+               getConnector().sendMessage(message);
+
+               return true;
+       }
+
+       @Override
+       void initializeEventMessage() {
+               message = new EventMessage(1024);
+               message.setEventTypeBuffer(EventType.SENSOR);
+       }
+
+       // get function
+       public int getLightValue() throws IOException, ConnectionException {
+               message.clear();
+               msgLength = 0;
+               sendMessage(ActionID.LIGHT_VALUE);
+
+               synchronized(this) {
+                       // wait 5 second
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+
+               int level = -1;
+               if (returnMsg != null) {
+                       if (returnMsg.getEventHeader().getActionID()
+                                       != ActionID.LIGHT_VALUE.getId()) {
+                               EILogger.getLogger().warning("An unexpected event occurs.");
+                       } else {
+                               if (returnMsg.getDataBuffer().position() != 0) {
+                                       level = ByteUtil.byte2int
+                                               (returnMsg.getDataBuffer().array(), 14);
+                               }
+                       }
+                       returnMsg = null;
+               }
+
+               return level;           
+       }
+
+       public ProximityStatus getProxiStatus() throws IOException, ConnectionException {
+               message.clear();
+               msgLength = 0;
+               sendMessage(ActionID.PROXI_VALUE);
+
+               synchronized(this) {
+                       // wait 5 second
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+
+               int value = -1;
+               ProximityStatus status = null;
+               if (returnMsg != null) {
+                       if (returnMsg.getEventHeader().getActionID()
+                                       != ActionID.PROXI_VALUE.getId()) {
+                               EILogger.getLogger().warning("An unexpected event occurs.");
+                       } else {
+                               if (returnMsg.getDataBuffer().position() != 0) {
+                                       value = ByteUtil.byte2int
+                                                       (returnMsg.getDataBuffer().array(), 14);
+                                       for (ProximityStatus s : ProximityStatus.values()) {
+                                               if (s.getValue() == value) {
+                                                       status = s;
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+                       returnMsg = null;
+               }
+
+               return status;
+       }
+
+       public String getSensorValue(SensorEventType type) throws IOException, ConnectionException {
+               message.clear();
+               msgLength = 0;
+               switch(type){
+               case ACCEL:
+                       sendMessage(ActionID.ACCEL_VALUE);
+                       break;
+               case GYRO:
+                       sendMessage(ActionID.GYRO_VALUE);
+                       break;
+               case MAGNETIC:
+                       sendMessage(ActionID.MAG_VALUE);
+                       break;
+               default:
+                       return null;
+               }
+
+               synchronized(this) {
+                       // wait 5 second
+                       try {
+                               this.wait(5000);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
+                               EILogger.getLogger().warning(e.getMessage());
+                       }
+               }
+
+               String value = null;
+               if (returnMsg != null) {
+                       if (returnMsg.getDataBuffer().position() != 0) {
+                               value = new String(returnMsg.getDataBuffer().array(),
+                                                               14, returnMsg.getDataBuffer().limit());
+                       }
+                       returnMsg = null;
+               }
+
+               return value;
+       }
+
+       public void fireEvent(EventMessage message) {
+               synchronized(this) {
+                       this.returnMsg = message;
+                       this.notifyAll();
+               }
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/BatteryCharger.java b/ei-library/src/org/tizen/eilib/events/type/BatteryCharger.java
new file mode 100644 (file)
index 0000000..3cded83
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum BatteryCharger {
+       DISCONNECT(0, "off"),
+       CONNECT(1, "on");
+
+       private int value;
+       private String status;
+       BatteryCharger(int v, String s) {
+               this.value  = v;
+               this.status = s;
+       }
+
+       public int getValue() {
+               return value;
+       }
+
+       public String toString() {
+               return status;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/CallErrorCode.java b/ei-library/src/org/tizen/eilib/events/type/CallErrorCode.java
new file mode 100644 (file)
index 0000000..0bf9937
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum CallErrorCode {
+       Success(32768, "success");
+       int code;
+       String str;
+
+       CallErrorCode(int c, String s) {
+               code    = c;
+               str             = s;
+       }
+
+       public int value() {
+               return code;
+       }
+
+       //@Override
+       public String toString() {
+               return str;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/CallEventType.java b/ei-library/src/org/tizen/eilib/events/type/CallEventType.java
new file mode 100644 (file)
index 0000000..ac33ae0
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum CallEventType {
+       NONE, INCOMING, LIST22, LIST26, LIST29;
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/CallStatus.java b/ei-library/src/org/tizen/eilib/events/type/CallStatus.java
new file mode 100644 (file)
index 0000000..e569f12
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum CallStatus {
+       NONE(0, "NONE"),
+       ACTIVE(1, "VOICE"),
+       HELD(2, "DATA"),
+       DIALING(3, "DIALING"),
+       ALERT(4, "ALERT"),
+       INCOMING(5, "INCOMING"),
+       WAITING(6, "WATING"),
+       MAX(7, "MAX");
+
+       int id;
+       String value;
+
+       CallStatus(int id, String value) {
+               this.id                 = id;
+               this.value  = value;
+       }
+
+       public int getID() {
+               return id;
+       }
+
+       public String toString() {
+               return value;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/CallType.java b/ei-library/src/org/tizen/eilib/events/type/CallType.java
new file mode 100644 (file)
index 0000000..bd9c3d0
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum CallType {
+       NONE(0,"NONE"),
+       VOICE(1,"VOICE"),
+       DATA(2,"DATA"),
+       MAX(3,"MAX"),
+       EMERGENCY(7, "EMERGENCY");
+
+       int id;
+       String value;
+
+       CallType(int id, String value) {
+               this.id         = id;
+               this.value      = value;
+       }
+
+       public int getID() {
+               return id;
+       }
+
+       public String toString() {
+               return value;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/EarJackStatus.java b/ei-library/src/org/tizen/eilib/events/type/EarJackStatus.java
new file mode 100644 (file)
index 0000000..8a6c11e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum EarJackStatus {
+       DISCONNECT(0, "off"),
+       WIRE3_CONNECT(1, "3wire"),
+       WIRE4_CONNECT(3, "4wire");
+
+       private int value;
+       private String status;
+       EarJackStatus(int i, String s) {
+               this.value  = i;
+               this.status = s;
+       }
+
+       public int getValue() {
+               return value;
+       }
+
+       @Override
+       public String toString() {
+               return status;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/LocationEventMode.java b/ei-library/src/org/tizen/eilib/events/type/LocationEventMode.java
new file mode 100644 (file)
index 0000000..152f056
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum LocationEventMode {
+       NONE(-1, "-1"),
+       STOPMODE(0, "0"),
+       LOGMODE(1, "1"),
+       MANUALMODE(2, "2");
+       
+       int     mode;
+       String  strMode;
+
+       LocationEventMode(int m, String s) {
+               mode    = m;
+               strMode = s;
+       }
+
+       public int getMode() {
+               return mode;
+       }
+
+       public String toString() {
+               return strMode;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/MMSStatus.java b/ei-library/src/org/tizen/eilib/events/type/MMSStatus.java
new file mode 100644 (file)
index 0000000..0a97f85
--- /dev/null
@@ -0,0 +1,23 @@
+package org.tizen.eilib.events.type;
+
+public enum MMSStatus {
+       OK(10, "success"),
+       Failure(11, "failure");
+
+       int value;
+       String str;
+
+       MMSStatus(int v, String s) {
+               value = v;
+               str       = s;
+       }
+
+       public int getValue() {
+               return value;
+       }
+
+       //@Override
+       public String toString() {
+               return str;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/MimeTypeList.java b/ei-library/src/org/tizen/eilib/events/type/MimeTypeList.java
new file mode 100644 (file)
index 0000000..fafb046
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.events.type;
+
+import java.util.ArrayList;
+
+public class MimeTypeList
+{
+       private static MimeTypeList typelist = new MimeTypeList();
+       private ArrayList<MimeType> list;
+       
+       public static MimeTypeList getInstance()
+       {
+               return typelist;
+       }
+
+       private MimeTypeList()
+       {
+               list = new ArrayList<MimeType>();
+               list.add(new MimeType("vcf", "application/vcard"));
+               list.add(new MimeType("jpeg", "image/jpeg"));
+               list.add(new MimeType("mpeg", "image/mpeg"));
+               list.add(new MimeType("png", "image/png"));
+               list.add(new MimeType("gif", "image/gif"));
+               list.add(new MimeType("bmp", "image/bmp"));
+               list.add(new MimeType("jpg", "image/jpeg"));
+               list.add(new MimeType("jpe", "image/jpeg"));
+               list.add(new MimeType("mp3", "audio/mpeg"));
+               list.add(new MimeType("mid", "audio/midi"));
+               list.add(new MimeType("wav", "audio/x-wav"));
+               list.add(new MimeType("mp4", "video/mp4"));
+               list.add(new MimeType("mpe", "video/mpeg"));
+               list.add(new MimeType("mpg", "video/mpeg"));
+               list.add(new MimeType("mov", "video/quicktime"));
+               list.add(new MimeType("flv", "video/x-flv"));
+               list.add(new MimeType("asf", "video/x-ms-asf"));
+               list.add(new MimeType("avi", "video/x-msvideo"));
+       }
+       
+       public String findMimeType(String ex)
+       {
+
+               for (MimeType mimetype : list) {
+                       if (mimetype.getExtension().equals(ex)) {
+                               return mimetype.getMimetype();
+                       }
+               }
+
+               return null;
+       }
+}
+
+class MimeType
+{
+       private String extension;
+       private String mimetype;
+       
+       public MimeType(String ex, String type)
+       {
+               setExtension(ex);
+               setMimetype(type);
+       }
+
+       public String getExtension()
+       {
+               return extension;
+       }
+
+       public void setExtension(String extension)
+       {
+               this.extension = extension;
+       }
+
+       public String getMimetype()
+       {
+               return mimetype;
+       }
+
+       public void setMimetype(String mimetype)
+       {
+               this.mimetype = mimetype;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/MobileType.java b/ei-library/src/org/tizen/eilib/events/type/MobileType.java
new file mode 100644 (file)
index 0000000..9ed0561
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum MobileType {
+       // Mobile Originated 송신
+       MO(1, "MO"),
+       // Mobile Treminated 수진
+       MT(2,"MT");
+       
+       int id;
+       String value;
+
+       MobileType(int id, String value) {
+               this.id                 = id;
+               this.value  = value;
+       }
+
+       public int getID() {
+               return id;
+       }
+
+       public String toString() {
+               return value;
+       } 
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/MotionEventType.java b/ei-library/src/org/tizen/eilib/events/type/MotionEventType.java
new file mode 100644 (file)
index 0000000..363c851
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum MotionEventType {
+       DoubleTap(1, "double-tab"),
+       ShakeStart(2, "start-shake"),
+       ShakeEnd(3, "end-shake"),
+       SnapXp(4, "snapx+"),
+       SnapXm(5, "snapx-"),
+       SnapYp(6, "snapy+"),
+       SanpYm(7, "snapy-"),
+       SnapZp(8, "snapz+"),
+       SnapZm(9, "snapz-"),
+       MoveToEar(12, "move-to-ear");
+
+       int type;
+       String event;
+       MotionEventType(int t, String event) {
+               type = t;
+               this.event = event;
+       }
+
+       public int getType() {
+               return type;
+       }
+
+       @Override
+       public String toString() {
+               return event;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/NDEFFormat.java b/ei-library/src/org/tizen/eilib/events/type/NDEFFormat.java
new file mode 100644 (file)
index 0000000..44e371c
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum NDEFFormat {
+       EMPTY("0", "empty", "NDEF_TNF_EMPTY"),
+       WELL_KNOWN("1", "well-known", "NDEF_TNF_WELL_KNOWN"),
+       MEDIA("2", "mine-media", "NDEF_TNF_MINE_MEDIA"),
+       URI("3", "uri", "NDEF_TNF_ABSOLUTE_URI"),
+       EXTERNAL("4", "external", "NDEF_TNF_EXTERNAL"),
+       UKNONWN("5", "unknown", "NDEF_TNF_UNKNOWN");
+
+       String shortName;
+       String longName;
+       String format;
+
+       NDEFFormat(String f, String sName, String lName) {
+               format  = f;
+               shortName = sName;
+               longName  = lName;
+       }
+
+       public String getFormat() {
+               return format;
+       }
+
+       public String getShortName() {
+               return shortName;
+       }
+
+       public String toString() {
+               return longName;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/NDEFRecord.java b/ei-library/src/org/tizen/eilib/events/type/NDEFRecord.java
new file mode 100644 (file)
index 0000000..d2f5ad7
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public class NDEFRecord {
+       private NDEFFormat format       = null;
+       private String typeName         = null;
+       private String id                       = null;
+       private String payload          = null;
+
+       public NDEFRecord(NDEFFormat f, String name, String id, String payload) {
+               this.format     = f;
+               this.typeName   = name;
+               this.id                 = id;
+               this.payload    = payload;
+       }
+
+       public NDEFFormat getFormat() {
+               return format;
+       }
+
+       public void setFormat(NDEFFormat format) {
+               this.format = format;
+       }
+
+       public String getTypeName() {
+               return typeName;
+       }
+
+       public void setTypeName(String typeName) {
+               this.typeName = typeName;
+       }
+
+       public String getId() {
+               return id;
+       }
+
+       public void setId(String id) {
+               this.id = id;
+       }
+
+       public String getPayload() {
+               return payload;
+       }
+
+       public void setPayload(String payload) {
+               this.payload = payload;
+       }
+
+       public String getMessage() {
+               return format.getFormat() + ","
+                               + typeName + "," + id + "," + payload;
+       }
+       @Override
+       public String toString() {
+               return format.toString() + "(" + format.getShortName() + "),"
+                               + typeName + "," + id + "," + payload;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/NfcTagType.java b/ei-library/src/org/tizen/eilib/events/type/NfcTagType.java
new file mode 100644 (file)
index 0000000..5bc2109
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum NfcTagType {
+       TYPE1(1, "type1", "Topaz Jewel (Type1)"),
+       TYPE2(2, "type2", "Mifare UL (Type2)"),
+       TYPE3(3, "type3", "Felica (Type3)"),
+       TYPE4(4, "type4", "Mifare Desfiel (Type4)"),
+       P2P(5, "", "");
+
+       int     type;
+       String  longName;
+       String  shortName;
+
+       NfcTagType(int t, String sName, String lName) {
+               this.type       = t;
+               shortName = sName;
+               longName  = lName;
+       }
+
+       public int getType() {
+               return type;
+       }
+
+       public String getShortName() {
+               return shortName;
+       }
+
+       public String toString() {
+               return longName;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/ProximityStatus.java b/ei-library/src/org/tizen/eilib/events/type/ProximityStatus.java
new file mode 100644 (file)
index 0000000..4b2e2f3
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum ProximityStatus {
+
+       ON(0, "on"),
+       OFF(8, "off");
+
+       private int status;
+       private String str;
+
+       ProximityStatus(int i, String s) {
+               this.status = i;
+               this.str        = s;
+       }
+
+       public int getValue() {
+               return status;
+       }
+
+       public String toString() {
+               return str;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/SDCardEventType.java b/ei-library/src/org/tizen/eilib/events/type/SDCardEventType.java
new file mode 100644 (file)
index 0000000..67e916a
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public class SDCardEventType {
+       public static final int Action_Unmount  = 0;
+       public static final int Action_Mount    = 1;
+       public static final int Status_Unmount  = 2;
+       public static final int Status_Mount    = 3;
+       public static final int Fail_Unmount    = 4;
+       public static final int Fail_Mount              = 5;
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/SMSEventType.java b/ei-library/src/org/tizen/eilib/events/type/SMSEventType.java
new file mode 100644 (file)
index 0000000..061f5d7
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum SMSEventType {
+
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/SMSStatus.java b/ei-library/src/org/tizen/eilib/events/type/SMSStatus.java
new file mode 100644 (file)
index 0000000..639a43c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum SMSStatus {
+       OK(0, "available"),
+       NotAvaliable(1, "unavailable");
+
+       int value;
+       String str;
+       
+       SMSStatus(int v, String s) {
+               value = v;
+               str       = s;
+       }
+
+       public int getValue() {
+               return value;
+       }
+
+       //@Override
+       public String toString() {
+               return str;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/SensorEventType.java b/ei-library/src/org/tizen/eilib/events/type/SensorEventType.java
new file mode 100644 (file)
index 0000000..e2c03bd
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum SensorEventType {
+       NONE("0\n", ""), ACCEL("1\n", "accel" ), PROXI("2\n", "proxi"), LIGHT("3\n", "light"),
+       GYRO("4\n", "gyro"), GEO("5\n", "geo"),
+       MOTION("6\n", "motion"), TILT("12\n", "tilt"), MAGNETIC("13\n", "magnetic"),
+       FILE_ACCEL("14\n", "accel"), FILE_MAGNETIC("15\n", "magnetic"), FILE_GYRO("16\n", "gyro");
+
+       String type;
+       String name;
+       SensorEventType(String t, String n) {
+               type = t;
+               name = n;
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public String getType() {
+               return type;
+       }
+
+       public String toString() {
+               return name;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/events/type/USBStatus.java b/ei-library/src/org/tizen/eilib/events/type/USBStatus.java
new file mode 100644 (file)
index 0000000..cfdeacb
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.events.type;
+
+public enum USBStatus {
+       DISCONNECT(0, "off"),
+       CONNECT(1, "on");
+
+       private int value;
+       private String status;
+
+       USBStatus(int i, String s) {
+               this.value  = i;
+               this.status = s;
+       }
+
+       public int getValue() {
+               return value;
+       }
+
+       @Override
+       public String toString() {
+               return status;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/exception/CallEventException.java b/ei-library/src/org/tizen/eilib/exception/CallEventException.java
new file mode 100644 (file)
index 0000000..7036c01
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.exception;
+
+public class CallEventException extends InjectorLibraryException {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 6495891796872101374L;
+
+       /**
+        * Throw error about call event.
+        * @param message
+        */
+       public CallEventException(EILibError e) {
+               super(e);
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/exception/ConnectionException.java b/ei-library/src/org/tizen/eilib/exception/ConnectionException.java
new file mode 100644 (file)
index 0000000..fc1ff0e
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.exception;
+
+public class ConnectionException extends Exception {
+
+       private EILibError error;
+
+       public ConnectionException(EILibError e) {
+               super(e.toString());
+               this.error = e;
+       }
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+
+       public int getErrorNumber() {
+               return error.getErrorNumber();
+       }
+
+       public EILibError getError() {
+               return error;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/exception/DeviceEventException.java b/ei-library/src/org/tizen/eilib/exception/DeviceEventException.java
new file mode 100644 (file)
index 0000000..a3c55b5
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.exception;
+
+public class DeviceEventException extends InjectorLibraryException {
+
+       /**
+        * Throw error about device event.
+        * @param message
+        */
+       public DeviceEventException(EILibError e) {
+               super(e);
+       }
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 5262679766405871861L;
+
+}
diff --git a/ei-library/src/org/tizen/eilib/exception/EILibError.java b/ei-library/src/org/tizen/eilib/exception/EILibError.java
new file mode 100644 (file)
index 0000000..f1077c7
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.exception;
+
+class ErrorNumber {
+       public static final int Library = 1000;
+       public static final int NFC     = 1100;
+       public static final int Device  = 1200;
+       public static final int Modem   = 1300;
+       public static final int Sensor  = 1400;
+       public static final int Location = 1500;
+}
+public enum EILibError {
+       Error1(1, "ErrorMessaeg"),
+
+       // Library
+       EmulatorNotExist(ErrorNumber.Library, "Running Emulator does not exist. Retry after to start emulator."),
+       EmulatorNotOne(ErrorNumber.Library + 1, "More than one emulator are exist."),
+       EmuldTerminated(ErrorNumber.Library + 2, "To send event to the emulator is failed. Please check emulator daemon."),
+       EmuldVersionOld(ErrorNumber.Library + 3, "Emuld version is old version."),
+
+       //NFC
+       RecordCountIsZero(ErrorNumber.NFC, "List of NDEF record is empty.\nAt least one or more records are required."),
+       RecordCountIsMax(ErrorNumber.NFC + 1, "The number of NDEF records has reached the maximum limit of 5."),
+       NDEFMessageLenIsMax(ErrorNumber.NFC + 2,"The length of the NDEF message has reached the maximun limit of 4096 bytes."),
+       MediaFileException(ErrorNumber.NFC + 3, "The exception has been thrown while selecting media file."),
+       CheckVconfException(ErrorNumber.NFC + 4, "The exception has been thrown while checking NFC state of emulator."),
+       SelecTagType(ErrorNumber.NFC + 5, "Tag type can not be null. Select Tag Type!!"),
+       // check char of NFDE record
+       InvalidCharNewLine(ErrorNumber.NFC + 6, "You can not enter a newline character."),
+       InvalidChar(ErrorNumber.NFC + 7, "You can not enter ',' character.\nThis character is used to separator character."),
+       InvalidCharAscii(ErrorNumber.NFC + 8, "Invalid characters has been entered.\nOnly ASCII characters can be entered."),
+       // well known
+       InvalidWellKnownType(ErrorNumber.NFC + 9, "Type name of NDEF_TNF_WELL_KNOWN format is possible only U or T."),
+       // select media file
+       NotSelectFile(ErrorNumber.NFC + 10, "Please, input mime media file path."),
+       CheckMediaFileException(ErrorNumber.NFC + 11, "The exception has been thrown while checking media file size."),
+       NotMimeType(ErrorNumber.NFC + 12, "Type of selected file is not mime media type."),
+       BigSizeFile(ErrorNumber.NFC + 13, "Size of selected file is too big.\nAvailable file size is under of 10KB."),
+       // check vconf
+       NFCIsDisable(ErrorNumber.NFC + 14, "NFC state is 'Off' in the emulator.\nPlease change NFC state to 'On' on the setting menu."),
+
+       FailedRemoveRecord(ErrorNumber.NFC + 15, "Failed to remove a record."),
+       TagAttachState(ErrorNumber.NFC + 16, "State of NFC is already tag attch state."),
+       P2PAttachState(ErrorNumber.NFC + 16, "State of NFC is already p2p attch state."),
+       CanNotDettach(ErrorNumber.NFC + 17, "State of NFC is already detach state or attach other type's event."),
+       CanNotSend(ErrorNumber.NFC + 18, "First make state of NFC to the P2P attach state."),
+
+       NullRecord(ErrorNumber.NFC + 19, "Input record is null"),
+
+       // DEVICE
+       InvalidValue(ErrorNumber.Device, "Input value is not avaliable."),
+       FailedGetValue(ErrorNumber.Device + 1, "Failed to get value from emulator."),
+       EmulatorIsMounted(ErrorNumber.Device + 2, "This Emulator has already mounted with SD card."),
+       SDCardIsMounted(ErrorNumber.Device + 3, "This SD card has been mounted by the other emulator."),
+
+       // MODEM
+       RSSIIsZero(ErrorNumber.Modem, "RSSI level is zero.\nPlease try again later."),
+       //BusyMode(ErrorNumber.Modem + 1, "User is busy.\nPlease try again later."),
+       NumberFormatError(ErrorNumber.Modem + 2, "Format of phone number is wrong."),
+       NumberIsEmpty(ErrorNumber.Modem + 3, "Phone number is empty."),
+       NumberIsTooLong(ErrorNumber.Modem + 4, "The maximum length of phone number is 15."),
+       NumberNotFound(ErrorNumber.Modem + 5, "This phone number does not exist in the call list."),
+       MessageIsTooLong(ErrorNumber.Modem + 6, "Limit size of text message is 80."),
+       SendMessageFailed(ErrorNumber.Modem + 7, "Message transmission has been failed"),
+       NotExistCall(ErrorNumber.Modem + 8, "Avaliable call does not exist."),
+       IncomingCall(ErrorNumber.Modem + 9, "User is busy.\nPlease try again later."),
+       NowBusy(ErrorNumber.Modem + 10, "User is busy.\nCall waiting mode of emulator is off. Please try again later."),
+       ListFull(ErrorNumber.Modem + 11, "There are many pending connections.\nCan't connect anymore."),
+       // SENSOR
+       InvalidSensorValue(ErrorNumber.Sensor, "Input sensor's values are not avaliable."),
+       NotExistLogFile(ErrorNumber.Sensor + 1, "No such log file. Please check your input file path."),
+
+       // Location
+       InvalidLocationValue(ErrorNumber.Device, "Input location values are not avaliable. Check again value of latitude, longitude.");
+
+       int number;
+       String message;
+       
+       EILibError(int n, String m) {
+               number  = n;
+               message = m;
+       }
+
+       public int getErrorNumber() {
+               return number;
+       }
+
+       public String getMessage() {
+               return message;
+       }
+
+       public String toString() {
+               return "[" + number + "]" + message;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/exception/InjectorLibraryException.java b/ei-library/src/org/tizen/eilib/exception/InjectorLibraryException.java
new file mode 100644 (file)
index 0000000..5dbb877
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.exception;
+
+public class InjectorLibraryException extends Exception {
+       /**
+        * 
+        */
+       private static final long serialVersionUID = -5585311695949728907L;
+
+       private EILibError error;
+       /**
+        * 
+        * @param e
+        */
+       public InjectorLibraryException(EILibError e) {
+               super(e.toString());
+               this.error = e;
+       }
+
+       public int getErrorNumber() {
+               return error.getErrorNumber();
+       }
+
+       public EILibError getError() {
+               return error;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/exception/InvalidTypeException.java b/ei-library/src/org/tizen/eilib/exception/InvalidTypeException.java
new file mode 100644 (file)
index 0000000..97f9f6f
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.exception;
+
+@SuppressWarnings("serial")
+public class InvalidTypeException extends Exception {
+
+       public InvalidTypeException(String message) {
+               super(message);
+       }
+
+}
diff --git a/ei-library/src/org/tizen/eilib/exception/NfcEventException.java b/ei-library/src/org/tizen/eilib/exception/NfcEventException.java
new file mode 100644 (file)
index 0000000..69fe87b
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.exception;
+
+public class NfcEventException extends InjectorLibraryException {
+
+       /**
+        * 
+        * @param e
+        */
+       public NfcEventException(EILibError e) {
+               super(e);
+               // TODO Auto-generated constructor stub
+       }
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 2300982711964476792L;
+
+}
diff --git a/ei-library/src/org/tizen/eilib/exception/SMSEventException.java b/ei-library/src/org/tizen/eilib/exception/SMSEventException.java
new file mode 100644 (file)
index 0000000..6ecf315
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.exception;
+
+public class SMSEventException extends InjectorLibraryException {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 6495891796872101374L;
+
+       /**
+        * Throw error about sms event.
+        * @param message
+        */
+       public SMSEventException(EILibError e) {
+               super(e);
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/exception/SensorEventException.java b/ei-library/src/org/tizen/eilib/exception/SensorEventException.java
new file mode 100644 (file)
index 0000000..9eaa8a1
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.eilib.exception;
+
+public class SensorEventException extends InjectorLibraryException {
+
+       /**
+        * Throw error about sensor event.
+        * @param e
+        */
+       public SensorEventException(EILibError e) {
+               super(e);
+               // TODO Auto-generated constructor stub
+       }
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/encription/DecodeMsg.java b/ei-library/src/org/tizen/eilib/modem/encription/DecodeMsg.java
new file mode 100644 (file)
index 0000000..f9993a2
--- /dev/null
@@ -0,0 +1,684 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.encription;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashSet;
+
+public class DecodeMsg {
+       int ton, npi;
+       public static boolean deliveryReport = false;
+       public static char[] smsbuffer = new char[4096];
+       public static int smsbuffer_index = 0;
+       public static boolean relayedsms = false;
+       public static int relay_cnt = 0;
+       public static int udhl = 0;
+       public static HashSet<String> deliveryReportNum_set = new HashSet<String>();
+       public static boolean isDecodeEnd = true;
+       
+       public void DecodeSmsSubmitTpdu(TPDU_SMS_SUBMIT tpdu_submit, int pdu_len, char[] pPDU) {
+               isDecodeEnd = false;
+               int scaAddr_len = 0;
+               int destAddr_len = 0;
+               char[] diallingNum = new char[EnumConstants.TAPI_NETTEXT_ADDRESS_LEN_MAX+1];
+               char[] scaAddr = new char[EnumConstants.TAPI_NETTEXT_SCADDRESS_LEN_MAX+1];
+               char[] destAddr = new char[EnumConstants.TAPI_NETTEXT_ADDRESS_LEN_MAX+1];
+//             char[] inData = new char[EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX+1];
+
+               int position = 0;
+
+               SmsUtilDecodeAddrField_sca(diallingNum, pPDU);
+
+               position += 2;
+
+               scaAddr_len = getSize(diallingNum);
+
+               if ((scaAddr_len % 2) != 0) {
+                       position += scaAddr_len / 2 + 1;
+               } else {
+                       position += scaAddr_len / 2;
+               }
+
+               if (ton == EnumConstants.SIM_TON_INTERNATIONAL) {
+                       scaAddr[0] = '+';
+                       for(int i = 0; i < scaAddr_len; i++) {
+                               scaAddr[i+1] = diallingNum[i];
+                               scaAddr[scaAddr_len+1] = '\0';
+                       }
+               } else {
+                       for(int i = 0; i < scaAddr_len; i++) {
+                               scaAddr[i] = diallingNum[i];
+                               scaAddr[scaAddr_len] = '\0';
+                       }
+               }
+               
+               /* TP-MTI, TP-RD, TP-VPF, TP-RP, TP_UDHI, TP-SRR */
+               tpdu_submit.msgType = EnumConstants.SMS_TPDU_SUBMIT;
+               tpdu_submit.rd = ((pPDU[position] & 0x04) != 0) ? true : false;
+               tpdu_submit.vpf = (pPDU[position] & 0x18) >> 3;
+               tpdu_submit.srr = ((pPDU[position] & 0x20) != 0) ? true : false;
+               tpdu_submit.udhi = ((pPDU[position] & 0x40) != 0) ? true : false;
+               tpdu_submit.rp = ((pPDU[position] & 0x80) != 0) ? true : false;
+               
+               position++;
+               
+               /* TP-MR */
+               tpdu_submit.mr = pPDU[position];
+               
+               position++;
+               
+               /* TP-DA */
+               for(int i = 0; i < diallingNum.length; i++) {
+                       diallingNum[i] = 0x00;
+               }
+               
+               SmsUtilDecodeAddrField_dst(diallingNum, getCharArray(pPDU, position));
+               
+               position+=2;
+               
+               destAddr_len = getSize(diallingNum);
+               
+               if((destAddr_len %2) != 0) {
+                       position += destAddr_len / 2 + 1;
+               } else {
+                       position += destAddr_len / 2;
+               }
+
+               if (ton == EnumConstants.SIM_TON_INTERNATIONAL) {
+                       destAddr[0] = '+';
+                       for(int i = 0; i < destAddr_len; i++) {
+                               destAddr[i+1] = diallingNum[i];
+                               destAddr[destAddr_len+1] = '\0';
+                       }
+                       tpdu_submit.destAddr.dialnumlen = destAddr_len+1;
+                       for(int i = 0; i < destAddr_len+1; i++) {
+                               tpdu_submit.destAddr.diallingNum[i] = destAddr[i];
+                       }
+               } else {
+                       for(int i = 0; i < destAddr_len; i++) {
+                               destAddr[i] = diallingNum[i];
+                               destAddr[destAddr_len] = '\0';
+                       }
+                       tpdu_submit.destAddr.dialnumlen = destAddr_len;
+                       for(int i = 0; i < destAddr_len; i++) {
+                               tpdu_submit.destAddr.diallingNum[i] = destAddr[i];
+                       }
+               }
+               
+               tpdu_submit.destAddr.npi = npi;
+               tpdu_submit.destAddr.ton = ton;
+               
+               /* TP-PID */
+               tpdu_submit.pId = pPDU[position];
+               position++;
+               
+               /* TP DCS */
+               SmsUtilDecodeDCS(tpdu_submit.dcs, pPDU[position]);
+               position++;
+               
+               /* TP VP */
+//             tpdu_submit.vp.vpType = EnumConstants.TAPI_NETTEXT_VP_RELATIVE;
+               
+               switch(tpdu_submit.vp.vpType) {
+                       case EnumConstants.TAPI_NETTEXT_VP_RELATIVE:
+                               tpdu_submit.vp.vpValue = pPDU[position];
+                               tpdu_submit.vp.vpRelativeType = EnumConstants.TAPI_NETTEXT_VP_REL_1D;
+                               position++;
+                               break;
+                       case EnumConstants.TAPI_NETTEXT_VP_ABSOLUTE:
+                       case EnumConstants.TAPI_NETTEXT_VP_ENHANCED:
+                               position += 7;
+                               break;
+                       default:
+                               break;
+               }
+               
+               /* TP UDL */
+               tpdu_submit.udl = pPDU[position] & 0x00FF;
+               
+               if(tpdu_submit.udl > EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX) {
+                       tpdu_submit.udl = EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX;
+               }
+               
+               position++;
+               
+               /* TP UD */
+               if(tpdu_submit.udhi)
+               {
+                       udhl = pPDU[position];
+                       int fillbits = 7 - ((pPDU[position] * 8) % 7);
+                       position += udhl;
+                       udhl += fillbits;
+                       
+                       if(pPDU[position] == 1)
+                       {
+                               relay_cnt = pPDU[position - 1];
+                               for(int i = 0; i < smsbuffer.length; i++) {
+                                       smsbuffer[i] = '\0';
+                               }
+                       }
+                       position++;
+                       
+                       relayedsms = true;
+               }
+               else
+               {
+                       if(relayedsms)
+                       {
+                               for(int i = 0; i < smsbuffer.length; i++) {
+                                       smsbuffer[i] = '\0';
+                               }
+                               
+                               smsbuffer_index = 0;
+                               relayedsms = false;
+                       }
+               }
+               
+               int i = 0;
+               tpdu_submit.userData = new char[EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX+1];
+               //System.out.println("Position : " + position);
+               if(tpdu_submit.dcs.alphabetType == EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT) {
+                       char[] inData = new char[EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX+1];
+                       for(i = 0; i < tpdu_submit.udl; i++) {
+                               inData[i] = (char)(pPDU[position + i] & 0xff);
+                               if(relay_cnt == 1)      // last or single sms
+                               {
+                                       if(i == tpdu_submit.udl - udhl) {
+                                               break;
+                                       }
+                               }
+                               else
+                               {
+                                       if(tpdu_submit.udhi == true)
+                                       {
+                                               if(i == tpdu_submit.udl - udhl) {
+                                                       break;
+                                               }
+                                       }
+                                       else
+                                       {
+                                               if(i == tpdu_submit.udl) {
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+                       
+                       inData[i] = '\0';
+                       
+                       for(int j = 0; j < i; j++) {
+                               tpdu_submit.userData[j] = inData[j];    
+                       }
+                       
+                       if(relayedsms)
+                       {
+                               String tmp1 = new String(smsbuffer);
+                               String tmp2 = new String(inData);
+                               String tmp3 = tmp1.trim() + tmp2.trim();
+                               smsbuffer = tmp3.toCharArray();
+                       }
+                       // SmsUtilUnpackGSMCode(tpdu_submit.userData, inData, tpdu_submit.udl);
+               }
+               else if(tpdu_submit.dcs.alphabetType == EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2)
+               {
+                       byte[] inData = new byte[EnumConstants.TAPI_NETTEXT_SMDATA_SIZE_MAX+1];
+                       for(i = 0; i < tpdu_submit.udl; i++) {
+                               inData[i] = (byte)(pPDU[position + i] & 0xff);
+                               if(relay_cnt == 1)      // last or single sms
+                               {
+                                       if(i == tpdu_submit.udl - udhl + 1) {
+                                               break;
+                                       }
+                               }
+                               else
+                               {
+                                       if(tpdu_submit.udhi == true)
+                                       {
+                                               if(i == tpdu_submit.udl - udhl) {
+                                                       break;
+                                               }
+                                       }
+                                       else
+                                       {
+                                               if(i == tpdu_submit.udl) {
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+                       
+                       try {
+                               inData[i] = '\0';
+                               tpdu_submit.userData = ucs2ToUTF16(inData, i/2);        
+                       } catch (UnsupportedEncodingException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
+               }
+       
+               if(tpdu_submit.srr)
+               {
+               //      System.out.println("SRR: A status report is requested");
+                       deliveryReportNum_set.add(String.valueOf(diallingNum).trim());
+                       deliveryReport = true;
+               }
+               else
+               {
+               //      System.out.println("SRR: A status report is not requested");
+                       deliveryReport = false;
+               }
+               isDecodeEnd = true;
+       }
+
+       private char[] getCharArray(char[] org, int start) {
+               int length = org.length - start;
+               char[] result = new char[length];
+               
+               for(int i = 0; i < length; i++) {
+                       result[i] = org[start + i];
+               }
+               return result;
+       }
+       
+       private void SmsUtilDecodeDCS(TapiNetTextCodingScheme pCodingScheme, char dcs) {
+               if ( dcs < 0x40 ) { // bits 7..4 = 00xx : general data coding indication
+                       pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS;
+
+                       if ((dcs & 0x20) != 0) {// bit 5 = 1 : indicates the text is compressed
+                               pCodingScheme.bCompressed = true;
+                       }
+
+                       if ((dcs & 0x10) != 0) // bit 4 = 1 : indicates that bits  1 to 0 have a message class meaning
+                       {
+                               pCodingScheme.bMsgClassSet = true;
+
+                               switch ( dcs & 0x03 ) // bits 1 to 0 : message class
+                               {
+                                       case 0x00:
+                                               pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_0;
+                                               break;
+                                       case 0x01:
+                                               pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_1;
+                                               break;
+                                       case 0x02:
+                                               pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_2;
+                                               break;
+                                       case 0x03:
+                                               pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_3;
+                                               break;
+                                       default:
+                                               break;
+                               }
+                       }
+                       else {// bit 4 = 0 : indicates that bits 1 to 0 are reserved and have no message class meaning
+                               pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_NONE;
+                       }
+
+                       switch ( dcs & 0x0C ) // bits 4 to 3 : character set
+                       {
+                               case 0x00:
+                                       pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT;
+                                       break;
+                               case 0x04:
+                                       pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT;
+                                       break;
+                               case 0x08:
+                                       pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2;
+                                       break;
+                               case 0x0C:
+                                       pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_MAX;
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+               else if ( dcs >= 0x40 && dcs < 0x80 ) // bits 7..4 = 01xx : message marked for automatic deletion group. bits 5..0 are coded exactly the same as group 00xx
+               {
+                       pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_AUTO_DELETION;
+
+                       if ((dcs & 0x20) != 0) {// bit 5 = 1 : indicates the text is compressed
+                               pCodingScheme.bCompressed = true;
+                       }
+
+                       if ((dcs & 0x10) != 0) // bit 4 = 1 : indicates that bits  1 to 0 have a message class meaning
+                       {
+                               pCodingScheme.bMsgClassSet = true;
+
+                               switch ( dcs & 0x03 ) // bits 1 to 0 : message class
+                               {
+                                       case 0x00:
+                                               pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_0;
+                                               break;
+                                       case 0x01:
+                                               pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_1;
+                                               break;
+                                       case 0x02:
+                                               pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_2;
+                                               break;
+                                       case 0x03:
+                                               pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_3;
+                                               break;
+                                       default:
+                                               break;
+                               }
+                       }
+                       else {// bit 4 = 0 : indicates that bits 1 to 0 are reserved and have no message class meaning
+                               pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_NONE;
+                       }
+
+                       switch ( dcs & 0x0C ) // bits 4 to 3 : character set
+                       {
+                               case 0x00:
+                                       pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT;
+                                       break;
+                               case 0x04:
+                                       pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT;
+                                       break;
+                               case 0x08:
+                                       pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2;
+                                       break;
+                               case 0x0C:
+                                       pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_MAX;
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+               // bits 7..4 = 1000 ~ 1011 : reserved
+               else if (dcs == 0xC0) // bits 7..4 = 1100 : message waiting indication group, discard message
+               {
+                       pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_DISCARD;
+               }
+               else if (dcs < 0xE0)
+               {
+                       pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_STORE;
+
+                       if ((dcs & 0x08) != 0) {
+                               pCodingScheme.bMsgIndActive = true;
+                       }
+
+                       switch (dcs & 0x03)
+                       {
+                               case 0x00:
+                                       pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_VOICE_MSG;
+                                       break;
+                               case 0x01:
+                                       pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_FAX_MSG;
+                                       break;
+                               case 0x02:
+                                       pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_EMAIL_MSG;
+                                       break;
+                               case 0x03:
+                                       pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_OTHER_MSG;
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+               else if (dcs < 0xF0)
+               {
+                       pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_STORE_UCS2;
+
+                       if ((dcs & 0x08) != 0) {
+                               pCodingScheme.bMsgIndActive = true;
+                       }
+
+                       switch (dcs & 0x03)
+                       {
+                               case 0x00:
+                                       pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_VOICE_MSG;
+                                       break;
+                               case 0x01:
+                                       pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_FAX_MSG;
+                                       break;
+                               case 0x02:
+                                       pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_EMAIL_MSG;
+                                       break;
+                               case 0x03:
+                                       pCodingScheme.waitingType = EnumConstants.TAPI_NETTEXT_WAITING_OTHER_MSG;
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+               else
+               {
+                       pCodingScheme.codingGroupType = EnumConstants.TAPI_NETTEXT_CODGRP_SM_CLASS_CODING;
+
+                       if ((dcs & 0x04) != 0) {
+                               pCodingScheme.alphabetType = EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT;
+                       }
+
+                       switch (dcs & 0x03)
+                       {
+                               case 0x00:
+                                       pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_0;
+                                       break;
+                               case 0x01:
+                                       pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_1;
+                                       break;
+                               case 0x02:
+                                       pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_2;
+                                       break;
+                               case 0x03:
+                                       pCodingScheme.classType = EnumConstants.TAPI_NETTEXT_CLASS_3;
+                                       break;
+                               default:
+                                       break;
+                       }
+               }
+       }
+
+       private void SmsUtilDecodeAddrField_sca(char[] diallingNum, char[] pAddrField) {
+//             int ton, npi;
+               int index = 0;
+               int dialnumLen = 0;
+               int length = 0;
+               
+               ton = (pAddrField[index+1] & 0x70) >> 4;
+               npi = pAddrField[index+1] & 0x0F;
+               
+               if(ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) {
+                       length = pAddrField[index];
+                       if(length > 1) {
+                               dialnumLen = (pAddrField[index++] - 1) * 2;
+                       }
+               } else {
+                       dialnumLen = (((pAddrField[index++] + 1) / 2) * 8) / 7;
+               }
+
+               if(dialnumLen > EnumConstants.SIM_SMSP_ADDRESS_LEN) {
+                       dialnumLen = EnumConstants.SIM_SMSP_ADDRESS_LEN;
+               }
+               
+               // Ignore type of address field
+               index++;
+               
+               if(ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) {
+                       SmsUtilConvertBCD2Digit(diallingNum, getCharArray(pAddrField, index), dialnumLen);
+               } else {
+                       SmsUtilUnpackGSMCode(diallingNum, getCharArray(pAddrField, index), dialnumLen);
+               }
+       }
+       
+       private void SmsUtilDecodeAddrField_dst(char[] diallingNum, char[] pAddrField) {
+//             int ton, npi;
+               int index = 0;
+               int dialnumLen = 0;
+               
+               ton = (pAddrField[index+1] & 0x70) >> 4;
+               npi = pAddrField[index+1] & 0x0F;
+               
+               if(ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) {
+                       dialnumLen = pAddrField[index++];
+               } else {
+                       dialnumLen = (((pAddrField[index++] + 1) / 2) * 8) / 7;
+               }
+               if(dialnumLen > EnumConstants.SIM_SMSP_ADDRESS_LEN) {
+                       dialnumLen = EnumConstants.SIM_SMSP_ADDRESS_LEN;
+               }
+               // Ignore type of address field
+               index++;
+               
+               if(ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) {
+                       SmsUtilConvertBCD2Digit(diallingNum, getCharArray(pAddrField, index), dialnumLen);
+               } else {
+                       SmsUtilUnpackGSMCode(diallingNum, getCharArray(pAddrField, index), dialnumLen);
+               }
+               //System.out.println(diallingNum);
+       }
+       
+       private void SmsUtilConvertBCD2Digit(char[] pDigits, char[] pBCD, int digitLen) {
+               int i, bcdLen;
+               char[] c = {0x00, 0x00};
+               char higher, lower;
+               
+               if(pBCD == null || pDigits == null) {
+                       return;
+                       //throw new NullPointerException("SmsUtilConvertBCD2Digit"); //$NON-NLS-1$
+               }
+                       
+               
+               if(digitLen == 0) {
+                       pDigits[0] = 0x00;
+                       return;
+               }
+               
+               if((digitLen % 2) != 0) {
+                       bcdLen = digitLen / 2 + 1;
+               } else {
+                       bcdLen = digitLen / 2;
+               }
+               
+               for(i = 0; i < bcdLen; i++) {
+                       lower = (char)(pBCD[i] & 0x0F);
+                       
+                       if(lower == 0x0A) {
+                               lower = '*';
+                       } else if(lower == 0x0B) {
+                               lower = '#';
+                       } else if(lower == 0x0C) {
+                               lower = 'p';
+                       } else if(lower == 0x0F) {
+                               lower = 0;
+                       } else {
+                               AcItoa(lower, c, 16);
+                               lower = (char)AcToupper(c[0]);
+                       }
+                       
+                       higher = (char)((pBCD[i] >> 4) & 0x0F);
+                       
+                       if(higher == 0x0A) {
+                               higher = '*';
+                       } else if(higher == 0x0B) {
+                               higher = '#';
+                       } else if(higher == 0x0C) {
+                               higher = 'p';
+                       } else if(higher == 0x0F) {
+                               pDigits[getSize(pDigits)] = lower;
+                               pDigits[bcdLen*2-1] = '\0';
+                               return;
+                       }
+                       else {
+                               AcItoa(higher, c, 16);
+                               higher = (char)AcToupper(c[0]);
+                       }
+                       pDigits[getSize(pDigits)] = lower;
+                       pDigits[getSize(pDigits)] = higher;
+               }
+               pDigits[digitLen] = '\0';
+       }
+       
+       private int getSize(char[] array) {
+               int ret = 0;
+               String str = new String(array);
+               ret = str.indexOf('\0');
+               return ret;
+       }
+       
+       private int AcToupper(int ch) {
+               return (('a' <= (ch) && (ch) <= 'z') ? ((ch) - ('a' - 'A')) : (ch));
+       }
+       
+       private void AcItoa(int n, char[] str, int b) {
+               int i = 0;
+               String arr = new String("0123456789ABCDEF"); //$NON-NLS-1$
+               do
+                       str[i++] = arr.charAt(n%b);
+               while((n /= b) > 0);
+               reverse(str, i);
+               str[i] = '\0';
+       }
+       
+       private void reverse(char[] x, int len) {
+               int i, j = len-1;
+               for(i = 0; i < j; i++) {
+                       char t = x[i];
+                       x[i] = x[j];
+                       x[j--] = t;
+               }
+       }
+       
+       private void SmsUtilUnpackGSMCode(char[] szData, char[] pIn, int in_len) {
+               int shift = 0;
+               int pos = 0;
+               
+               for(int i = 0; i < in_len; i++, pos++) {
+                       szData[i] = (char)((pIn[pos] << shift) & 0x7F);
+                       if(pos != 0) {
+                               /* except the first byte, a character contains some bits
+                                * from the previous byte
+                                */
+                               szData[i] |= pIn[pos-1] >> (8-shift);
+                       }
+                       shift++;
+                       
+                       if(shift == 7) {
+                               shift = 0;
+                               /* a possible extra complete character is available */
+                               i++;
+                               szData[i] = (char)(pIn[pos] >> 1);
+                               /* This is the end of the input, quit */
+                               if(szData[i] == 0) {
+                                       break;
+                               }
+                       }
+               }
+       }
+       
+       public char[] ucs2ToUTF16(byte[] ucs2Bytes, int length) throws UnsupportedEncodingException{    
+               String unicode = new String(ucs2Bytes, "UTF-16");
+               char[] str = unicode.toCharArray();
+               
+               String tmp1 = new String(smsbuffer);
+               String tmp2 = unicode.substring(0, length);
+               String tmp3 = tmp1.trim() + tmp2.trim();
+               smsbuffer = tmp3.toCharArray();
+
+               return str;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/encription/EncodeMsg.java b/ei-library/src/org/tizen/eilib/modem/encription/EncodeMsg.java
new file mode 100644 (file)
index 0000000..29b3c9d
--- /dev/null
@@ -0,0 +1,578 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.encription;
+
+public class EncodeMsg {
+       int index;
+
+       public int EncodeSmsDeliverTpdu(SmsAddressInfo SCA,
+                       TPDU_SMS_DELIVER tpdu_deliver, char[] packet, int pid, int dcs) {
+               // char tp_dcs; // BYTE
+               char[] timeStamp = new char[21];
+               char[] scaNumber = new char[21];
+               char[] orgNumber = new char[21];
+               int scaLength;
+               int orgLength;
+               int i;
+
+               index = 0;
+
+               if (SCA.diallingNum[0] == '+') {
+                       SCA.ton = 1;
+                       SCA.npi = 1;
+                       for (i = 0; i < SCA.dialnumlen-1; i++) {
+                               scaNumber[i] = SCA.diallingNum[i + 1];
+                       }
+                       scaLength = SCA.dialnumlen - 1;
+                       scaNumber[scaLength] = '\0';
+               } else {
+                       SCA.ton = 0;
+                       SCA.npi = 0;
+                       for (i = 0; i < SCA.dialnumlen; i++) {
+                               scaNumber[i] = SCA.diallingNum[i];
+                       }
+                       scaLength = SCA.dialnumlen;
+                       scaNumber[scaLength] = '\0';
+               }
+
+               SmsUtilEncodeAddrField_sca(packet, scaNumber, scaLength, SCA.ton, SCA.npi);
+
+               tpdu_deliver.msgType = EnumConstants.SMS_TPDU_DELIVER;
+
+               packet[index] = (char) tpdu_deliver.msgType;
+               packet[index] |= tpdu_deliver.mms ? 0x04 : 0;
+               packet[index] |= tpdu_deliver.sri ? 0x20 : 0;
+               packet[index] |= tpdu_deliver.udhi ? 0x40 : 0;
+               packet[index] |= tpdu_deliver.rp ? 0x80 : 0;
+
+               index++;
+               
+               if (tpdu_deliver.orgAddr.diallingNum[0] == '+') {
+                       tpdu_deliver.orgAddr.ton = 1;
+                       tpdu_deliver.orgAddr.npi = 1;
+                       for (i = 0; i < tpdu_deliver.orgAddr.dialnumlen-1; i++) {
+                               orgNumber[i] = tpdu_deliver.orgAddr.diallingNum[i + 1];
+                       }
+                       orgLength = tpdu_deliver.orgAddr.dialnumlen - 1;
+                       orgNumber[orgLength] = '\0';
+               } else {
+                       tpdu_deliver.orgAddr.ton = 0;
+                       tpdu_deliver.orgAddr.npi = 0;
+                       for (i = 0; i < tpdu_deliver.orgAddr.dialnumlen; i++) {
+                               orgNumber[i] = tpdu_deliver.orgAddr.diallingNum[i];
+                       }
+                       orgLength = tpdu_deliver.orgAddr.dialnumlen;
+                       orgNumber[orgLength] = '\0';
+               }
+
+               /* TP-OA */
+               SmsUtilEncodeAddrField_dst(packet, orgNumber, orgLength, tpdu_deliver.orgAddr.ton, tpdu_deliver.orgAddr.npi);
+
+               /* TP-PID */
+               packet[index++] = (char) pid;
+
+               int tp_dcs = SmsUtilEncodeDCS(tpdu_deliver.dcs);
+
+               packet[index++] = (char) tp_dcs;
+
+               SmsUtilEncodeTimeStamp(tpdu_deliver.scts, timeStamp);
+
+               for (i = 0; i < 7; i++) {
+                       packet[index++] = timeStamp[i];
+               }
+
+               /* TP-UD */
+               switch(tpdu_deliver.dcs.alphabetType) {
+                       case EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT:
+                               /* UDL */
+                               packet[index++] = (char) tpdu_deliver.userData.data.length;
+                               SmsUtilPackGSMCode(packet, new String(tpdu_deliver.userData.data).toCharArray(),
+                                               tpdu_deliver.userData.data.length);
+                               break;
+                       case EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT:
+                               packet[index++] = (char) tpdu_deliver.userData.data.length;
+                               SmsUtilPackGSM8Code(packet, new String(tpdu_deliver.userData.data).toCharArray(),
+                                               tpdu_deliver.userData.data.length);
+                               break;
+                       case EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2:
+                               int udhl                = 0;
+                               int fillBits    = 0;
+                               int tempIndex   = index;
+
+                               if (tpdu_deliver.userData.headerCnt > 0) {
+                                       index = index + 2;
+                               } else {
+                                       index = index + 1;
+                               }
+
+                               // setting HEADER
+                               int headerLen   = 6;
+                               for (i = 0; i < tpdu_deliver.userData.headerCnt; i++)
+                               {
+                                       packet[index++] = 0x08; // SMS_UDH_CONCAT_16BIT;
+                                       packet[index++] = 0x04; // offset
+                                       packet[index++] = (char)(tpdu_deliver.userData.smsUDH.msgRef >> 8);
+                                       packet[index++] = (char)(tpdu_deliver.userData.smsUDH.msgRef & 0x00FF);
+                                       packet[index++] = tpdu_deliver.userData.smsUDH.totalSeg;
+                                       packet[index++] = tpdu_deliver.userData.smsUDH.seqNum;
+                                       udhl += headerLen;
+                               }
+
+                               if (udhl > 0) {
+                                       packet[tempIndex]        = (char)((udhl+1) + fillBits + tpdu_deliver.userData.length);
+                                       packet[tempIndex+ 1] = (char)udhl;
+                               } else {
+                                       packet[tempIndex]       = (char)(tpdu_deliver.userData.length);
+                               }
+
+                               for(int ind = 0; ind < tpdu_deliver.userData.length; ind++) {
+                                       packet[index++] = (char)tpdu_deliver.userData.data[ind];
+                               }
+                               break;
+                       //      throw new NullPointerException(Messages.EncodeMsg_0);
+                       default:
+                               //throw new NullPointerException("Unknown alphabetType UCS2!\n");
+                               break;
+               }
+
+               return index;
+       }
+
+       private void SmsUtilPackGSMCode(char[] pOut, char[] szData, int in_len) {
+               int shift = 0;
+
+               for (int i = 0; i < in_len; index++, i++) {
+                       /* pack the high bits using the low bits of the next character */
+                       pOut[index] = (char) (szData[i] >> shift);
+                       if (i + 1 < in_len) {
+                               /* pack the high bits using the low bits of the next character */
+                               pOut[index] |= szData[i + 1] << (7 - shift);
+                               pOut[index] &= 0xFF;
+                               shift++;
+
+                               if (shift == 7) {
+                                       shift = 0;
+                                       i++;
+                               }
+                       }
+               }
+       }
+
+       private void SmsUtilPackGSM8Code(char[] pOut, char[] szData, int in_len) {
+               for(int i = 0; i < in_len; i++) {
+                       pOut[index++] = szData[i];
+               }
+       }
+       
+       private void SmsUtilEncodeTimeStamp(TmDateTime tmDateTime, char[] timeStamp) {
+               char[] szBuf = null;
+               char[] tmpBuf = new char[20];
+               int year;
+
+               for (int i = 0; i < 7; i++) {
+                       timeStamp[i] = 0x00;
+               }
+
+               year = tmDateTime.year - 2000;
+               if (year < 0) {
+                       year += 100;
+               }
+
+               szBuf = String.format("%02d", year).toCharArray(); //$NON-NLS-1$
+               SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2);
+               timeStamp[0] = tmpBuf[0];
+               szBuf = String.format("%02d", tmDateTime.month).toCharArray(); //$NON-NLS-1$
+               SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2);
+               timeStamp[1] = tmpBuf[0];
+               szBuf = String.format("%02d", tmDateTime.day).toCharArray(); //$NON-NLS-1$
+               SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2);
+               timeStamp[2] = tmpBuf[0];
+               szBuf = String.format("%02d", tmDateTime.hour).toCharArray(); //$NON-NLS-1$
+               SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2);
+               timeStamp[3] = tmpBuf[0];
+               szBuf = String.format("%02d", tmDateTime.minute).toCharArray(); //$NON-NLS-1$
+               SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2);
+               timeStamp[4] = tmpBuf[0];
+               szBuf = String.format("%02d", tmDateTime.second).toCharArray(); //$NON-NLS-1$
+               SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2);
+               timeStamp[5] = tmpBuf[0];
+               szBuf = String.format("%02d", 0x00).toCharArray(); //$NON-NLS-1$
+               SmsUtilConvertDigit2BCD(tmpBuf, szBuf, 2);
+               timeStamp[6] = tmpBuf[0];
+       }
+
+       private char SmsUtilEncodeDCS(TapiNetTextCodingScheme codingScheme) {
+               char dcs = 0x00;
+
+               switch (codingScheme.codingGroupType) {
+               case EnumConstants.TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS: // bit 7..4 is
+                                                                                                                               // 00xx
+               {
+                       if (codingScheme.bCompressed) {
+                               dcs |= 0x20; // bit 5 is 1
+                       }
+
+                       if (codingScheme.bMsgClassSet) {
+                               dcs |= 0x10; // bit 4 is 1
+
+                               switch (codingScheme.classType) {
+                               case EnumConstants.TAPI_NETTEXT_CLASS_0: // bit 1..0 is 00
+                               {
+                                       dcs |= 0x00;
+                                       break;
+                               }
+                               case EnumConstants.TAPI_NETTEXT_CLASS_1: // bit 1..0 is 01
+                               {
+                                       dcs |= 0x01;
+                                       break;
+                               }
+                               case EnumConstants.TAPI_NETTEXT_CLASS_2: // bit 1..0 is 10
+                               {
+                                       dcs |= 0x02;
+                                       break;
+                               }
+                               case EnumConstants.TAPI_NETTEXT_CLASS_3: // bit 1..0 is 11
+                               {
+                                       dcs |= 0x03;
+                                       break;
+                               }
+                               default:
+                                       break;
+                               }
+                       }
+
+                       switch (codingScheme.alphabetType) {
+                       case EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT: // bit 3..2 is 00
+                       {
+                               dcs |= 0x00;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT: // bit 3..2 is 01
+                       {
+                               dcs |= 0x04;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_ALPHABET_UCS2: // bit 3..2 is 10
+                       {
+                               dcs |= 0x08;
+                               break;
+                       }
+                       default: // bit 3..2 is 11
+                       {
+                               dcs |= 0x0C;
+                               break;
+                       }
+                       }
+
+                       break;
+               }
+               case EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_DISCARD: // bit 7..4
+                                                                                                                                       // is 1100
+               {
+                       dcs |= 0xC0;
+
+                       break;
+               }
+               case EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_STORE: // bit 7..4 is
+                                                                                                                                       // 1101
+               {
+                       dcs |= 0xD0;
+
+                       if (codingScheme.bMsgIndActive) {// bit 3..2 is 10
+                               dcs |= 0x08;
+                       }
+
+                       switch (codingScheme.waitingType) {
+                       case EnumConstants.TAPI_NETTEXT_WAITING_VOICE_MSG: // bit 1..0 is 00
+                       {
+                               dcs |= 0x00;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_WAITING_FAX_MSG: // bit 1..0 is 01
+                       {
+                               dcs |= 0x01;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_WAITING_EMAIL_MSG: // bit 1..0 is 10
+                       {
+                               dcs |= 0x02;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_WAITING_OTHER_MSG: // bit 1..0 is 11
+                       {
+                               dcs |= 0x03;
+                               break;
+                       }
+                       default:
+                               break;
+                       }
+
+                       break;
+               }
+               case EnumConstants.TAPI_NETTEXT_CODGRP_SM_WAITING_STORE_UCS2: // bit
+                                                                                                                                               // 7..4
+                                                                                                                                               // is
+                                                                                                                                               // 1110
+               {
+                       dcs |= 0xE0;
+
+                       if (codingScheme.bMsgIndActive) {// bit 3..2 is 10
+                               dcs |= 0x08;
+                       }
+
+                       switch (codingScheme.waitingType) {
+                       case EnumConstants.TAPI_NETTEXT_WAITING_VOICE_MSG: // bit 1..0 is 00
+                       {
+                               dcs |= 0x00;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_WAITING_FAX_MSG: // bit 1..0 is 01
+                       {
+                               dcs |= 0x01;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_WAITING_EMAIL_MSG: // bit 1..0 is 10
+                       {
+                               dcs |= 0x02;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_WAITING_OTHER_MSG: // bit 1..0 is 11
+                       {
+                               dcs |= 0x03;
+                               break;
+                       }
+                       default:
+                               break;
+                       }
+
+                       break;
+               }
+               case EnumConstants.TAPI_NETTEXT_CODGRP_SM_CLASS_CODING: // bit 7..4 is
+                                                                                                                               // 1111
+               {
+                       dcs |= 0xF0;
+
+                       switch (codingScheme.alphabetType) {
+                       case EnumConstants.TAPI_NETTEXT_ALPHABET_DEFAULT: // bit 2 is 0
+                       {
+                               dcs |= 0x00;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_ALPHABET_8BIT: // bit 2 is 1
+                       {
+                               dcs |= 0x04;
+                               break;
+                       }
+                       default:
+                               break;
+                       }
+
+                       switch (codingScheme.classType) {
+                       case EnumConstants.TAPI_NETTEXT_CLASS_0: // bit 1..0 is 00
+                       {
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_CLASS_1: // bit 1..0 is 01
+                       {
+                               dcs |= 0x01;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_CLASS_2: // bit 1..0 is 10
+                       {
+                               dcs |= 0x02;
+                               break;
+                       }
+                       case EnumConstants.TAPI_NETTEXT_CLASS_3: // bit 1..0 is 11
+                       {
+                               dcs |= 0x03;
+                               break;
+                       }
+                       default:
+                               break;
+                       }
+
+                       break;
+               }
+               case EnumConstants.TAPI_NETTEXT_CODGRP_SM_RESERVED: // bit 7..4 is 1111
+               {
+                       dcs = (char) ((codingScheme.codingGroup << 4) & 0xF0);
+                       dcs |= (codingScheme.code & 0x0F);
+                       break;
+               }
+               default:
+                       break;
+               }
+               return dcs;
+       }
+       
+       private void SmsUtilEncodeAddrField_sca(char[] pAddrField, char[] diallingNum,
+                       int dialnumLen, int ton, int npi) {
+//             int index = 0;
+               
+               if (pAddrField == null || diallingNum == null) {
+                       return;
+                       //throw new NullPointerException("SmsUtilEncodeAddrField"); //$NON-NLS-1$
+               }
+
+               if (ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) {
+                       if((dialnumLen % 2) != 0) {
+                               pAddrField[index++] = (char)(dialnumLen / 2 + 1 + 1);
+                       } else {
+                               pAddrField[index++] = (char)(dialnumLen / 2 + 1);
+                       }
+               } else {
+                       pAddrField[index] = (char) (((dialnumLen * 7 + 7) / 8) * 2);
+                       if (((dialnumLen * 7) % 8) <= 4) {
+                               pAddrField[index]--;
+                       }
+                       index++;
+               }
+
+               // SET_TON_NPI
+               pAddrField[index] = 0x80;
+               pAddrField[index] |= (ton & 0x07) << 4;
+               pAddrField[index] |= npi & 0x0F;
+
+               index++;
+
+               if (ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) {
+                       int i, j, k;
+                       char[] tmpBuf = new char[dialnumLen];
+                       SmsUtilConvertDigit2BCD(tmpBuf, diallingNum, dialnumLen);
+                       j = index;
+                       
+                       if((dialnumLen % 2) != 0) {
+                               index += dialnumLen / 2 + 1;
+                       }
+                       else {
+                               index += dialnumLen / 2;
+                       }
+
+                       for(i = j, k = 0; i < index; i++, k++) {
+                               pAddrField[i] = tmpBuf[k];
+                       }
+               } else {
+                       SmsUtilPackGSMCode(pAddrField, diallingNum, (int) dialnumLen);
+               }
+       }
+       
+       private void SmsUtilEncodeAddrField_dst(char[] packet, char[] diallingNum,
+                       int dialnumLen, int ton, int npi) {
+//             int index = 0;
+               
+               if (packet == null || diallingNum == null) {
+                       return;
+                       //throw new NullPointerException("SmsUtilEncodeAddrField"); //$NON-NLS-1$
+               }
+
+               if (ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) {
+                       packet[index++] = (char) dialnumLen;
+               } else {
+                       packet[index] = (char) (((dialnumLen * 7 + 7) / 8) * 2);
+                       if (((dialnumLen * 7) % 8) <= 4) {
+                               packet[index]--;
+                       }
+                       index++;
+               }
+
+               // SET_TON_NPI
+               packet[index] = 0x80;
+               packet[index] |= (ton & 0x07) << 4;
+               packet[index] |= npi & 0x0F;
+
+               index++;
+
+               if (ton != EnumConstants.SIM_TON_ALPHA_NUMERIC) {
+                       int i, j, k;
+                       char[] tmpBuf = new char[dialnumLen];
+                       for (i = 0; i < dialnumLen; i++) {
+                               tmpBuf[i] = 0x00;
+                       }
+
+                       SmsUtilConvertDigit2BCD(tmpBuf, diallingNum, dialnumLen);
+                       j = index;
+
+                       if ((dialnumLen % 2) != 0) {
+                               index += dialnumLen / 2 + 1;
+                       } else {
+                               index += dialnumLen / 2;
+                       }
+                       for (i = j, k = 0; i < index; i++, k++) {
+                               packet[i] = tmpBuf[k];
+                       }
+               } else {
+                       SmsUtilPackGSMCode(packet, diallingNum, (int) dialnumLen);
+               }
+       }
+
+       private void SmsUtilConvertDigit2BCD(char[] pBCD, char[] pDigits,
+                       long digitLen) {
+               int i, j, digit;
+               char higher, lower;
+
+               if (pBCD == null || pDigits == null) {
+                       return;
+                       //throw new NullPointerException("SmsUtilConvertDigit2BCD"); //$NON-NLS-1$
+               }
+
+               for (i = 0, j = 0; i < digitLen; i = i + 2, j++) {
+                       if (pDigits[i] == '*') {
+                               digit = 0x0A;
+                       } else if (pDigits[i] == '#') {
+                               digit = 0x0B;
+                       } else if (AcToupper(pDigits[i]) == 'P') {
+                               digit = 0x0C;
+                       } else {
+                               digit = (int) (pDigits[i] - '0');
+                       }
+
+                       lower = (char) (digit & 0x0F);
+
+                       if (digitLen != i + 1) {
+                               if (pDigits[i + 1] == '*') {
+                                       digit = 0x0A;
+                               } else if (pDigits[i + 1] == '#') {
+                                       digit = 0x0B;
+                               } else if (AcToupper(pDigits[i + 1]) == 'P') {
+                                       digit = 0x0C;
+                               } else {
+                                       digit = (int) (pDigits[i + 1] - '0');
+                               }       
+
+                               higher = (char) (digit & 0x0F);
+                       } else {
+                               higher = 0xFF;
+                       }
+                       pBCD[j] = (char) ((higher << 4) | lower);
+                       pBCD[j] &= 0xFF;
+               }
+       }
+
+       private int AcToupper(int ch) {
+               return (('a' <= (ch) && (ch) <= 'z') ? ((ch) - ('a' - 'A')) : (ch));
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/encription/EnumConstants.java b/ei-library/src/org/tizen/eilib/modem/encription/EnumConstants.java
new file mode 100644 (file)
index 0000000..36ae9b8
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.encription;
+
+public class EnumConstants {
+       // SmsTPDUType
+       public static final int SMS_TPDU_DELIVER = 0x00;
+       public static final int SMS_TPDU_DELIVER_REPORT = 0x00;
+       public static final int SMS_TPDU_SUBMIT = 0x01;
+       public static final int SMS_TPDU_SUBMIT_REPORT = 0x01;
+       public static final int SMS_TPDU_STATUS_REPORT = 0x02;
+       public static final int SMS_TPDU_COMMAND = 0x02;
+       public static final int SMS_PDU_INVALID_TYPE = 0x03;
+       
+       // NumberingPlan
+       public static final int NUMBERING_PLAN_IDENTIFICATION_UNKNOWN = 0x00;
+       public static final int NUMBERING_PLAN_IDENTIFICATIN_ISDN_TELEPHONE = 0x01;
+
+       // TapiNetTextCodingGroupType
+       public static final int TAPI_NETTEXT_CODGRP_SM_GENERAL_DCS = 0x00;
+       public static final int TAPI_NETTEXT_CODGRP_CB_GENERAL_LANG = 0x01;
+       public static final int TAPI_NETTEXT_CODGRP_CB_ALPHA = 0x02;
+       public static final int TAPI_NETTEXT_CODGRP_CB_RES1 = 0x03;
+       public static final int TAPI_NETTEXT_CODGRP_CB_RES2 = 0x04;
+       public static final int TAPI_NETTEXT_CODGRP_SM_AUTO_DELETION = 0x05;
+       public static final int TAPI_NETTEXT_CODGRP_CB_GENERAL_DCS = 0x06;
+       public static final int TAPI_NETTEXT_CODGRP_SM_WAITING_DISCARD = 0x07;
+       public static final int TAPI_NETTEXT_CODGRP_SM_WAITING_STORE = 0x08;
+       public static final int TAPI_NETTEXT_CODGRP_SM_WAITING_STORE_UCS2 = 0x09;
+       public static final int TAPI_NETTEXT_CODGRP_CB_WAP = 0x0A;
+       public static final int TAPI_NETTEXT_CODGRP_SM_CLASS_CODING = 0x0B;
+       public static final int TAPI_NETTEXT_CODGRP_CB_CLASS_CODING = 0x0C;
+       public static final int TAPI_NETTEXT_CODGRP_SM_RESERVED = 0x0D;
+       public static final int TAPI_NETTEXT_CODGRP_MAX = 0x0E;
+       
+       // TapiNetTextWaitingType
+       public static final int TAPI_NETTEXT_WAITING_VOICE_MSG = 0x00;
+       public static final int TAPI_NETTEXT_WAITING_FAX_MSG = 0x01;
+       public static final int TAPI_NETTEXT_WAITING_EMAIL_MSG = 0x02;
+       public static final int TAPI_NETTEXT_WAITING_OTHER_MSG = 0x03;
+       public static final int TAPI_NETTEXT_WAITING_MAX = 0x04;
+       
+       // TapiNetTextAlphabetType
+       public static final int TAPI_NETTEXT_ALPHABET_DEFAULT = 0x00;
+       public static final int TAPI_NETTEXT_ALPHABET_8BIT = 0x01;
+       public static final int TAPI_NETTEXT_ALPHABET_UCS2 = 0x02;
+       public static final int TAPI_NETTEXT_ALPHABET_KSC5601 = 0x03;
+       public static final int TAPI_NETTEXT_ALPHABET_MAX = 0x04;
+       
+       // TapiNetTextClasstype
+       public static final int TAPI_NETTEXT_CLASS_0 = 0x00;
+       public static final int TAPI_NETTEXT_CLASS_1 = 0x01;
+       public static final int TAPI_NETTEXT_CLASS_2 = 0x02;
+       public static final int TAPI_NETTEXT_CLASS_3 = 0x03;
+       public static final int TAPI_NETTEXT_CLASS_NONE = 0x04;
+       public static final int TAPI_NETTEXT_CLASS_MAX = 0x05;
+       
+       // TapiNetTextVPType
+       public static final int TAPI_NETTEXT_VP_NOT_USED = 0;
+       public static final int TAPI_NETTEXT_VP_RELATIVE = 2;
+       public static final int TAPI_NETTEXT_VP_ABSOLUTE = 3;
+       public static final int TAPI_NETTEXT_VP_ENHANCED = 1;
+       public static final int TAPI_NETTEXT_VP_MAX = 4;
+       
+       // TapiNetTextVPRelValue;
+       public static final int TAPI_NETTEXT_VP_REL_1H = 0;
+       public static final int TAPI_NETTEXT_VP_REL_6H = 1;
+       public static final int TAPI_NETTEXT_VP_REL_12H = 2;
+       public static final int TAPI_NETTEXT_VP_REL_1D = 3;
+       public static final int TAPI_NETTEXT_VP_REL_1W = 4;
+       public static final int TAPI_NETTEXT_VP_REL_1M = 5;
+       public static final int TAPI_NETTEXT_VP_REL_MAX = 6;
+       public static final int TAPI_NETTEXT_SMDATA_SIZE_MAX = 255;
+       public static final int TAPI_NETTEXT_ADDRESS_LEN_MAX = 255;
+       public static final int TAPI_NETTEXT_SCADDRESS_LEN_MAX = 20;
+       
+       // define
+       public static final int SIM_TON_INTERNATIONAL = 1;
+       public static final int SIM_TON_ALPHA_NUMERIC = 5;
+       public static final int SIM_SMSP_ADDRESS_LEN = 20;
+
+
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/encription/SMS_USERDATA.java b/ei-library/src/org/tizen/eilib/modem/encription/SMS_USERDATA.java
new file mode 100644 (file)
index 0000000..da0014f
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.encription;
+
+public class SMS_USERDATA {
+       public SMS_USERDATA() {
+               smsUDH = new SMS_UDH();
+       }
+       public void setSMSUDH(char type, short ref, char seg, char num)
+       {
+               smsUDH.udhType = type;
+               smsUDH.msgRef = ref;
+               smsUDH.totalSeg = seg;
+               smsUDH.seqNum = num;
+       }
+       public int headerCnt;
+       public SMS_UDH smsUDH;
+       public int length;
+       public byte[] data;
+}
+class SMS_UDH {
+       public char udhType;
+       public short msgRef;
+       public char totalSeg;
+       public char seqNum;
+}
\ No newline at end of file
diff --git a/ei-library/src/org/tizen/eilib/modem/encription/SmsAddressInfo.java b/ei-library/src/org/tizen/eilib/modem/encription/SmsAddressInfo.java
new file mode 100644 (file)
index 0000000..cf43ee2
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.encription;
+
+public class SmsAddressInfo {
+       public int ton;         // NumberType
+        public int npi;                // NumberingPlan
+        public int dialnumlen; // UINT32
+        public char diallingNum[] = new char[21];  // unsigned char
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_DELIVER.java b/ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_DELIVER.java
new file mode 100644 (file)
index 0000000..be66976
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.encription;
+
+public class TPDU_SMS_DELIVER {
+       public int msgType;    // SmsTPDUType
+       public boolean mms;     // BOOL
+       public boolean rp;      // BOOL
+       public boolean udhi;    // BOOL
+       public boolean sri;     // BOOL
+       
+       public SmsAddressInfo orgAddr;
+       public byte pId;         // BYTE
+       public TmDateTime scts;
+       public TapiNetTextCodingScheme dcs;
+       public int udl;    // UINT
+       //public char[] userData; // byte *
+       public SMS_USERDATA userData;
+       public TPDU_SMS_DELIVER() {
+               orgAddr = new SmsAddressInfo();
+               scts = new TmDateTime();
+               dcs = new TapiNetTextCodingScheme();
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_SUBMIT.java b/ei-library/src/org/tizen/eilib/modem/encription/TPDU_SMS_SUBMIT.java
new file mode 100644 (file)
index 0000000..a570015
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.eilib.modem.encription;
+
+public class TPDU_SMS_SUBMIT {
+       // message type
+       int msgType;  // SmsTPDUType bit 0,1
+       
+       // reject duplicates
+       boolean rd;  // bit 2
+       
+       // validity period format
+       int vpf; // TapiNetTextVPType bits 3,4
+       
+       // reply path
+       boolean rp;  // bit 7
+       
+       // user data header indication
+       boolean udhi;  // bit 6
+       
+       // status report request
+       boolean srr;  // bit 5
+       
+       /******  BODY *******/
+       //message reference
+       int mr;
+       
+       // destination address
+       public SmsAddressInfo destAddr;
+       
+       // protocol identifier
+       char pId;
+       
+       //data coding scheme
+       TapiNetTextCodingScheme dcs;
+       
+       // validity period
+       TapiNetTextVP vp;
+       
+       // user data length
+       public int udl;
+       
+       // user data
+       public char[] userData;
+       
+       public TPDU_SMS_SUBMIT() {
+               dcs = new TapiNetTextCodingScheme();
+               destAddr = new SmsAddressInfo();
+               vp = new TapiNetTextVP();
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextCodingScheme.java b/ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextCodingScheme.java
new file mode 100644 (file)
index 0000000..adc487c
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.encription;
+
+public class TapiNetTextCodingScheme {
+       public boolean bSMSCinSIM;              /**< if SMSC is stored in SIM this is TRUE */
+       public boolean bCompressed;             /**< if text is compressed this is TRUE */
+       public boolean bMsgClassSet;    /**< message class indication. if TRUE = bits 1..0, if FALSE = reserved */
+       public boolean bMsgIndActive;   /**< message indication group. if TRUE = on, FALSE = off */
+       public int codingGroupType;  // TapiNetTextCodingGroupType
+       public int waitingType;      // TapiNetTextWaitingType
+       public int alphabetType;     // TapiNetTextAlphabetType
+       public int classType;        // TapiNetTextClassType
+       public byte codingGroup;
+       public byte code;
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextVP.java b/ei-library/src/org/tizen/eilib/modem/encription/TapiNetTextVP.java
new file mode 100644 (file)
index 0000000..5844421
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.encription;
+
+public class TapiNetTextVP {
+       int vpType;  // TapiNetTextVPType
+       int vpRelativeType; // TapiNetVPRelValue
+       long vpValue;  // UINT32
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/encription/TmDateTime.java b/ei-library/src/org/tizen/eilib/modem/encription/TmDateTime.java
new file mode 100644 (file)
index 0000000..b233c2a
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.encription;
+
+public class TmDateTime {
+       public int year;
+       public int month;
+       public int day;
+       public int hour;
+       public int minute;
+       public int second;
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/AbstractGA.java b/ei-library/src/org/tizen/eilib/modem/protocol/AbstractGA.java
new file mode 100644 (file)
index 0000000..0635680
--- /dev/null
@@ -0,0 +1,213 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+import java.nio.ByteBuffer;
+
+import org.tizen.eilib.connection.message.EventMessage;
+
+
+abstract public class AbstractGA {
+
+       private static final int SINGLE_ROW_INDEX = 0;
+
+       private int groupId;
+       private int actionId;
+       private int length = 0;
+       private StructureGA header;
+       private StructureGA body;
+
+       public AbstractGA(int groupId, int actionId) {
+               this.groupId = groupId;
+               this.actionId = actionId;
+       }
+
+       abstract protected void makeBody();
+
+       abstract protected void makeHeader();
+
+       public void intialize() {
+               header = new StructureGA();
+               makeHeader();
+               body = new StructureGA();
+               makeBody();
+       }
+
+       public void intialize(ByteBuffer packet) {
+               AbstractItem item = null;
+               length = packet.position();
+               if (length == 0) {
+                       intialize();
+                       return;
+               }
+
+               packet.clear();
+
+               header = new StructureGA();
+               makeHeader();
+               for (int j = 0; j < header.getItemCount(); j++) {
+                       item = header.getItem(j);
+                       putBufferToItem(item, SINGLE_ROW_INDEX, packet);
+               }
+
+               body = new StructureGA();
+               makeBody();
+
+               int loopCount = getLoopCount();
+               body.setLoopCount(loopCount);
+
+               for (int i = 0; i < loopCount; i++) {
+                       for (int j = 0; j < body.getItemCount(); j++) {
+                               item = body.getItem(j);
+                               putBufferToItem(item, i, packet);
+                       }
+               }
+       }
+
+       private int getLoopCount() {
+               return (int) Math.ceil((double) (length - header.getByteLength())
+                               / body.getByteLength());
+       }
+
+       public void makeStarterPacket(EventMessage message) {
+               int byteLength = (short)getSendLength();
+
+               ByteBuffer buffer = message.getHeaderBuffer();
+               buffer.clear();
+               buffer.putShort((short)byteLength);
+               buffer.put(((Integer) groupId).byteValue());
+               buffer.put(((Integer) actionId).byteValue());
+       }
+
+       public void makePacket(EventMessage message) {
+               ByteBuffer buffer = message.getDataBuffer();
+               buffer.clear();
+
+               AbstractItem item = null;
+               for (int j = 0; j < header.getItemCount(); j++) {
+                       item = header.getItem(j);
+                       putItemToBuffer(item, SINGLE_ROW_INDEX, buffer);
+               }
+
+               for (int i = 0; i < body.getLoopCount(); i++) {
+                       for (int j = 0; j < body.getItemCount(); j++) {
+                               item = body.getItem(j);
+                               putItemToBuffer(item, i, buffer);
+                       }
+               }
+       }
+
+       private void putItemToBuffer(AbstractItem item, int idx, ByteBuffer buffer) {
+               ItemType type = item.getType();
+               if (type == ItemType.BYTE) {
+                       buffer.put(getIntValue(item, idx).byteValue());
+               } else if (type == ItemType.SHORT) {
+                       buffer.putShort(getIntValue(item, idx).shortValue());
+               } else if (type == ItemType.INT) {
+                       buffer.putInt(getIntValue(item, idx));
+               } else if (type == ItemType.ByteArray) {
+                       if (item instanceof ByteArrayItem) {
+                               byte[] buf = ((ByteArrayItem) item).getValue(idx);
+                               int length = item.getByteLength();
+                               int pos = buffer.position();
+       
+                               if (buf.length > length) {
+                                       buffer.put(buf, 0, length);
+                               } else {
+                                       buffer.put(buf);
+                               }
+       
+                               buffer.position(pos + length);
+                       }
+               }
+       }
+
+       private Integer getIntValue(AbstractItem item, int idx) {
+               if (item instanceof IntItem) {
+                       return ((IntItem) item).getValue(idx);
+               } else {
+                       return null;
+               }
+       }
+
+       private void putBufferToItem(AbstractItem item, int idx, ByteBuffer buffer) {
+               ItemType type = item.getType();
+               if (type == ItemType.BYTE) {
+                       if (item instanceof IntItem) {
+                               ((IntItem) item).setValue(idx, buffer.get() & 0xff);
+                       }
+               } else if (type == ItemType.SHORT) {
+                       if (item instanceof IntItem) {
+                               ((IntItem) item).setValue(idx, buffer.getShort());
+                       }
+               } else if (type == ItemType.INT) {
+                       if (item instanceof IntItem) {
+                               ((IntItem) item).setValue(idx, buffer.getInt());
+                       }
+               } else if (type == ItemType.ByteArray) {
+                       int length = item.getByteLength();
+                       int remain = buffer.remaining();
+
+                       byte[] buf = null;
+                       if (length > remain) {
+                               buf = new byte[remain];
+                       } else {
+                               if(item.getName() == "CALL_NUMBER") {
+                                       buf = new byte[remain];
+                               } else {
+                                       buf = new byte[length];
+                               }
+                       }
+
+                       buffer.get(buf, 0, buf.length);
+                       if (item instanceof ByteArrayItem) {
+                               ((ByteArrayItem) item).setValue(idx, buf);
+                       }
+               }
+       }
+
+       public String getKey() {
+               return StringUtil.makeKey(groupId, actionId);
+       }
+
+       public int getSendLength() {
+               return header.getByteLength() + body.getByteLength()
+                               * body.getLoopCount();
+       }
+
+       public int getReceiveLength() {
+               return this.length;
+       }
+
+       public StructureGA getBody() {
+               return body;
+       }
+
+       public StructureGA getHeader() {
+               return header;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/AbstractItem.java b/ei-library/src/org/tizen/eilib/modem/protocol/AbstractItem.java
new file mode 100644 (file)
index 0000000..dbbd7e2
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.eilib.modem.protocol;
+
+public class AbstractItem {
+       private ItemType type;
+       private int length;
+       private String name;
+       
+       
+       public AbstractItem(ItemType type, String name, int length){
+//             if(this.type!=ItemType.CHAR)
+//                     throw new InvalidTypeException("CHAR type should be created by the constructor,  IntItem(ItemType type, String name, int length)");
+               this.type = type;
+               this.name = name;
+               this.length = length;
+       }
+       
+       public ItemType getType() {
+               return type;
+       }
+       
+       public int getByteLength() {
+               return length;
+       }
+       
+       public String getName() {
+               return name;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/ByteArrayItem.java b/ei-library/src/org/tizen/eilib/modem/protocol/ByteArrayItem.java
new file mode 100644 (file)
index 0000000..bd3a556
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+import java.util.ArrayList;
+
+public class ByteArrayItem extends AbstractItem {
+       private ArrayList<byte[]> value;
+
+       public ByteArrayItem(ItemType type, String name, int length) {
+               super(type, name, length);
+               this.value = new ArrayList<byte[]>();
+       }
+
+       public void setValue(int idx, byte[] value) {
+               this.value.add(value);
+       }
+
+       public byte[] getValue(int idx) {
+               return this.value.get(idx);
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/ByteUtil.java b/ei-library/src/org/tizen/eilib/modem/protocol/ByteUtil.java
new file mode 100644 (file)
index 0000000..657e8c5
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+public class ByteUtil {
+       private static final ByteOrder BYTE_ORDER = ByteOrder.LITTLE_ENDIAN;
+       public static final int BYTE_LENGTH = 1;
+       public static final int SHORT_LENGTH = 2;
+       public static final int INT_LENGTH = 4;
+
+       public static ByteBuffer getByteBuffer(byte[] buf) {
+               ByteBuffer byteBuffer = ByteBuffer.allocate(buf.length);
+               byteBuffer.order(BYTE_ORDER);
+               byteBuffer.put(buf);
+               byteBuffer.rewind();
+
+               return byteBuffer;
+       }
+
+       public static ByteBuffer getByteBuffer(int length) {
+               ByteBuffer byteBuffer = ByteBuffer.allocate(length);
+               byteBuffer.order(BYTE_ORDER);
+
+               return byteBuffer;
+       }
+
+       public static byte[] short2byte(short s) {
+               byte dest[] = new byte[2];
+               dest[1] = (byte) (s & 0xff);
+               dest[0] = (byte) (s >>> 8 & 0xff);
+               return dest;
+       }
+
+       public static byte[] int2byte(int i) {
+               byte dest[] = new byte[4];
+               dest[3] = (byte) (i & 0xff);
+               dest[2] = (byte) (i >>> 8 & 0xff);
+               dest[1] = (byte) (i >>> 16 & 0xff);
+               dest[0] = (byte) (i >>> 24 & 0xff);
+               return dest;
+       }
+
+       public static byte[] long2byte(long l) {
+               byte dest[] = new byte[8];
+               dest[7] = (byte) (int) (l & 255L);
+               dest[6] = (byte) (int) (l >>> 8 & 255L);
+               dest[5] = (byte) (int) (l >>> 16 & 255L);
+               dest[4] = (byte) (int) (l >>> 24 & 255L);
+               dest[3] = (byte) (int) (l >>> 32 & 255L);
+               dest[2] = (byte) (int) (l >>> 40 & 255L);
+               dest[1] = (byte) (int) (l >>> 48 & 255L);
+               dest[0] = (byte) (int) (l >>> 56 & 255L);
+               return dest;
+       }
+
+       public static short byte2short(byte src[]) {
+               return (short) ((src[0] & 0xff) << 8 | src[1] & 0xff);
+       }
+
+       public static int byte2int(byte src[]) {
+               return (src[0] & 0xff) << 24 | (src[1] & 0xff) << 16
+                               | (src[2] & 0xff) << 8 | src[3] & 0xff;
+       }
+
+       public static int byte2int(byte src[], int offset) {
+               return (src[offset] & 0xff) << 24 | (src[offset + 1] & 0xff) << 16
+                               | (src[offset + 2] & 0xff) << 8 | src[offset + 3] & 0xff;
+       }
+
+       public static long byte2long(byte src[]) {
+               return (long) byte2int(src) << 32 | (long) byte2int(src, 4)
+                               & 0xffffffffL;
+       }
+
+       public static String byte2hex(byte[] src) {
+               if (src == null) {
+                       return null;
+               }
+
+               StringBuilder sb = new StringBuilder();
+               for (int i = 0; i < src.length; i++) {
+                       sb.append(Integer.toHexString(src[i] & 0xff));
+               }
+               return sb.toString();
+       }
+
+       public static byte[] hex2byte(String src) {
+               if (src == null) {
+                       return null;
+               }
+
+               if (src.length() % 2 != 0) {
+                       src = "0" + src; //$NON-NLS-1$
+               }
+
+               byte[] result = new byte[src.length() / 2];
+               for (int i = 0; i < result.length; i++) {
+                       result[i] = (byte) Integer.parseInt(
+                                       src.substring(2 * i, 2 * i + 2), 16);
+               }
+               return result;
+       }
+
+       // will be removed
+       /*
+       public static void printHex(byte[] buf, String flag) {
+               System.out.print("\n### " + flag + " : "); //$NON-NLS-1$ //$NON-NLS-2$
+               for (int i = 0; i < buf.length; i++) {
+                       System.out.format("%02X ", buf[i]); //$NON-NLS-1$
+               }
+       }
+       */
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A07.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A07.java
new file mode 100644 (file)
index 0000000..574eb8e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G01A07 extends AbstractGA{
+
+       public G01A07(){
+               super(0x01, 0x07);
+       }
+
+       @Override
+       protected void makeBody() {
+               StructureGA ga = getBody();
+               ga.addByteItem("ERROR_CAUSE_0");
+               ga.addByteItem("ERROR_CAUSE_1");
+       }
+
+       @Override
+       protected void makeHeader() {
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A21MO.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A21MO.java
new file mode 100644 (file)
index 0000000..0e31b4b
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G01A21MO extends AbstractGA{
+
+       public G01A21MO(){
+               super(0x01, 0x21);
+       }
+
+       @Override
+       protected void makeBody() {
+               StructureGA ga = getBody();
+               ga.addByteItem("CALL_ID");
+               ga.addByteItem("CALL_TYPE");
+               ga.addByteItem("LEN");
+               ga.addByteArrayItem("CALL_NUMBER", 10);
+       }
+
+       @Override
+       protected void makeHeader() {
+               
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A21MT.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A21MT.java
new file mode 100644 (file)
index 0000000..fc65a81
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G01A21MT extends AbstractGA{
+
+       public G01A21MT(){
+               super(0x01, 0x21);
+       }
+
+       @Override
+       protected void makeBody() {
+               StructureGA ga = getBody();
+               ga.addByteItem("CALL_TYPE");
+               ga.addByteItem("FORWARDED_STATUS");
+               ga.addByteItem("CLIR_STATUS");
+               ga.addByteItem("NUM_LEN");
+               ga.addByteItem("NUM_TYPE");
+               ga.addByteItem("CLI_PRESENT_ID");
+               ga.addByteItem("NO_CLI_CAUSE");
+               ga.addByteArrayItem("CALL_NUMBER", 45);
+       }
+
+       @Override
+       protected void makeHeader() {
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A22.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A22.java
new file mode 100644 (file)
index 0000000..55706a1
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G01A22 extends AbstractGA{
+
+       public G01A22(){
+               super(0x01, 0x22);
+       }
+
+       @Override
+       protected void makeBody() {
+               StructureGA ga = getBody();
+               ga.addIntItem("IDX");
+               ga.addIntItem("DIR");
+               ga.addIntItem("STAT");
+               ga.addIntItem("CALL_TYPE");
+               ga.addByteItem("MULTIPARTY");
+               ga.addByteArrayItem("NUMBER", 32);
+               ga.addByteArrayItem("dummy", 3);
+               ga.addIntItem("TYPE");
+               ga.addIntItem("NUM_LEN");
+               ga.addIntItem("NUM_OF_TYPE");
+               ga.addByteArrayItem("ALPHA",32);
+       }
+
+       @Override
+       protected void makeHeader() {
+               StructureGA ga = getHeader();
+               ga.addIntItem("COUNT");
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A22End.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A22End.java
new file mode 100644 (file)
index 0000000..a248c44
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G01A22End extends AbstractGA{
+
+       public G01A22End(){
+               super(0x01, 0x22);
+       }
+
+       @Override
+       protected void makeBody() {
+               StructureGA ga = getBody();
+               ga.addByteItem("CALL_ID");
+       }
+
+       @Override
+       protected void makeHeader() {
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A23.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A23.java
new file mode 100644 (file)
index 0000000..efc0b33
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G01A23 extends AbstractGA{
+
+       public G01A23(){
+               super(0x01, 0x23);
+       }
+
+       @Override
+       protected void makeBody() {
+       }
+
+       @Override
+       protected void makeHeader() {
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A26.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A26.java
new file mode 100644 (file)
index 0000000..39f86e7
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G01A26 extends AbstractGA{
+
+       public G01A26(){
+               super(0x01, 0x26);
+       }
+
+       @Override
+       protected void makeBody() {
+               StructureGA ga = getBody();
+               ga.addIntItem("IDX");
+               ga.addIntItem("DIR");
+               ga.addIntItem("STAT");
+               ga.addIntItem("CALL_TYPE");
+               ga.addByteItem("MULTIPARTY");
+               ga.addByteArrayItem("NUMBER", 32);
+               ga.addByteArrayItem("dummy", 3);
+               ga.addIntItem("TYPE");
+               ga.addIntItem("NUM_LEN");
+               ga.addIntItem("NUM_OF_TYPE");
+               ga.addByteArrayItem("ALPHA",32);
+       }
+
+       @Override
+       protected void makeHeader() {
+               StructureGA ga = getHeader();
+               ga.addIntItem("COUNT");
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A29.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A29.java
new file mode 100644 (file)
index 0000000..1c553db
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G01A29 extends AbstractGA{
+
+       public G01A29(){
+               super(0x01, 0x29);
+       }
+
+       @Override
+       protected void makeBody() {
+               StructureGA ga = getBody();
+               ga.addIntItem("IDX");
+               ga.addIntItem("DIR");
+               ga.addIntItem("STAT");
+               ga.addIntItem("CALL_TYPE");
+               ga.addByteItem("MULTIPARTY");
+               ga.addByteArrayItem("NUMBER", 32);
+               ga.addByteArrayItem("dummy", 3);
+               ga.addIntItem("TYPE");
+               ga.addIntItem("NUM_LEN");
+               ga.addIntItem("NUM_OF_TYPE");
+               ga.addByteArrayItem("ALPHA",32);
+       }
+
+       @Override
+       protected void makeHeader() {
+               StructureGA ga = getHeader();
+               ga.addIntItem("COUNT");
+       }
+       
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G01A62.java b/ei-library/src/org/tizen/eilib/modem/protocol/G01A62.java
new file mode 100644 (file)
index 0000000..a344936
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G01A62 extends AbstractGA{
+
+       public G01A62(){
+               super(0x01, 0x62);
+       }
+
+       @Override
+       protected void makeBody() {
+       }
+
+       @Override
+       protected void makeHeader() {
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G02A31.java b/ei-library/src/org/tizen/eilib/modem/protocol/G02A31.java
new file mode 100644 (file)
index 0000000..9a73809
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G02A31 extends AbstractGA{
+
+       public G02A31(){
+               super(0x02, 0x31);
+       }
+
+       @Override
+       protected void makeBody() {
+               StructureGA ga = getBody();
+               ga.addByteItem("NET_ACT_TYPE");
+               ga.addByteItem("NET_SVC_DOMAIN");
+               ga.addByteItem("NET_REG_STATUS");
+               ga.addByteItem("NET_EDGE_SUPPORT");
+               ga.addByteItem("LAC0");
+               ga.addByteItem("LAC1");
+               ga.addByteItem("CELL_ID0");
+               ga.addByteItem("CELL_ID1");
+               ga.addByteItem("CELL_ID2");
+               ga.addByteItem("CELL_ID3");
+               ga.addByteItem("REJ_CAUSE");
+       }
+
+       @Override
+       protected void makeHeader() {
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G04A01.java b/ei-library/src/org/tizen/eilib/modem/protocol/G04A01.java
new file mode 100644 (file)
index 0000000..659afbe
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G04A01 extends AbstractGA{
+
+       public G04A01(){
+               super(0x04, 0x01);
+       }
+
+       @Override
+       protected void makeBody() {
+               StructureGA ga = getBody();
+               ga.addByteArrayItem("DATA",500); //$NON-NLS-1$
+       }
+
+       @Override
+       protected void makeHeader() {
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/G04A05.java b/ei-library/src/org/tizen/eilib/modem/protocol/G04A05.java
new file mode 100644 (file)
index 0000000..6c85b41
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class G04A05 extends AbstractGA{
+       public G04A05(){
+               super(0x04, 0x05);
+       }
+
+       @Override
+       protected void makeBody() {
+               StructureGA ga = getBody();
+               ga.addByteItem("DATA1"); //$NON-NLS-1$
+               ga.addByteItem("DATA2"); //$NON-NLS-1$
+       }
+
+       @Override
+       protected void makeHeader() {
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/IntItem.java b/ei-library/src/org/tizen/eilib/modem/protocol/IntItem.java
new file mode 100644 (file)
index 0000000..49d0d6a
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+import java.util.ArrayList;
+
+public class IntItem extends AbstractItem {
+       private ArrayList<Integer> value;
+
+       public IntItem(ItemType type, String name, int length) {
+               super(type, name, length);
+               this.value = new ArrayList<Integer>();
+       }
+
+       public void setValue(int idx, int value) {
+               this.value.add(value);
+       }
+
+       public int getValue(int idx) {
+               return this.value.get(idx);
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/ItemType.java b/ei-library/src/org/tizen/eilib/modem/protocol/ItemType.java
new file mode 100644 (file)
index 0000000..b55f0a9
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public enum ItemType {
+       BYTE, SHORT, INT, ByteArray
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/StringUtil.java b/ei-library/src/org/tizen/eilib/modem/protocol/StringUtil.java
new file mode 100644 (file)
index 0000000..3fb2409
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+public class StringUtil {
+       public static String lpad(String strSource, int totalLength, String pad) {
+               if(totalLength <= strSource.length()) {
+                       return strSource;
+               }
+
+               StringBuilder sb = new StringBuilder(strSource);
+               for (int i = 0; i < totalLength-sb.length(); i++) {
+                       sb.insert(0, pad);
+               }
+
+               return sb.toString();
+       }
+
+       public static String rpad(String strSource, int totalLength, String pad) {
+               if(totalLength <= strSource.length()) {
+                       return strSource;
+               }
+
+               StringBuilder sb = new StringBuilder(strSource);
+               for (int i = 0; i < totalLength-sb.length(); i++) {
+                       sb.append(pad);
+               }
+               
+               return sb.toString();
+       }
+
+       public static String makeKey(int groupId, int actionId) {
+               return groupId + ":" + actionId; //$NON-NLS-1$
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/modem/protocol/StructureGA.java b/ei-library/src/org/tizen/eilib/modem/protocol/StructureGA.java
new file mode 100644 (file)
index 0000000..a078707
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.modem.protocol;
+
+import java.util.ArrayList;
+
+
+
+public class StructureGA {
+       
+       public static final int SINGLE_ROW_INDEX = 0;
+       
+       private int loopCount = 1;
+       private ArrayList<AbstractItem> list;
+       
+       public StructureGA(){
+               list = new ArrayList<AbstractItem>();
+       }
+       
+       public void addShortItem(String name) {
+               list.add(new IntItem(ItemType.SHORT, name, ByteUtil.SHORT_LENGTH));
+       }
+       
+       public void addByteItem(String name) {
+               list.add(new IntItem(ItemType.BYTE, name, ByteUtil.BYTE_LENGTH));
+       }
+       
+       public void addIntItem(String name) {
+               list.add(new IntItem(ItemType.INT, name, ByteUtil.INT_LENGTH));
+       }
+
+       public void addByteArrayItem(String name, int length) {
+               list.add(new ByteArrayItem(ItemType.ByteArray, name, length));
+       }
+       
+       public int getByteLength(){
+               int sum = 0;
+               for(int i=0; i<list.size(); i++) {
+                       sum += list.get(i).getByteLength();
+               }
+               return sum;
+       }
+       
+       public void setByteArray(String name, byte[] value){
+               setByteArray(name, SINGLE_ROW_INDEX, value);
+       }
+
+       public void setByteArray(String name, int idx, byte[] value){
+               ByteArrayItem item = (ByteArrayItem)getItem(name);
+               if(item==null) {
+                       return;
+               }
+               
+               item.setValue(idx, value);
+       }
+       
+       public void setInt(String name, int value){
+               setInt(name, SINGLE_ROW_INDEX, value);
+       };
+       
+       public void setInt(String name, int idx, int value){
+               IntItem item = (IntItem)getItem(name);
+               if(item==null) {
+                       return;
+               }
+               
+               item.setValue(idx, value);
+       }
+       
+       public byte[] getByteArray(String name){
+               return getByteArray(name, SINGLE_ROW_INDEX);
+       }
+       
+       public byte[] getByteArray(String name, int idx){
+               ByteArrayItem item = (ByteArrayItem)getItem(name);
+               if(item==null) {
+                       return null;
+               }
+               
+               return item.getValue(idx);
+       }
+       
+       public int getInt(String name){
+               return getInt(name, SINGLE_ROW_INDEX);
+       }
+       
+       public int getInt(String name, int idx){
+               IntItem item = (IntItem)getItem(name);
+               if(item==null) {
+                       return 0;
+               }
+               
+               return item.getValue(idx);
+       }
+       
+       
+       private AbstractItem getItem(String name){
+               if(name==null) {
+                       return null;
+               }
+               
+               AbstractItem result = null;
+               for(int i=0;i<list.size();i++){
+                       AbstractItem item = list.get(i);
+                       if(name.equals(item.getName())){
+                               result= item;
+                               break;
+                       }
+               }
+               
+               return result;
+       }
+       
+       public AbstractItem getItem(int idx){
+               return list.get(idx);
+       }
+       
+       public int getItemCount(){
+               return list.size();
+       }
+       
+       
+       public void setLoopCount(int loopCount){
+               this.loopCount = loopCount;
+       }
+       
+       public int getLoopCount(){
+               return this.loopCount;
+       }
+}
diff --git a/ei-library/src/org/tizen/eilib/tools/EILogger.java b/ei-library/src/org/tizen/eilib/tools/EILogger.java
new file mode 100644 (file)
index 0000000..cb1a8cb
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+ * EventInjector Library
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.eilib.tools;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.logging.FileHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+/**
+ * This class is event injector logger class.
+ * <p>
+ * This class is need initialization using <code>initLogger</code> or
+ * <code>intiFileLogger</code>.
+ * </p><p>
+ */
+public class EILogger {
+       private static Logger logger = null;
+
+       /**
+        * Return logger instance.
+        * logger instance is created using initLogger, initFileLgger
+        */
+       public static Logger getLogger() {
+               if (logger == null) {
+                       initLogger("Event Injector", Level.OFF);
+                       /*
+                       File log = new File("eilib.log");
+                       try {
+                               log.createNewFile();
+                       } catch (IOException e) {
+                               initLogger("Event Injector", Level.OFF);
+                               return logger;
+                       }
+                       initFileLogger(new File("eilib.log"), "Event Injector", Level.WARNING, false);
+                       */
+               }
+               return logger;
+       }
+
+       /**
+        * Initialize Logger instance.
+        *
+        * @param name logger name
+        * @param level logger level
+        * 
+        */
+       public static void initLogger(String name, Level level) {
+               logger = Logger.getLogger(name);
+               logger.setLevel(level);
+
+               Handler[] logHandlers = logger.getParent().getHandlers();
+
+               for (Handler handler : logHandlers) {
+                       handler.setFormatter(new ConsoleLoggerFormatter());
+               }
+       }
+
+       /**
+        * Initialize Logger instance.
+        *
+        * @param logFile log file
+        * @param name logger name
+        * @param level logger level
+        * @param onConsoleLog if this value is true, print console log, otherwise does not print console log.
+        * 
+        * @exception SecurityException<ul></ul>
+        * @exception IOException<ul></ul>
+        */
+       public static void initFileLogger(File logFile, String name, Level level, boolean onConsoleLog) {
+               initLogger(name, level);
+
+               logger.setUseParentHandlers(onConsoleLog);
+
+               Handler logFileHandler = null;
+               try {
+                       logFileHandler = new FileHandler(logFile.getAbsolutePath());
+               } catch (SecurityException e) {
+                       e.printStackTrace();
+                       return;
+               } catch (IOException e) {
+                       e.printStackTrace();
+                       return;
+               }
+
+               logFileHandler.setLevel(level);
+               logFileHandler.setFormatter(new FileLoggerFormatter());
+               logger.addHandler(logFileHandler);
+       }
+}
+
+class FileLoggerFormatter extends Formatter {
+    public String format(LogRecord record) {
+        StringBuffer sb = new StringBuffer();
+        Calendar cal = Calendar.getInstance();
+        cal.setTimeInMillis(record.getMillis());
+
+        // [YYYY.MM.DD HH:MM:SS][LEVEL][CLASS.METHOD] MESSAGE
+        sb.append('[');
+        sb.append(cal.get(Calendar.YEAR));
+        sb.append('.');
+        sb.append(cal.get(Calendar.MONTH));
+        sb.append('.');
+        sb.append(cal.get(Calendar.DAY_OF_MONTH));
+        sb.append(' ');
+        sb.append(cal.get(Calendar.HOUR_OF_DAY));
+        sb.append(':');
+        sb.append(cal.get(Calendar.MINUTE));
+        sb.append(':');
+        sb.append(cal.get(Calendar.SECOND));
+        sb.append(']');
+        sb.append('[');
+        sb.append(record.getLevel());
+        sb.append(']');
+        sb.append('[');
+        sb.append(record.getSourceClassName().substring(record.getSourceClassName().lastIndexOf(".") + 1));
+        sb.append('.');
+        sb.append(record.getSourceMethodName());
+        sb.append("] ");
+        sb.append(record.getMessage());
+
+        // in case when called Logger.throwing()
+        Throwable t = record.getThrown();
+        if (t != null) {
+            StackTraceElement[] stacks = t.getStackTrace();
+            sb.append('\n');
+            sb.append(t.toString());
+            for (int i = 0; i < stacks.length; i++) {
+                sb.append('\n');
+                sb.append(stacks[i].toString());
+            }
+        }
+        sb.append('\n');
+        return sb.toString();
+    }
+}
+
+class ConsoleLoggerFormatter extends Formatter {
+    public String format(LogRecord record) {
+        StringBuffer sb = new StringBuffer();
+
+        // [LEVEL][CLASS.METHOD] MESSAGE
+        sb.append('[');
+        sb.append(record.getLevel());
+        sb.append(']');
+        sb.append('[');
+        sb.append(record.getSourceClassName().substring(record.getSourceClassName().lastIndexOf(".") + 1));
+        sb.append('.');
+        sb.append(record.getSourceMethodName());
+        sb.append("] ");
+        sb.append(record.getMessage());
+
+        // in case when called Logger.throwing()
+        Throwable t = record.getThrown();
+        if (t != null) {
+            StackTraceElement[] stacks = t.getStackTrace();
+            sb.append('\n');
+            sb.append(t.toString());
+            for (int i = 0; i < stacks.length; i++) {
+                sb.append('\n');
+                sb.append(stacks[i].toString());
+            }            
+        }
+        sb.append('\n');
+        return sb.toString();
+    }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/.classpath b/eventinjector-cli/.classpath
new file mode 100644 (file)
index 0000000..af3ce1e
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="lib" path="lib/eilib.jar"/>
+       <classpathentry kind="lib" path="lib/jline-1.0.jar"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+       <classpathentry kind="lib" path="lib/sdblib.jar"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/eventinjector-cli/.project b/eventinjector-cli/.project
new file mode 100644 (file)
index 0000000..f605fd8
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>EventInjectorCLI</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/eventinjector-cli/.settings/org.eclipse.jdt.core.prefs b/eventinjector-cli/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..8cf4b08
--- /dev/null
@@ -0,0 +1,12 @@
+#Mon Oct 22 17:57:04 KST 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/eventinjector-cli/build.xml b/eventinjector-cli/build.xml
new file mode 100644 (file)
index 0000000..e40772f
--- /dev/null
@@ -0,0 +1,63 @@
+<?xml version="1.0" standalone="yes"?>
+<project name="event-injector" basedir="." default="make-jar">
+
+       <property name="jar.file" value="../eventinjector-cli.jar" />
+       <property name="mainclass" value="org.tizen.injector.EventInjector" />
+
+       <property name="ei.file"  value="eilib.jar" />
+       <property name="jline.file"  value="jline-1.0.jar" />
+
+       <path id="classpath">
+               <fileset dir="lib" includes="${ei.file}" />
+               <fileset dir="lib" includes="${jline.file}" />
+       </path>
+
+       <target name="clean">
+               <echo message="cleaning..." />
+               <delete dir="build" />
+               <delete file="${jar.file}" />
+       </target>
+
+       <target name="prepare-compile">
+               <echo message="prepare for compile..." />
+               <delete dir="build" />
+               <mkdir dir="build" />
+       </target>
+       <target name="compile" depends="prepare-compile">
+               <echo message="compiling..." />
+               <javac encoding="UTF-8" fork="true" srcdir="src" destdir="build" debug="on" memorymaximumsize="128m">
+                       <classpath refid="classpath" />
+               </javac>
+       </target>
+
+       <target name="create-jar">
+               <echo message="creating jar..." />
+               <jar jarfile="${jar.file}" basedir="build" duplicate="add">
+                       <manifest>
+                               <attribute name="Main-Class" value="${mainclass}" />
+                               <attribute name="Class-path" value="${ei.file} ${jline.file}" />
+                       </manifest>
+
+               </jar>
+               <delete dir="build" />
+       </target>
+
+       <target name="make-jar" depends="compile, create-jar" />
+
+       <!-- for dibs system... -->
+       <path id="classpath-dibs">
+               <fileset dir="${classpath.dibs}" includes="${jline.file}" />
+               <fileset dir="${classpath.dibs}" includes="${ei.file}" />
+       </path>
+
+       <target name="compile-dibs" depends="prepare-compile">
+               <echo message="compiling..." />
+               <javac encoding="UTF-8" fork="true" srcdir="src" destdir="build" debug="on" memorymaximumsize="128m">
+                       <classpath refid="classpath-dibs" />
+               </javac>
+       </target>
+
+       <target name="make-jar-dibs" depends="compile-dibs, create-jar" />
+
+</project>
diff --git a/eventinjector-cli/src/org/tizen/injector/DeviceList.java b/eventinjector-cli/src/org/tizen/injector/DeviceList.java
new file mode 100644 (file)
index 0000000..ff77806
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector;
+
+import java.util.ArrayList;
+
+import org.tizen.injector.device.Device;
+import org.tizen.injector.device.EmulatorDevice;
+import org.tizen.injector.device.ExitDevice;
+import org.tizen.injector.device.HelpDevice;
+import org.tizen.injector.device.Record;
+import org.tizen.injector.device.device.Battery;
+import org.tizen.injector.device.device.EarJack;
+import org.tizen.injector.device.device.RSSI;
+import org.tizen.injector.device.device.SDCard;
+import org.tizen.injector.device.device.USBDevice;
+import org.tizen.injector.device.location.Location;
+import org.tizen.injector.device.modem.Call;
+import org.tizen.injector.device.modem.SMS;
+import org.tizen.injector.device.nfc.Nfc;
+import org.tizen.injector.device.sensor.Motion;
+import org.tizen.injector.device.sensor.Sensor;
+
+public class DeviceList {
+       private ArrayList<Device> deviceList = new ArrayList<Device>();
+       private Nfc nfc = new Nfc();
+       public DeviceList() {
+               initDefalutDeviceList();
+       }
+
+       private void initDefalutDeviceList() {
+               deviceList.add(new Sensor());
+               deviceList.add(new Motion());
+               deviceList.add(new Battery());
+               deviceList.add(new EarJack());
+               deviceList.add(new USBDevice());
+               deviceList.add(new RSSI());
+               deviceList.add(new SDCard());
+               deviceList.add(new Location());
+               deviceList.add(new SMS());
+               deviceList.add(new Call());
+               deviceList.add(nfc);
+       }
+
+       public Device findDevice(String name) {
+               for(Device d : deviceList) {
+                       if (d.getName().equals(name)) {
+                               return d;
+                       }
+               }
+               return null;
+       }
+
+       public ArrayList<Device> getDeviceList() {
+               return deviceList;
+       }
+
+       public void startSession() {
+               nfc.initSessionMode();
+               // add emulator, help, exit
+               deviceList.add(new Record(EventInjector.getInstance().getRecorder()));
+               deviceList.add(new EmulatorDevice());
+               deviceList.add(new HelpDevice());
+               deviceList.add(new ExitDevice());
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/EventInjector.java b/eventinjector-cli/src/org/tizen/injector/EventInjector.java
new file mode 100644 (file)
index 0000000..981adaa
--- /dev/null
@@ -0,0 +1,343 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import jline.ArgumentCompletor;
+import jline.ArgumentCompletor.AbstractArgumentDelimiter;
+import jline.Completor;
+import jline.ConsoleReader;
+import jline.NullCompletor;
+
+import org.tizen.eilib.connection.ConnectionToEmulator;
+import org.tizen.eilib.connection.Emulator;
+import org.tizen.eilib.connection.IEmulatorChangeListener;
+import org.tizen.eilib.events.EventInjectorCreator;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.ArgCompletor;
+import org.tizen.injector.parser.Args;
+import org.tizen.injector.parser.CommandCompletor;
+import org.tizen.injector.parser.CommandParser;
+import org.tizen.injector.parser.DeviceCompletor;
+import org.tizen.injector.parser.HelpMessage;
+
+public class EventInjector {
+       private static ConnectionToEmulator connector   = null;
+       private static EventInjectorCreator creator             = null;
+       private static Emulator currentEmulator = null;
+
+       private static CommandParser parser = null;
+       private GlobalOption options = null;
+       private DeviceList deviceList = null;
+       private Args argsList = null;
+
+       private static boolean isSession = false;
+
+       private static EventInjector injector = null;
+       public static EventInjector getInstance() {
+               return injector;
+       }
+
+       private EventInjector() {
+               options         = new GlobalOption();
+               deviceList      = new DeviceList();
+               parser          = new CommandParser(this);
+               HelpMessage.setting(options, deviceList);
+       }
+
+       public static void main(String[] args) {
+
+               
+               try {
+                       connector = new ConnectionToEmulator();
+                       creator   = new EventInjectorCreator(connector);
+
+                       connector.addDeviceChangeListener(new MonitorEmulator());
+
+                       injector = new EventInjector();
+
+                       // global option
+                       injector.argsList = new Args(args);
+                       injector.argsList = parser.parseOptions(injector.argsList);
+       
+                       if (parser.isHasOptions()) {
+                               parser.getOptions().process();
+                       }
+       
+                       if (!parser.isHasOptions() || 
+                               (parser.isHasOptions() && parser.getOptions().isHasSessionOption())) {
+                               if (injector.argsList != null) {
+                                       injector.OnceSession();
+                               } else {
+                                       injector.Session();
+                               }
+                       }
+
+               } catch (ConsoleException ce) {
+                       //System.out.println("Error:" + ce.getMessage());
+                       exitEventInjector(ce.getErrorNumber());
+               } catch (InjectorLibraryException ie) {
+                       System.out.println("Error:" + ie.getMessage());
+                       if (ie.getError() == EILibError.EmulatorNotOne) {
+                               System.out.println("Use --connect | -c option to select emulator.");
+                       }
+                       exitEventInjector(ie.getErrorNumber());
+               } catch (Throwable t) {
+                       System.out.println("Error:" + t.getMessage());
+                       exitEventInjector(1);
+               }
+
+               exitEventInjector(0);
+       }
+
+       /**
+        * 
+        * @param args
+        * @return error number (exit value)
+        */
+       public int process(Args args) {
+               Device device = null;
+               try {
+                       device = parser.parseDevice(args);
+               } catch (ConsoleException e) {
+                       HelpMessage.printHelp(e, isSession);
+                       return e.getErrorNumber();
+               }
+
+               Command command = null;
+               try {
+                       command = parser.parseCommand(device, args);
+               } catch (ConsoleException e) {
+                       HelpMessage.printHelp(device, e);
+                       return e.getErrorNumber();
+               }
+
+               if (command != null) {
+                       int re = 0;
+                               try {
+                                       re = parser.parseArgument(command, args);
+                               
+                                       if (re != 0) {
+                                               return re;
+                                       }
+
+                                       re = command.process();
+
+                                       
+                               } catch (ConnectionException e) {
+                                       re = e.getErrorNumber();
+                               } catch (ConsoleException e) {
+                                       re = e.getErrorNumber();
+                               }
+                               if (re != 0) {
+                                       return re;
+                               }
+
+                       System.out.println("OK");
+
+               } else {
+                       HelpMessage.printHelp(device, null);
+                       return 1;
+               }
+
+               return 0;
+       }
+
+       private void OnceSession() throws IOException, InjectorLibraryException {
+               try {
+                       connector.connect();
+               } catch (InjectorLibraryException e) {
+                       if (e.getError() == EILibError.EmuldVersionOld) {
+                               System.out.println("Error: " + e.getMessage());
+                               System.out.println("Some command does not work...!");
+                               System.out.println("Please update emulator that has emuld over " + connector.getEmuldVersion() + " version");
+                       } else {
+                               throw e;
+                       }
+               }
+               currentEmulator = connector.getCurrentEmulator();
+
+               int exitValue = process(argsList);
+               if (exitValue != 0) {
+                       exitEventInjector(exitValue);
+               }
+       }
+
+       private static boolean isRecordMode = false;
+       private static EventRecorder recorder = new EventRecorder();
+       private void Session() throws ConsoleException, InjectorLibraryException, IOException {
+               // init
+               isSession = true;
+               deviceList.startSession();
+               HelpMessage.setting(options, deviceList);
+               //
+
+               try {
+                       connector.connect();
+               } catch (InjectorLibraryException e) {
+                       if (e.getError() == EILibError.EmuldVersionOld) {
+                               System.out.println("Error: " + e.getMessage());
+                               System.out.println("Some command does not work...!");
+                               System.out.println("Please update emulator that has emuld over " + connector.getEmuldVersion() + " version");
+                       } else {
+                               throw e;
+                       }
+               }
+               currentEmulator = connector.getCurrentEmulator();
+
+               System.out.println("Start event injector..");
+
+               ConsoleReader reader = new ConsoleReader();
+               reader.setBellEnabled(false);
+
+        List<Completor> completors = new LinkedList<Completor>();
+      
+        DeviceCompletor dCompletor = new DeviceCompletor();
+        completors.add(dCompletor);
+        CommandCompletor cCompletor = new CommandCompletor(dCompletor);
+        completors.add(cCompletor);
+        completors.add(new ArgCompletor(cCompletor, 1));
+        completors.add(new ArgCompletor(cCompletor, 2));
+        completors.add(new NullCompletor());
+        reader.addCompletor(new ArgumentCompletor(completors));
+        
+        String line;
+        //PrintWriter out = new PrintWriter(System.out);
+        while ((line = reader.readLine(">> ")) != null) {
+               Args args = new Args(line.split(" "));
+               if (process(args) == 0) {
+                       if (isRecordMode()) {
+                               recorder.addCommand(line);
+                       }
+               }
+        }
+       }
+
+       public static void exitEventInjector(int exitValue) {
+               if (connector != null) {
+                       connector.terminate();
+               }
+
+               if (injector.isRecordMode()) {
+                       try {
+                               recorder.endRecord();
+                       } catch (ConsoleException e) {
+                               System.out.println(e.getMessage());
+                       }
+               }
+
+               System.exit(exitValue);
+       }
+
+       public static ConnectionToEmulator getConnector() {
+               return connector;
+       }
+
+       public static EventInjectorCreator getCreator() {
+               return creator;
+       }
+
+       public static Emulator getCurrentEmulator() {
+               return currentEmulator;
+       }
+
+       public static CommandParser getParser() {
+               return parser;
+       }
+
+       public GlobalOption getOptions() {
+               return options;
+       }
+
+       public DeviceList getDeviceList() {
+               return deviceList;
+       }
+
+       public boolean isRecordMode() {
+               return isRecordMode;
+       }
+
+       public void setRecordMode(boolean isRecordMode) {
+               EventInjector.isRecordMode = isRecordMode;
+       }
+
+       public EventRecorder getRecorder() {
+               return recorder;
+       }
+
+       public static boolean isSessionMode() {
+               return isSession;
+       }
+}
+
+class MonitorEmulator extends IEmulatorChangeListener {
+
+       @Override
+       public void deviceConnected(Emulator device) {
+               // empty function
+       }
+
+       @Override
+       public void deviceDisconnected(Emulator device) {
+               if (EventInjector.getCurrentEmulator() != null) {
+                       if (device.equals(EventInjector.getCurrentEmulator())) {
+                               EventInjector.exitEventInjector(0);
+                       }
+               }
+       }
+
+       @Override
+       public void deviceChanged(Emulator device, int changeMask) {
+               // empty function
+       }
+       
+}
+
+class Delimiter extends AbstractArgumentDelimiter {
+
+       @Override
+       public boolean isDelimiterChar(String buffer, int pos) {
+                if (pos <= 0) {
+             return false;
+         }
+                if (buffer.charAt(pos) == ' ') {
+                        return !isDelimiterChar(buffer, pos -1);
+                }
+
+         return false;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/EventRecorder.java b/eventinjector-cli/src/org/tizen/injector/EventRecorder.java
new file mode 100644 (file)
index 0000000..4b98fa1
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.injector;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+
+public class EventRecorder {
+       private ArrayList<String> commands = null;
+       private PrintWriter output = null;
+       private int maxSize = 1000;
+
+       private String fileName = "";
+       private String filePath = "";
+       private File recordFile = null;
+
+       private boolean isRecording = false;
+       public EventRecorder() {
+               commands = new ArrayList<String>();
+       }
+
+       public String getFileName() {
+               return fileName;
+       }
+
+       public void setFileName(String fileName) {
+               this.fileName = fileName;
+       }
+
+       public String getFilePath() {
+               return filePath;
+       }
+
+       public void setFilePath(String filePath) {
+               this.filePath = filePath;
+       }
+
+       public boolean isRecording() {
+               return isRecording;
+       }
+
+       public void addCommand(String command) throws ConsoleException {
+               if (commands.size() == maxSize) {
+                       throw new ConsoleException(ConsoleError.FullCommandBuffer);
+               }
+
+               if (!command.startsWith("record")) {
+                       commands.add(command);
+               }
+       }
+
+       private SimpleDateFormat dayTime = new SimpleDateFormat("yyMMdd-HHmmss");
+       public String startRecord() throws ConsoleException, IOException {
+               if (isRecording) {
+                       throw new ConsoleException(ConsoleError.AlreadyStartRecording);
+               }
+
+               String name = "";
+               if (fileName.isEmpty()) {
+                       String str = dayTime.format(new Date(System.currentTimeMillis()));
+                       name = "record" + str +".txt"; 
+               } else {
+                       name = fileName;
+               }
+
+               if (filePath.isEmpty()) {
+                       recordFile = new File(name);
+               } else {
+                       recordFile = new File(filePath + File.separator + name);
+               }
+
+               try {
+                       recordFile = recordFile.getCanonicalFile();
+                       if(!recordFile.exists()) {
+                               recordFile.createNewFile();
+                       }
+                       this.output = new PrintWriter(new FileWriter(recordFile), true);
+               } catch (IOException e) {
+                       fileName = "";
+                       filePath = "";
+                       throw e;
+               }
+
+               isRecording = true;
+               return recordFile.getPath();
+       }
+
+       public String endRecord() throws ConsoleException {
+               if (!isRecording) {
+                       throw new ConsoleException(ConsoleError.AlreadyStopRecording);
+               }
+
+               if (this.output != null) {
+                       for (Iterator<String> i = commands.iterator(); i.hasNext();
+                                       this.output.println(i.next())) {
+                               ;
+                       }
+
+                       this.output.flush();
+                       this.output.close();
+               }
+
+               commands.clear();
+               isRecording = false;
+               fileName = "";
+               filePath = "";
+               return recordFile.getPath();
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/GlobalOption.java b/eventinjector-cli/src/org/tizen/injector/GlobalOption.java
new file mode 100644 (file)
index 0000000..262a022
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector;
+
+import java.util.ArrayList;
+import org.tizen.eilib.connection.Emulator;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.device.Option;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.HelpMessage;
+
+public class GlobalOption {
+       private ArrayList<Option> options;
+       private boolean hasSessionOption = false;
+
+       public GlobalOption() {
+               options = new ArrayList<Option>();
+
+               options.add(new Option("help", "h",
+                               "Pirnt help message", false, true));
+               options.add(new Option("emulator", "e",
+                               "Display running emulator list", false, true));
+               options.add(new Option("connect", "c",
+                               "Select emulator.", true, false));
+       }
+
+       public Option findShortNameOption(String option) {
+               for(Option o : options) {
+                       if (o.getShortName().equals(option)) {
+                               return o;
+                       }
+               }
+               return null;
+       }
+
+       public Option findLongNameOption(String option) {
+               for(Option o : options) {
+                       if (o.getLongName().equals(option)) {
+                               return o;
+                       }
+               }
+               return null;
+       }
+
+       public void process() throws InjectorLibraryException, ConsoleException{
+               for (Option o : options) {
+                       if (o.isInCommandLine()) {
+                               hasSessionOption |= (!o.isExitOption());
+                               switch(o.getShortName().charAt(0)) {
+                               case 'h': //help
+                                       printHelpMessage();
+                                       break;
+                               case 'e': //get emulator list
+                                       displayEmualtorList();
+                                       break;
+                               case 'c': // connect to emulator
+                                       setPortInfomation(o);
+                                       break;
+                               default:
+                                       return;
+                               }
+                       }
+               }
+       }
+
+       private void printHelpMessage() {
+               HelpMessage.printHelp(null, false);
+       }
+
+       private void displayEmualtorList() throws InjectorLibraryException {
+               ArrayList<Emulator> list = EventInjector.getConnector().getEmulatorList();
+               if (list.isEmpty()) {
+                       throw new InjectorLibraryException(EILibError.EmulatorNotExist);
+               }
+
+               for (Emulator e : list) {
+                       System.out.println(e.toString());
+               }
+       }
+
+       private void setPortInfomation(Option o) throws ConsoleException {
+               String value = o.getCurrentValue();
+               int port = 0;
+               String em = "";
+               try {
+                       port = Integer.parseInt(value);
+               } catch (NumberFormatException t) {
+                       // empty -> go to the next step.
+                       port = 0;
+               }
+
+               for (Emulator e : EventInjector.getConnector().getEmulatorList()) {
+                       if (port != 0 && port == e.getPort()) {
+                               em = e.getDeviceName();
+                       } else if (e.getDeviceName().equals(value)) {
+                               em = value;
+                               port = e.getPort();
+                       }
+               }
+
+               if (em.isEmpty()) {
+                       throw new ConsoleException(ConsoleError.NotAvaliableEM);
+               }
+
+               EventInjector.getConnector().setPort(port);
+       }
+
+       public boolean isHasSessionOption() {
+               return hasSessionOption;
+       }
+
+       public ArrayList<Option> getOptionList() {
+               return options;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/StringResource.java b/eventinjector-cli/src/org/tizen/injector/StringResource.java
new file mode 100644 (file)
index 0000000..ae0c4f1
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector;
+
+public class StringResource {
+       public static String AvailableState = "This device is avaliable.";
+       public static String NotAvailableState = "This device is not available.";
+
+       public static String NotAvaliableGettingStatus = "Getting the value from emulator is not supported.";
+
+       public static String FailedGetValue = "Failed to get the value of device from emulator.";
+
+       public static String EmulatorDesc="Display running emulator list.";
+       public static String ExitDesc="Terminate event injector.";
+       public static String HelpDesc="Print help message about event injector or selected device";
+
+       //
+       public static String Command = " command [command args]";
+       public static String Usage = "Usage: ";
+       public static String CommandSyntax = "Command syntax:";
+       public static String CommandArgument = "Command argument:";
+
+       // record
+       public static String RecordDesc="Record commands to the file.";
+       public static String RecordStopDesc="Stop to record commands.";
+       public static String RecordStartDesc="Start to record commands.";
+       public static String StopSuccess="Recording commands is complete : ";
+       public static String StopFailed="Failed to be complete recording commands.";
+
+       public static String StartFileDesc=/*'file-path'*/"is address of file recorded commands." +
+                       "\n\tDefalut path is current directory and defalut file name is recordYYMMDD-HHMMSS." +
+                       "\n\tIf input only file name, file path is current directory + file name." +
+                       "\n\tIf input only directory path, file path is directory path + default name";
+       public static String StartSuccess="Start to record commands to the file: ";
+       public static String StartFailed="Failed to start recording command.";
+
+       public static String RecordPlayDesc="Play events from the file that has commamds.";
+       public static String PlayFileDesc=/*'file-path'*/"is address of event log file.";
+
+       // battery
+       public static String BatteryDesc = "Set level or charger state of battery.";
+       public static String BatteryStatusDesc = "is to display status of battery device";
+       public static String BatteryLevelDesc = "is setting battery level.";
+       public static String BatteryChargerDesc = "is setting state of charger.";
+       public static String ArgChargerDesc = "is state of battery charger.";
+       public static String ArgLevelDesc = "is battery level.";
+
+       // earjack
+       public static String EarJackDesc = "Set status of ear jack.";
+       public static String EarJackStatusDesc ="is to display status of ear jack device";
+       public static String EarJackSetDesc = "is setting state of ear jack.";
+       public static String ArgEarJackDesc = "is current state of ear jack.";
+
+       // rssi
+       public static String RssiDesc = "Set rssi information.";
+       public static String RssiStatusDesc = "is to display status of rssi.";
+       public static String RssiSetDesc = "is setting rssi level.";
+       public static String ArgRssiDesc = "is rssi level.";
+
+       // sdcard
+       public static String SdcardDesc = "Mount or unmount sd card.";
+       public static String SdcardStatusDesc = "is to display status of sdcard device.";
+       public static String SdcardMountDesc = "is to mount sd card to the emulator.";
+       public static String ArgSdcardNameDesc = "is name of sdcard image";
+       public static String SdcardUmountDesc = "is to unmount sd card to the emulator.";
+
+       // usb
+       public static String UsbDesc = "Send usb status.";
+       public static String UsbStatusDesc = "is to display status of usb device.";
+       public static String UsbSetDesc = "is setting usb status.";
+       public static String ArgUsbDesc = "is current state of USB.";
+
+       // location
+       public static String LocationDesc = "Send location information.";
+       public static String LocationStatusDesc = "is to display status of location";
+       public static String LocaiontCodiDesc = "is setting location information.";
+       public static String ArgLatitudeDesc = "'latitude' of a place is its distance from the equator.";
+       public static String ArgLongitudeDesc = "'longitude' of a place is its distance to the west or east"
+                                                                                        + "of a line passing through Greenwich.";
+       public static String LocationFileDesc = "is setting location value of emulator using log file.(NMEA type file)";
+       public static String ArgLocationFileDesc = "is address of log file." +
+                       "\n\tThis file will be sent to emulator and used to event injector.";
+       public static String LocationStopDesc = "is to stop location event.";
+
+       // call
+       public static String CallDesc = "Handling call event associated the emulator";
+       public static String CallStatusDesc = "is to display status of call including call list";
+       public static String CallListDesc = "is to display list of call.";
+       public static String CallListEmpty = "Call list is empty.";
+
+       public static String CallDialDesc = "is sending phone call event to the emulator.";
+       public static String CallHiddenDesc = "is sending phone call event with hidden number.";
+       public static String CallAlertDesc = "is to change call state  to the alert state.";
+       public static String CallConnectDesc = "is to change call state to the connect state.";
+       public static String CallDisconnectDesc = "is to change call state to the disconnect state.";
+       //public static String CallDisconnectHelp = "If you want to disconnect hidden call, do not input number.";
+
+       public static String ArgCallNumberDesc = "is phone number";
+       public static String ArgCallIDDesc = "is id of call event. You can check id using 'call list' command.";
+       public static String ArgCallErrorCodeDesc = "is result of call event.";
+
+       // sms
+       public static String SMSDesc = "Send sms message or status to the emulator.";
+       public static String SMSStatusDesc = "is to display status of sms.";
+       public static String SMSSendDesc = "is sending SMS text message to the emulator.";
+       public static String ArgSMSNumberDesc = "is phone number";
+       public static String ArgSMSTextDesc = "is contents of sms";
+       public static String SMSSetStatusDesc = "is sending status of message(SMS) sent from the emulator.";
+       public static String ArgSMSStatusDesc = "is reslut of message sent from emulator.";
+       public static String MMSSetStatusDesc = "is sending status of message(MMS) sent from the emulator.";
+       public static String ArgMMSStatusDesc = "is reslut of message sent from emulator.";
+
+       // nfc
+       public static String NfcDesc = "Send nfc message to the emulator.";
+       public static String NfcHelpMessage = "\t"+ "'event-type' is event type of each command." +
+                       "\n\tIf you want more detail, enter 'nfc [command]' or 'help nfc [command]'";
+       public static String NfcStatusDesc = "is to display status of nfc device";
+       public static String NDEFListEmpty = "Message list is empty";
+
+       public static String NfcMessageDesc = "is to create or remove ndef message." +
+                       "\nBefore attaching nfc tag, at least one more message should exist in the list.";
+       public static String NfcTagDesc = "send tag event to the emulator. You can attach with one NDEF message." +
+                       "\nIf you want to send more message, use session mode.";
+       public static String NfcTagSessionDesc = "send tag event to the emulator." +
+                       "\nBefore attaching nfc tag, at least one more message should exist in the list.";
+
+       public static String NfcP2PDesc = "send p2p event to the emulator. You can send with one NDEF message." +
+                       "\nIf you want to send more message, use session mode.";
+       public static String NfcP2PSessionDesc = "send p2p event to the emulator." +
+                       "\nBefore p2p send event, at least one more message shoud exist in the list.";
+       public static String ArgNfcTagTypeDesc = "is event type of tag command.";
+       public static String ArgP2PTypeDesc = "is event type of p2p command.";
+       public static String ArgNDEFMessageDesc = "is ndef message.";
+       public static String ArgMessageIndexDesc = "is index of ndef message list.";
+
+       // sensor
+       public static String SensorDesc ="Send sensor device's value to the emulator.";
+       public static String SensorStatusDesc = "is to display status of sensor device.";
+       public static String SensorGetDesc = "is getting sensor value from emulator.";
+       public static String SensorSetDesc = "is setting sensor value of emulator.";
+       public static String SensorFileDesc = "is setting sensor value of emulator by using log file.";
+
+       public static String ArgSensorNameDesc = "is sensor device of emulator";
+       public static String ArgSensorFilePathDesc = "is address of log file." +
+                       "\n\tThis file will be sent to emulator and used to event injection.";
+       public static String ArgSensorValueDesc = "is appropriate sensor data for each sensor.";
+
+       public static String ArgAccelValueDesc = "In particular, the force of gravity is always influencing the measured acceleration.";
+       public static String ArgMagneticValueDesc = "All values are in micro-Tesla (uT) and measure the ambient magnetic" +
+                       "\n\tfield in the X, Y and Z axis.";
+       public static String ArgGyroValueDesc = "All values are in radians/second and measure the rate of rotation"+
+                       "\n\taround the device's local X, Y and Z axis.";
+       public static String ArgLightValueDesc = "Ambient light level.";
+       public static String ArgProxiValueDesc = "Proximity sensor only support near or far measurement." +
+                       "\n\tNear is on and far is off.";
+
+       // motion
+       public static String MotionDesc = "Send motion sensor value to the emulator.";
+       public static String MotionStatusDesc = "is to display status of motion sensor.";
+
+       public static String MotionSetDesc = "is setting motion sensor value of emulator.";
+       public static String ArgMotionDesc = "is name of motion sensor.";
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/Argument.java b/eventinjector-cli/src/org/tizen/injector/device/Argument.java
new file mode 100644 (file)
index 0000000..52d29cb
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device;
+
+import java.util.ArrayList;
+
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public abstract class Argument {
+       /**
+        * name of argument.
+        */
+       protected String name            = "";
+       /**
+        */
+       protected String description = "";
+
+       private boolean isUsingFile = false;
+
+       protected abstract void initialize();
+
+       /**
+        * Return name of argument
+        * @return
+        */
+       public String getName() {
+               return name;
+       }
+
+       /**
+        * Return description printing 'Command Arguments:'
+        * @return
+        */
+       public String getDescription() {
+               return description;
+       }
+
+       public void printHelpMessage(Exception e) {
+               if (e !=null) {
+                       System.out.println("Error:" + e.getMessage());
+                       System.out.println("Avaliable value:");
+               }
+               System.out.println("\t"+ getDescription());
+       }
+
+       /**
+        * 
+        * @param args
+        * @return
+        * @throws ConsoleException 
+        */
+       public abstract boolean parseArgs(Args args) throws InjectorLibraryException, ConsoleException;
+
+       protected ArrayList<String> values = null;
+       public abstract ArrayList<String> getPassibleValue();
+
+       public boolean isUsingFile() {
+               return isUsingFile;
+       }
+
+       protected void setUsingFile(boolean isUsingFile) {
+               this.isUsingFile = isUsingFile;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/Command.java b/eventinjector-cli/src/org/tizen/injector/device/Command.java
new file mode 100644 (file)
index 0000000..167581d
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.injector.device;
+
+import java.util.ArrayList;
+
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public abstract class Command {
+       protected Device device                 = null;
+       protected String name                   = "";
+       protected String syntax                 = "";
+       protected String description    = "";
+       protected boolean isDefault     = false;
+       protected boolean hasArguments  = false;
+       protected boolean isStandalone  = false;
+
+       protected ArrayList<Argument> argList = null;
+
+       public Command(Device device, boolean isDefault, boolean hasArguments) {
+               this.device                     = device;
+               this.isDefault          = isDefault;
+               this.hasArguments       = hasArguments;
+               this.argList = new ArrayList<Argument>();
+       }
+
+       public Device getDevice() {
+               return device;
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public String getSyntax() {
+               return syntax;
+       }
+       public String getDescription() {
+               return description;
+       }
+
+       public boolean isDefault() {
+               return isDefault;
+       }
+
+       public boolean hasArguments() {
+               return hasArguments;
+       }
+
+       public boolean isStandalone() {
+               return isStandalone;
+       }
+
+       public void addArgument(Argument arg) {
+               if (argList == null) {
+                       return;
+               }
+               argList.add(arg);
+       }
+
+       public ArrayList<Argument> getArgumentList() {
+               return argList;
+       }
+
+
+       public void printHelpMessage(Exception e) {
+               if (e != null) {
+                       System.out.println("Error:" + e.getMessage());
+                       System.out.println();
+               }
+               System.out.println(getDescription());
+               System.out.println();
+               System.out.println(StringResource.CommandSyntax);
+               System.out.println("\t"+ getSyntax());
+               System.out.println();
+               System.out.println(StringResource.CommandArgument);
+               for (Argument a : getArgumentList()) {
+                       System.out.println("\t" + a.getDescription());
+               }
+       }
+
+       public void printArgumentHelp(Exception e) {
+               if (e != null) {
+                       System.out.println("Error:" + e.getMessage());
+                       System.out.println();
+               }
+               System.out.println(StringResource.Usage + device.getName() +
+                               " " + syntax);
+               System.out.println();
+               System.out.println(StringResource.CommandArgument);
+               for (Argument a : argList) {
+                       a.printHelpMessage(null);
+               }
+       }
+
+       public int parseArgs(Args args) throws InjectorLibraryException, ConsoleException
+       {
+               if (!this.hasArguments) {
+                       return 1;
+               } else {
+                       for (Argument a : argList) {
+                               if (!a.parseArgs(args)) {
+                                       ConsoleException e = new ConsoleException(ConsoleError.WrongArgument);
+                                       this.printArgumentHelp(e);
+                                       return e.getErrorNumber();
+                               }
+                       }
+
+                       if (args.peek() != null) {
+                               ConsoleException e = new ConsoleException(ConsoleError.WrongArgument);
+                               this.printArgumentHelp(e);
+                               return e.getErrorNumber();
+                       }
+
+                       return 0;
+               }
+       }
+
+       protected abstract void initialize();
+       public abstract int process() throws ConnectionException;
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/Device.java b/eventinjector-cli/src/org/tizen/injector/device/Device.java
new file mode 100644 (file)
index 0000000..b4e53fc
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device;
+
+import java.util.ArrayList;
+
+import org.tizen.injector.StringResource;
+
+public abstract class Device {
+       protected String name                   = null;
+       protected String description    = null;
+       protected String usage                  = null;
+
+       protected ArrayList<Command> commandList = null;
+
+       public Device() {
+               commandList = new ArrayList<Command>();
+       }
+
+       public String getName() {
+               return name;
+       }
+       public String getDescription() {
+               return description;
+       }
+
+       public String getUsage() {
+               return usage;
+       }
+
+       public void addCommand(Command c) {
+               commandList.add(c);
+       }
+
+       public ArrayList<Command> getCommandList() {
+               return commandList;
+       }
+
+       public Command findCommand(String name) {
+               if (name != null) {
+                       for (Command c : commandList) {
+                               if (c.getName().equals(name)) {
+                                       return c;
+                               }
+                       }
+               }
+
+               return null;
+       }
+
+       public Command getDefalutCommand() {
+               for (Command c : commandList) {
+                       if (c.isDefault()) {
+                               return c;
+                       }
+               }
+
+               return null;
+       }
+
+       ArrayList<Argument> argsList = null;
+       public void printHelpMessage() {
+               //System.out.println(getDescription());
+               System.out.println(StringResource.Usage + getUsage());
+               System.out.println();
+               System.out.println(StringResource.CommandSyntax);
+               for (Command c : commandList) {
+                       if(!c.getSyntax().isEmpty()) {
+                               System.out.println("\t" + c.getSyntax());
+                       }
+               }
+               System.out.println();
+               System.out.println(StringResource.CommandArgument);
+
+               if (argsList == null) {
+                       argsList = new ArrayList<Argument>();
+                       boolean isExist = false;
+                       for (Command c : commandList) {
+                               for (Argument a : c.getArgumentList()) {
+                                       for (Argument a2 : argsList) {
+                                               if (a2.getName().equals(a.getName())) {
+                                                       isExist = true;
+                                                       continue;
+                                               }
+                                       }
+                                       if (!isExist) {
+                                               argsList.add(a);
+                                       }
+                                       isExist = false;
+                               }
+                       }
+               }
+
+               for (Argument a : argsList) {
+                       System.out.println("\t"+ a.getDescription());
+               }
+       }
+
+       protected abstract void initialize();
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/EmulatorDevice.java b/eventinjector-cli/src/org/tizen/injector/device/EmulatorDevice.java
new file mode 100644 (file)
index 0000000..a7d9ee0
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device;
+
+import java.util.ArrayList;
+
+import org.tizen.eilib.connection.Emulator;
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+
+public class EmulatorDevice extends Device{
+       public EmulatorDevice() {
+               commandList.add(new EmulatorCommand(this, true));
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "emulator";
+               usage = name;
+               description = StringResource.EmulatorDesc;
+       }
+}
+
+class EmulatorCommand extends Command {
+
+       public EmulatorCommand(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               this.isStandalone = true;
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "";
+               description = "";
+       }
+
+       @Override
+       public int process() {
+               ArrayList<Emulator> list = EventInjector.getConnector().getEmulatorList();
+               Emulator em = EventInjector.getConnector().getCurrentEmulator();
+               if (list.isEmpty()) {
+                       System.out.println(EILibError.EmulatorNotExist.getMessage());
+               }
+
+               for (Emulator e : list) {
+                       System.out.print(e.toString());
+                       if (e.equals(em)) {
+                               System.out.println(" * ");
+                       } else {
+                               System.out.println();
+                       }
+               }
+
+               return 0;
+       }
+       
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/ExitDevice.java b/eventinjector-cli/src/org/tizen/injector/device/ExitDevice.java
new file mode 100644 (file)
index 0000000..6fa3dba
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device;
+
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+
+public class ExitDevice extends Device {
+       public ExitDevice() {
+               commandList.add(new ExitCommand(this, true));
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "exit";
+               usage = name;
+               description = StringResource.ExitDesc;
+       }
+}
+
+class ExitCommand extends Command {
+
+       public ExitCommand(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               this.isStandalone = true;
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "";
+               description = "";
+       }
+
+       @Override
+       public int process() {
+               EventInjector.exitEventInjector(0);
+               return 0;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/HelpDevice.java b/eventinjector-cli/src/org/tizen/injector/device/HelpDevice.java
new file mode 100644 (file)
index 0000000..c93cb0d
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device;
+
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+import org.tizen.injector.parser.HelpMessage;
+
+public class HelpDevice extends Device {
+       public HelpDevice() {
+               commandList.add(new HelpCommand(this, true));
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "help";
+               usage = name + " [device] [command]";
+               description = "Print help message about event injector or selected device.";
+       }
+}
+
+class HelpCommand extends Command {
+       private Device helpDevice       = null;
+       private Command helpCommand = null;
+
+       public HelpCommand(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               this.isStandalone = true;
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "";
+               description = "";
+       }
+
+       @Override
+       public int parseArgs(Args args) throws InjectorLibraryException {
+               helpDevice  = null;
+               helpCommand = null;
+               if (args.peek() != null) {
+                       try {
+                               helpDevice = EventInjector.getParser().parseDevice(args);
+                       } catch (ConsoleException e) {
+                               System.out.println(e.getMessage());
+                               return 1;
+                       }
+               }
+
+               if (args.peek() != null) {
+                       try {
+                               helpCommand = EventInjector.getParser().parseCommand(helpDevice, args);
+                       } catch (ConsoleException e) {
+                               System.out.println(e.getMessage());
+                       }
+               }
+               return 0;
+       }
+
+       @Override
+       public int process() {
+               if (helpDevice == null) {
+                       HelpMessage.printHelp(null, true);
+               } else if (helpCommand == null) {
+                       HelpMessage.printHelp(helpDevice, null);
+               } else { // helpDevice != null && helpCommand != null
+                       HelpMessage.printHelp(helpCommand, null);
+               }
+               return 0;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/Option.java b/eventinjector-cli/src/org/tizen/injector/device/Option.java
new file mode 100644 (file)
index 0000000..809967d
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device;
+
+public class Option {
+       private String longName;
+       private String shortName;
+       private String description;
+       private String currentValue;
+       private boolean needsExtra;
+       private boolean isExitOption;
+       private boolean isInCommandLine;
+
+       public Option(String longName, String shortName,
+                       String description, boolean needsExtra, boolean isExitOption) {
+               this.longName   = longName;
+               this.shortName  = shortName;
+               this.description = description;
+               this.needsExtra = needsExtra;
+               this.isExitOption = isExitOption;
+               this.isInCommandLine = false;
+               this.currentValue       = null;
+       }
+
+       public String getLongName() {
+               return longName;
+       }
+
+       public String getShortName() {
+               return shortName;
+       }
+
+       public String getDescription() {
+               return description;
+       }
+
+       public boolean isNeedsExtra() {
+               return needsExtra;
+       }
+
+       public boolean isExitOption() {
+               return isExitOption;
+       }
+
+       public boolean isInCommandLine() {
+               return isInCommandLine;
+       }
+
+       public void setInCommandLine(boolean isInCommandLine) {
+               this.isInCommandLine = isInCommandLine;
+       }
+
+       public String getCurrentValue() {
+               return currentValue;
+       }
+
+       public void setCurrentValue(String currentValue) {
+               this.currentValue = currentValue;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/Record.java b/eventinjector-cli/src/org/tizen/injector/device/Record.java
new file mode 100644 (file)
index 0000000..daad24d
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device;
+
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.EventRecorder;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.exception.ConsoleException;
+
+public class Record extends Device {
+       public Record(EventRecorder recorder) {
+               commandList.add(new RecordStart(this, false, recorder));
+               commandList.add(new RecordStop(this, false, recorder));
+               commandList.add(new RecordPlay(this, false, recorder));
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "record";
+               usage = name + StringResource.Command;
+               description = StringResource.RecordDesc;
+       }
+}
+
+class RecordStop extends Command {
+       private EventRecorder recorder;
+
+       public RecordStop(Device device, boolean isDefault, EventRecorder recorder) {
+               super(device, isDefault, false);
+               this.recorder = recorder;
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "stop";
+
+               description = StringResource.RecordStopDesc;
+       }
+
+       @Override
+       public int process() {
+               String path;
+               try {
+                       path = recorder.endRecord();
+               } catch (ConsoleException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               } catch (Throwable e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+
+               if (path != null) {
+                       System.out.println(StringResource.StopSuccess + path);
+               } else {
+                       System.out.println(StringResource.StopFailed);
+                       return 1;
+               }
+
+               EventInjector.getInstance().setRecordMode(false);
+               return 0;
+       }
+       
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/RecordPlay.java b/eventinjector-cli/src/org/tizen/injector/device/RecordPlay.java
new file mode 100644 (file)
index 0000000..c06362c
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.EventRecorder;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class RecordPlay extends Command {
+       private EventRecorder recorder;
+       private ArgPlayFilePath path = null;
+       public RecordPlay(Device device, boolean isDefault, EventRecorder recorder) {
+               super(device, isDefault, true);
+               this.recorder = recorder;
+
+               path = new ArgPlayFilePath();
+               argList.add(path);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "play";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = StringResource.RecordPlayDesc;
+       }
+
+       @Override
+       public int process() {
+               if (recorder.isRecording()) {
+                       ConsoleException e = new ConsoleException(ConsoleError.AlreadyRecording);
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               }
+               BufferedReader reader = null;
+               try {
+                       reader = new BufferedReader(new FileReader(path.getLogFile()));
+               } catch (FileNotFoundException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+
+               String line = null;
+               try {
+                       while ((line = reader.readLine()) != null) {
+                               System.out.println(line);
+                               Args args = new Args(line.split(" "));
+                               EventInjector.getInstance().process(args);
+                               synchronized(this) {
+                                       try {
+                                               this.wait(1000);
+                                       } catch (InterruptedException e) {
+                                               System.out.println("Error:" + e.getMessage());
+                                       }
+                               }
+                       }
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+}
+
+class ArgPlayFilePath extends Argument {
+       private File logFile = null;
+       public ArgPlayFilePath() {
+               setUsingFile(true);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "file-path";
+
+               description = "'"+ name + "' " + StringResource.PlayFileDesc;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               if (args.remain() == 1) {
+                       String path = args.pop();
+                       File f = new File(path);
+                       if (!f.exists()) {
+                               ConsoleException e = new ConsoleException(ConsoleError.NotExistLogFile);
+                               System.out.println("Error:" + e.getMessage());
+                               return false;
+                       } else {
+                               logFile = f;
+                       }
+               } else {
+                       return false;
+               }
+
+               return true;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+
+       public File getLogFile() {
+               return logFile;
+       }
+       
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/RecordStart.java b/eventinjector-cli/src/org/tizen/injector/device/RecordStart.java
new file mode 100644 (file)
index 0000000..5420233
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.EventRecorder;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class RecordStart extends Command {
+       private EventRecorder recorder;
+
+       public RecordStart(Device device, boolean isDefault, EventRecorder recorder) {
+               super(device, isDefault, true);
+               this.recorder = recorder;
+               this.isStandalone = true;
+
+               argList.add(new ArgRecordFilePath(recorder));
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "start";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = StringResource.RecordStartDesc;
+       }
+
+       @Override
+       public int process() {
+               String path = null;
+               try {
+                       path = recorder.startRecord();
+               } catch (ConsoleException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+
+               if (path != null) {
+                       System.out.println(StringResource.StartSuccess + path);
+               } else {
+                       System.out.println(StringResource.StartFailed);
+                       return 1;
+               }
+               EventInjector.getInstance().setRecordMode(true);
+               return 0;
+       }
+}
+
+class ArgRecordFilePath extends Argument {
+       private EventRecorder recorder;
+       public ArgRecordFilePath(EventRecorder recorder) {
+               this.recorder = recorder;
+               setUsingFile(true);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "file-path";
+
+               description = "'"+ name + "' " + StringResource.StartFileDesc; 
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               if (args.remain() == 1) {
+                       String path = args.pop();
+                       File f = new File(path);
+                       if (path.contains(File.separator)) {
+                               try {
+                                       f = f.getCanonicalFile();
+                               } catch (IOException e) {
+                                       System.out.println("Error: " + e.getMessage());
+                                       return false;
+                               }
+
+                               if (f.isDirectory()) {
+                                       recorder.setFilePath(f.getPath());
+                               } else {
+                                       recorder.setFilePath(f.getParent());
+                                       recorder.setFileName(f.getName());
+                               }
+                       } else { // file name
+                               recorder.setFileName(f.getName());
+                       }
+               } else if (args.peek() == null) {
+                       // using defalut setting
+                       return true;
+               } else {
+                       return false;
+               }
+
+               return true;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+       
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/ArgBatteryCharger.java b/eventinjector-cli/src/org/tizen/injector/device/device/ArgBatteryCharger.java
new file mode 100644 (file)
index 0000000..e376467
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.injector.device.device;
+
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.type.BatteryCharger;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.parser.Args;
+
+
+public class ArgBatteryCharger extends Argument {
+       private BatteryCharger charger = null;
+
+       public ArgBatteryCharger() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "state";
+               description = "'" + name + "' " + StringResource.ArgChargerDesc +
+                               "\n\tand this value has " + BatteryCharger.CONNECT.toString() +
+                               " | " + BatteryCharger.DISCONNECT.toString() + ".";
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               if (args.remain() != 1) {
+                       return false;
+               }
+
+               String arg = args.pop().trim();
+
+               if (arg.equals(BatteryCharger.CONNECT.toString())) {
+                       charger = BatteryCharger.CONNECT;
+               } else if (arg.equals(BatteryCharger.DISCONNECT.toString())) {
+                       charger = BatteryCharger.DISCONNECT;
+               } else {
+                       return false;
+               }
+
+               return true;
+       }
+
+       public BatteryCharger getCharger() {
+               return charger;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+
+                       values.add(BatteryCharger.CONNECT.toString());
+                       values.add(BatteryCharger.DISCONNECT.toString());
+               }
+       
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/ArgBatteryLevel.java b/eventinjector-cli/src/org/tizen/injector/device/device/ArgBatteryLevel.java
new file mode 100644 (file)
index 0000000..29bab82
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.util.ArrayList;
+
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.parser.Args;
+
+public class ArgBatteryLevel extends Argument {
+       private static String[] units = {"%"};
+       private String unit = null;
+       private int level = 50;
+       private int maxLevel;
+       private int minLevel;
+
+       public ArgBatteryLevel(int min, int max) {
+               maxLevel = max;
+               minLevel = min;
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "value";
+               description = "'" + name + "' " + StringResource.ArgLevelDesc +
+                               "\n\tand this value has between " + Integer.toString(minLevel) +
+                               " and " + Integer.toString(maxLevel) + ". ";
+               if (units.length > 1) {
+                       description += "Units are ";
+                       for (String u : units) {
+                               description += "'" + u + "' ";
+                       }
+                       description +=".";
+               } else {
+                       description += "Unit is '" + units[0] + "' .";
+               }
+               // TODO
+               unit = units[0];
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               if (args.remain() != 1) {
+                       return false;
+               }
+
+               // clear
+               unit = null;
+
+               String arg = args.pop().trim();
+
+               for (String u : units) {
+                       if (arg.endsWith(u)) {
+                               unit = u;
+                               arg = arg.substring(0, arg.length() - u.length());
+                       }
+               }
+
+               try {
+                       level = Integer.parseInt(arg);
+               } catch (NumberFormatException t) {
+                       return false;
+               }
+
+               return true;
+       }
+
+       public String getUnit() {
+               return unit;
+       }
+
+       public int getLevel() {
+               return level;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/Battery.java b/eventinjector-cli/src/org/tizen/injector/device/device/Battery.java
new file mode 100644 (file)
index 0000000..4630f58
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+
+import org.tizen.eilib.events.BatteryEventInjector;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.eilib.events.type.BatteryCharger;
+
+public class Battery extends Device {
+       public Battery() {
+               commandList.add(new BatteryStatus(this, false));
+               commandList.add(new BatteryLevel(this, false));
+               commandList.add(new BatterySetCharger(this, false));
+               initialize();
+       }
+       @Override
+       protected void initialize() {
+               name = "battery";
+               usage = name + StringResource.Command;
+               description = StringResource.BatteryDesc;
+       }
+}
+
+class BatteryStatus extends Command {
+       public BatteryStatus(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               System.out.println(StringResource.AvailableState);
+               System.out.println("Battery status");
+
+               BatteryEventInjector injector = EventInjector.getCreator().getBatteryEventInjector();
+               int level = -1;
+               BatteryCharger charger = null;
+               int errorNumber = 0;
+               try {
+                       level   = injector.getLevel();
+                       charger = injector.getChargerState();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       errorNumber = 1;
+               } catch (InjectorLibraryException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       errorNumber = e.getErrorNumber();
+               }
+
+               if (errorNumber != 0) {
+                       System.out.println("\tLevel: " + StringResource.FailedGetValue);
+                       System.out.println("\tCharger: " + StringResource.FailedGetValue);
+               } else {
+                       System.out.println("\tLevel: " + level);
+                       System.out.println("\tCharger: " + charger.toString());
+               }
+
+               System.out.println();
+
+               return errorNumber;
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.BatteryStatusDesc;     
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/BatteryLevel.java b/eventinjector-cli/src/org/tizen/injector/device/device/BatteryLevel.java
new file mode 100644 (file)
index 0000000..d71e1f5
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+
+import org.tizen.eilib.events.BatteryEventInjector;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class BatteryLevel extends Command {
+       private BatteryEventInjector injector;
+       private ArgBatteryLevel batteryLevel;
+
+       public BatteryLevel(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               injector = EventInjector.getCreator().getBatteryEventInjector();
+
+               batteryLevel = new ArgBatteryLevel(injector.getMinBatteryLevel(), injector.getMaxBatteryLevel());
+               argList.add(batteryLevel);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "level";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.BatteryLevelDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       injector.setLevel(batteryLevel.getLevel());
+               } catch (DeviceEventException e) {
+                       batteryLevel.printHelpMessage(e);
+                       return e.getErrorNumber();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/BatterySetCharger.java b/eventinjector-cli/src/org/tizen/injector/device/device/BatterySetCharger.java
new file mode 100644 (file)
index 0000000..e99281d
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class BatterySetCharger extends Command {
+       private ArgBatteryCharger charger;
+
+       public BatterySetCharger(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+
+               charger = new ArgBatteryCharger();
+               argList.add(charger);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "charger";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.BatteryChargerDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator().getBatteryEventInjector()
+                               .setChargerState(charger.getCharger());
+               } catch (DeviceEventException e) {
+                       charger.printHelpMessage(e);
+                       return e.getErrorNumber();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+}
+
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/EarJack.java b/eventinjector-cli/src/org/tizen/injector/device/device/EarJack.java
new file mode 100644 (file)
index 0000000..ce73ca3
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+
+import org.tizen.eilib.events.type.EarJackStatus;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class EarJack extends Device {
+       public EarJack() {
+               commandList.add(new EarJackStatusCommand(this, false));
+               commandList.add(new EarJackSet(this, false));
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name  = "earjack";
+               usage = name + StringResource.Command;
+               description = StringResource.EarJackDesc;
+       }
+}
+
+class EarJackStatusCommand extends Command {
+
+       public EarJackStatusCommand(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.EarJackStatusDesc;     
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               System.out.println(StringResource.AvailableState);
+
+               EarJackStatus status = null;
+               int errorNumber = 0;
+               try {
+                       status = EventInjector.getCreator().getEarJackInjector().getStatus();
+               } catch (DeviceEventException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       errorNumber = e.getErrorNumber();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       errorNumber = 1;
+               }
+
+               if (errorNumber != 0 || status == null) {
+                       System.out.println("EarJack status: " + StringResource.FailedGetValue);
+               } else {
+                       System.out.println("EarJack status: " + status.toString());
+               }
+
+               System.out.println();
+               return 0;
+       }
+       
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/EarJackSet.java b/eventinjector-cli/src/org/tizen/injector/device/device/EarJackSet.java
new file mode 100644 (file)
index 0000000..a88a64a
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.eilib.events.type.EarJackStatus;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.parser.Args;
+
+public class EarJackSet extends Command {
+       private ArgEarJack earjack;
+       public EarJackSet(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               earjack = new ArgEarJack();
+               argList.add(earjack);
+               
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "set";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.EarJackStatusDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator().getEarJackInjector()
+                                       .setStatus(earjack.getStatus());
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+}
+
+class ArgEarJack extends Argument {
+       private EarJackStatus status = null;
+
+       public ArgEarJack() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "status";
+               description = "'" + name + "' " + StringResource.ArgEarJackDesc +
+                               "\n\tThis value has ";
+
+               for (EarJackStatus e : EarJackStatus.values()) {
+                       description += e.toString() + " | ";
+               }
+               description = description.substring(0,  description.length() - 3);
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               status = null;
+
+               if (args.remain() == 1) {
+                       String arg = args.pop().trim();
+       
+                       for (EarJackStatus e : EarJackStatus.values()) {
+                               if (e.toString().equals(arg)) {
+                                       status = e;
+                                       break;
+                               }
+                       }
+               }
+
+               return status == null ? false : true;
+       }
+
+       public EarJackStatus getStatus() {
+               return status;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+
+                       for (EarJackStatus e : EarJackStatus.values()) {
+                               values.add(e.toString());
+                       }
+               }
+               
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/RSSI.java b/eventinjector-cli/src/org/tizen/injector/device/device/RSSI.java
new file mode 100644 (file)
index 0000000..f1de911
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class RSSI extends Device {
+
+       public RSSI() {
+               commandList.add(new RssiStatus(this, false));
+               commandList.add(new RssiSet(this, false));
+
+               initialize();
+       }
+       @Override
+       protected void initialize() {
+               name  = "rssi";
+               usage = name + StringResource.Command;
+               description = StringResource.RssiDesc;
+       }
+
+}
+
+class RssiStatus extends Command {
+
+       public RssiStatus(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.RssiStatusDesc;        
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               System.out.println(StringResource.AvailableState);
+
+               int level = -1;
+               int errorNumber = 0;
+               try {
+                       level = EventInjector.getCreator().getRssiEventInjector().getLevel();
+               } catch (DeviceEventException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       errorNumber = e.getErrorNumber();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       errorNumber = 1;
+               }
+
+               if (errorNumber != 0) {
+                       System.out.println("RSSI level: " + StringResource.FailedGetValue);
+               } else {
+                       System.out.println("RSSI level: " + level);
+               }
+
+               System.out.println();
+               return 0;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/RssiSet.java b/eventinjector-cli/src/org/tizen/injector/device/device/RssiSet.java
new file mode 100644 (file)
index 0000000..a23f4e8
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.RSSIEventInjector;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.parser.Args;
+
+public class RssiSet extends Command {
+
+       private RSSIEventInjector injector;
+       private ArgRssiLevel rssi;
+
+       public RssiSet(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               injector = EventInjector.getCreator().getRssiEventInjector();
+               
+               rssi = new ArgRssiLevel(injector.getMinLevel(), injector.getMaxLevel());
+               argList.add(rssi);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "set";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " + StringResource.RssiSetDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       injector.setLevel(rssi.getLevel());
+               } catch (DeviceEventException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+}
+
+class ArgRssiLevel extends Argument {
+       private int level = 0;
+       private int minLevel;
+       private int maxLevel;
+
+       public ArgRssiLevel(int min, int max) {
+               minLevel = min;
+               maxLevel = max;
+               initialize();
+       }
+       @Override
+       protected void initialize() {
+               name = "level";
+               
+               description = "'" + name + "' " +
+                               "\n\tThis value has between " + Integer.toString(minLevel) +
+                               " and " + Integer.toString(maxLevel) + ". ";
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               if (args.remain() == 1) {
+                       try {
+                               level = Integer.valueOf(args.pop());
+                       } catch (NumberFormatException t) {
+                               return false;
+                       }
+                       return true;
+               }
+
+               return false;
+       }
+
+       public int getLevel() {
+               return level;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/SDCard.java b/eventinjector-cli/src/org/tizen/injector/device/device/SDCard.java
new file mode 100644 (file)
index 0000000..dcc98ae
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Device;
+
+public class SDCard extends Device {
+       public SDCard() {
+               commandList.add(new SDCardStatus(this, false));
+               commandList.add(new SDCardMount(this, false));
+               commandList.add(new SDCardUnmount(this, false));
+               initialize();
+       }
+       @Override
+       protected void initialize() {
+               name = "sdcard";
+               usage = name + StringResource.Command;
+               description = StringResource.SdcardDesc;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/SDCardMount.java b/eventinjector-cli/src/org/tizen/injector/device/device/SDCardMount.java
new file mode 100644 (file)
index 0000000..d6250ff
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.SDCardEventInjector;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class SDCardMount extends Command {
+       private ArgSDCardName sdCard;
+       public SDCardMount(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               sdCard = new ArgSDCardName();
+               argList.add(sdCard);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "mount";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.SdcardMountDesc;
+       }
+
+       private SDCardEventInjector injector = null;
+       @Override
+       public int process() throws ConnectionException {
+               if (injector == null) {
+                       try {
+                               injector = EventInjector.getCreator().getSDCardInjector();
+                       } catch (IOException e) {
+                               System.out.println("Error: " + e.getMessage());
+                               return 1;
+                       } catch (DeviceEventException e) {
+                               System.out.println("Error: " + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+               }
+
+               try {
+                       if(!injector.mount(sdCard.getCardName(), true)) {
+                               ConsoleException e = new ConsoleException(ConsoleError.MountFailed);
+                               System.out.println("Error: " + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+               } catch (IOException io) {
+                       System.out.println("Error: " + io.getMessage());
+                       return 1;
+               }  catch (InjectorLibraryException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               }
+
+               return 0;
+       }
+
+}
+
+class ArgSDCardName extends Argument {
+       private String cardName = null;
+
+       public ArgSDCardName() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "sdcard-name";
+               description = "'" + name + "' " + StringResource.ArgSdcardNameDesc +
+                               "\n\tThis value has";
+               for (String s : SDCardImageList.getImages().keySet()) {
+                       description += " " + s + " |";
+               }
+               description = description.substring(0, description.length() - 2);
+               description += ".";
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               if (args.remain() != 1) {
+                       return false;
+               }
+
+               String arg = args.pop().trim();
+
+               for (String s : SDCardImageList.getImages().keySet()) {
+                       if (s.equals(arg)) {
+                               setCardName(arg);
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+
+       public String getCardName() {
+               return cardName;
+       }
+
+       public void setCardName(String cardName) {
+               this.cardName = cardName;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+
+                       for (String s : SDCardImageList.getImages().keySet()) {
+                               values.add(s);
+                       }
+               }
+
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/SDCardStatus.java b/eventinjector-cli/src/org/tizen/injector/device/device/SDCardStatus.java
new file mode 100644 (file)
index 0000000..d850fad
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.tizen.eilib.connection.Emulator;
+import org.tizen.eilib.events.SDCardEventInjector;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class SDCardStatus extends Command {
+       public SDCardStatus(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       public int setting() throws ConnectionException {
+               SDCardEventInjector injector = null;
+               try {
+                       injector = EventInjector.getCreator().getSDCardInjector();
+                       injector.queryMountStatus();
+                       //injector.getCurrentMountStatus(true);
+               } catch (IOException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return 1;
+               } catch (DeviceEventException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return e.getErrorNumber();
+               }
+
+               
+               ArrayList<Emulator> list = EventInjector.getConnector().getEmulatorList();
+               SDCardImageList.initMap();
+               for (Emulator e : list) {
+                       if (e.isMounted()) {
+                               SDCardImageList.putEmulator(e.getSDCardName(), e);
+                       }
+               }
+               return 0;
+       }
+       @Override
+       public int process() throws ConnectionException {
+               int re = setting();
+               if (re != 0) {
+                       return re;
+               }
+
+               System.out.println(StringResource.AvailableState);
+               System.out.println("SDCard status:");
+
+               SDCardImageList.printStatus();
+               System.out.println();
+               return 0;
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.SdcardStatusDesc;
+       }
+}
+
+class SDCardImageList {
+       private static Map<String, Emulator> images;
+       private static ArrayList<String> SDCardList = new ArrayList<String>();
+       static {
+               SDCardList.add("sdcard_ext4_4G.img");
+               SDCardList.add("sdcard_ext4_8G.img");
+               SDCardList.add("sdcard_ext4_16G.img");
+               SDCardList.add("sdcard_ext4_32G.img");
+
+               images = new HashMap<String, Emulator>();
+               for (String s : SDCardList) {
+                       images.put(s, null);
+               }
+       }
+
+       public static Emulator findEmulator(String key) {
+               return images.get(key);
+       }
+
+       public static void putEmulator(String key, Emulator e) {
+               if (images.containsKey(key)) {
+                       images.remove(key);
+               }
+               images.put(key, e);
+       }
+
+       public static void printStatus() {
+               Emulator e = null;
+               for (String key : images.keySet()) {
+                       System.out.print(String.format("\t%s", key));
+                       e = images.get(key);
+                       if (e != null && e.isMounted()) {
+                               System.out.println(" - mounted by the '" + e.getDeviceName() + "'");
+                       } else {
+                               System.out.println();
+                       }
+               }
+       }
+
+       public static Map<String, Emulator> getImages() {
+               return images;
+       }
+
+       public static void initMap() {
+               images.clear();
+               for (String s : SDCardList) {
+                       images.put(s, null);
+               }
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/SDCardUnmount.java b/eventinjector-cli/src/org/tizen/injector/device/device/SDCardUnmount.java
new file mode 100644 (file)
index 0000000..1e5a3be
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+
+import org.tizen.eilib.events.SDCardEventInjector;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+
+public class SDCardUnmount extends Command {
+
+       public SDCardUnmount(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "umount";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.SdcardUmountDesc;
+       }
+
+       private SDCardEventInjector injector = null;
+       @Override
+       public int process() throws ConnectionException {
+               if (injector == null) {
+                       try {
+                               injector = EventInjector.getCreator().getSDCardInjector();
+                       } catch (IOException e) {
+                               System.out.println("Error: " + e.getMessage());
+                               return 1;
+                       } catch (DeviceEventException e) {
+                               System.out.println("Error: " + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+               }
+
+               try {
+                       if(!injector.unmount(true)) {
+                               ConsoleException e = new ConsoleException(ConsoleError.UmountFailed);
+                               System.out.println("Error: " + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+               } catch (IOException io) {
+                       System.out.println("Error: " + io.getMessage());
+                       return 1;
+               }
+
+               return 0;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/USBDevice.java b/eventinjector-cli/src/org/tizen/injector/device/device/USBDevice.java
new file mode 100644 (file)
index 0000000..30d6ea2
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+
+import org.tizen.eilib.events.type.USBStatus;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.DeviceEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class USBDevice extends Device {
+
+       public USBDevice() {
+               commandList.add(new USBDeviceStatus(this, false));
+               commandList.add(new USBDeviceSet(this, false));
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name  = "usb";
+               usage = name + StringResource.Command;
+               description = StringResource.UsbDesc;
+       }
+
+}
+
+class USBDeviceStatus extends Command {
+
+       public USBDeviceStatus(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.UsbStatusDesc; 
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               System.out.println(StringResource.AvailableState);
+
+               USBStatus status = null;
+               int errorNumber = 0;
+               try {
+                       status = EventInjector.getCreator().getUSBEventInjector().getStatus();
+               } catch (DeviceEventException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       errorNumber = e.getErrorNumber();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       errorNumber = 1;
+               }
+
+               if (errorNumber != 0 || status == null) {
+                       System.out.println("USB status: " + StringResource.FailedGetValue);
+               } else {
+                       System.out.println("USB status: " + status.toString());
+               }
+
+               System.out.println();
+               return 0;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/device/USBDeviceSet.java b/eventinjector-cli/src/org/tizen/injector/device/device/USBDeviceSet.java
new file mode 100644 (file)
index 0000000..b0b0938
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.device;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.eilib.events.type.USBStatus;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.parser.Args;
+
+public class USBDeviceSet extends Command {
+       private ArgUSB usb;
+
+       public USBDeviceSet(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               usb = new ArgUSB();
+               argList.add(usb);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "set";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.UsbSetDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator().getUSBEventInjector()
+                               .setStatus(usb.getStatus());
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+}
+
+class ArgUSB extends Argument {
+       private USBStatus status = null;
+
+       public ArgUSB() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "status";
+
+               description = "'" + name + "' " + StringResource.ArgUsbDesc +
+                               "\n\tThis value has ";
+               for (USBStatus u : USBStatus.values()) {
+                       description += u.toString() + " | ";
+               }
+               description = description.substring(0,  description.length() - 3);
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               status = null;
+
+               if (args.remain() == 1) {
+                       String arg = args.pop().trim();
+       
+                       for (USBStatus u : USBStatus.values()) {
+                               if (u.toString().equals(arg)) {
+                                       status = u;
+                                       break;
+                               }
+                       }
+               }
+
+               return status == null ? false : true;
+       }
+
+       public USBStatus getStatus() {
+               return status;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+                       for (USBStatus u : USBStatus.values()) {
+                               values.add(u.toString());
+                       }
+               }
+
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/location/Location.java b/eventinjector-cli/src/org/tizen/injector/device/location/Location.java
new file mode 100644 (file)
index 0000000..f5562e6
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.location;
+
+import java.io.IOException;
+
+import org.tizen.eilib.events.LocationEvent;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class Location extends Device {
+       public Location() {
+               commandList.add(new LocationStatus(this, false));
+               commandList.add(new LocationCoordinate(this, false));
+               commandList.add(new LocationLogFile(this, false));
+               commandList.add(new LocationStop(this, false));
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name  = "location";
+               usage = name + StringResource.Command;
+               description = StringResource.LocationDesc;
+       }
+
+}
+
+class LocationStatus extends Command {
+
+       public LocationStatus(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.LocationStatusDesc;    
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               System.out.println(StringResource.AvailableState);
+               try {
+                       LocationEvent event = EventInjector.getCreator()
+                                               .getLocationInjector().getLocationStatus();
+                       if (event != null) {
+                               System.out.println("Location status:");
+                               switch (event.getMode()) {
+                               case STOPMODE:
+                                       System.out.println("\tMode: stop ");
+                                       break;
+                               case LOGMODE:
+                                       System.out.println("\tMode: file log");
+                                       System.out.println("\tFile name: " + event.getFileName());
+                                       break;
+                               case MANUALMODE:
+                                       System.out.println("\tMode: manual");
+                                       System.out.println("\tLatitude: " + event.getLatitude());
+                                       System.out.println("\tLogitude: " + event.getLogitude());
+                                       break;
+                               default:
+                                       System.out.println("Location status: " + StringResource.FailedGetValue);
+                                       break;
+                               }
+                       } else {
+                               System.out.println("Location status: " + StringResource.FailedGetValue);
+                       }
+               } catch (IOException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return 1;
+               } catch (InjectorLibraryException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return e.getErrorNumber();
+               }
+
+               System.out.println();
+
+               return 0;
+       }
+       
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/location/LocationCoordinate.java b/eventinjector-cli/src/org/tizen/injector/device/location/LocationCoordinate.java
new file mode 100644 (file)
index 0000000..6870c03
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.location;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.LocationEventInjector;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.parser.Args;
+
+public class LocationCoordinate extends Command {
+       private ArgLatitude latitude;
+       private ArgLongitude longitude;
+       private LocationEventInjector injector;
+       public LocationCoordinate(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               injector = EventInjector.getCreator().getLocationInjector();
+               latitude = new ArgLatitude(injector.getMinLatitude(), injector.getMaxLatitude());
+               longitude = new ArgLongitude(injector.getMinLongitude(), injector.getMaxLongitude());
+
+               argList.add(latitude);
+               argList.add(longitude);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "set";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.LocaiontCodiDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       injector.sendLocation(latitude.getValue(), longitude.getValue());
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               } catch (InjectorLibraryException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               }
+
+               return 0;
+       }
+
+}
+
+class ArgLatitude extends Argument {
+       private double value = 0;
+       private int maxValue;
+       private int minValue;
+       public ArgLatitude(int min, int max) {
+               minValue = min;
+               maxValue = max;
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "latitude";
+       
+               description = StringResource.ArgLatitudeDesc +
+                               "\n\tThis value has between " + Integer.toString(minValue) +
+                               " and " + Integer.toString(maxValue) + ". ";
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               if (args.peek() != null) {
+                       String arg = args.pop().trim();
+                       try{
+                               value = Double.valueOf(arg);
+                       } catch (NumberFormatException t) {
+                               return false;
+                       }
+                       return true;
+               }
+
+               return false;
+       }
+
+       public double getValue() {
+               return value;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
+
+class ArgLongitude extends Argument {
+       private double value = 0;
+       private int maxValue;
+       private int minValue;
+
+       public ArgLongitude(int min, int max) {
+               minValue = min;
+               maxValue = max;
+               initialize();
+       }
+       @Override
+       protected void initialize() {
+               name = "longitude";
+               
+               description = StringResource.ArgLongitudeDesc +
+                               "\n\tThis value has between " + Integer.toString(minValue) +
+                               " and " + Integer.toString(maxValue) + ". ";
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               if (args.peek() != null) {
+                       String arg = args.pop().trim();
+                       try{
+                               value = Double.valueOf(arg);
+                       } catch (NumberFormatException t) {
+                               return false;
+                       }
+                       return true;
+               }
+
+               return false;
+       }
+
+       public double getValue() {
+               return value;
+       }
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/location/LocationLogFile.java b/eventinjector-cli/src/org/tizen/injector/device/location/LocationLogFile.java
new file mode 100644 (file)
index 0000000..82ddc18
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+package org.tizen.injector.device.location;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.parser.Args;
+
+public class LocationLogFile extends Command {
+       private ArgLocationFilePath path;
+       public LocationLogFile(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               path = new ArgLocationFilePath();
+               argList.add(path);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "file";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                                       StringResource.LocationFileDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator().getLocationInjector()
+                               .sendLocationFile(path.getFilePath());
+               } catch (IOException e) {
+                       System.out.println("Error: "+ e.getMessage());
+                       return 1;
+               } catch (InjectorLibraryException e) {
+                       System.out.println("Error: "+ e.getMessage());
+                       return e.getErrorNumber();
+               }
+               return 0;
+       }
+}
+
+class ArgLocationFilePath extends Argument {
+       private String filePath = null;
+
+       public ArgLocationFilePath() {
+               setUsingFile(true);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "file-path";
+
+               description = "'" + name + "' " + StringResource.ArgLocationFileDesc;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+
+               if (args.remain() == 1) {
+                       filePath = args.pop();
+               }
+               return true;
+       }
+
+       public String getFilePath() {
+               return filePath;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/location/LocationStop.java b/eventinjector-cli/src/org/tizen/injector/device/location/LocationStop.java
new file mode 100644 (file)
index 0000000..6a5f7cb
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.location;
+
+import java.io.IOException;
+
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class LocationStop extends Command{
+
+       public LocationStop(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "stop";
+       
+               description = "'" + name + "' " +
+                                       StringResource.LocationStopDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator().getLocationInjector()
+                                       .setStopMode();
+               } catch (IOException e) {
+                       System.out.println("Error: "+ e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/ArgCallNumber.java b/eventinjector-cli/src/org/tizen/injector/device/modem/ArgCallNumber.java
new file mode 100644 (file)
index 0000000..f6bf673
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import java.util.ArrayList;
+
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.parser.Args;
+
+public class ArgCallNumber extends Argument {
+       private String number = "";
+
+       public ArgCallNumber() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "number";
+               description = "'" + name + "' " + StringResource.ArgCallNumberDesc;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               if (args.remain() == 1) {
+                       number = args.pop().trim();
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       public String getNumber() {
+               return number;
+       }
+
+       void setNumber(String num) {
+               number = num;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/Call.java b/eventinjector-cli/src/org/tizen/injector/device/modem/Call.java
new file mode 100644 (file)
index 0000000..5712bbc
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.CallItem;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class Call extends Device {
+       public Call() {
+               commandList.add(new CallStatus(this, false));
+               commandList.add(new CallDial(this, false));
+               commandList.add(new CallHidden(this, false));
+               commandList.add(new CallAlert(this, false));
+               commandList.add(new CallConnect(this, false));
+               commandList.add(new CallDisconnect(this, false));
+               commandList.add(new CallList(this, false));
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name  = "call";
+               usage = name + StringResource.Command;
+               description = StringResource.CallDesc;
+       }
+
+}
+
+class CallStatus extends Command {
+
+       public CallStatus(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.CallStatusDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               System.out.println(StringResource.AvailableState);
+               System.out.println("Call list: ");
+               ArrayList<CallItem> callList = EventInjector.getCreator().getCallEventInjector().getCallItemList();
+               if (callList != null && !callList.isEmpty()) {
+                       for (CallItem i : callList) {
+                               System.out.println(i.toString());
+                               System.out.println("----------------");
+                       }
+               } else {
+                       System.out.println("\t" + StringResource.CallListEmpty);
+               }
+
+               System.out.println();
+               return 0;
+       }
+
+}
+
+class CallList extends Command {
+
+       public CallList(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "list";
+               description = "'" + name + "' " + StringResource.CallListDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException{
+               System.out.println("Call list: ");
+               ArrayList<CallItem> callList = EventInjector.getCreator().getCallEventInjector().getCallItemList();
+               if (callList != null && !callList.isEmpty()) {
+                       for (CallItem i : callList) {
+                               System.out.println(i.toString());
+                               System.out.println("----------------");
+                       }
+               } else {
+                       System.out.println("\t" + StringResource.CallListEmpty);
+               }
+               
+               return 0;
+       }
+       
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/CallAlert.java b/eventinjector-cli/src/org/tizen/injector/device/modem/CallAlert.java
new file mode 100644 (file)
index 0000000..21c934f
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import java.io.IOException;
+
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+
+public class CallAlert extends Command {
+
+       public CallAlert(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "alert";
+               description = "'" + name + "' "
+                               + StringResource.CallAlertDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException{
+               try {
+                       if (!EventInjector.getCreator()
+                                       .getCallEventInjector().alterCall()) {
+                               ConsoleException e = new ConsoleException(ConsoleError.CallCommandFailed);
+                               System.out.println("Error:" + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               } catch (InjectorLibraryException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               }
+               return 0;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/CallConnect.java b/eventinjector-cli/src/org/tizen/injector/device/modem/CallConnect.java
new file mode 100644 (file)
index 0000000..b7307a2
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import java.io.IOException;
+
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+
+public class CallConnect extends Command {
+
+       public CallConnect(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "connect";
+               description = "'" + name + "' " + StringResource.CallConnectDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       if (!EventInjector.getCreator()
+                                       .getCallEventInjector().connectCall()) {
+                               ConsoleException e = new ConsoleException(ConsoleError.CallCommandFailed);
+                               System.out.println("Error:" + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }  catch (InjectorLibraryException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               }
+               return 0;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/CallDial.java b/eventinjector-cli/src/org/tizen/injector/device/modem/CallDial.java
new file mode 100644 (file)
index 0000000..ba9c0fc
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import java.io.IOException;
+
+import org.tizen.eilib.exception.CallEventException;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class CallDial extends Command {
+       private ArgCallNumber num;
+
+       public CallDial(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               num = new ArgCallNumber();
+
+               argList.add(num);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "dial";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.CallDialDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException{
+               try {
+                       EventInjector.getCreator()
+                               .getCallEventInjector().calling(num.getNumber());
+               } catch (CallEventException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+}
+
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/CallDisconnect.java b/eventinjector-cli/src/org/tizen/injector/device/modem/CallDisconnect.java
new file mode 100644 (file)
index 0000000..806116e
--- /dev/null
@@ -0,0 +1,202 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.type.CallErrorCode;
+import org.tizen.eilib.exception.CallEventException;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class CallDisconnect extends Command {
+       private ArgCallID id;
+
+       public CallDisconnect(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               this.isStandalone = true;
+
+               id = new ArgCallID();
+               argList.add(id);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "disconnect";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.CallDisconnectDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator()
+                               .getCallEventInjector().disconnectCall(id.getID());
+               } catch (CallEventException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+       @Override
+       public int parseArgs(Args args) throws InjectorLibraryException
+       {
+               if (!this.hasArguments) {
+                       return 1;
+               } else {
+                       if (!id.parseArgs(args)) {
+                               ConsoleException e = new ConsoleException(ConsoleError.WrongArgument);
+                               this.printArgumentHelp(e);
+                               return e.getErrorNumber();
+                       }
+
+                       if (args.peek() != null) {
+                               ConsoleException e = new ConsoleException(ConsoleError.WrongArgument);
+                               this.printArgumentHelp(e);
+                               return e.getErrorNumber();
+                       }
+
+                       return 0;
+               }
+       }
+}
+
+class ArgCallID extends Argument {
+       private int id = -1;
+       public ArgCallID() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "id";
+               
+               description = "'" + name + "' " + StringResource.ArgCallIDDesc;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               if (args.peek() != null) {
+                       try {
+                               id = Integer.valueOf(args.pop().trim());
+                       } catch (NumberFormatException t) {
+                               this.printHelpMessage(t);
+                               return false;
+                       }
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       public int getID() {
+               return id;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
+
+class ArgCallErrorCode extends Argument {
+       private CallErrorCode code = null;
+
+       public ArgCallErrorCode() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "error-code";
+               description = "'" + name + "' " + StringResource.ArgCallErrorCodeDesc +
+                               "\n\tThis status has "; 
+               for (CallErrorCode e : CallErrorCode.values()) {
+                       description += e.toString() + " | "; 
+               }
+
+               description = description.substring(0, description.length() - 3);
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               code = null;
+
+               if (args.peek() != null) {
+                       String arg = args.pop().trim();
+                       for (CallErrorCode c : CallErrorCode.values()) {
+                               if (arg.equals(c.toString())) {
+                                       code = c;
+                                       break;
+                               }
+                       }
+               }
+
+               return code == null ? false : true;
+       }
+
+       public CallErrorCode getCode() {
+               return code;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+                       for (CallErrorCode e : CallErrorCode.values()) {
+                               values.add(e.toString());
+                       }
+               }
+
+               return values;
+       }
+       
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/CallHidden.java b/eventinjector-cli/src/org/tizen/injector/device/modem/CallHidden.java
new file mode 100644 (file)
index 0000000..ef351a5
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import java.io.IOException;
+
+import org.tizen.eilib.exception.CallEventException;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class CallHidden extends Command{
+       //private ArgCallNumber num;
+       private static String hiddenNumber = "1234";
+
+       public CallHidden(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               //num = new ArgCallNumber();
+
+               //argList.add(num);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "hidden-dial";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.CallHiddenDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator()
+                               .getCallEventInjector().calling(hiddenNumber, true);
+               } catch (CallEventException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/MmsSetStatus.java b/eventinjector-cli/src/org/tizen/injector/device/modem/MmsSetStatus.java
new file mode 100644 (file)
index 0000000..90ffda7
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.type.MMSStatus;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.parser.Args;
+
+public class MmsSetStatus extends Command{
+       private ArgMmsStatus status;
+       public MmsSetStatus(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               status = new ArgMmsStatus();
+               argList.add(status);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "set_mms";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.MMSSetStatusDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator().getSMSEventInjector()
+                               .sendStatus(status.getMmsStatus());
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+}
+
+class ArgMmsStatus extends Argument {
+       private MMSStatus status;
+
+       public ArgMmsStatus() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "mms_status";
+               description = "'" + name + "' " + StringResource.ArgSMSStatusDesc +
+                               "\n\tThis status has "; 
+               for (MMSStatus s : MMSStatus.values()) {
+                       description += s.toString() + " | "; 
+               }
+
+               description = description.substring(0, description.length() - 3);
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               status = null;
+
+               if (args.remain() == 1) {
+                       String arg = args.pop().trim();
+                       for (MMSStatus s : MMSStatus.values()) {
+                               if (s.toString().equals(arg)) {
+                                       status = s;
+                                       break;
+                               }
+                       }
+               }
+
+               return status == null ? false : true;
+       }
+
+       public MMSStatus getMmsStatus() {
+               return status;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+                       for (MMSStatus s : MMSStatus.values()) {
+                               values.add(s.toString());
+                       }
+               }
+
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/SMS.java b/eventinjector-cli/src/org/tizen/injector/device/modem/SMS.java
new file mode 100644 (file)
index 0000000..7674833
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class SMS extends Device {
+       public SMS() {
+               commandList.add(new SmsStatus(this, false));
+               commandList.add(new SmsSend(this, false));
+               commandList.add(new SmsSetStatus(this, false));
+               commandList.add(new MmsSetStatus(this, false));
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name  = "sms";
+               usage = name + StringResource.Command;
+               description = StringResource.SMSDesc;
+       }
+}
+
+class SmsStatus extends Command {
+       public SmsStatus(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.SMSStatusDesc;
+       }
+
+       @Override
+       public int process() {
+               System.out.println(StringResource.AvailableState);
+               System.out.println(StringResource.NotAvaliableGettingStatus);
+               System.out.println("SMS status: not support");
+               System.out.println();
+               return 0;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/SmsSend.java b/eventinjector-cli/src/org/tizen/injector/device/modem/SmsSend.java
new file mode 100644 (file)
index 0000000..be20659
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.SMSEventInjector;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.eilib.exception.SMSEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.parser.Args;
+
+public class SmsSend extends Command {
+       private ArgSmsNumber number;
+       private ArgSmsMessage msg;
+
+       public SmsSend(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               number = new ArgSmsNumber();
+               msg = new ArgSmsMessage();
+
+               argList.add(number);
+               argList.add(msg);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "send";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.SMSSendDesc;
+       }
+
+       private SMSEventInjector injector = null;
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       if (injector == null) {
+                               injector = EventInjector.getCreator().getSMSEventInjector();
+                       }
+                       injector.sendMessage(number.getNumber(), msg.getMessage(), true);
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               } catch (SMSEventException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return e.getErrorNumber();
+               }
+               return 0;
+       }
+}
+
+class ArgSmsNumber extends Argument {
+       private String number = "";
+
+       public ArgSmsNumber() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "number";
+               
+               description = "'" + name + "' " + StringResource.ArgSMSNumberDesc;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               if (args.peek() != null) {
+                       number = args.pop().trim();
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       public String getNumber() {
+               return number;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
+
+class ArgSmsMessage extends Argument {
+       private String message = "";
+
+       public ArgSmsMessage() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "message";
+               
+               description = "'" + name + "' " + StringResource.ArgSMSTextDesc;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               message = "";
+
+               while (args.peek() != null) {
+                       message += args.pop() + " ";
+               }
+               if (!message.isEmpty()) {
+                       message = message.substring(0, message.length() - 1);
+               }
+
+               return message.isEmpty() ? false : true;
+       }
+
+       public String getMessage() {
+               return message;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/modem/SmsSetStatus.java b/eventinjector-cli/src/org/tizen/injector/device/modem/SmsSetStatus.java
new file mode 100644 (file)
index 0000000..7a99913
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.modem;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.type.SMSStatus;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.parser.Args;
+
+public class SmsSetStatus extends Command{
+       private ArgSmsStatus status;
+       public SmsSetStatus(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               status = new ArgSmsStatus();
+               argList.add(status);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "set";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                               StringResource.SMSSetStatusDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator().getSMSEventInjector()
+                               .sendStatus(status.getSmsStatus());
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+}
+
+class ArgSmsStatus extends Argument {
+       private SMSStatus status;
+
+       public ArgSmsStatus() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "status";
+               description = "'" + name + "' " + StringResource.ArgSMSStatusDesc +
+                               "\n\tThis status has "; 
+               for (SMSStatus s : SMSStatus.values()) {
+                       description += s.toString() + " | "; 
+               }
+
+               description = description.substring(0, description.length() - 3);
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               status = null;
+
+               if (args.remain() == 1) {
+                       String arg = args.pop().trim();
+                       for (SMSStatus s : SMSStatus.values()) {
+                               if (s.toString().equals(arg)) {
+                                       status = s;
+                                       break;
+                               }
+                       }
+               }
+
+               return status == null ? false : true;
+       }
+
+       public SMSStatus getSmsStatus() {
+               return status;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+                       for (SMSStatus s : SMSStatus.values()) {
+                               values.add(s.toString());
+                       }
+               }
+
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/nfc/ArgMessageEventType.java b/eventinjector-cli/src/org/tizen/injector/device/nfc/ArgMessageEventType.java
new file mode 100644 (file)
index 0000000..25d64fa
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.nfc;
+
+import java.util.ArrayList;
+
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.parser.Args;
+
+public class ArgMessageEventType extends Argument {
+       private RecordEventType type = null;
+
+       public ArgMessageEventType() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "event-type";
+               description = "'" + name + "' is event type of message command." +
+                               "\n\t Event type: " + RecordEventType.Add +
+                               ", " + RecordEventType.Remove + ", " + RecordEventType.List;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               if (args.peek() == null) {
+                       return false;
+               } else {
+                       type = null;
+                       String arg = args.pop();
+                       for (RecordEventType t : RecordEventType.values()) {
+                               if (t.toString().equals(arg)) {
+                                       type = t;
+                                       break;
+                               }
+                       }
+
+                       return type == null ? false : true;
+               }
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               return RecordEventType.getCommandList();
+       }
+
+       public RecordEventType getType() {
+               return type;
+       }
+}
+
+enum RecordEventType
+{
+       Add("add"), Remove("remove"), List("list");
+
+       private String command;
+       private static ArrayList<String> list = new ArrayList<String>();
+       RecordEventType(String cmd) {
+               command = cmd;
+       }
+
+       @Override
+       public String toString() {
+               return command;
+       }
+
+       public static ArrayList<String> getCommandList() {
+               if (list.isEmpty()) {
+                       for (RecordEventType t : RecordEventType.values()) {
+                               list.add(t.toString());
+                       }
+               }
+               return list;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/nfc/ArgMessageIndex.java b/eventinjector-cli/src/org/tizen/injector/device/nfc/ArgMessageIndex.java
new file mode 100644 (file)
index 0000000..1bad5e1
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.nfc;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.NfcEventInjector;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class ArgMessageIndex extends Argument{
+       private int index = -1;
+       private NfcEventInjector injector;
+
+       public ArgMessageIndex() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "index";
+               description = "'"+ name + "' " + StringResource.ArgMessageIndexDesc;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException, ConsoleException {
+               try {
+                       injector = EventInjector.getCreator().getNfcEventInjector();
+               } catch (IOException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return false;
+               } catch (ConnectionException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return false;
+               }
+
+               if (args.length() != 1) {
+                       return false;
+               } else {
+                       index= -1;
+                       try {
+                               index = Integer.valueOf(args.pop());
+                       } catch (NumberFormatException t) {
+                               throw new ConsoleException(ConsoleError.WrongIntegerValue);
+                       }
+                       
+                       if (index < 0 || index > (injector.getRecordList().size() - 1)) {
+                               throw new ConsoleException(ConsoleError.ChecktNfcRecordList);
+                       }
+                       return true;
+               }
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+
+       public int getIndex() {
+               return index;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/nfc/ArgNDEFMessage.java b/eventinjector-cli/src/org/tizen/injector/device/nfc/ArgNDEFMessage.java
new file mode 100644 (file)
index 0000000..4897009
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.nfc;
+
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.type.NDEFFormat;
+import org.tizen.eilib.events.type.NDEFRecord;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class ArgNDEFMessage extends Argument {
+       private NDEFRecord record = null;
+       private String token = ",";
+
+       public ArgNDEFMessage() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "ndef-message";
+               description = "'"+ name + "' " + StringResource.ArgNDEFMessageDesc +
+                               "\n\t Input: ndef-format, typed-name, id, payload" +
+                               "\n\t NDEF format: ";
+               for (NDEFFormat f : NDEFFormat.values()) {
+                       description += f.getShortName() + ", ";
+               }
+               description  = description.substring(0, description.length() - 2);
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws ConsoleException{
+               record = null;
+
+               String arg = "";
+               while(args.peek() != null) {
+                       arg += args.pop();
+               }
+
+               String[] data = arg.split(token);
+               if (data.length != 4) {
+                       throw new ConsoleException(ConsoleError.WrongArgument);
+               }
+
+               NDEFFormat format = null;
+               for (NDEFFormat f : NDEFFormat.values()) {
+                       if (f.getShortName().equals(data[0])) {
+                               format = f;
+                               break;
+                       }
+               }
+               if (format == null) {
+                       throw new ConsoleException(ConsoleError.NotExistNDEFFormat);
+               }
+       
+               record = new NDEFRecord(format, data[1], data[2], data[3]);
+               return true;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+
+       public NDEFRecord getRecord() {
+               return record;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/nfc/ArgNfcTagEvent.java b/eventinjector-cli/src/org/tizen/injector/device/nfc/ArgNfcTagEvent.java
new file mode 100644 (file)
index 0000000..8fb51c6
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.nfc;
+
+import java.util.ArrayList;
+
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.parser.Args;
+
+public class ArgNfcTagEvent extends Argument {
+       private NfcTagEventType type = null;
+
+       public ArgNfcTagEvent() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "event-type";
+               description = "'" + name + "' " + StringResource.ArgMessageIndexDesc + 
+                               "\n\t Event type: " +
+                               NfcTagEventType.Attach + ", " + NfcTagEventType.Detach;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               if (args.peek() == null) {
+                       return false;
+               } else {
+                       type = null;
+                       String arg = args.pop();
+                       for (NfcTagEventType t : NfcTagEventType.values()) {
+                               if (t.toString().equals(arg)) {
+                                       type = t;
+                                       break;
+                               }
+                       }
+
+                       return type == null ? false : true;
+               }
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               return NfcTagEventType.getCommandList();
+       }
+
+       public NfcTagEventType getType() {
+               return type;
+       }
+}
+
+enum NfcTagEventType
+{
+       Attach("attach"), Detach("detach");
+
+       private String command;
+       private static ArrayList<String> list = new ArrayList<String>();
+       NfcTagEventType(String cmd) {
+               command = cmd;
+       }
+
+       @Override
+       public String toString() {
+               return command;
+       }
+
+       public static ArrayList<String> getCommandList() {
+               if (list.isEmpty()) {
+                       for (NfcTagEventType t : NfcTagEventType.values()) {
+                               list.add(t.toString());
+                       }
+               }
+               return list;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/nfc/Nfc.java b/eventinjector-cli/src/org/tizen/injector/device/nfc/Nfc.java
new file mode 100644 (file)
index 0000000..6151505
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.nfc;
+
+import java.io.IOException;
+
+import org.tizen.eilib.events.NfcEventInjector;
+import org.tizen.eilib.events.NfcEventType;
+import org.tizen.eilib.events.type.NDEFRecord;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.NfcEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class Nfc extends Device {
+       public Nfc() {
+               commandList.add(new NfcStatus(this, false));
+               commandList.add(new NfcTag(this, false));
+               commandList.add(new NfcP2P(this, false));
+               initialize();
+       }
+       @Override
+       protected void initialize() {
+               name  = "nfc";
+               usage = name + StringResource.Command; 
+               description = StringResource.NfcDesc;
+       }
+
+       @Override
+       public void printHelpMessage() {
+               //System.out.println(getDescription());
+               System.out.println(StringResource.Usage + getUsage());
+               System.out.println();
+               System.out.println(StringResource.CommandSyntax);
+               for (Command c : commandList) {
+                       if(!c.getSyntax().isEmpty()) {
+                               System.out.println("\t" + c.getSyntax());
+                       }
+               }
+               System.out.println();
+               System.out.println(StringResource.CommandArgument);
+               System.out.println(StringResource.NfcHelpMessage);
+       }
+
+       public void initSessionMode() {
+               commandList.add(new NfcMessage(this, false));
+       }
+}
+
+class NfcStatus extends Command {
+
+       public NfcStatus(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.NfcStatusDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               System.out.println(StringResource.AvailableState);
+               NfcEventInjector injector = null;
+               try {
+                       injector = EventInjector.getCreator().getNfcEventInjector();
+                       System.out.println("NFC status: " + injector.getNfcStatus());
+               } catch (IOException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return 1;
+               } catch (NfcEventException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return e.getErrorNumber();
+               }
+
+               if (injector.getCurrentEventType() == NfcEventType.TAG_DISCOVERED
+                               || injector.getCurrentEventType() == NfcEventType.P2P_SEND) {
+                       System.out.println("Attached NDEF message list:");
+                       for (NDEFRecord r : injector.getAttachedRecordList()) {
+                               System.out.println("\t" + r.toString());
+                       }
+               }
+
+               System.out.println();
+               if (EventInjector.isSessionMode()) {
+                       System.out.println("NDEF message list:");
+                       for (NDEFRecord r : injector.getRecordList()) {
+                               System.out.println("\t" + r.toString());
+                       }
+                       if (injector.getRecordList().isEmpty()) {
+                               System.out.println("\t" + StringResource.NDEFListEmpty);
+                       }
+               }
+               return 0;
+       }
+       
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/nfc/NfcMessage.java b/eventinjector-cli/src/org/tizen/injector/device/nfc/NfcMessage.java
new file mode 100644 (file)
index 0000000..aaad104
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.nfc;
+
+import java.io.IOException;
+
+import org.tizen.eilib.events.NfcEventInjector;
+import org.tizen.eilib.events.type.NDEFRecord;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.eilib.exception.NfcEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class NfcMessage extends Command {
+       private ArgMessageEventType type;
+       private ArgMessageIndex index;
+       private ArgNDEFMessage message;
+       private String syntax2;
+
+       public NfcMessage(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+
+               type    = new ArgMessageEventType();
+               index   = new ArgMessageIndex();
+               message = new ArgNDEFMessage();
+
+               argList.add(type);
+               argList.add(index);
+               argList.add(message);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "message";
+
+               syntax  = name + " " + type.getName();
+
+               syntax2 = name + " " + RecordEventType.Add + " ndef-message" +
+                               "\n\t" + name + " " + RecordEventType.Remove + " index" +
+                               "\n\t" + name + " " + RecordEventType.List;
+
+               description = "'" + name + "' " + StringResource.NfcMessageDesc;
+       }
+
+       private ConsoleException e = null;
+       @Override
+       public int parseArgs(Args args) {
+               if (type.parseArgs(args)) {
+                       switch(type.getType()) {
+                       case Add:
+                               try {
+                                       if(message.parseArgs(args)) {
+                                               return 0;
+                                       }
+                               } catch (ConsoleException e1) {
+                                       printHelpMessage(e1);
+                                       return e1.getErrorNumber();
+                               }
+                               break;
+                       case Remove:
+                               try {
+                                       if (index.parseArgs(args)) {
+                                               return 0;
+                                       }
+                               } catch (InjectorLibraryException e1) {
+                                       printHelpMessage(e1);
+                                       return e1.getErrorNumber();
+                               } catch (ConsoleException e1) {
+                                       printHelpMessage(e1);
+                                       return e1.getErrorNumber();
+                               }
+                               break;
+                       case List:
+                               break;
+                       default:
+                               break;
+                       }
+
+                       if (args.peek() == null) {
+                               return 0;
+                       }
+               }
+
+               e = new ConsoleException(ConsoleError.WrongArgument);
+               printHelpMessage(e);
+               return e.getErrorNumber();
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               NfcEventInjector injector = null;
+               try {
+                       injector = EventInjector.getCreator().getNfcEventInjector();
+               } catch (IOException e1) {
+                       System.out.println("Error: " + e1.getMessage());
+                       return 1;
+               }
+
+               switch(type.getType()) {
+               case Add:
+                       try {
+                               injector.addNDEFRecord(message.getRecord());
+                       } catch (NfcEventException e) {
+                               System.out.println("Error: " + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+                       break;
+               case Remove:
+                       try {
+                               injector.removeNDEFRecord(index.getIndex());
+                       } catch (NfcEventException e) {
+                               System.out.println("Error: " + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+                       break;
+               case List:
+                       System.out.println("NDEF message list:");
+                       for (NDEFRecord r : injector.getRecordList()) {
+                               System.out.println("\t" + r.toString());
+                       }
+                       if (injector.getRecordList().isEmpty()) {
+                               System.out.println("\t" + StringResource.NDEFListEmpty);
+                       }
+                       break;
+               default:
+                               break;
+               }
+               return 0;
+       }
+
+       @Override
+       public void printHelpMessage(Exception e) {
+               if (e != null) {
+                       System.out.println("Error:" + e.getMessage());
+                       System.out.println();
+               }
+               System.out.println(getDescription());
+               System.out.println();
+               System.out.println(StringResource.CommandSyntax);
+               System.out.println("\t"+ syntax2);
+               System.out.println();
+               System.out.println(StringResource.CommandArgument);
+               for (Argument a : getArgumentList()) {
+                       System.out.println("\t" + a.getDescription());
+               }
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/nfc/NfcP2P.java b/eventinjector-cli/src/org/tizen/injector/device/nfc/NfcP2P.java
new file mode 100644 (file)
index 0000000..5b3163b
--- /dev/null
@@ -0,0 +1,263 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.nfc;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.NfcEventInjector;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.eilib.exception.NfcEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class NfcP2P extends Command {
+       private ArgNDEFMessage message;
+       private ArgP2PType type;
+
+       private String onceSyntax;
+       private String sessionSyntax;
+       private String sessionDescription;
+
+       public NfcP2P(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               type = new ArgP2PType();
+               message = new ArgNDEFMessage();
+
+               argList.add(type);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "p2p";
+
+               syntax  = name + " " + type.getName();
+
+               onceSyntax = name + " " + P2PEventType.Attach +
+                               "\n\t" + name + " " + P2PEventType.Send + " ndef-message" +
+                               "\n\t" + name + " " + P2PEventType.Detach;
+
+               sessionSyntax = name + " " + P2PEventType.Attach +
+                               "\n\t" + name + " " + P2PEventType.Send +
+                               "\n\t" + name + " " + P2PEventType.Detach;
+
+               description = "'" + name + "' " + StringResource.NfcP2PDesc;
+
+               sessionDescription = "'" + name + "' " + StringResource.NfcP2PSessionDesc;
+       }
+
+       private ConsoleException e = null;
+       @Override
+       public int parseArgs(Args args) throws InjectorLibraryException, ConsoleException {
+               if (EventInjector.isSessionMode()) {
+                       return super.parseArgs(args);
+               }
+               if (type.parseArgs(args)) {
+                       if (type.getType() == P2PEventType.Send
+                                       && !EventInjector.isSessionMode()) {
+                               try {
+                                       if (message.parseArgs(args)) {
+                                               return 0;
+                                       }
+                               } catch (ConsoleException e1) {
+                                       printHelpMessage(e1);
+                                       return e1.getErrorNumber();
+                               }
+                       }
+                       return 0;
+               }
+
+               e = new ConsoleException(ConsoleError.WrongArgument);
+               printHelpMessage(e);
+               return e.getErrorNumber();
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               NfcEventInjector injector = null;
+               try {
+                       injector = EventInjector.getCreator().getNfcEventInjector();
+               } catch (IOException e1) {
+                       System.out.println("Error:" + e1.getMessage());
+                       return 1;
+               }
+
+               switch (type.getType()) {
+               case Attach:
+                       try {
+                               injector.sendP2PDiscovered();
+                       } catch (NfcEventException e) {
+                               System.out.println("Error:" + e.getMessage());
+                               return e.getErrorNumber();
+                       } catch (IOException e) {
+                               System.out.println("Error:" + e.getMessage());
+                               return 1;
+                       }
+                       break;
+               case Detach:
+                       try {
+                               injector.sendP2PDetached();
+                       } catch (NfcEventException e) {
+                               System.out.println("Error:" + e.getMessage());
+                               return e.getErrorNumber();
+                       } catch (IOException e) {
+                               System.out.println("Error:" + e.getMessage());
+                               return 1;
+                       }
+                       break;
+               case Send:
+                       if (!EventInjector.isSessionMode()) {
+                               try {
+                                       injector.addNDEFRecord(message.getRecord());
+                               } catch (NfcEventException e) {
+                                       System.out.println("Error: " + e.getMessage());
+                                       return e.getErrorNumber();
+                               }
+                       }
+
+                       try {
+                               injector.sendP2PSend();
+                       } catch (NfcEventException e) {
+                               System.out.println("Error:" + e.getMessage());
+                               return e.getErrorNumber();
+                       } catch (IOException e) {
+                               System.out.println("Error:" + e.getMessage());
+                               return 1;
+                       }
+                       break;
+               default:
+                               break;
+               }
+               return 0;
+       }
+
+       @Override
+       public void printHelpMessage(Exception e) {
+               if (e != null) {
+                       System.out.println("Error:" + e.getMessage());
+                       System.out.println();
+               }
+               if (EventInjector.isSessionMode()) {
+                       System.out.println(sessionDescription);
+                       System.out.println();
+                       System.out.println(StringResource.CommandSyntax);
+                       System.out.println("\t" + sessionSyntax);
+
+               } else {
+                       System.out.println(getDescription());
+                       System.out.println();
+                       System.out.println(StringResource.CommandSyntax);
+                       System.out.println("\t"+ onceSyntax);
+               }
+               System.out.println();
+               System.out.println(StringResource.CommandSyntax);
+               for (Argument a : getArgumentList()) {
+                       System.out.println("\t" + a.getDescription());
+               }
+               if (!EventInjector.isSessionMode()) {
+                       System.out.println("\t" + message.getDescription());
+               }
+       }
+}
+
+class ArgP2PType extends Argument {
+       private P2PEventType type = null;
+
+       public ArgP2PType() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "event-type";
+               description = "'" + name + "' " + StringResource.ArgP2PTypeDesc +
+                               "\n\t Event type: " + P2PEventType.Attach +
+                               ", " + P2PEventType.Send + ", " + P2PEventType.Detach;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               if (args.peek() == null) {
+                       return false;
+               } else {
+                       type = null;
+                       String arg = args.pop();
+                       for (P2PEventType t : P2PEventType.values()) {
+                               if (t.toString().equals(arg)) {
+                                       type = t;
+                                       break;
+                               }
+                       }
+
+                       return type == null ? false : true;
+               }
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               return P2PEventType.getCommandList();
+       }
+
+       public P2PEventType getType() {
+               return type;
+       }
+       
+}
+
+enum P2PEventType
+{
+       Attach("attach"), Send("send"), Detach("detach");
+
+       private String command;
+       private static ArrayList<String> list = new ArrayList<String>();
+       P2PEventType(String cmd) {
+               command = cmd;
+       }
+
+       @Override
+       public String toString() {
+               return command;
+       }
+
+       public static ArrayList<String> getCommandList() {
+               if (list.isEmpty()) {
+                       for (P2PEventType t : P2PEventType.values()) {
+                               list.add(t.toString());
+                       }
+               }
+               return list;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/nfc/NfcTag.java b/eventinjector-cli/src/org/tizen/injector/device/nfc/NfcTag.java
new file mode 100644 (file)
index 0000000..332e034
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.nfc;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.NfcEventInjector;
+import org.tizen.eilib.events.type.NfcTagType;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.NfcEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class NfcTag extends Command {
+       private ArgNDEFMessage message;
+       private ArgNfcTagEvent event;
+       private ArgTagType type;
+       private String onceSyntax;
+       private String sessionSyntax;
+       private String sessionDescription;
+
+       public NfcTag(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               event = new ArgNfcTagEvent();
+               type  = new ArgTagType();
+               message = new ArgNDEFMessage();
+
+               argList.add(event);
+               argList.add(type);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "tag";
+
+               syntax = name + " " + event.getName();
+
+               onceSyntax = name + " " + NfcTagEventType.Attach + " tag-type ndef-message" +
+                               "\n\t" + name + " " + NfcTagEventType.Detach;
+       
+               sessionSyntax = name + " " + NfcTagEventType.Attach + " tag-type" +
+                               "\n\t" + name + " " + NfcTagEventType.Detach;
+
+               description = "'" + name + "' " +
+                               StringResource.NfcTagDesc;
+
+               sessionDescription = "'" + name + "' " +
+                                       StringResource.NfcTagSessionDesc;
+
+       }
+
+       private ConsoleException e = null;
+       @Override
+       public int parseArgs(Args args) {
+               if (event.parseArgs(args)) {
+                       switch(event.getType()) {
+                       case Attach:
+                               if (type.parseArgs(args)) {
+                                       if (!EventInjector.isSessionMode()) {
+                                               try {
+                                                       if (message.parseArgs(args)) {
+                                                               return 0;
+                                                       }
+                                               } catch (ConsoleException e1) {
+                                                       printHelpMessage(e1);
+                                                       return e1.getErrorNumber();
+                                               }
+                                       } else {
+                                               return 0;
+                                       }
+                               }
+
+                               break;
+                       case Detach:
+                               if (args.peek() != null) {
+                                       if (type.parseArgs(args)) {
+                                               return 0;
+                                       }
+                               } else {
+                                       return 0;
+                               }
+                               break;
+                       default:
+                               return 1;
+                       }
+               }
+               e = new ConsoleException(ConsoleError.WrongArgument);
+               printHelpMessage(e);
+               return e.getErrorNumber();
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               NfcEventInjector injector = null;
+               try {
+                       injector = EventInjector.getCreator().getNfcEventInjector();
+               } catch (IOException e1) {
+                       System.out.println("Error: " + e.getMessage());
+                       return 1;
+               }
+
+               switch (event.getType()) {
+               case Attach:
+                       if (!EventInjector.isSessionMode()) {
+                               try {
+                                       injector.addNDEFRecord(message.getRecord());
+                               } catch (NfcEventException e) {
+                                       System.out.println("Error: " + e.getMessage());
+                                       return e.getErrorNumber();
+                               }
+                       }
+
+                       try {
+                               injector.sendTagDiscovered(type.getTagType());
+                       } catch (IOException e) {
+                               System.out.println("Error: " + e.getMessage());
+                               return 1;
+                       } catch (NfcEventException e) {
+                               System.out.println("Error:" + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+                       break;
+               case Detach:
+                       try {
+                               injector.sendTagDetached();
+                       } catch (IOException e) {
+                               System.out.println("Error: " + e.getMessage());
+                               return 1;
+                       } catch (NfcEventException e) {
+                               System.out.println("Error:" + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+                       break;
+               default:
+                       return 1;
+               }
+               return 0;
+       }
+
+       @Override
+       public void printHelpMessage(Exception e) {
+               if (e != null) {
+                       System.out.println("Error:" + e.getMessage());
+                       System.out.println();
+               }
+
+               if (EventInjector.isSessionMode()) {
+                       System.out.println(sessionDescription);
+                       System.out.println();
+                       System.out.println(StringResource.CommandSyntax);
+                       System.out.println("\t" + sessionSyntax);
+
+               } else {
+                       System.out.println(getDescription());
+                       System.out.println();
+                       System.out.println(StringResource.CommandSyntax);
+                       System.out.println("\t"+ onceSyntax);
+               }
+               System.out.println();
+               System.out.println(StringResource.CommandArgument);
+               for (Argument a : getArgumentList()) {
+                       System.out.println("\t" + a.getDescription());
+               }
+               if (!EventInjector.isSessionMode()) {
+                       System.out.println("\t" + message.getDescription());
+               }
+       }
+}
+
+class ArgTagType extends Argument {
+       private NfcTagType tagType = null;
+
+       public ArgTagType() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "tag-type";
+               description = "'" + name + "' is type of nfc tag." +
+                               "\tTag type: ";
+               for (NfcTagType f : NfcTagType.values()) {
+                       description += f.getShortName() + ", ";
+               }
+               description  = description.substring(0, description.length() - 2);
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               if (args.peek() == null) {
+                       return false;
+               } else {
+                       tagType = null;
+                       String arg = args.pop();
+                       for (NfcTagType t : NfcTagType.values()) {
+                               if (t.getShortName().equals(arg)) {
+                                       tagType = t;
+                                       break;
+                               }
+                       }
+
+                       return tagType == null ? false : true;
+               }
+       }
+
+       private static ArrayList<String> list = new ArrayList<String>();
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (list.isEmpty()) {
+                       for (NfcTagType t : NfcTagType.values()) {
+                               list.add(t.getShortName());
+                       }
+               }
+
+               return list;
+       }
+
+       public NfcTagType getTagType() {
+               return tagType;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgAccelValue.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgAccelValue.java
new file mode 100644 (file)
index 0000000..bf4b48f
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import org.tizen.injector.StringResource;
+import org.tizen.injector.parser.Args;
+
+public class ArgAccelValue extends ArgSensorValue {
+       private static String[] units = {"g"};
+       private String unit = null;
+       private double[] values = new double[3];
+       private String token = ",";
+
+       private double maxValue;
+       private double minValue;
+
+       public ArgAccelValue(double min, double max) {
+               minValue = min;
+               maxValue = max;
+               initialize();
+       }
+
+       public double getX() {
+               return values[0];
+       }
+
+       public double getY() {
+               return values[1];
+       }
+
+       public double getZ() {
+               return values[2];
+       }
+
+       @Override
+       protected void initialize() {
+               super.initialize();
+               valueDescription = "x, y, z" +
+                               "\n\t" + StringResource.ArgAccelValueDesc + 
+                               "\n\tThis value has between " + Double.toString(minValue) +
+                               " and " + Double.toString(maxValue) + ". ";
+
+               if (units.length > 1) {
+                       valueDescription += "Units are ";
+                       for (String u : units) {
+                               valueDescription += "'" + u + "' ";
+                       }
+                       valueDescription +=".";
+               } else {
+                       valueDescription += "Unit is '" + units[0] + "' .";
+               }
+
+               // TODO
+               unit = units[0];
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               String arg = "";
+               while(args.peek() != null) {
+                       arg += args.pop();
+               }
+
+               String[] data = arg.split(token);
+               if (data.length != 3) {
+                       return false;
+               }
+
+               String a;
+               for (int i = 0; i < 3; i++){
+                       a = data[i].trim();
+
+                       for (String u : units) {
+                               if (a.endsWith(u)) {
+                                       unit = u;
+                                       a = a.substring(0, a.length() - u.length());
+                               }
+                       }
+
+                       try {
+                               values[i] = Double.parseDouble(a);
+                       } catch (NumberFormatException t) {
+                               return false;
+                       }
+               }
+
+               return true;
+       }
+
+       public String getUnit() {
+               return unit;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgGyroValue.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgGyroValue.java
new file mode 100644 (file)
index 0000000..0ce9f4f
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import org.tizen.injector.StringResource;
+import org.tizen.injector.parser.Args;
+
+public class ArgGyroValue extends ArgSensorValue {
+       private static String[] units = {"r/s"};
+       private String unit = null;
+       private double[] values = new double[3];
+       private String token = ",";
+
+       private double maxValue;
+       private double minValue;
+
+       public ArgGyroValue(double min, double max) {
+               minValue = min;
+               maxValue = max;
+               initialize();
+       }
+
+       public double getX() {
+               return values[0];
+       }
+
+       public double getY() {
+               return values[1];
+       }
+
+       public double getZ() {
+               return values[2];
+       }
+
+       @Override
+       protected void initialize() {
+               super.initialize();
+               valueDescription = "x, y, z" +
+                               "\n\t" + StringResource.ArgGyroValueDesc +
+                               "\n\tThis value has between " + Double.toString(minValue) +
+                               " and " + Double.toString(maxValue) + ". ";
+
+               if (units.length > 1) {
+                       valueDescription += "Units are ";
+                       for (String u : units) {
+                               valueDescription += "'" + u + "' ";
+                       }
+                       valueDescription +=".";
+               } else {
+                       valueDescription += "Unit is '" + units[0] + "' .";
+               }
+
+               // TODO
+               unit = units[0];
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               String arg = "";
+               while(args.peek() != null) {
+                       arg += args.pop();
+               }
+
+               String[] data = arg.split(token);
+               if (data.length != 3) {
+                       return false;
+               }
+
+               String a;
+               for (int i = 0; i < 3; i++){
+                       a = data[i].trim();
+                       for (String u : units) {
+                               if (a.endsWith(u)) {
+                                       unit = u;
+                                       a = a.substring(0, a.length() - u.length());
+                               }
+                       }
+
+                       try {
+                               values[i] = Double.parseDouble(a);
+                       } catch (NumberFormatException t) {
+                               return false;
+                       }
+               }
+
+               return true;
+       }
+
+       public String getUnit() {
+               return unit;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgLightValue.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgLightValue.java
new file mode 100644 (file)
index 0000000..b004553
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import org.tizen.injector.StringResource;
+import org.tizen.injector.parser.Args;
+
+public class ArgLightValue extends ArgSensorValue {
+       private static String[] units = {"lux"};
+       private String unit = null;
+       private int value = 0;
+
+       private int maxValue;
+       private int minValue;
+
+       public ArgLightValue(int min, int max) {
+               minValue = min;
+               maxValue = max;
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               super.initialize();
+               valueDescription = "value" +
+                               "\n\t" + StringResource.ArgLightValueDesc +
+                               "\n\tThis value has between " + Integer.toString(minValue) +
+                               " and " + Integer.toString(maxValue) + ". ";
+               if (units.length > 1) {
+                       valueDescription += "Units are ";
+                       for (String u : units) {
+                               valueDescription += "'" + u + "' ";
+                       }
+                       valueDescription +=".";
+               } else {
+                       valueDescription += "Unit is '" + units[0] + "' .";
+               }
+
+               // TODO
+               unit = units[0];
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               if (args.remain() != 1) {
+                       return false;
+               }
+
+               String arg = args.pop().trim();
+
+               for (String u : units) {
+                       if (arg.endsWith(u)) {
+                               unit = u;
+                               arg = arg.substring(0, arg.length() - u.length());
+                       }
+               }
+
+               try {
+                       value = Integer.parseInt(arg);
+               } catch (NumberFormatException t) {
+                       return false;
+               }
+
+               return true;
+       }
+
+       public int getValue() {
+               return value;
+       }
+
+       public String getUnit() {
+               return unit;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgMagneticValue.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgMagneticValue.java
new file mode 100644 (file)
index 0000000..4d65b15
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.injector.device.sensor;
+
+import org.tizen.injector.StringResource;
+import org.tizen.injector.parser.Args;
+
+public class ArgMagneticValue extends ArgSensorValue {
+       private static String[] units = {"uT"};
+       private String unit = null;
+       private int[] values = new int[3];
+       private String token = ",";
+
+       private int maxValue;
+       private int minValue;
+
+       public ArgMagneticValue(int min, int max) {
+               minValue = min;
+               maxValue = max;
+               initialize();
+       }
+
+       public int getX() {
+               return values[0];
+       }
+
+       public int getY() {
+               return values[1];
+       }
+
+       public int getZ() {
+               return values[2];
+       }
+
+       @Override
+       protected void initialize() {
+               super.initialize();
+               valueDescription = "x, y, z" +
+                               "\n\t" + StringResource.ArgMagneticValueDesc + 
+                               "\n\tThis value has between " + Integer.toString(minValue) +
+                               " and " + Integer.toString(maxValue) + ". ";
+
+               if (units.length > 1) {
+                       valueDescription += "Units are ";
+                       for (String u : units) {
+                               valueDescription += "'" + u + "' ";
+                       }
+                       valueDescription +=".";
+               } else {
+                       valueDescription += "Unit is '" + units[0] + "' .";
+               }
+               // TODO
+               unit = units[0];
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               String arg = "";
+               while(args.peek() != null) {
+                       arg += args.pop();
+               }
+
+               String[] data = arg.split(token);
+               if (data.length != 3) {
+                       return false;
+               }
+
+               String a;
+               for (int i = 0; i < 3; i++){
+                       a = data[i].trim();
+
+                       for (String u : units) {
+                               if (a.endsWith(u)) {
+                                       unit = u;
+                                       a = a.substring(0, a.length() - u.length());
+                               }
+                       }
+
+                       try {
+                               values[i] = Integer.parseInt(a);
+                       } catch (NumberFormatException t) {
+                               return false;
+                       }
+               }
+
+               return true;
+       }
+
+       public String getUnit() {
+               return unit;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgProxiValue.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgProxiValue.java
new file mode 100644 (file)
index 0000000..199e5a6
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import org.tizen.eilib.events.type.ProximityStatus;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.parser.Args;
+
+public class ArgProxiValue extends ArgSensorValue {
+       private ProximityStatus status = null;
+
+       public ArgProxiValue() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               super.initialize();
+               ProximityStatus[] status = ProximityStatus.values();
+               ProximityStatus s;
+               String values = "";
+               for (int i = 0; i < status.length; i++) {
+                       s = status[i];
+                       values += s.toString();
+                       if (i+1 != status.length) {
+                               values += " | ";
+                       }
+               }
+
+               valueDescription = values + "\n\t" + StringResource.ArgProxiValueDesc;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               if (args.remain() != 1) {
+                       return false;
+               }
+
+               status = null;
+
+               String arg = args.pop().toLowerCase();
+               for (ProximityStatus s : ProximityStatus.values()) {
+                       if (s.toString().equals(arg)) {
+                               status = s;
+                               break;
+                       }
+               }
+               return status == null ? false : true;
+       }
+
+       public ProximityStatus getStatus() {
+               return status;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorFilePath.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorFilePath.java
new file mode 100644 (file)
index 0000000..c8c6b27
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.exception.EILibError;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.parser.Args;
+
+public class ArgSensorFilePath extends Argument {
+       private String filePath = null;
+       public ArgSensorFilePath() {
+               setUsingFile(true);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "file-path";
+
+               description = "'" + name + "' " + StringResource.ArgSensorFilePathDesc;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               //arg = arg.trim();
+               if (args.remain() == 1) {
+                       File f = new File(args.pop());
+                       if (!f.exists()) {
+                               throw new InjectorLibraryException(EILibError.NotExistLogFile);
+                       }
+       
+                       try {
+                               filePath = f.getCanonicalPath();
+                       } catch (IOException e) {
+                               System.out.println("Error: "+ e.getMessage());
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       public String getFilePath() {
+               return filePath;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorName.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorName.java
new file mode 100644 (file)
index 0000000..797a049
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.type.SensorEventType;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.parser.Args;
+
+public class ArgSensorName extends Argument{
+       private ArrayList<SensorEventType> sensorNames;
+       private SensorEventType eventType;
+
+       /**
+        * 
+        * @param isLogFile
+        */
+       public ArgSensorName(boolean isLogFile) {
+
+               eventType       = SensorEventType.NONE;
+               sensorNames = new ArrayList<SensorEventType>();
+
+               if(isLogFile) {
+                       initLogFileSensorNames();
+               } else {
+                       initSensorNames();
+               }
+               initialize();
+       }
+
+       private void initLogFileSensorNames() {
+               sensorNames.add(SensorEventType.FILE_ACCEL);
+               sensorNames.add(SensorEventType.FILE_GYRO);
+               sensorNames.add(SensorEventType.FILE_MAGNETIC);
+       }
+
+       private void initSensorNames() {
+               sensorNames.add(SensorEventType.ACCEL);
+               sensorNames.add(SensorEventType.GYRO);
+               sensorNames.add(SensorEventType.MAGNETIC);
+               sensorNames.add(SensorEventType.PROXI);
+               sensorNames.add(SensorEventType.LIGHT);
+       }
+
+       /**
+        * 
+        * @return
+        */
+       public SensorEventType getEventType() {
+               return eventType;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               if (args.remain() < 1) {
+                       return false;
+               }
+
+               String name = args.pop();
+               for(SensorEventType s : sensorNames) {
+                       if (s.getName().equals(name)) {
+                               eventType = s;
+                               return true;
+                       }
+               }
+               return false;
+       }
+
+       @Override
+       protected void initialize() {
+               name = "sensor-name";
+               description = "'" + name + "'" + StringResource.ArgSensorNameDesc;
+       }
+
+       public ArrayList<SensorEventType> getSensorNames() {
+               return sensorNames;
+       }
+
+       public void printHelpMessage(Exception e) {
+               super.printHelpMessage(e);
+               System.out.println("Sensor name:");
+               for (SensorEventType type : sensorNames) {
+                       System.out.println("\t" + type.getName());
+               }
+               System.out.println();
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+                       for (SensorEventType s : sensorNames) {
+                               values.add(s.getName());
+                       }
+               }
+
+               return values;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorValue.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/ArgSensorValue.java
new file mode 100644 (file)
index 0000000..26b0b5c
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import java.util.ArrayList;
+
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.parser.Args;
+
+public class ArgSensorValue extends Argument {
+       protected String valueDescription = "";
+
+       public ArgSensorValue() {
+               initialize();
+       }
+
+       public String getValueDescription() {
+               return valueDescription;
+       }
+
+       @Override
+       protected void initialize() {
+               name            = "sensor-value";
+               description = "'"+ name + "' " + StringResource.ArgSensorValueDesc;
+       }
+
+       @Override
+       public boolean parseArgs(Args args) {
+               return false;
+       }
+
+       public void printHelpMessage(Exception e) {
+               super.printHelpMessage(e);
+               System.out.println("Sensor value:");
+               System.out.println("\t" + getValueDescription());
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+               }
+
+               return values;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/Motion.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/Motion.java
new file mode 100644 (file)
index 0000000..1bbfa3b
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.injector.device.sensor;
+
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class Motion extends Device {
+       public Motion() {
+               commandList.add(new MotionStatus(this, false));
+               commandList.add(new MotionSet(this, false));
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name  = "motion";
+               usage = name + StringResource.Command;
+               description = StringResource.MotionDesc;
+       }
+
+}
+
+class MotionStatus extends Command {
+       public MotionStatus(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.MotionStatusDesc;
+       }
+
+       @Override
+       public int process() {
+               System.out.println(StringResource.AvailableState);
+               System.out.println(StringResource.NotAvaliableGettingStatus);
+               System.out.println("Motion status: not support");
+               System.out.println();
+               return 0;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/MotionSet.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/MotionSet.java
new file mode 100644 (file)
index 0000000..193ee3f
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.tizen.eilib.events.type.MotionEventType;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.parser.Args;
+
+public class MotionSet extends Command {
+       private ArgMotion motion;
+       public MotionSet(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               motion = new ArgMotion();
+               argList.add(motion);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "set";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                                       StringResource.MotionSetDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator().getSensorInjector()
+                                       .motionEvent(motion.getMotionType());
+               } catch (IOException e) {
+                       System.out.println("Error:" + e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+}
+
+class ArgMotion extends Argument {
+       private MotionEventType motionType = null;
+
+       public ArgMotion() {
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name = "motion-type";
+               description = "'" + name + "' " + StringResource.ArgMotionDesc +
+                               "\n\tThis type has "; 
+               for (MotionEventType t : MotionEventType.values()) {
+                       description += t.toString() + " | "; 
+               }
+
+               description = description.substring(0, description.length() - 3);
+       }
+
+       @Override
+       public boolean parseArgs(Args args) throws InjectorLibraryException {
+               motionType = null;
+
+               if (args.remain() == 1) {
+                       String arg = args.pop().trim();
+       
+                       for (MotionEventType t : MotionEventType.values()) {
+                               if (t.toString().equals(arg)) {
+                                       motionType = t;
+                                       break;
+                               }
+                       }
+               }
+
+               return motionType == null ? false : true;
+       }
+
+       public MotionEventType getMotionType() {
+               return motionType;
+       }
+
+       @Override
+       public ArrayList<String> getPassibleValue() {
+               if (values == null) {
+                       values = new ArrayList<String>();
+                       for (MotionEventType t : MotionEventType.values()) {
+                               values.add(t.toString());
+                       }
+               }
+
+               return values;
+       }
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/Sensor.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/Sensor.java
new file mode 100644 (file)
index 0000000..8098ac5
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import java.io.IOException;
+
+import org.tizen.eilib.events.SensorEventInjector;
+import org.tizen.eilib.events.type.ProximityStatus;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+public class Sensor extends Device {
+       private SensorSet sensorSet;
+       public Sensor() {
+               sensorSet = new SensorSet(this, false);
+               commandList.add(new SensorStatus(this, false));
+               commandList.add(new SensorGet(this, false));
+               commandList.add(sensorSet);
+               commandList.add(new SensorFile(this, false));
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               name  = "sensor";
+               usage = name + StringResource.Command; 
+               description = StringResource.SensorDesc;
+       }
+/*
+       @Override
+       public void printHelpMessage() {
+               super.printHelpMessage();
+
+               System.out.println();
+               System.out.println("Set command's value argument:");
+               
+               Map<String, SensorValue> map = sensorSet.getValueMap();
+               ArrayList<SensorEventType> sensorTypes = sensorSet.getSensorNames();
+
+               for (SensorEventType type : sensorTypes) {
+                       SensorValue value = map.get(type.getName());
+                       if (value != null) {
+                               System.out.println(value.getValueDescription());
+                       }
+               }
+       }
+       */
+}
+
+class SensorStatus extends Command {
+
+       public SensorStatus(Device device, boolean isDefault) {
+               super(device, isDefault, false);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "status";
+               description = "'" + name + "' " + StringResource.SensorStatusDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               System.out.println(StringResource.AvailableState);
+               System.out.println("Sensor status:");
+               SensorEventInjector injector = EventInjector.getCreator().getSensorInjector();
+               try {
+                       double[] accel = injector.getAccelValue();
+                       if (accel != null) {
+                               System.out.println(String.format("\tAcceleration: %.2f, %.2f, %.2f",
+                                               accel[0], accel[1], accel[2]));
+                       } else {
+                               System.out.println("Acceleration: " + StringResource.FailedGetValue);
+                       }
+                       double[] gyro = injector.getGyroValue();
+                       if (gyro != null) {
+                               System.out.println(String.format("\tGyroscope: %.2f, %.2f, %.2f",
+                                               gyro[0], gyro[1], gyro[2]));
+                       } else {
+                               System.out.println("Gyroscope: " + StringResource.FailedGetValue);
+                       }
+                       int[] mag = injector.getMagneticValue();
+                       if (mag != null) {
+                               System.out.println("\tMagnetic: " + mag[0] + ", "+ mag[1] + ", " + mag[2]);
+                       } else {
+                               System.out.println("Magnetic: " + StringResource.FailedGetValue);
+                       }
+                       ProximityStatus s = injector.getProximityStatus();
+                       if (s != null) {
+                               System.out.println("\tProximity: " + s.toString()); 
+                       } else {
+                               System.out.println("Proximity: " + StringResource.FailedGetValue);
+                       }
+                       int level = -1;
+                       level = injector.getLightValue();
+                       if (level != -1) {
+                               System.out.println("\tLight: " + level);
+                       } else {
+                               System.out.println("Light: " + StringResource.FailedGetValue);
+                       }
+               } catch (IOException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return 1;
+               } catch (InjectorLibraryException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return e.getErrorNumber();
+               }
+
+               System.out.println();
+               return 0;
+       }
+
+}
\ No newline at end of file
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/SensorFile.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/SensorFile.java
new file mode 100644 (file)
index 0000000..1a25bb2
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import java.io.IOException;
+
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class SensorFile extends Command {
+       private ArgSensorName   sensorName;
+       private ArgSensorFilePath       filePath;
+       public SensorFile(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               sensorName  = new ArgSensorName(true);
+               filePath        = new ArgSensorFilePath();
+               argList.add(sensorName);
+               argList.add(filePath);
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "file";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                                       StringResource.SensorFileDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       EventInjector.getCreator().getSensorInjector()
+                               .sendLogFileEvent(sensorName.getEventType(), filePath.getFilePath());
+               } catch (IOException e) {
+                       System.out.println("Error: "+ e.getMessage());
+                       return 1;
+               }
+               return 0;
+       }
+
+       private ConsoleException e = null;
+       @Override
+       public int parseArgs(Args args) {
+               if (sensorName.parseArgs(args)) {
+                       try {
+                               if (!filePath.parseArgs(args)) {
+                                       e = new ConsoleException(ConsoleError.WrongArgument);
+                                       printFileHelp(e);
+                                       return e.getErrorNumber();
+                               } else {
+                                       return 0;
+                               }
+                       } catch (InjectorLibraryException e1) {
+                               printFileHelp(e1);
+                               return e1.getErrorNumber();
+                       }
+               }
+               e = new ConsoleException(ConsoleError.WrongArgument);
+               printSensorNameHelp(e);
+               return e.getErrorNumber();
+       }
+
+       private void printSensorNameHelp(Exception e) {
+               printArgumentHelp(e);
+               System.out.println("\t" + filePath.getDescription());
+               sensorName.printHelpMessage(null);
+       }
+
+       private void printFileHelp(Exception e) {
+               printArgumentHelp(e);
+               System.out.println("\t" + sensorName.getDescription());
+               System.out.println("\t" + filePath.getDescription());
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/SensorGet.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/SensorGet.java
new file mode 100644 (file)
index 0000000..3692e5d
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import java.io.IOException;
+
+import org.tizen.eilib.events.SensorEventInjector;
+import org.tizen.eilib.events.type.ProximityStatus;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class SensorGet extends Command {
+       private ArgSensorName sensorName;
+
+       private SensorEventInjector injector;
+       public SensorGet(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               injector = EventInjector.getCreator().getSensorInjector();
+               sensorName = new ArgSensorName(false);
+               argList.add(sensorName);
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "get";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                                       StringResource.SensorGetDesc;
+       }
+
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       switch(sensorName.getEventType()) {
+                       case ACCEL:
+                               double[] accel = injector.getAccelValue();
+                               if (accel != null) {
+                                       System.out.println(String.format("Acceleration: %.2f, %.2f, %.2f",
+                                                       accel[0], accel[1], accel[2]));
+                               } else {
+                                       System.out.println("Acceleration: " + StringResource.FailedGetValue);
+                               }
+                               break;
+                       case GYRO:
+                               double[] gyro = injector.getGyroValue();
+                               if (gyro != null) {
+                                       System.out.println(String.format("Gyroscope: %.2f, %.2f, %.2f",
+                                                       gyro[0], gyro[1], gyro[2]));
+                               } else {
+                                       System.out.println("Gyroscope: " + StringResource.FailedGetValue);
+                               }
+                               break;
+                       case MAGNETIC:
+                               int[] mag = injector.getMagneticValue();
+                               if (mag != null) {
+                                       System.out.println("Magnetic: " + mag[0] + ", "
+                                                       + mag[1] + ", " + mag[2]);
+                               } else {
+                                       System.out.println("Magnetic: " + StringResource.FailedGetValue);
+                               }
+                               break;
+                       case PROXI:
+                               ProximityStatus s = injector.getProximityStatus();
+                               if (s != null) {
+                                       System.out.println("Proximity: " + s.toString()); 
+                               } else {
+                                       System.out.println("Proximity: " + StringResource.FailedGetValue);
+                               }
+                               break;
+                       case LIGHT:
+                               int level = injector.getLightValue();
+                               if (level != -1) {
+                                       System.out.println("Light: " + level);
+                               } else {
+                                       System.out.println("Light: " + StringResource.FailedGetValue);
+                               }
+                               break;
+                       default:
+                               ConsoleException e = new ConsoleException(ConsoleError.WrongArgument);
+                               System.out.println("Error: " + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+               }  catch (IOException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return 1;
+               } catch (InjectorLibraryException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return e.getErrorNumber();
+               }
+
+               return 0;
+       }
+
+       @Override
+       public int parseArgs(Args args) {
+               if(!sensorName.parseArgs(args) || args.remain() != 0) {
+                       ConsoleException e = new ConsoleException(ConsoleError.WrongArgument);
+                       printHelp(e);
+                       return e.getErrorNumber();
+               }
+
+               return 0;
+       }
+
+       private void printHelp(Exception e) {
+               printArgumentHelp(e);
+               //sensorName.printHelpMessage(null);
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/device/sensor/SensorSet.java b/eventinjector-cli/src/org/tizen/injector/device/sensor/SensorSet.java
new file mode 100644 (file)
index 0000000..7798bc8
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.device.sensor;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.tizen.eilib.events.SensorEventInjector;
+import org.tizen.eilib.events.type.SensorEventType;
+import org.tizen.eilib.exception.ConnectionException;
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.eilib.exception.SensorEventException;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.StringResource;
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+import org.tizen.injector.parser.Args;
+
+public class SensorSet extends Command {
+       private ArgSensorName   sensorName;
+       private ArgSensorValue sensorValue;
+       private Map<String, ArgSensorValue> valueMap;
+       private ConsoleException e = null;
+
+       private SensorEventInjector injector;
+       public SensorSet(Device device, boolean isDefault) {
+               super(device, isDefault, true);
+               injector = EventInjector.getCreator().getSensorInjector();
+
+               sensorName      = new ArgSensorName(false);
+               sensorValue = new ArgSensorValue();
+               argList.add(sensorName);
+               argList.add(sensorValue);
+
+               valueMap = new HashMap<String, ArgSensorValue>();
+               valueMap.put(SensorEventType.ACCEL.getName(),
+                               new ArgAccelValue(injector.getMinAccelValue(), injector.getMaxAccelValue()));
+               valueMap.put(SensorEventType.GYRO.getName(),
+                               new ArgGyroValue(injector.getMinGyroValue(), injector.getMaxGyroValue()));
+               valueMap.put(SensorEventType.MAGNETIC.getName(),
+                               new ArgMagneticValue(injector.getMinMagneticValue(), injector.getMaxMagneticValue()));
+               valueMap.put(SensorEventType.PROXI.getName(),
+                               new ArgProxiValue());
+               valueMap.put(SensorEventType.LIGHT.getName(),
+                               new ArgLightValue(injector.getMinLightValue(), injector.getMaxLightValue()));
+
+               initialize();
+       }
+
+       @Override
+       protected void initialize() {
+               syntax = name = "set";
+
+               for (Argument arg : argList) {
+                       syntax += " " + arg.getName();
+               }
+
+               description = "'" + name + "' " +
+                                       StringResource.SensorSetDesc;
+       }
+
+       private ArgAccelValue accel = null;
+       private ArgGyroValue gyro = null;
+       private ArgMagneticValue mag = null;
+       private ArgProxiValue proxi = null;
+       private ArgLightValue light = null;
+       @Override
+       public int process() throws ConnectionException {
+               try {
+                       switch(sensorName.getEventType()) {
+                       case ACCEL:
+                               if (accel == null) {
+                                       accel = (ArgAccelValue)valueMap.get(sensorName.getEventType().getName());
+                               }
+                               injector.accelEvent(accel.getX(), accel.getY(), accel.getZ());
+                               break;
+                       case GYRO:
+                               if (gyro == null) {
+                                       gyro = (ArgGyroValue)valueMap.get(sensorName.getEventType().getName());
+                               }
+                               injector.gyroEvent(gyro.getX(), gyro.getY(), gyro.getZ());
+                               break;
+                       case MAGNETIC:
+                               if (mag == null) {
+                                       mag = (ArgMagneticValue)valueMap.get(sensorName.getEventType().getName());
+                               }
+                               injector.magneticEvent(mag.getX(), mag.getY(), mag.getZ());
+                               break;
+                       case PROXI:
+                               if (proxi == null) {
+                                       proxi = (ArgProxiValue)valueMap.get(sensorName.getEventType().getName());
+                               }
+                               injector.proximityEvent(proxi.getStatus());
+                               break;
+                       case LIGHT:
+                               if (light == null) {
+                                       light = (ArgLightValue)valueMap.get(sensorName.getEventType().getName());
+                               }
+                               injector.ligthEvent(light.getValue());
+                               break;
+                       default:
+                               e = new ConsoleException(ConsoleError.WrongArgument);
+                               System.out.println("Error: " + e.getMessage());
+                               return e.getErrorNumber();
+                       }
+               } catch (IOException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return 1;
+               } catch (SensorEventException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return e.getErrorNumber();
+               } catch (InjectorLibraryException e) {
+                       System.out.println("Error: " + e.getMessage());
+                       return e.getErrorNumber();
+               }
+               return 0;
+       }
+
+       public Map<String, ArgSensorValue> getValueMap() {
+               return valueMap;
+       }
+
+       public ArrayList<SensorEventType> getSensorNames() {
+               return sensorName.getSensorNames();
+       }
+
+       @Override
+       public int parseArgs(Args args) {
+               if (sensorName.parseArgs(args)) {
+                       ArgSensorValue value = valueMap.get(sensorName.getEventType().getName());
+                       if (value != null) {
+                               boolean re = value.parseArgs(args);
+                               if (!re){
+                                       e = new ConsoleException(ConsoleError.WrongArgument);
+                                       printSensorValueHelp(value, e);
+                                       return e.getErrorNumber();
+                               }
+                               return 0;
+                       }
+               }
+               e = new ConsoleException(ConsoleError.WrongArgument);
+               printSensorNameHelp(e);
+               return e.getErrorNumber();
+       }
+
+       public void printArgumentHelp(Exception e) {
+               if (e != null) {
+                       System.out.println("Error:" + e.getMessage());
+                       System.out.println();
+               }
+               System.out.println(StringResource.Usage + device.getName() +
+                               " " + syntax);
+               System.out.println();
+               System.out.println(StringResource.CommandArgument);
+       }
+
+       private void printSensorNameHelp(Exception e) {
+               printArgumentHelp(e);
+               System.out.println("\t" + sensorValue.getDescription());
+               sensorName.printHelpMessage(null);
+       }
+
+       private void printSensorValueHelp(ArgSensorValue value, Exception e) {
+               printArgumentHelp(e);
+               System.out.println("\t" + sensorName.getDescription());
+               value.printHelpMessage(null);
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/exception/ConsoleError.java b/eventinjector-cli/src/org/tizen/injector/exception/ConsoleError.java
new file mode 100644 (file)
index 0000000..6d5b122
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+
+package org.tizen.injector.exception;
+
+class ErrorNumber {
+       public static int Console = 2000;
+}
+
+public enum ConsoleError {
+       WrongAction(ErrorNumber.Console, "This action name not found."),
+       MissingArg(ErrorNumber.Console + 1, "Need command arguments."),
+       //NotAvaliableArg(ErrorNumber.Console + 2, "This is not avaliable argument."),
+       
+
+       NotAvaliableEM(ErrorNumber.Console + 3, "Emulator's port number or name is not avaliable.\nPlease check running emulator list by using '--emulator | -e' option."),
+       
+
+       WrongDevice(ErrorNumber.Console + 4, "This device not found."),
+       WrongCommand(ErrorNumber.Console + 5, "This command not found."),
+       CommandMissingArg(ErrorNumber.Console + 6, " Need command arguments."),
+       WrongArgument(ErrorNumber.Console + 7, "This argument not found."),
+
+       //SDCard
+       MountFailed(ErrorNumber.Console + 8, "To mount sdcard is failed."),
+       UmountFailed(ErrorNumber.Console + 9, "To unmount sdcard is failed."),
+
+       CallCommandFailed(ErrorNumber.Console + 10, "Handling call event is faied."),
+
+       // record command
+       FullCommandBuffer(ErrorNumber.Console + 11, "Buffer of commands is full.."),
+       AlreadyStartRecording(ErrorNumber.Console + 12, "Already to start recording commands. If you want new recoring process, first, stop recording."),
+       AlreadyStopRecording(ErrorNumber.Console + 13, "Already to stop recoring commands, first, start recording process."),
+       NotExistLogFile(ErrorNumber.Console + 14, "This log file does not exist."),
+       AlreadyRecording(ErrorNumber.Console + 15, "Already to start recording commands. If you want play commands, first, stop recording process."),
+       
+       
+       // nfc command
+       WrongIntegerValue(ErrorNumber.Console + 16, "This value does not integer format."),
+       ChecktNfcRecordList(ErrorNumber.Console + 17, "This index does not exist."),
+       NotExistNDEFFormat(ErrorNumber.Console + 18, "This ndef format does not exist."),
+       ConsoleError(1, "ErrorMessage");
+
+       int number;
+       String message;
+       
+       ConsoleError(int n, String m) {
+               number  = n;
+               message = m;
+       }
+
+       public int getErrorNumber() {
+               return number;
+       }
+
+       public String getMessage() {
+               return message;
+       }
+
+       public String toString() {
+               return "[" + number + "]" + message;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/exception/ConsoleException.java b/eventinjector-cli/src/org/tizen/injector/exception/ConsoleException.java
new file mode 100644 (file)
index 0000000..980bc70
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.exception;
+
+public class ConsoleException extends Exception {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = -5081419709474405128L;
+
+       private ConsoleError error;
+       public ConsoleException(ConsoleError e) {
+               super(e.toString());
+               this.error = e;
+       }
+
+       public ConsoleException(ConsoleError e, String add) {
+               super(e.toString() + "\n" + add);
+               this.error = e;
+       }
+
+       public int getErrorNumber() {
+               return error.getErrorNumber();
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/parser/ArgCompletor.java b/eventinjector-cli/src/org/tizen/injector/parser/ArgCompletor.java
new file mode 100644 (file)
index 0000000..f10d117
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.tizen.injector.device.Argument;
+import org.tizen.injector.device.Command;
+
+import jline.Completor;
+import jline.FileNameCompletor;
+
+public class ArgCompletor implements Completor {
+       private ArrayList<Argument> list = null;
+       private Command matchCommand = null;
+       private CommandCompletor superCompletor;
+       private FileNameCompletor fileCompletor;
+       private int order;
+
+       public ArgCompletor(CommandCompletor completor, int order) {
+               superCompletor = completor;
+               this.order = order;
+               fileCompletor = new FileNameCompletor();
+       }
+
+       @SuppressWarnings("rawtypes")
+       @Override
+       public int complete(String buf, int cursor, List clist) {
+               matchCommand = superCompletor.getMatchCommand();
+               if (matchCommand != null) {
+                       list = matchCommand.getArgumentList();
+                       if (list.size() >= order) {
+                               if (list.get(order-1).isUsingFile()) {
+                                       return fileCompletor.complete(buf, cursor, clist);
+                               } else {
+                                       for (String s : list.get(order-1).getPassibleValue()) {
+                                               if (buf == null || s.startsWith(buf)) {
+                                                       clist.add(s);
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               if (clist.size() == 1) {
+            clist.set(0, ((String) clist.get(0)) + " ");
+        }
+
+                return (clist.size() == 0) ? (-1) : 0;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/parser/Args.java b/eventinjector-cli/src/org/tizen/injector/parser/Args.java
new file mode 100644 (file)
index 0000000..2378754
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.parser;
+
+public class Args {
+       private String[] args;
+       private int index;
+       private int length;
+       public Args(String[] args) {
+               this.args = args;
+               index  = 0;
+               length = args.length;
+       }
+
+       public String[] getArgs() {
+               return args;
+       }
+
+       public int index() {
+               return index;
+       }
+
+       public int length() {
+               return length;
+       }
+
+       public int remain() {
+               return length - index;
+       }
+
+       /**
+        * Return next string. but not increment index.
+        * @return
+        */
+       public String peek() {
+               String s = pop();
+               if (s != null) {
+                       index--;
+               }
+               return s;
+       }
+
+       /**
+        * Return next string.
+        * @return
+        */
+       public String pop() {
+               if (index < length) {
+                       return args[index++];
+               } else {
+                       return null;
+               }
+       }
+
+       /**
+        * Clear buffer's index.
+        */
+       public void clear() {
+               index = 0;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/parser/CommandCompletor.java b/eventinjector-cli/src/org/tizen/injector/parser/CommandCompletor.java
new file mode 100644 (file)
index 0000000..61b03b3
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+
+import jline.Completor;
+
+public class CommandCompletor implements Completor {
+       private ArrayList<Command> list = null;
+       private Device matchDevice = null;
+       private DeviceCompletor superCompletor;
+       private Command matchCommand = null;
+       public CommandCompletor(DeviceCompletor completor) {
+               superCompletor = completor;
+       }
+
+       @SuppressWarnings("rawtypes")
+       @Override
+       public int complete(String buf, int cursor, List clist) {
+               matchDevice = superCompletor.getMatchDevice();
+
+               if (matchDevice != null) {
+
+                       list = matchDevice.getCommandList();
+                       
+                       for (Command c : list) {
+                               if (buf == null || c.getName().startsWith(buf)) {
+                                       clist.add(c.getName());
+                               }
+                       }
+               }
+
+               if (clist.size() == 1) {
+                       matchCommand = matchDevice.findCommand((String)clist.get(0));
+            clist.set(0, ((String) clist.get(0)) + " ");
+        }
+
+        // the index of the completion is always from the beginning of
+        // the buffer.
+        return (clist.size() == 0) ? (-1) : 0;
+       }
+
+       public Device getMatchDevice() {
+               return matchDevice;
+       }
+
+       public void setMatchDevice(Device matchDevice) {
+               this.matchDevice = matchDevice;
+       }
+
+       public Command getMatchCommand() {
+               return matchCommand;
+       }
+
+       public void setMatchCommand(Command matchCommand) {
+               this.matchCommand = matchCommand;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/parser/CommandParser.java b/eventinjector-cli/src/org/tizen/injector/parser/CommandParser.java
new file mode 100644 (file)
index 0000000..46c17fa
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.parser;
+
+import org.tizen.eilib.exception.InjectorLibraryException;
+import org.tizen.injector.DeviceList;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.GlobalOption;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.device.Option;
+import org.tizen.injector.exception.ConsoleError;
+import org.tizen.injector.exception.ConsoleException;
+
+public class CommandParser {
+       private GlobalOption options  = null;
+       private DeviceList deviceList = null;
+
+       private boolean hasOptions = false;
+
+       public CommandParser(EventInjector injector) {
+               deviceList      = injector.getDeviceList();
+               options         = injector.getOptions();
+       }
+
+       /**
+        * 
+        * @param args
+        * @return String array except options
+        * @throws Throwable 
+        */
+       public Args parseOptions(Args args) throws ConsoleException, Throwable{
+               try {
+                       int count = args.length();
+                       String a;
+                       for (int i = 0; i < count; i++) {
+                               a = args.pop();
+                               if (a.equals("--")) { // Device command
+                                       return args;
+                               } else {
+                                       Option option = null;
+                                       if (a.startsWith("--")) {
+                                               option = options.findLongNameOption(a.substring(2));
+                                       } else {
+                                               option = options.findShortNameOption(a.substring(1));
+                                       }
+                                       if (option == null) {
+                                               throw new ConsoleException(ConsoleError.WrongAction);
+                                       } else {
+                                               if (option.isNeedsExtra()) {
+                                                       if (++i >= count) {
+                                                               throw new ConsoleException(ConsoleError.MissingArg);
+                                                       }
+                                                       if (args.peek().startsWith("-")) {
+                                                               throw new ConsoleException(ConsoleError.WrongArgument);
+                                                       }
+                                                       option.setCurrentValue(args.pop());
+                                               }
+                                               option.setInCommandLine(true);
+                                               hasOptions = true;
+                                       }
+                               }
+                       }
+               } catch (ConsoleException c) {
+                       HelpMessage.printHelp(c, false);
+                       throw c;
+               } catch (Throwable t) {
+                       HelpMessage.printHelp(null, false);
+                       throw t;
+               }
+               return null;
+       }
+
+       public Device parseDevice(Args args) throws ConsoleException {
+               Device device = null;
+               if (args.peek() != null) {
+                       device = deviceList.findDevice(args.pop());
+                       if (device != null) {
+                               return device;
+                       }
+               }
+
+               throw new ConsoleException(ConsoleError.WrongDevice);
+       }
+
+       public Command parseCommand(Device device, Args args) throws ConsoleException {
+               if (device != null) {
+                       Command command = device.findCommand(args.peek());
+                       if (command == null) {
+                               command = device.getDefalutCommand();
+                       } else {
+                               args.pop();
+                       }
+
+                       if (command != null) {
+                               return command;
+                       }
+               }
+
+               throw new ConsoleException(ConsoleError.WrongCommand);
+       }
+
+       public int parseArgument(Command command, Args args) throws ConsoleException {
+               if (command != null) {
+                       if (command.hasArguments()) {
+                               if (!command.isStandalone() && args.remain() == 0) {
+                                       ConsoleException e = new ConsoleException(ConsoleError.CommandMissingArg);
+                                       HelpMessage.printHelp(command, e);
+                                       return e.getErrorNumber();
+                               }
+
+                               try {
+                                       int re = command.parseArgs(args);
+                                       if (re != 0) {
+                                               return re;
+                                       }
+                               } catch (InjectorLibraryException e) {
+                                       System.out.println("Error: " + e.getMessage());
+                                       return e.getErrorNumber();
+                               }
+                       } else {
+                               if (args.peek() != null) {
+                                       ConsoleException e = new ConsoleException(ConsoleError.WrongArgument);
+                                       command.printArgumentHelp(e);
+                                       return e.getErrorNumber();
+                               }
+                       }
+               }
+               return 0;
+       }
+
+       public boolean isHasOptions() {
+               return hasOptions;
+       }
+
+       public void setHasOptions(boolean hasOptions) {
+               this.hasOptions = hasOptions;
+       }
+
+       public GlobalOption getOptions() {
+               return options;
+       }
+
+       public DeviceList getDeviceList() {
+               return deviceList;
+       }
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/parser/DeviceCompletor.java b/eventinjector-cli/src/org/tizen/injector/parser/DeviceCompletor.java
new file mode 100644 (file)
index 0000000..f9e3eb3
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.parser;
+
+import java.util.List;
+
+import org.tizen.injector.DeviceList;
+import org.tizen.injector.EventInjector;
+import org.tizen.injector.device.Device;
+
+import jline.Completor;
+
+public class DeviceCompletor implements Completor {
+       private DeviceList list;
+       private static Device matchDevice = null;
+
+       public DeviceCompletor() {
+               list = EventInjector.getParser().getDeviceList();
+       }
+
+       @SuppressWarnings("rawtypes")
+       @Override
+       public int complete(String buf, int cursor, List clist) {
+               for (Device d: list.getDeviceList()) {
+                       if (buf == null || d.getName().startsWith(buf)) {
+                               clist.add(d.getName());
+                       }
+               }
+
+               if (clist.size() == 1) {
+                       matchDevice = list.findDevice((String)clist.get(0));
+            clist.set(0, ((String) clist.get(0)) + " ");
+        }
+
+        // the index of the completion is always from the beginning of
+        // the buffer.
+        return (clist.size() == 0) ? (-1) : 0;
+       }
+
+       public Device getMatchDevice() {
+               return matchDevice;
+       }
+
+       public void setMatchDevice(Device matchDevice) {
+               this.matchDevice = matchDevice;
+       }
+
+}
diff --git a/eventinjector-cli/src/org/tizen/injector/parser/HelpMessage.java b/eventinjector-cli/src/org/tizen/injector/parser/HelpMessage.java
new file mode 100644 (file)
index 0000000..8b7854c
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * EventInjector CLI Program
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * SooYoung Ha <yoosah.ha@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.injector.parser;
+
+import org.tizen.injector.DeviceList;
+import org.tizen.injector.GlobalOption;
+import org.tizen.injector.device.Command;
+import org.tizen.injector.device.Device;
+import org.tizen.injector.device.Option;
+
+public class HelpMessage {
+       private HelpMessage(){}
+
+       private static GlobalOption options = null;
+       private static DeviceList deviceList = null;
+
+       public static void setting(GlobalOption options, DeviceList devices) {
+               HelpMessage.options    = options;
+               HelpMessage.deviceList = devices;
+       }
+
+       public static void printHelp(Exception c, boolean isSession) {
+               if (c != null) {
+                       System.out.println("Error:" + c.getMessage());
+                       System.out.println();
+               }
+
+               // main help
+               System.out.println("The event injector send event to the emulator.");
+               if (!isSession) {
+                       System.out.println("Usage1: eventinjector [options] -- device command [args]");
+                       System.out.println("Usage2: eventinjector [options]");
+                       System.out.println("    device [command] [args]");
+                       System.out.println();
+                       System.out.println("Options:");
+                       if (options != null) {
+                               for (Option o : options.getOptionList()) {
+                                       System.out.println(String.format("\t-%s, --%s\t: %s",
+                                                       o.getShortName(), o.getLongName(), o.getDescription()));
+                               }
+                       }
+               } else {
+                       System.out.println("Usage: device [command] [args]");
+               }
+
+               System.out.println();
+               System.out.println("Device:");
+               if (deviceList != null) {
+                       for(Device d : deviceList.getDeviceList()) {
+                               System.out.println(String.format("\t%-10s: %s", d.getName(), d.getDescription()));
+                       }
+               }
+       }
+
+       /**
+        * Display help message.
+        * Note : If device is not null, print device's help message.
+        * Note : If c(ConsoleException) is not null, exit program.
+        * @param device
+        * @param c
+        */
+       public static void printHelp(Device device, Exception c) {
+               if (c != null) {
+                       System.out.println("Error:" + c.getMessage());
+                       System.out.println();
+               }
+
+               device.printHelpMessage();
+       }
+
+       public static void printHelp(Command command, Exception c) {
+               if (c != null) {
+                       System.out.println("Error:" + c.getMessage());
+                       System.out.println();
+               }
+
+               command.printHelpMessage(null);
+       }
+}
diff --git a/library/COPYING.BSD b/library/COPYING.BSD
new file mode 100644 (file)
index 0000000..1cdc44c
--- /dev/null
@@ -0,0 +1,33 @@
+Copyright (c) 2002-2006, Marc Prud'hommeaux <mwp1@cornell.edu>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the following
+conditions are met:
+
+Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with
+the distribution.
+
+Neither the name of JLine nor the names of its contributors
+may be used to endorse or promote products derived from this
+software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
diff --git a/library/jline-1.0.jar b/library/jline-1.0.jar
new file mode 100644 (file)
index 0000000..6c949b2
Binary files /dev/null and b/library/jline-1.0.jar differ
diff --git a/package/build.linux b/package/build.linux
new file mode 100644 (file)
index 0000000..9be950a
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/sh -xe *)
+#clean
+clean()
+{
+       echo "$SRCDIR"
+       rm -rf $SRCDIR/*.jar
+       rm -rf $SRCDIR/*.zip
+       rm -rf $SRCDIR/*.tar.gz
+}
+
+#build
+build() 
+{
+       cp $SRCDIR/library/* $SRCDIR/
+
+       cd $SRCDIR/ei-library
+       ant -buildfile build.xml -Dclasspath.dibs=${ROOTDIR}/tools/ide/lib make-jar-dibs
+
+       cd $SRCDIR/eventinjector-cli
+       ant -buildfile build.xml -Dclasspath.dibs=${SRCDIR} make-jar-dibs
+}
+
+#install
+install()
+{
+       CLI_BIN_DIR=$SRCDIR/package/eventinjector-cli.package.$TARGET_OS/data/tools/emulator
+
+       mkdir -p $CLI_BIN_DIR/bin
+
+       cp $SRCDIR/library/* $CLI_BIN_DIR/bin
+
+       mv $SRCDIR/eilib.jar $CLI_BIN_DIR/bin
+       mv $SRCDIR/eventinjector-cli.jar $CLI_BIN_DIR/bin
+
+       case ${TARGET_OS} in
+               ubuntu-32)
+                       cp $SRCDIR/supplement/eventinjector-cli.sh $CLI_BIN_DIR/bin/eventinjector
+                       ;;
+               ubuntu-64)
+                       cp $SRCDIR/supplement/eventinjector-cli.sh $CLI_BIN_DIR/bin/eventinjector
+                       ;;
+               windows-32)
+                       cp $SRCDIR/supplement/eventinjector-cli.bat $CLI_BIN_DIR/bin/eventinjector.bat
+                       ;;
+               windows-64)
+                       cp $SRCDIR/supplement/eventinjector-cli.bat $CLI_BIN_DIR/bin/eventinjector.bat
+                       ;;
+               macos-64)
+                       cp $SRCDIR/supplement/eventinjector-cli-mac.sh $CLI_BIN_DIR/bin/eventinjector
+                       ;;
+                *)
+                       echo "${TARGET_OS} is not support yet."
+                       ;;
+       esac
+
+}
+
+[ "$1" = "clean" ] && clean
+[ "$1" = "build" ] && build
+[ "$1" = "install" ] && install
+
+echo "success"
diff --git a/package/changelog b/package/changelog
new file mode 100644 (file)
index 0000000..2b3295d
--- /dev/null
@@ -0,0 +1,81 @@
+* 2.1.6
+- version up
+== jihye1128.kim <jihye1128.kim@samsugn.com> 2013-06-10
+
+* 2.1.5
+- modify script for multi version SDK
+== jihye1128.kim <jihye1128.kim@samsung.com> 2013-06-07
+
+* 2.1.4
+- Refactoring sdblib
+== kh5325.kim <kh5325.kim@samsung.com> 2013-06-04
+
+* 2.1.3
+- Refactored to sdblib
+== kh5325.kim <kh5325.kim@samsung.com> 2013-05-23
+
+* 2.1.2
+- Refactored to sdblib
+== kh5325.kim <kh5325.kim@samsung.com> 2013-05-22
+
+* 2.1.1
+- modify mms command name
+== jihye kim <jihye1128.kim@samsung.com> 2013-04-03
+
+* 2.1.0
+- update version
+== jihye kim <jihye1128.kim@samsung.com> 2013-04-03
+
+* 2.0.0
+- update version
+- change sdcard name(ext4 format)
+- add move-to-ear motion event
+- add mms function
+== jihye kim <jihye1128.kim@samsung.com> 2013-03-29
+
+* 1.0.10
+- update version
+== Sooyoung Ha <yoosah.ha@samsung.com> 2013-03-08
+
+* 1.0.9
+- modify telephony checking routine
+- change disconnect call (number -> id)
+== jihye kim <jihye1128.kim@samsung.com> 2013-01-26
+
+* 1.0.8
+- add listener
+- update emuld version(0.2.22 -> 0.2.23)
+== jihye kim <jihye1128.kim@samsung.com> 2013-01-03
+
+* 1.0.7
+- change license to apache
+- modify routine that initialize adb
+== jihye kim <jihye1128.kim@samsung.com> 2013-01-02
+
+* 1.0.6
+- modify string resource
+== jihye kim <jihye1128.kim@samsung.com> 2012-12-24
+
+* 1.0.5
+- modify string resource
+== jihye kim <jihye1128.kim@samsung.com> 2012-12-18
+
+* 1.0.4
+- modify proximity value (on 1 -> 0, off 0 -> 8)
+== jihye kim <jihye1128.kim@samsung.com> 2012-12-05
+
+* 1.0.3
+- modify check nfc status of emulator(vconftool)
+== jihye kim <jihye1128.kim@samsung.com> 2012-11-27
+
+* 1.0.2
+- fix bug
+== jihye kim <jihye1128.kim@samsung.com> 2012-11-27
+
+*1.0.1
+- modify record file path
+== jihye kim <jihye1128.kim@samsung.com> 2012-11-21
+
+*1.0.0
+- initialize event injector cli program
+== jihye kim <jihye1128.kim@samsung.com> 2012-11-19
diff --git a/package/pkginfo.manifest b/package/pkginfo.manifest
new file mode 100644 (file)
index 0000000..982f225
--- /dev/null
@@ -0,0 +1,38 @@
+Source: event-injector
+Version: 2.1.6
+Maintainer: Yeong-Kyoon Lee<yeongkyoon.lee@samsung.com>
+
+Package: eventinjector-cli
+OS: ubuntu-32
+Build-host-os: ubuntu-32
+Build-dependency: sdblib [ ubuntu-32 ]
+Install-dependency: sdblib
+Description: Tizen Event Injector CLI Program
+
+Package: eventinjector-cli
+OS: ubuntu-64
+Build-host-os: ubuntu-64
+Build-dependency: sdblib [ ubuntu-64 ]
+Install-dependency: sdblib
+Description: Tizen Event Injector CLI Program
+
+Package: eventinjector-cli
+OS: windows-32
+Build-host-os: ubuntu-32
+Build-dependency: sdblib [ windows-32 ]
+Install-dependency: sdblib
+Description: Tizen Event Injector CLI Program
+
+Package: eventinjector-cli
+OS: windows-64
+Build-host-os: ubuntu-64
+Build-dependency: sdblib [ windows-64 ]
+Install-dependency: sdblib
+Description: Tizen Event Injector CLI ProgramPackage: eventinjector-cli
+
+Package: eventinjector-cli
+OS: macos-64
+Build-host-os: ubuntu-64
+Build-dependency: sdblib [ ubuntu-64 ]
+Install-dependency: sdblib
+Description: Tizen Event Injector CLI Program
diff --git a/supplement/eventinjector-cli-mac.sh b/supplement/eventinjector-cli-mac.sh
new file mode 100644 (file)
index 0000000..2667316
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+### find location of script file ###
+pushd . > /dev/null
+SCRIPT_PATH="${BASH_SOURCE[0]}";
+    while([ -h "${SCRIPT_PATH}" ]) do
+        cd "`dirname "${SCRIPT_PATH}"`"
+        SCRIPT_PATH="$(readlink "`basename "${SCRIPT_PATH}"`")";
+    done
+cd "`dirname "${SCRIPT_PATH}"`" > /dev/null
+SCRIPT_PATH="`pwd`";
+popd > /dev/null
+#echo "script=[${SCRIPT_PATH}]"
+###
+
+eventinjector="/eventinjector-cli.jar"
+
+ei_path=`echo "${SCRIPT_PATH}${eventinjector}"`
+#echo "ei_path=[${ei_path}]"
+
+current_path=`pwd`
+current_injector="$current_path${eventinjector}"
+
+if [ -f $current_injector ]
+then
+java -XstartOnFirstThread -jar "$current_injector" "$@"
+else
+java -XstartOnFirstThread -jar "$ei_path" "$@"
+fi
diff --git a/supplement/eventinjector-cli.bat b/supplement/eventinjector-cli.bat
new file mode 100644 (file)
index 0000000..7d67eb4
--- /dev/null
@@ -0,0 +1,16 @@
+@ECHO OFF
+
+set sdk_path=%~dp0
+IF EXIST "%sdk_path%" (
+       set ei_path=%sdk_path%
+) ELSE (
+       set ei_path="."
+)
+
+set current_path=%CD%\eventinjector-cli.jar
+
+IF EXIST "%current_path%" (
+       java -jar "%current_path%" %*
+) ELSE (
+       java -jar "%ei_path%\eventinjector-cli.jar" %*
+)
diff --git a/supplement/eventinjector-cli.sh b/supplement/eventinjector-cli.sh
new file mode 100644 (file)
index 0000000..c1c637f
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+### find location of script file ###
+pushd . > /dev/null
+SCRIPT_PATH="${BASH_SOURCE[0]}";
+    while([ -h "${SCRIPT_PATH}" ]) do
+        cd "`dirname "${SCRIPT_PATH}"`"
+        SCRIPT_PATH="$(readlink "`basename "${SCRIPT_PATH}"`")";
+    done
+cd "`dirname "${SCRIPT_PATH}"`" > /dev/null
+SCRIPT_PATH="`pwd`";
+popd > /dev/null
+#echo "script=[${SCRIPT_PATH}]"
+###
+
+eventinjector="/eventinjector-cli.jar"
+
+ei_path=`echo "${SCRIPT_PATH}${eventinjector}"`
+#echo "ei_path=[${ei_path}]"
+
+current_path=`pwd`
+current_injector="$current_path${eventinjector}"
+
+if [ -f $current_injector ]
+then
+java -jar "$current_injector" "$@"
+else
+java -jar "$ei_path" "$@"
+fi