TizenRefApp-8410 [Call UI] Implement IndicatorStateProvider and ConnectionStateSource 84/125984/4
authorIgor Olshevskyi <i.olshevskyi@samsung.com>
Wed, 19 Apr 2017 13:29:59 +0000 (16:29 +0300)
committerIgor Olshevskyi <i.olshevskyi@samsung.com>
Thu, 20 Apr 2017 11:17:39 +0000 (14:17 +0300)
Change-Id: Ic2e2bddeca8cf45be4685929c4acf84b8ff7adb9

14 files changed:
inc/model/ICall.h
inc/model/IIndicatorStateListener.h [new file with mode: 0644]
inc/model/IIndicatorStateProvider.h [new file with mode: 0644]
inc/model/IndicatorState.h [new file with mode: 0644]
inc/model/types.h
src/model/Call.cpp
src/model/Call.h
src/model/ConnectionStateSource.cpp [new file with mode: 0644]
src/model/ConnectionStateSource.h [new file with mode: 0644]
src/model/IIndicatorStateSource.h [new file with mode: 0644]
src/model/IndicatorStateProvider.cpp [new file with mode: 0644]
src/model/IndicatorStateProvider.h [new file with mode: 0644]
src/model/implTypes.h
tizen-manifest.xml

index c5fcf5b24d717490a5e90628b40633e893b60f47..521b197aa2217bb13996a17f6402cdcffd776c13 100644 (file)
@@ -28,6 +28,7 @@ namespace callui {
                virtual ucl::Result processAppControl(app_control_h appControl) = 0;
                virtual ISoundManagerSRef getSoundManager() = 0;
                virtual ICallManagerSRef getCallManager() = 0;
+               virtual IIndicatorStateProviderSRef getIndicatorStateProvider() = 0;
        };
 
 }
diff --git a/inc/model/IIndicatorStateListener.h b/inc/model/IIndicatorStateListener.h
new file mode 100644 (file)
index 0000000..39fd64d
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CALLUI_MODEL_I_INDICATOR_STATE_LISTENER_H__
+#define __CALLUI_MODEL_I_INDICATOR_STATE_LISTENER_H__
+
+#include "types.h"
+
+namespace callui {
+
+       class IIndicatorStateListener: public ucl::Polymorphic {
+       public:
+               virtual void onStateChanged(IndicatorProperty property) const = 0;
+       };
+
+}
+
+#endif // __CALLUI_MODEL_I_INDICATOR_STATE_LISTENER_H__
diff --git a/inc/model/IIndicatorStateProvider.h b/inc/model/IIndicatorStateProvider.h
new file mode 100644 (file)
index 0000000..11255b6
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CALLUI_MODEL_I_INDICATOR_STATE_PROVIDER_H__
+#define __CALLUI_MODEL_I_INDICATOR_STATE_PROVIDER_H__
+
+#include <model/IndicatorState.h>
+#include "types.h"
+
+namespace callui {
+
+       class IIndicatorStateProvider : public ucl::Polymorphic {
+       public:
+               virtual IndicatorState getState(IndicatorProperty property) const = 0;
+               virtual void setListener(IIndicatorStateListenerWRef listener) = 0;
+       };
+
+}
+
+#endif // __CALLUI_MODEL_I_INDICATOR_STATE_PROVIDER_H__
diff --git a/inc/model/IndicatorState.h b/inc/model/IndicatorState.h
new file mode 100644 (file)
index 0000000..cd7ab13
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CALLUI_MODEL_INDICATOR_STATE_H__
+#define __CALLUI_MODEL_INDICATOR_STATE_H__
+
+#include "types.h"
+
+namespace callui {
+
+       struct IndicatorState {
+               uint64_t value;
+       };
+
+       ConnectionType getConnectionState(IndicatorState state);
+       PacketDirection getPacketDirection(IndicatorState state);
+}
+
+#endif // __CALLUI_MODEL_INDICATOR_STATE_H__
index 41eac45cba4e8fabf6773996727532ca25343825..ed47e7d68cf67466c5933437235dbe02d93b2027 100644 (file)
@@ -84,6 +84,42 @@ namespace callui {
                NAME
        };
 
+       enum class ConnectionType {
+               NONE = 0,
+               EDGE_E,
+               GPRS_G,
+               SIMPLE_2G,
+               HSDPA_H,
+               HSPA_H_PLUS,
+               LTE_4G,
+               UMTS_3G,
+               UMTS_3G_PLUS,
+               NO_SIM,
+               WIFI_00,
+               WIFI_01,
+               WIFI_02,
+               WIFI_03,
+               WIFI_04,
+               NO_SIGNAL
+       };
+
+       enum class PacketDirection {
+               NONE = 0,
+               NO_INPUT,
+               IN,
+               OUT,
+               INOUT
+       };
+
+       enum class IndicatorProperty {
+               NW_CONNECTION = 0,
+               RSSI,
+               BATTERY,
+               SIM_SLOT,
+               HD_CALL,
+               VOICE_ANSWER,
+       };
+
        UCL_DECLARE_REF_ALIASES(ICall);
        UCL_DECLARE_REF_ALIASES(ICallListener);
 
@@ -102,6 +138,9 @@ namespace callui {
        UCL_DECLARE_REF_ALIASES(IRejectMsgProvider);
        UCL_DECLARE_REF_ALIASES(IRejectMsg);
 
+       UCL_DECLARE_REF_ALIASES(IIndicatorStateProvider);
+       UCL_DECLARE_REF_ALIASES(IIndicatorStateListener);
+
        using AudioStateHandler = ucl::Delegate<void(AudioStateType)>;
        using MuteStateHandler = ucl::Delegate<void(bool)>;
 
index 68d9d67e6482b300d1f8213fa577fcabfbd8b7f9..6346ea4fe1e2e8effdf04f54f0327f4f3f8a8bd9 100644 (file)
@@ -23,6 +23,9 @@
 #include "SoundManager.h"
 #include "model/ICallListener.h"
 
+#include "IndicatorStateProvider.h"
+#include "ConnectionStateSource.h"
+
 #include "common.h"
 
 namespace callui {
@@ -111,7 +114,7 @@ namespace callui {
 
        Result Call::prepare()
        {
-               CallClientSRef callClient = CallClient::newInstance();
+               auto callClient = CallClient::newInstance();
                if (!callClient) {
                        LOG_RETURN(RES_FAIL, "Client::newInstance() failed!");
                }
@@ -126,6 +129,27 @@ namespace callui {
                        LOG_RETURN(RES_FAIL, "SoundManage::newInstance() failed!");
                }
 
+               FAIL_RETURN(initInidcatorStateProvider(), "Init Indicator State Provider failed!");
+
+               return RES_OK;
+       }
+
+       Result Call::initInidcatorStateProvider()
+       {
+               m_indicatorStateProvider = IndicatorStateProvider::newInstance();
+               if (!m_indicatorStateProvider) {
+                       LOG_RETURN(RES_FAIL, "IndicatorStateProvider::newInstance() failed!");
+               }
+
+               auto connectionStateSource = ConnectionStateSource::newInstance();
+               if (!connectionStateSource) {
+                       LOG_RETURN(RES_FAIL, "ConnectionStateSource::newInstance() failed!");
+               }
+
+               FAIL_RETURN(m_indicatorStateProvider->setStateSource(
+                               IndicatorProperty::NW_CONNECTION, connectionStateSource),
+                               "setStateSource() failed!");
+
                return RES_OK;
        }
 
@@ -139,6 +163,11 @@ namespace callui {
                return m_soundManager;
        }
 
+       IIndicatorStateProviderSRef Call::getIndicatorStateProvider()
+       {
+               return m_indicatorStateProvider;
+       }
+
        void Call::onCallEvent(CallEventType type)
        {
                if (m_listener) {
@@ -148,7 +177,7 @@ namespace callui {
 
        void Call::onError(CallManagerErr err)
        {
-               CallErr callErr = CallErr::DIAL_FAIL;
+               auto callErr = CallErr::DIAL_FAIL;
                switch (err) {
                case CallManagerErr::DIAL_CANCEL:
                        callErr = CallErr::DIAL_CANCEL;
index 2754e79eaf7273a4432659d790ac96949924ffa4..d03bf5d3f122fc9607440b8814187624bef8e00e 100644 (file)
@@ -41,6 +41,7 @@ namespace callui {
                virtual ucl::Result processAppControl(app_control_h appControl) override final;
                virtual ISoundManagerSRef getSoundManager() override final;
                virtual ICallManagerSRef getCallManager() override final;
+               virtual IIndicatorStateProviderSRef getIndicatorStateProvider() override final;
 
                // ICallManagerListener
 
@@ -54,10 +55,13 @@ namespace callui {
 
                ucl::Result prepare();
 
+               ucl::Result initInidcatorStateProvider();
+
        private:
                CallManagerSRef m_callManager;
                SoundManagerSRef m_soundManager;
                ICallListenerWRef m_listener;
+               IndicatorStateProviderSRef m_indicatorStateProvider;
        };
 
 }
diff --git a/src/model/ConnectionStateSource.cpp b/src/model/ConnectionStateSource.cpp
new file mode 100644 (file)
index 0000000..6c77f1a
--- /dev/null
@@ -0,0 +1,412 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ConnectionStateSource.h"
+
+#include "model/IndicatorState.h"
+
+#include "common.h"
+
+namespace callui {
+
+       using namespace ucl;
+
+       ConnectionStateSource::Bits::Bits():
+                       value(0)
+       {
+               property = convertEnumValueToInt(IndicatorProperty::NW_CONNECTION);
+       }
+
+       ConnectionStateSource::Bits::Bits(const IndicatorState &state):
+                       value(state.value)
+       {
+       }
+
+       ConnectionStateSource::ConnectionStateSource()
+       {
+       }
+
+       ConnectionStateSource::~ConnectionStateSource()
+       {
+               unsignSystStateCallbacks();
+       }
+
+       IIndicatorStateSourceSRef ConnectionStateSource::newInstance()
+       {
+               auto result = makeShared<ConnectionStateSource>();
+               FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!");
+               return result;
+       }
+
+       Result ConnectionStateSource::prepare()
+       {
+               FAIL_RETURN(signSysStateCallbacks(), "signSysStateCallbacks() failed!");
+
+               updateConnType();
+               updatePacketDir();
+
+               return RES_OK;
+       }
+
+       bool ConnectionStateSource::isWifiConnected() const
+       {
+               int state = VCONFKEY_WIFI_UNCONNECTED;
+               if (vconf_get_int(VCONFKEY_WIFI_STATE, &state) < 0) {
+                       ELOG("Get WiFi connection state failed");
+                       return false;
+               }
+               return (state == VCONFKEY_WIFI_CONNECTED);
+       }
+
+       bool ConnectionStateSource::isFlightMode() const
+       {
+               int status = false;;
+               if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &status) < 0) {
+                       ELOG("Get Flight mode status failed!");
+                       return false;
+               }
+               return status;
+       }
+
+       bool ConnectionStateSource::isDnetConnected() const
+       {
+               int status = VCONFKEY_DNET_OFF;
+               if (vconf_get_int(VCONFKEY_DNET_STATE, &status) < 0) {
+                       ELOG("Get Dnet status failed!");
+                       return false;
+               }
+               return (status != VCONFKEY_DNET_OFF);
+       }
+
+       ConnectionType ConnectionStateSource::getConnTypeByWiFiStrength() const
+       {
+               int wifiStrength = 0;
+               if (vconf_get_int(VCONFKEY_WIFI_STRENGTH, &wifiStrength) == 0) {
+                       switch (wifiStrength) {
+                       case 1:
+                               return ConnectionType::WIFI_01;
+                       case 2:
+                               return ConnectionType::WIFI_02;
+                       case 3:
+                               return ConnectionType::WIFI_03;
+                       case 4:
+                               return ConnectionType::WIFI_04;
+                       default:
+                               return ConnectionType::WIFI_00;
+                       }
+               } else {
+                       ELOG("Get WiFi connection type failed!");
+               }
+               return ConnectionType::NONE;
+       }
+
+       ConnectionType ConnectionStateSource::getConnTypeByTelephonyPsType() const
+       {
+               int type = 0;
+               if (vconf_get_int(VCONFKEY_TELEPHONY_PSTYPE, &type) == 0) {
+                       switch (type) {
+                       case VCONFKEY_TELEPHONY_PSTYPE_HSDPA:
+                       case VCONFKEY_TELEPHONY_PSTYPE_HSUPA:
+                               return ConnectionType::HSDPA_H;
+                       case VCONFKEY_TELEPHONY_PSTYPE_HSPA:
+                       case VCONFKEY_TELEPHONY_PSTYPE_HSPAP:
+                               return ConnectionType::HSPA_H_PLUS;
+                       default:
+                               break;
+                       }
+               } else {
+                       ELOG("Get connection PS type failed!");
+               }
+               return ConnectionType::NONE;
+       }
+
+       ConnectionType ConnectionStateSource::getConnTypeByTelephonySvcType() const
+       {
+               int svcType = 0;
+               if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &svcType) == 0) {
+                       switch (svcType) {
+                       case VCONFKEY_TELEPHONY_SVCTYPE_2G:
+                               return ConnectionType::SIMPLE_2G;
+                       case VCONFKEY_TELEPHONY_SVCTYPE_2_5G:
+                               return ConnectionType::GPRS_G;
+                       case VCONFKEY_TELEPHONY_SVCTYPE_3G:
+                               return ConnectionType::UMTS_3G;
+                       case VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE:
+                               return ConnectionType::EDGE_E;
+                       case VCONFKEY_TELEPHONY_SVCTYPE_LTE:
+                               return ConnectionType::LTE_4G;
+                       default:
+                               break;
+                       }
+               } else {
+                       ELOG("Get connection SVC type failed!");
+               }
+               return ConnectionType::NONE;
+       }
+
+       bool ConnectionStateSource::updateConnTypeBits(ConnectionType connType)
+       {
+               int connTypeInt = convertEnumValueToInt(connType);
+               if (connTypeInt != m_bits.connState) {
+                       m_bits.connState = connTypeInt;
+                       return true;
+               }
+               return false;
+       }
+
+       bool ConnectionStateSource::updatePacketDirBits(PacketDirection direction)
+       {
+               int directionInt = convertEnumValueToInt(direction);
+               if (directionInt != m_bits.packetDirection) {
+                       m_bits.packetDirection = directionInt;
+                       return true;
+               }
+               return false;
+       }
+
+       bool ConnectionStateSource::updateConnType()
+       {
+               if (isFlightMode()) {
+                       return updateConnTypeBits(ConnectionType::NONE);
+               }
+
+               if (isWifiConnected()) {
+                       return updateConnTypeBits(getConnTypeByWiFiStrength());
+               }
+
+               if (!isDnetConnected()) {
+                       return updateConnTypeBits(ConnectionType::NONE);
+               }
+
+               ConnectionType connType = getConnTypeByTelephonyPsType();
+               if (connType != ConnectionType::NONE) {
+                       return updateConnTypeBits(connType);
+               }
+
+               connType = getConnTypeByTelephonySvcType();
+               if (connType != ConnectionType::NONE) {
+                       return updateConnTypeBits(connType);
+               }
+
+               return updateConnTypeBits(ConnectionType::NONE);
+       }
+
+       void ConnectionStateSource::onConnTypeChangedCb(keynode_t *node)
+       {
+               ILOG();
+
+               bool needNotify = updateConnType();
+               if (updatePacketDir()) {
+                       needNotify = true;
+               }
+
+               if (needNotify && m_handler) {
+                       m_handler();
+               }
+       }
+
+       PacketDirection ConnectionStateSource::getPacketDirByWiFiState() const
+       {
+               int transferState = 0;
+               if (vconf_get_int(VCONFKEY_WIFI_TRANSFER_STATE, &transferState) == 0) {
+                       switch (transferState) {
+                       case VCONFKEY_WIFI_TRANSFER_STATE_RX:
+                               return PacketDirection::IN;
+                       case VCONFKEY_WIFI_TRANSFER_STATE_TX:
+                               return PacketDirection::OUT;
+                       case VCONFKEY_WIFI_TRANSFER_STATE_TXRX:
+                               return PacketDirection::INOUT;
+                       default:
+                               return PacketDirection::NO_INPUT;
+                       }
+               } else {
+                       ELOG("Get WiFi transfer state failed");
+               }
+               return PacketDirection::NONE;
+       }
+
+       PacketDirection ConnectionStateSource::getPacketDirByPacketState() const
+       {
+               int state = 0;
+               if (vconf_get_int(VCONFKEY_PACKET_STATE, &state) == 0) {
+                       switch (state) {
+                       case VCONFKEY_PACKET_RX:
+                               return PacketDirection::IN;
+                       case VCONFKEY_PACKET_TX:
+                               return PacketDirection::OUT;
+                       case VCONFKEY_PACKET_RXTX:
+                               return PacketDirection::INOUT;
+                       default:
+                               return PacketDirection::NO_INPUT;
+                       }
+               } else {
+                       ELOG("Get packet state failed");
+               }
+               return PacketDirection::NONE;
+       }
+
+       bool ConnectionStateSource::updatePacketDir()
+       {
+               ILOG();
+               PacketDirection direction = PacketDirection::NONE;
+
+               if (isFlightMode()) {
+                       return updatePacketDirBits(direction);
+               }
+
+               if (isWifiConnected()) {
+                       direction = getPacketDirByWiFiState();
+               } else if (isDnetConnected()) {
+                       direction = getPacketDirByPacketState();
+               }
+               return updatePacketDirBits(direction);
+       }
+
+       void ConnectionStateSource::onPacketStateChangedCb(keynode_t *node)
+       {
+               ILOG();
+               if (updatePacketDir() && m_handler) {
+                       m_handler();
+               }
+       }
+
+       Result ConnectionStateSource::signSysStateCallbacks()
+       {
+               // CONNECTION
+               int res = vconf_notify_key_changed(VCONFKEY_WIFI_STRENGTH,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb), this);
+               if (res != 0) {
+                       LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed");
+               }
+
+               res = vconf_notify_key_changed(VCONFKEY_WIFI_STATE,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb), this);
+               if (res != 0) {
+                       LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed");
+               }
+
+               res = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb), this);
+               if (res != 0) {
+                       LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed");
+               }
+
+               res = vconf_notify_key_changed(VCONFKEY_DNET_STATE,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb), this);
+               if (res != 0) {
+                       LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed");
+               }
+
+               res = vconf_notify_key_changed(VCONFKEY_TELEPHONY_PSTYPE,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb), this);
+               if (res != 0) {
+                       LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed");
+               }
+
+               res = vconf_notify_key_changed(VCONFKEY_TELEPHONY_SVCTYPE,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb), this);
+               if (res != 0) {
+                       LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed");
+               }
+
+               res = vconf_notify_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb), this);
+               if (res != 0) {
+                       LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed");
+               }
+
+               res = vconf_notify_key_changed(VCONFKEY_TELEPHONY_EMERGENCY_CB_MODE_CDMA,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb), this);
+
+               // PACKET
+               res = vconf_notify_key_changed(VCONFKEY_PACKET_STATE,
+                               CALLBACK_B(ConnectionStateSource::onPacketStateChangedCb), this);
+               if (res != 0) {
+                       LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed");
+               }
+
+               res = vconf_notify_key_changed(VCONFKEY_WIFI_TRANSFER_STATE,
+                               CALLBACK_B(ConnectionStateSource::onPacketStateChangedCb), this);
+               if (res != 0) {
+                       LOG_RETURN(RES_FAIL, "vconf_notify_key_changed() failed");
+               }
+
+               return RES_OK;
+
+       }
+
+       void ConnectionStateSource::unsignSystStateCallbacks()
+       {
+               // CONNECTION
+               vconf_ignore_key_changed(VCONFKEY_WIFI_STRENGTH,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb));
+               vconf_ignore_key_changed(VCONFKEY_WIFI_STATE,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb));
+               vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb));
+               vconf_ignore_key_changed(VCONFKEY_DNET_STATE,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb));
+               vconf_ignore_key_changed(VCONFKEY_TELEPHONY_PSTYPE,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb));
+               vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SVCTYPE,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb));
+               vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SIM_SLOT,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb));
+               vconf_ignore_key_changed(VCONFKEY_TELEPHONY_EMERGENCY_CB_MODE_CDMA,
+                               CALLBACK_B(ConnectionStateSource::onConnTypeChangedCb));
+
+               // PACKET
+               vconf_ignore_key_changed(VCONFKEY_PACKET_STATE,
+                               CALLBACK_B(ConnectionStateSource::onPacketStateChangedCb));
+               vconf_ignore_key_changed(VCONFKEY_WIFI_TRANSFER_STATE,
+                               CALLBACK_B(ConnectionStateSource::onPacketStateChangedCb));
+
+       }
+
+       IndicatorState ConnectionStateSource::getState() const
+       {
+               return {m_bits.value};
+       }
+
+       void ConnectionStateSource::setStateChangeHandler(StateChangeHandler handler)
+       {
+               m_handler = handler;
+       }
+
+       ConnectionStateSource::Bits ConnectionStateSource::asBits(IndicatorState state)
+       {
+               Bits bits(state);
+               if (static_cast<IndicatorProperty>(bits.property) != IndicatorProperty::NW_CONNECTION) {
+                       ELOG("State of incorrect property type [%d]", bits.property);
+                       return {};
+               }
+
+               return bits;
+       }
+
+       ConnectionType getConnectionState(IndicatorState state)
+       {
+               return static_cast<ConnectionType>(
+                               ConnectionStateSource::asBits(state).connState);
+       }
+
+       PacketDirection getPacketDirection(IndicatorState state)
+       {
+               return static_cast<PacketDirection>(
+                               ConnectionStateSource::asBits(state).packetDirection);
+       }
+
+}
diff --git a/src/model/ConnectionStateSource.h b/src/model/ConnectionStateSource.h
new file mode 100644 (file)
index 0000000..8627f50
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CALLUI_MODEL_CONNECTION_STATE_SOURCE_H__
+#define __CALLUI_MODEL_CONNECTION_STATE_SOURCE_H__
+
+#include "IIndicatorStateSource.h"
+
+#include <vconf.h>
+
+namespace callui {
+
+       class ConnectionStateSource final : public IIndicatorStateSource {
+       public:
+               static IIndicatorStateSourceSRef newInstance();
+               virtual ~ConnectionStateSource();
+
+               // IIndicatorStateSource
+
+               virtual IndicatorState getState() const override final;
+               virtual void setStateChangeHandler(StateChangeHandler handler) override final;
+
+       private:
+               friend class ucl::RefCountObj<ConnectionStateSource>;
+               ConnectionStateSource();
+
+               ucl::Result prepare();
+
+               ucl::Result signSysStateCallbacks();
+               void unsignSystStateCallbacks();
+
+               void onConnTypeChangedCb(keynode_t *node);
+               void onPacketStateChangedCb(keynode_t *node);
+
+               bool isWifiConnected() const;
+               bool isFlightMode() const;
+               bool isDnetConnected() const;
+
+               bool updateConnTypeBits(ConnectionType connType);
+               ConnectionType getConnTypeByTelephonyPsType() const;
+               ConnectionType getConnTypeByTelephonySvcType() const;
+               ConnectionType getConnTypeByWiFiStrength() const;
+               bool updateConnType();
+
+               bool updatePacketDirBits(PacketDirection packetType);
+               PacketDirection getPacketDirByWiFiState() const;
+               PacketDirection getPacketDirByPacketState() const;
+               bool updatePacketDir();
+
+       private:
+               union Bits {
+                       struct {
+                               uint8_t property : 4;
+                               uint8_t connState : 8;
+                               uint8_t packetDirection : 4;
+                       };
+                       uint64_t value;
+
+                       Bits();
+                       Bits(const IndicatorState &state);
+               };
+       public:
+               static Bits asBits(IndicatorState state);
+
+       private:
+               Bits m_bits;
+               StateChangeHandler m_handler;
+       };
+
+}
+
+#endif // __CALLUI_MODEL_CONNECTION_STATE_SOURCE_H__
diff --git a/src/model/IIndicatorStateSource.h b/src/model/IIndicatorStateSource.h
new file mode 100644 (file)
index 0000000..d334a17
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CALLUI_MODEL_I_STATE_SOURCE_H__
+#define __CALLUI_MODEL_I_STATE_SOURCE_H__
+
+#include "implTypes.h"
+
+#include "model/IndicatorState.h"
+
+namespace callui {
+
+       class IIndicatorStateSource : public ucl::Polymorphic {
+       public:
+               virtual IndicatorState getState() const = 0;
+               virtual void setStateChangeHandler(StateChangeHandler handler) = 0;
+       };
+}
+
+#endif // __CALLUI_MODEL_I_STATE_SOURCE_H__
diff --git a/src/model/IndicatorStateProvider.cpp b/src/model/IndicatorStateProvider.cpp
new file mode 100644 (file)
index 0000000..6839269
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "IndicatorStateProvider.h"
+
+#include "model/IIndicatorStateListener.h"
+#include "IIndicatorStateSource.h"
+
+#include "common.h"
+
+namespace callui {
+
+       using namespace ucl;
+
+       class IndicatorStateProvider::SourceHandler :
+                       public RefCountAware {
+       public:
+               SourceHandler(RefCountObjBase &rc,
+                               IndicatorStateProvider &provider,
+                               IndicatorProperty property,
+                               IIndicatorStateSourceSRef source):
+                       RefCountAware(&rc),
+                       m_provider(provider),
+                       m_property(property),
+                       m_source(source)
+               {
+                       m_source->setStateChangeHandler(
+                                       WEAK_DELEGATE(SourceHandler::onStateChanged, asWeak(*this)));
+               }
+
+               IndicatorState getState() const
+               {
+                       return m_source->getState();
+               }
+       private:
+               void onStateChanged()
+               {
+                       m_provider.dispatchStateChanged(m_property);
+               }
+
+       private:
+               const IndicatorStateProvider &m_provider;
+               const IndicatorProperty m_property;
+               const IIndicatorStateSourceSRef m_source;
+       };
+
+       IndicatorStateProvider::IndicatorStateProvider():
+               m_listener(nullptr),
+               m_sources()
+       {
+       }
+
+       IndicatorStateProvider::~IndicatorStateProvider()
+       {
+       }
+
+       IndicatorStateProviderSRef IndicatorStateProvider::newInstance()
+       {
+               return makeShared<IndicatorStateProvider>();
+       }
+
+       Result IndicatorStateProvider::setStateSource(IndicatorProperty property,
+                       IIndicatorStateSourceSRef source)
+       {
+               if (!source) {
+                       LOG_RETURN(RES_INVALID_ARGUMENTS, "source is empty!");
+               }
+               m_sources[convertEnumValueToInt(property)] =
+                               makeShared<SourceHandler>(*this, property, source);
+
+               return RES_OK;
+       }
+
+       IndicatorState IndicatorStateProvider::getState(IndicatorProperty property) const
+       {
+               return m_sources[convertEnumValueToInt(property)]->getState();
+       }
+
+       void IndicatorStateProvider::setListener(IIndicatorStateListenerWRef listener)
+       {
+               m_listener = listener;
+       }
+
+       void IndicatorStateProvider::dispatchStateChanged(IndicatorProperty property) const
+       {
+               if (m_listener) {
+                       m_listener->onStateChanged(property);
+               }
+       }
+
+}
diff --git a/src/model/IndicatorStateProvider.h b/src/model/IndicatorStateProvider.h
new file mode 100644 (file)
index 0000000..cbf9b6d
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CALLUI_MODEL_INDICATOR_STATE_PROVIDER_H__
+#define __CALLUI_MODEL_INDICATOR_STATE_PROVIDER_H__
+
+#include "model/IIndicatorStateProvider.h"
+
+#include "implTypes.h"
+
+namespace callui {
+
+       class IIndicatorStateListener;
+
+       class IndicatorStateProvider final: public IIndicatorStateProvider {
+       public:
+               static IndicatorStateProviderSRef newInstance();
+
+               virtual ~IndicatorStateProvider();
+
+               virtual ucl::Result setStateSource(IndicatorProperty property,
+                               IIndicatorStateSourceSRef source);
+
+               // IIndicatorStateProvider
+
+               virtual IndicatorState getState(IndicatorProperty property) const override final;
+               virtual void setListener(IIndicatorStateListenerWRef listener) override final;
+
+       private:
+               friend class ucl::RefCountObj<IndicatorStateProvider>;
+               IndicatorStateProvider();
+
+               void dispatchStateChanged(IndicatorProperty property) const;
+
+       private:
+               enum {
+                       STATE_COUNT = 6
+               };
+
+               class SourceHandler;
+               UCL_DECLARE_REF_ALIASES(SourceHandler);
+
+       private:
+               IIndicatorStateListenerWRef m_listener;
+               std::array<SourceHandlerSRef, STATE_COUNT> m_sources;
+       };
+
+}
+
+#endif // __CALLUI_MODEL_INDICATOR_STATE_PROVIDER_H__
index 4b5536c874d6fbf945bf59edd9b1d88063be7936..701d4f8ea83605c8ce6393302008fc30d1acd723 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "model/types.h"
 #include "ucl/misc/Event.h"
+#include "ucl/misc/smartDelegation.h"
 
 namespace callui {
 
@@ -57,9 +58,13 @@ namespace callui {
        UCL_DECLARE_REF_ALIASES(RejectMsgProvider);
        UCL_DECLARE_REF_ALIASES(RejectMsg);
 
+       UCL_DECLARE_REF_ALIASES(IndicatorStateProvider);
+       UCL_DECLARE_REF_ALIASES(IIndicatorStateSource);
+
        using AudioStateEvent = ucl::Event<AudioStateHandler>;
        using MuteStateEvent = ucl::Event<MuteStateHandler>;
 
+       using StateChangeHandler = ucl::WeakDelegate<void()>;
 }
 
 #endif // __CALLUI_MODEL_IMPL_TYPES_H__
index 27ffd04982ab9adf81c9ca77cf710a3ff1fd4f75..e8fdd0fa4685e7165b2e9840f1f1c54fbb5e028f 100644 (file)
@@ -20,5 +20,8 @@
         <privilege>http://tizen.org/privilege/notification</privilege>
         <privilege>http://tizen.org/privilege/message.read</privilege>
         <privilege>http://tizen.org/privilege/display</privilege>
+        <privilege>http://tizen.org/privilege/telephony</privilege>
+        <privilege>http://tizen.org/privilege/telephony.admin</privilege>
+        <privilege>http://tizen.org/privilege/systemsettings.admin</privilege>
     </privileges>
 </manifest>