From: Igor Olshevskyi Date: Fri, 7 Apr 2017 07:00:32 +0000 (+0300) Subject: TizenRefApp-8350 [Call UI] Implement Call initialization logic X-Git-Tag: submit/tizen/20170630.111746~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f6bbd73e50435ff133df6b2c26132d9afec7aad2;p=profile%2Fwearable%2Fapps%2Fnative%2Fcall-ui.git TizenRefApp-8350 [Call UI] Implement Call initialization logic Change-Id: I97b7846718862e10b3e1a6b0f151a60ef547dc75 --- diff --git a/inc/main/Instance.h b/inc/main/Instance.h index 6bfbfc3..5302e33 100644 --- a/inc/main/Instance.h +++ b/inc/main/Instance.h @@ -24,7 +24,6 @@ #include "ucl/appfw/SysEventProvider.h" - #include "model/Call.h" namespace callui { @@ -35,6 +34,11 @@ namespace callui { public: Instance(ucl::SysEventProvider &sysEventProvider); + // For testing + ucl::WindowWRef getWindow(); + ucl::IInstanceContext *getContext(); + CallWRef getCall(); + // IInstance // virtual ucl::Result onCreate( @@ -54,7 +58,6 @@ namespace callui { ucl::SysEventProvider &m_sysEventProvider; ucl::IInstanceContext *m_context; ucl::WindowSRef m_win; - CallSRef m_call; }; } diff --git a/inc/model/Call.h b/inc/model/Call.h index 15183cf..5acb364 100644 --- a/inc/model/Call.h +++ b/inc/model/Call.h @@ -17,6 +17,8 @@ #ifndef __CALLUI_MODEL_CALL_H__ #define __CALLUI_MODEL_CALL_H__ +#include + #include "types.h" namespace callui { @@ -26,9 +28,19 @@ namespace callui { class Call final : public ucl::NonCopyable { public: - static CallSRef newInstance(); + class Builder { + public: + Builder(); + Builder &setListener(ICallManagerListenerWRef value); + CallSRef build() const; + private: + ICallManagerListenerWRef m_listener; + }; + + public: virtual ~Call(); + ucl::Result processAppControl(app_control_h appControl); ISoundManagerSRef getSoundManager(); ICallManagerSRef getCallManager(); @@ -36,7 +48,7 @@ namespace callui { friend class ucl::RefCountObj; Call(); - ucl::Result prepare(); + ucl::Result prepare(ICallManagerListenerWRef listener); private: CallManagerSRef m_callManager; diff --git a/inc/model/ICallDialer.h b/inc/model/ICallDialer.h deleted file mode 100644 index c9193d0..0000000 --- a/inc/model/ICallDialer.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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_CALL_DIALER_H__ -#define __CALLUI_MODEL_I_CALL_DIALER_H__ - -#include "types.h" - -namespace callui { - - class ICallDialer: public ucl::Polymorphic { - public: - virtual ucl::Result dialVoiceCall(const std::string &number, SimSlot simSlot) = 0; - virtual void addDialStatusHandler(DialStatusHandler handler) = 0; - virtual void removeDialStatusHandler(DialStatusHandler handler) = 0; - }; -} - -#endif // __CALLUI_MODEL_I_CALL_DIALER_H__ diff --git a/inc/model/ICallManager.h b/inc/model/ICallManager.h index 8442cfd..92bcbe8 100644 --- a/inc/model/ICallManager.h +++ b/inc/model/ICallManager.h @@ -23,13 +23,10 @@ namespace callui { class ICallManager : public ucl::Polymorphic { public: - virtual ICallDialerWRef getDialer() = 0; virtual IIncomingCallWRef getIncomingCall() = 0; virtual IActiveCallWRef getActiveCall() = 0; virtual IHeldCallWRef getHeldCall() = 0; virtual IEndCallWRef getEndCall() = 0; - virtual void addCallStateHandler(CallStateHandler handler) = 0; - virtual void removeCallStateHandler(CallStateHandler handler) = 0; }; } diff --git a/inc/model/ICallManagerListener.h b/inc/model/ICallManagerListener.h new file mode 100644 index 0000000..f3433ad --- /dev/null +++ b/inc/model/ICallManagerListener.h @@ -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_I_CALL_MANAGER_LISTENER_H__ +#define __CALLUI_MODEL_I_CALL_MANAGER_LISTENER_H__ + +#include "types.h" + +namespace callui { + + class ICallManagerListener : public ucl::Polymorphic { + public: + virtual void onCallEvent(CallEventType type) = 0; + virtual void onError(CallManagerErr err) = 0; + }; + +} + +#endif // __CALLUI_MODEL_I_CALL_MANAGER_LISTENER_H__ diff --git a/inc/model/types.h b/inc/model/types.h index a5a1ff2..2b86f22 100644 --- a/inc/model/types.h +++ b/inc/model/types.h @@ -24,11 +24,21 @@ namespace callui { enum class SimSlot { + UNDEFINED, FIRST, SECOND, DEFAULT }; + enum class CallManagerErr { + NONE, + DIAL_CANCEL, + DIAL_FAIL, + DIAL_FAIL_SS, + DIAL_FAIL_FDN, + DIAL_FLIGHT_MODE + }; + enum class CallAnswerType { NORMAL, HOLD_ACTIVE_AND_ACCEPT, @@ -37,15 +47,6 @@ namespace callui { RELEASE_ALL_AND_ACCEPT }; - enum class DialStatus { - SUCCESS, - CANCEL, - FAIL, - FAIL_SS, - FAIL_FDN, - FLIGHT_MODE - }; - enum class AudioStateType { NONE, SPEAKER, @@ -90,7 +91,8 @@ namespace callui { UCL_DECLARE_REF_ALIASES(ICallManager); UCL_DECLARE_REF_ALIASES(ISoundManager); - UCL_DECLARE_REF_ALIASES(ICallDialer); + + UCL_DECLARE_REF_ALIASES(ICallManagerListener); UCL_DECLARE_REF_ALIASES(IIncomingCall); UCL_DECLARE_REF_ALIASES(IActiveCall); @@ -104,10 +106,6 @@ namespace callui { UCL_DECLARE_REF_ALIASES(IRejectMsgProvider); UCL_DECLARE_REF_ALIASES(IRejectMsg); - using CallStateHandler = ucl::Delegate; - - using DialStatusHandler = ucl::Delegate; - using AudioStateHandler = ucl::Delegate; using MuteStateHandler = ucl::Delegate; diff --git a/src/main/Instance.cpp b/src/main/Instance.cpp index cdb0278..e2fbeff 100644 --- a/src/main/Instance.cpp +++ b/src/main/Instance.cpp @@ -16,15 +16,117 @@ #include "main/Instance.h" +#include "ucl/util/memory.h" + #include #include #include "../common.h" +#include "model/ICallManager.h" +#include "model/ICallManagerListener.h" +#include "model/IIncomingCall.h" +#include "model/IActiveCall.h" +#include "model/IHeldCall.h" +#include "model/IEndCall.h" +#include "model/ICallInfo.h" + namespace callui { using namespace ucl; + // For testing + UCL_DECLARE_REF_ALIASES(Listener); + class Listener : public ICallManagerListener { + public: + static ListenerSRef newInstance(Instance &instance) + { + return makeShared(instance); + } + virtual void onCallEvent(CallEventType type) override final + { + WindowWRef win = m_instance.getWindow(); + CallWRef call = m_instance.getCall(); + ICallManagerSRef callMng = {}; + if (call) { + callMng = call->getCallManager(); + } + + if (win && !win->isVisible()) { + show(*win); + } + + IIncomingCallWRef incom = callMng->getIncomingCall(); + IActiveCallWRef active = callMng->getActiveCall(); + IHeldCallWRef held = callMng->getHeldCall(); + IEndCallWRef end = callMng->getEndCall(); + + ILOG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + if (incom) { + ILOG("Incoming call available"); + logCallInfo(incom->getInfo()); + } else { + ILOG("No incoming call"); + } + + if (active) { + ILOG("Active call available"); + logCallInfo(active->getInfo()); + } else { + ILOG("No active call"); + } + + if (held) { + ILOG("Held call available"); + logCallInfo(held->getInfo()); + } else { + ILOG("No held call"); + } + + if (end) { + ILOG("End call available"); + logCallInfo(end->getInfo()); + } else { + ILOG("No end call"); + } + ILOG("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); + + if (type == CallEventType::END) { + if (!callMng->getIncomingCall() + && !callMng->getActiveCall() + && !callMng->getHeldCall()) { + IInstanceContext *ctx = m_instance.getContext(); + if (ctx) { + ctx->exitApp(); + } + } + } + } + + virtual void onError(CallManagerErr err) override final + { + ILOG(); + } + + private: + void logCallInfo(ICallInfoSCRef info) + { + ILOG("* call id [%d]", info->getCallId()); + ILOG("* phone number [%s]", info->getPhoneNumber().c_str()); + ILOG("* conference member count [%d]", info->getConferenceMemberCount()); + } + + private: + friend class ucl::RefCountObj; + Listener(Instance &instance): + m_instance(instance) + { + ILOG(); + } + private: + Instance &m_instance; + }; + Instance::Instance(SysEventProvider &sysEventProvider) : m_sysEventProvider(sysEventProvider), m_context(nullptr) @@ -43,7 +145,15 @@ namespace callui { eext_object_event_callback_add(*m_win, EEXT_CALLBACK_BACK, CALLBACK_A(Instance::onBack), this); - m_call = Call::newInstance(); + // For testing + static ListenerSRef listener = Listener::newInstance(*this); + m_call = Call::Builder(). + setListener(listener). + build(); + + if (!m_call) { + LOG_RETURN(RES_FAIL, "m_call is NULL"); + } return RES_OK; } @@ -65,8 +175,18 @@ namespace callui { ILOG("operation: %s", op); free(op); - if (!m_win->isVisible()) { - show(*m_win); + // For testing + Result res = m_call->processAppControl(appControl); + if (res != RES_OK) { + ELOG("processAppControl() failed!"); + ICallManagerSRef callManager = m_call->getCallManager(); + if (!callManager->getIncomingCall() + && !callManager->getActiveCall() + && !callManager->getHeldCall() + && !callManager->getEndCall()) { + ILOG("No calls. Exit application"); + m_context->exitApp(); + } } } @@ -94,4 +214,19 @@ namespace callui { break; } } + + WindowWRef Instance::getWindow() + { + return m_win; + } + + IInstanceContext *Instance::getContext() + { + return m_context; + } + + CallWRef Instance::getCall() + { + return m_call; + } } diff --git a/src/model/ActiveCall.cpp b/src/model/ActiveCall.cpp index e238abd..8bbc9a4 100644 --- a/src/model/ActiveCall.cpp +++ b/src/model/ActiveCall.cpp @@ -29,7 +29,6 @@ namespace callui { using namespace ucl; ActiveCall::ActiveCall(CallManager &cm, cm_call_data_h callData): - BaseCall(callData), m_cm(cm), m_isDialing(false) { @@ -46,20 +45,20 @@ namespace callui { } auto result = makeShared(cm, callData); - FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); + FAIL_RETURN_VALUE(result->prepare(callData), {}, "result->prepare() failed!"); return result; } - Result ActiveCall::prepare() + Result ActiveCall::prepare(cm_call_data_h callData) { - m_callInfo = CallInfo::newInstance(*m_cm.getCallClient(), m_callData); + m_callInfo = CallInfo::newInstance(*m_cm.getCallClient(), callData); if (!m_callInfo) { LOG_RETURN_VALUE(RES_FAIL, RES_FAIL, "CallInfo::newInstance() failed!"); } cm_call_state_e callState = CM_CALL_STATE_IDLE; FAIL_RETURN(convertCMResult( - cm_call_data_get_call_state(m_callData, &callState)), + cm_call_data_get_call_state(callData, &callState)), "cm_call_data_get_call_state() failed!"); m_isDialing = (callState == CM_CALL_STATE_DIALING); diff --git a/src/model/ActiveCall.h b/src/model/ActiveCall.h index 7a60d09..d85464c 100644 --- a/src/model/ActiveCall.h +++ b/src/model/ActiveCall.h @@ -19,16 +19,13 @@ #include -#include "BaseCall.h" #include "model/IActiveCall.h" #include "implTypes.h" namespace callui { - class ActiveCall final : - public BaseCall, - public IActiveCall { + class ActiveCall final : public IActiveCall { public: static ActiveCallSRef newInstance(CallManager &cm, cm_call_data_h callData); virtual ~ActiveCall(); @@ -45,7 +42,7 @@ namespace callui { friend class ucl::RefCountObj; ActiveCall(CallManager &cm, cm_call_data_h callData); - ucl::Result prepare(); + ucl::Result prepare(cm_call_data_h callData); private: CallManager &m_cm; diff --git a/src/model/BaseCall.cpp b/src/model/BaseCall.cpp deleted file mode 100644 index ece1fbb..0000000 --- a/src/model/BaseCall.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 "BaseCall.h" - -namespace callui { - - BaseCall::BaseCall(cm_call_data_h callData): - m_callData(callData) - { - } - - BaseCall::~BaseCall() - { - } - - cm_call_data_h BaseCall::getCallData() - { - return m_callData; - } - -} diff --git a/src/model/BaseCall.h b/src/model/BaseCall.h deleted file mode 100644 index 85c612b..0000000 --- a/src/model/BaseCall.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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_BASE_CALL_H__ -#define __CALLUI_MODEL_BASE_CALL_H__ - -#include - -namespace callui { - - class BaseCall { - public: - BaseCall(cm_call_data_h callData); - virtual ~BaseCall(); - - cm_call_data_h getCallData(); - protected: - cm_call_data_h m_callData; - }; - -} - -#endif // __CALLUI_MODEL_BASE_CALL_H__ diff --git a/src/model/Call.cpp b/src/model/Call.cpp index 0c4b716..327fefa 100644 --- a/src/model/Call.cpp +++ b/src/model/Call.cpp @@ -16,6 +16,8 @@ #include "model/Call.h" +#include + #include "CallClient.h" #include "CallManager.h" #include "SoundManager.h" @@ -26,29 +28,110 @@ namespace callui { using namespace ucl; - Call::Call() + Call::Builder::Builder(): + m_listener(nullptr) { } - Call::~Call() + Call::Builder &Call::Builder::setListener(ICallManagerListenerWRef value) { + m_listener = value; + return *this; } - CallSRef Call::newInstance() + CallSRef Call::Builder::build() const { auto result = makeShared(); - FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); + FAIL_RETURN_VALUE(result->prepare(m_listener), {}, "result->prepare() failed!"); return result; } - Result Call::prepare() + Call::Call() + { + } + + Call::~Call() + { + } + + Result Call::processAppControl(app_control_h appControl) + { + if (!appControl) { + FAIL_RETURN(RES_INVALID_ARGUMENTS, "appControl is NULL"); + } + + Result ret = RES_FAIL; + + char *operation = nullptr; + int res = app_control_get_operation(appControl, &operation); + if (res != APP_CONTROL_ERROR_NONE) { + LOG_RETURN(RES_FAIL, "app_control_get_operation() failed!"); + } + if (!operation) { + LOG_RETURN(RES_FAIL, "operation is NULL!"); + } + + char *uri = nullptr; + res = app_control_get_uri(appControl, &uri); + if (res != APP_CONTROL_ERROR_NONE) { + free(operation); + LOG_RETURN(RES_FAIL, "app_control_get_uri() failed!"); + } + if (!uri) { + free(operation); + LOG_RETURN(RES_FAIL, "uri is NULL!"); + } + + if (strcmp(operation, APP_CONTROL_OPERATION_CALL) || strncmp(uri, "tel:", 4)) { + free(operation); + free(uri); + LOG_RETURN(RES_FAIL, "Not processed operation!"); + } + + char *tmp = nullptr; + if (!strncmp(uri, "tel:MT", 6)) { + res = app_control_get_extra_data(appControl, "sim_slot", &tmp); + if (res != APP_CONTROL_ERROR_NONE) { + ELOG("app_control_get_extra_data() failed!"); + } + if (!tmp) { + free(operation); + free(uri); + LOG_RETURN(RES_FAIL, "Sim slot is NULL!"); + } + DLOG("Sim slot [%s]", tmp); + free(tmp); + + ret = m_callManager->processIncomingCall( + convertCMSimSlot(static_cast(atoi(tmp)))); + + } else { + tmp = static_cast(uri + 4); + DLOG("number [%s]", tmp); + + if (!tmp) { + free(operation); + free(uri); + LOG_RETURN(RES_FAIL, "number is NULL"); + } + + ret = m_callManager->processOutgoingCall(tmp); + } + + free(operation); + free(uri); + + return ret; + } + + Result Call::prepare(ICallManagerListenerWRef listener) { CallClientSRef callClient = CallClient::newInstance(); if (!callClient) { LOG_RETURN(RES_FAIL, "Client::newInstance() failed!"); } - m_callManager = CallManager::newInstance(callClient); + m_callManager = CallManager::newInstance(callClient, listener); if (!m_callManager) { LOG_RETURN(RES_FAIL, "CallManager::newInstance() failed!"); } diff --git a/src/model/CallDialer.cpp b/src/model/CallDialer.cpp deleted file mode 100644 index 4bfef71..0000000 --- a/src/model/CallDialer.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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 "CallDialer.h" - -#include "CallManager.h" -#include "CallClient.h" - -#include "common.h" - -namespace callui { - - using namespace ucl; - - CallDialer::CallDialer(CallManager &cm): - m_cm(cm) - { - } - - CallDialer::~CallDialer() - { - cm_unset_dial_status_cb(*(m_cm.getCallClient())); - } - - CallDialerSRef CallDialer::newInstance(CallManager &cm) - { - auto result = makeShared(cm); - FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); - return result; - } - - void CallDialer::DialStatusChangedCb(cm_dial_status_e status) - { - m_event.invoke(convertCMDialStatus(status)); - } - - Result CallDialer::prepare() - { - return convertCMResult( - cm_set_dial_status_cb(*(m_cm.getCallClient()), - CALLBACK_B(CallDialer::DialStatusChangedCb), this)); - } - - Result CallDialer::dialVoiceCall(const std::string &number, SimSlot simSlot) - { - char buff[TEL_NUMBER_MAX_SIZE] = { 0 }; - snprintf(buff, sizeof(buff), "%s", number.c_str()); - - return convertCMResult( - cm_dial_call(*(m_cm.getCallClient()), - buff, CM_CALL_TYPE_VOICE, convertCUISimSlot(simSlot))); - } - - void CallDialer::addDialStatusHandler(DialStatusHandler handler) - { - m_event += handler; - } - - void CallDialer::removeDialStatusHandler(DialStatusHandler handler) - { - m_event -= handler; - } -} diff --git a/src/model/CallDialer.h b/src/model/CallDialer.h deleted file mode 100644 index f1a7d5e..0000000 --- a/src/model/CallDialer.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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_CALL_DIALER_H__ -#define __CALLUI_MODEL_CALL_DIALER_H__ - -#include - -#include "model/ICallDialer.h" - -#include "implTypes.h" - -namespace callui { - - class CallDialer final : public ICallDialer { - public: - static CallDialerSRef newInstance(CallManager &cm); - virtual ~CallDialer(); - - // ICallDialer - - virtual ucl::Result dialVoiceCall(const std::string &number, SimSlot simSlot) override final; - virtual void addDialStatusHandler(DialStatusHandler handler) override final; - virtual void removeDialStatusHandler(DialStatusHandler handler) override final; - - private: - friend class ucl::RefCountObj; - CallDialer(CallManager &cm); - - ucl::Result prepare(); - void DialStatusChangedCb(cm_dial_status_e dial_status); - - private: - CallManager &m_cm; - DialStatusEvent m_event; - }; - -} - -#endif // __CALLUI_MODEL_CALL_DIALER_H__ diff --git a/src/model/CallManager.cpp b/src/model/CallManager.cpp index 5c4f823..ab507a5 100644 --- a/src/model/CallManager.cpp +++ b/src/model/CallManager.cpp @@ -16,9 +16,10 @@ #include "CallManager.h" +#include "model/ICallManagerListener.h" + #include "CallClient.h" #include "RejectMsgProvider.h" -#include "CallDialer.h" #include "IncomingCall.h" #include "ActiveCall.h" #include "HeldCall.h" @@ -33,8 +34,12 @@ namespace callui { using namespace ucl; - CallManager::CallManager(const CallClientSRef &callClient): - m_callClient(callClient) + CallManager::CallManager(const CallClientSRef &callClient, + ICallManagerListenerWRef listener): + m_callClient(callClient), + m_listener(listener), + m_slot(SimSlot::UNDEFINED), + m_waitDialing(false) { } @@ -42,24 +47,26 @@ namespace callui { { } - CallManagerSRef CallManager::newInstance(const CallClientSRef &callClient) + CallManagerSRef CallManager::newInstance(const CallClientSRef &callClient, + ICallManagerListenerWRef listener) { - auto result = makeShared(callClient); + auto result = makeShared(callClient, listener); FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); return result; } Result CallManager::prepare() { - m_dialer = CallDialer::newInstance(*this); - if (!m_dialer) { - LOG_RETURN(RES_FAIL, "CallDialer::getInstance() failed!"); - } - FAIL_RETURN(initCalls(), "initCalls() failed!"); FAIL_RETURN(convertCMResult( - cm_set_call_event_cb(*m_callClient, CALLBACK_B(CallManager::callEventCb), this)), + cm_set_dial_status_cb(*m_callClient, + CALLBACK_B(CallManager::dialStatusCb), this)), + "cm_set_call_event_cb() failed!"); + + FAIL_RETURN(convertCMResult( + cm_set_call_event_cb(*m_callClient, + CALLBACK_B(CallManager::callEventCb), this)), "cm_set_call_event_cb() failed!"); return RES_OK; @@ -75,66 +82,24 @@ namespace callui { cm_get_all_calldata(*m_callClient, &incom, &active, &held)), "cm_get_all_calldata() failed!"); - FAIL_RETURN(updateIncomingCall(incom), "updateIncomingCall() failed!"); - FAIL_RETURN(updateActiveCall(active), "updateActiveCall() failed!"); - FAIL_RETURN(updateHeldCall(held), "updateHeldCall() failed!"); + FAIL_RETURN(updateCall(m_incomingCall, incom), "updateCall() failed!"); + FAIL_RETURN(updateCall(m_activeCall, active), "updateCall() failed!"); + FAIL_RETURN(updateCall(m_heldCall, held), "updateCall() failed!"); return RES_OK; } - Result CallManager::updateIncomingCall(cm_call_data_h incom, SimSlot slot) + template + Result CallManager::updateCall(SharedRef &call, TYPE2 &&data) { - if (incom) { - m_incomingCall = IncomingCall::newInstance(*this, incom, slot); - if (!m_incomingCall) { - LOG_RETURN(RES_FAIL, "IncomingCall::newInstance() failed!"); - } - } else { - m_incomingCall.reset(); - } + call.reset(); - return RES_OK; - } - - Result CallManager::updateActiveCall(cm_call_data_h active) - { - if (active) { - m_activeCall = ActiveCall::newInstance(*this, active); - if (!m_activeCall) { - LOG_RETURN(RES_FAIL, "ActiveCall::newInstance() failed!"); + if (data) { + call = TYPE::newInstance(*this, std::forward(data)); + if (!call) { + LOG_RETURN(RES_FAIL, "newInstance() failed!"); } - } else { - m_activeCall.reset(); } - - return RES_OK; - } - - Result CallManager::updateHeldCall(cm_call_data_h held) - { - if (held) { - m_heldCall = HeldCall::newInstance(*this, held); - if (!m_heldCall) { - LOG_RETURN(RES_FAIL, "HeldCall::newInstance() failed!"); - } - } else { - m_heldCall.reset(); - } - - return RES_OK; - } - - Result CallManager::updateEndCall(cm_call_data_h end, SimSlot slot) - { - if (end) { - m_endCall = EndCall::newInstance(*this, end, slot); - if (!m_endCall) { - LOG_RETURN(RES_FAIL, "EndCall::newInstance() failed!"); - } - } else { - m_endCall.reset(); - } - return RES_OK; } @@ -143,9 +108,9 @@ namespace callui { return m_callClient; } - ICallDialerWRef CallManager::getDialer() + SimSlot CallManager::getSimSlot() const { - return m_dialer; + return m_slot; } IIncomingCallWRef CallManager::getIncomingCall() @@ -168,14 +133,13 @@ namespace callui { return m_endCall; } - void CallManager::addCallStateHandler(CallStateHandler handler) + Result CallManager::dialVoiceCall(const std::string &number) { - m_event += handler; - } + char buff[TEL_NUMBER_MAX_SIZE] = { 0 }; + snprintf(buff, sizeof(buff), "%s", number.c_str()); - void CallManager::removeCallStateHandler(CallStateHandler handler) - { - m_event -= handler; + return convertCMResult( + cm_dial_call(*m_callClient, buff, CM_CALL_TYPE_VOICE, convertCUISimSlot(m_slot))); } Result CallManager::endCall(unsigned int callId, CallReleaseType type) @@ -211,7 +175,7 @@ namespace callui { return m_rejectMsgProvider; } - Result CallManager::processEndCallEvent(cm_call_event_data_h callEventData, SimSlot simSlot) + Result CallManager::processEndCallEvent(cm_call_event_data_h callEventData) { unsigned int callId = 0; FAIL_RETURN(convertCMResult( @@ -220,26 +184,26 @@ namespace callui { Result res = RES_OK; if (m_incomingCall && callId == m_incomingCall->getInfo()->getCallId()) { - res = updateEndCall(m_incomingCall->getCallData(), simSlot); + res = updateCall(m_endCall, m_incomingCall->getInfo()); m_incomingCall.reset(); } else if (m_activeCall && callId == m_activeCall->getInfo()->getCallId()) { - res = updateEndCall(m_activeCall->getCallData(), simSlot); + res = updateCall(m_endCall, m_activeCall->getInfo()); m_activeCall.reset(); } else if (m_heldCall && callId == m_heldCall->getInfo()->getCallId()) { - res = updateEndCall(m_heldCall->getCallData(), simSlot); + res = updateCall(m_endCall, m_heldCall->getInfo()); m_heldCall.reset(); } else if (m_activeCall && m_activeCall->getInfo()->getConferenceMemberCount() > 1) { - res = updateEndCall(m_activeCall->getCallData(), simSlot); + res = updateCall(m_endCall, m_activeCall->getInfo()); m_activeCall.reset(); } else if (m_heldCall && m_heldCall->getInfo()->getConferenceMemberCount() > 1) { - res = updateEndCall(m_heldCall->getCallData(), simSlot); + res = updateCall(m_endCall, m_heldCall->getInfo()); m_heldCall.reset(); } return res; } - Result CallManager::processCommonCallEvent(cm_call_event_data_h callEventData, CallEventType type, SimSlot simSlot) + Result CallManager::processCommonCallEvent(cm_call_event_data_h callEventData, CallEventType type) { unsigned int callId = 0; cm_call_data_h cmIncom = nullptr; @@ -262,19 +226,17 @@ namespace callui { cm_call_event_data_get_held_call(callEventData, &cmHeld)), "cm_call_event_data_get_held_call() failed!"); - if (type == CallEventType::INCOMING) { - FAIL_RETURN(updateIncomingCall(cmIncom, simSlot), "updateIncomingCall() failed!"); - } else if (!cmIncom) { - m_incomingCall.reset(); - } - FAIL_RETURN(updateActiveCall(cmActive), "updateActiveCall() failed!"); - FAIL_RETURN(updateHeldCall(cmHeld), "updateHeldCall() failed!"); + FAIL_RETURN(updateCall(m_incomingCall, cmIncom), "updateCall() failed!"); + FAIL_RETURN(updateCall(m_activeCall, cmActive), "updateCall() failed!"); + FAIL_RETURN(updateCall(m_heldCall, cmHeld), "updateCall() failed!"); return RES_OK; } void CallManager::callEventCb(cm_call_event_e callEvent, cm_call_event_data_h callEventData) { + m_waitDialing = false; + if (!callEventData) { ELOG("callEventData is NULL"); return; @@ -286,17 +248,19 @@ namespace callui { DLOG("Call event changed on [%d]", type); - cm_multi_sim_slot_type_e cmSimSlot; - FAIL_RETURN_VOID(convertCMResult( - cm_call_event_data_get_sim_slot(callEventData, &cmSimSlot)), - "cm_call_event_data_get_sim_slot() failed!"); - SimSlot simSlot = convertCMSimSlot(cmSimSlot); + if (m_slot == SimSlot::UNDEFINED) { + cm_multi_sim_slot_type_e cmSimSlot; + FAIL_RETURN_VOID(convertCMResult( + cm_call_event_data_get_sim_slot(callEventData, &cmSimSlot)), + "cm_call_event_data_get_sim_slot() failed!"); + m_slot = convertCMSimSlot(cmSimSlot); + } m_endCall.reset(); switch (type) { case CallEventType::END: - FAIL_RETURN_VOID(processEndCallEvent(callEventData, simSlot), + FAIL_RETURN_VOID(processEndCallEvent(callEventData), "processEndCallEvent() failed!"); case CallEventType::ACTIVE: case CallEventType::INCOMING: @@ -306,14 +270,50 @@ namespace callui { case CallEventType::SWAPPED: case CallEventType::JOIN: case CallEventType::SPLIT: - FAIL_RETURN_VOID(processCommonCallEvent(callEventData, type, simSlot), + FAIL_RETURN_VOID(processCommonCallEvent(callEventData, type), "processCommonCallEvent() failed!"); break; default: return; } - m_event.invoke(type); + if (m_listener) { + m_listener->onCallEvent(type); + } + } + + void CallManager::dialStatusCb(cm_dial_status_e status) + { + m_waitDialing = false; + + CallManagerErr err = convertCMDialStatusIntoErr(status); + if (err != CallManagerErr::NONE && m_listener) { + m_listener->onError(err); + } + } + + Result CallManager::processOutgoingCall(const std::string &telNum) + { + if (!m_waitDialing) { + m_waitDialing = true; + return dialVoiceCall(telNum); + } + return RES_FAIL; + } + + Result CallManager::processIncomingCall(SimSlot slot) + { + if (m_incomingCall) { + if (m_slot == SimSlot::UNDEFINED) { + m_slot = slot; + } + if (m_listener) { + m_listener->onCallEvent(CallEventType::INCOMING); + } + return RES_OK; + } + ELOG("Incoming call is NULL"); + return RES_FAIL; } } diff --git a/src/model/CallManager.h b/src/model/CallManager.h index 4e2770b..6dba3f7 100644 --- a/src/model/CallManager.h +++ b/src/model/CallManager.h @@ -19,8 +19,6 @@ #include -#include "ucl/misc/Event.h" - #include "model/ICallManager.h" #include "implTypes.h" @@ -29,49 +27,56 @@ namespace callui { class CallManager final : public ICallManager { public: - static CallManagerSRef newInstance(const CallClientSRef &callClient); + static CallManagerSRef newInstance(const CallClientSRef &callClient, + ICallManagerListenerWRef listener); virtual ~CallManager(); CallClientSRef getCallClient(); + SimSlot getSimSlot() const; + ucl::Result dialVoiceCall(const std::string &number); ucl::Result endCall(unsigned int callId, CallReleaseType type); ucl::Result splitCalls(CallInfoSRef callInfo, const IConferenceCallInfoSCRef &confCallInfo); RejectMsgProviderSRef getRejectMsgProvider(); + ucl::Result processOutgoingCall(const std::string &telNum); + ucl::Result processIncomingCall(SimSlot slot); + // ICallManager - virtual ICallDialerWRef getDialer() override final; virtual IIncomingCallWRef getIncomingCall() override final; virtual IActiveCallWRef getActiveCall() override final; virtual IHeldCallWRef getHeldCall() override final; virtual IEndCallWRef getEndCall() override final; - virtual void addCallStateHandler(CallStateHandler handler) override final; - virtual void removeCallStateHandler(CallStateHandler handler) override final; private: friend class ucl::RefCountObj; - CallManager(const CallClientSRef &callClient); + CallManager(const CallClientSRef &callClient, + ICallManagerListenerWRef listener); ucl::Result prepare(); ucl::Result initCalls(); - ucl::Result updateIncomingCall(cm_call_data_h incom, SimSlot slot = SimSlot::DEFAULT); - ucl::Result updateActiveCall(cm_call_data_h active); - ucl::Result updateHeldCall(cm_call_data_h active); - ucl::Result updateEndCall(cm_call_data_h end, SimSlot slot = SimSlot::DEFAULT); - ucl::Result processEndCallEvent(cm_call_event_data_h callEventData, SimSlot slot); + + template + ucl::Result updateCall(ucl::SharedRef &call, TYPE2 &&data); + + ucl::Result processEndCallEvent(cm_call_event_data_h callEventData); ucl::Result processCommonCallEvent(cm_call_event_data_h callEventData, - CallEventType type, SimSlot simSlot); + CallEventType type); void callEventCb(cm_call_event_e call_event, cm_call_event_data_h call_state_data); + void dialStatusCb(cm_dial_status_e status); private: CallClientSRef m_callClient; RejectMsgProviderSRef m_rejectMsgProvider; - CallDialerSRef m_dialer; + MsgClientSRef m_msgClient; + ICallManagerListenerWRef m_listener; IncomingCallSRef m_incomingCall; ActiveCallSRef m_activeCall; HeldCallSRef m_heldCall; EndCallSRef m_endCall; - CallStateEvent m_event; + SimSlot m_slot; + bool m_waitDialing; }; } diff --git a/src/model/EndCall.cpp b/src/model/EndCall.cpp index 65a70c6..7d5881d 100644 --- a/src/model/EndCall.cpp +++ b/src/model/EndCall.cpp @@ -19,7 +19,6 @@ #include "CallClient.h" #include "CallManager.h" #include "CallInfo.h" -#include "model/ICallDialer.h" #include "common.h" @@ -27,10 +26,9 @@ namespace callui { using namespace ucl; - EndCall::EndCall(CallManager &cm, cm_call_data_h callData, SimSlot slot): - BaseCall(callData), + EndCall::EndCall(CallManager &cm, ICallInfoSCRef callInfo): m_cm(cm), - m_slot(slot) + m_callInfo(callInfo) { } @@ -38,24 +36,12 @@ namespace callui { { } - EndCallSRef EndCall::newInstance(CallManager &cm, cm_call_data_h callData, SimSlot slot) + EndCallSRef EndCall::newInstance(CallManager &cm, ICallInfoSCRef callInfo) { - if (!callData) { - LOG_RETURN_VALUE(RES_FAIL, {}, "callData is NULL"); + if (!callInfo) { + LOG_RETURN_VALUE(RES_FAIL, {}, "callInfo is NULL"); } - - auto result = makeShared(cm, callData, slot); - FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); - return result; - } - - Result EndCall::prepare() - { - m_callInfo = CallInfo::newInstance(*m_cm.getCallClient(), m_callData); - if (!m_callInfo) { - LOG_RETURN_VALUE(RES_FAIL, RES_FAIL, "CallInfo::newInstance() failed!"); - } - return RES_OK; + return makeShared(cm, callInfo); } ICallInfoSCRef EndCall::getInfo() const @@ -65,12 +51,7 @@ namespace callui { Result EndCall::callBack() { - ICallDialerWRef dialer = m_cm.getDialer(); - if (dialer) { - return dialer->dialVoiceCall(m_callInfo->getPhoneNumber(), m_slot); - } else { - return RES_FAIL; - } + return m_cm.dialVoiceCall(m_callInfo->getPhoneNumber()); } Result EndCall::writeMessage() diff --git a/src/model/EndCall.h b/src/model/EndCall.h index 7a60d89..ceff936 100644 --- a/src/model/EndCall.h +++ b/src/model/EndCall.h @@ -19,7 +19,6 @@ #include -#include "BaseCall.h" #include "model/IEndCall.h" #include "implTypes.h" @@ -28,13 +27,9 @@ namespace callui { class CallManager; - class EndCall final : - public BaseCall, - public IEndCall { + class EndCall final : public IEndCall { public: - static EndCallSRef newInstance(CallManager &cm, - cm_call_data_h callData, - SimSlot slot = SimSlot::DEFAULT); + static EndCallSRef newInstance(CallManager &cm, ICallInfoSCRef callInfo); virtual ~EndCall(); @@ -46,14 +41,13 @@ namespace callui { private: friend class ucl::RefCountObj; - EndCall(CallManager &cm, cm_call_data_h callData, SimSlot slot); + EndCall(CallManager &cm, ICallInfoSCRef callInfo); ucl::Result prepare(); private: CallManager &m_cm; - CallInfoSRef m_callInfo; - SimSlot m_slot; + ICallInfoSCRef m_callInfo; }; } diff --git a/src/model/HeldCall.cpp b/src/model/HeldCall.cpp index ff7766c..8bc5604 100644 --- a/src/model/HeldCall.cpp +++ b/src/model/HeldCall.cpp @@ -28,7 +28,6 @@ namespace callui { using namespace ucl; HeldCall::HeldCall(CallManager &cm, cm_call_data_h callData): - BaseCall(callData), m_cm(cm) { } @@ -44,13 +43,13 @@ namespace callui { } auto result = makeShared(cm, callData); - FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); + FAIL_RETURN_VALUE(result->prepare(callData), {}, "result->prepare() failed!"); return result; } - Result HeldCall::prepare() + Result HeldCall::prepare(cm_call_data_h callData) { - m_callInfo = CallInfo::newInstance(*m_cm.getCallClient(), m_callData); + m_callInfo = CallInfo::newInstance(*m_cm.getCallClient(), callData); if (!m_callInfo) { LOG_RETURN_VALUE(RES_FAIL, RES_FAIL, "CallInfo::newInstance() failed!"); } diff --git a/src/model/HeldCall.h b/src/model/HeldCall.h index 80f7d01..609c419 100644 --- a/src/model/HeldCall.h +++ b/src/model/HeldCall.h @@ -19,16 +19,13 @@ #include -#include "BaseCall.h" #include "model/IHeldCall.h" #include "implTypes.h" namespace callui { - class HeldCall final : - public BaseCall, - public IHeldCall { + class HeldCall final : public IHeldCall { public: static HeldCallSRef newInstance(CallManager &cm, cm_call_data_h callData); virtual ~HeldCall(); @@ -46,7 +43,7 @@ namespace callui { friend class ucl::RefCountObj; HeldCall(CallManager &cm, cm_call_data_h callData); - ucl::Result prepare(); + ucl::Result prepare(cm_call_data_h callData); private: CallManager &m_cm; diff --git a/src/model/IncomingCall.cpp b/src/model/IncomingCall.cpp index d45c105..0af24bf 100644 --- a/src/model/IncomingCall.cpp +++ b/src/model/IncomingCall.cpp @@ -29,10 +29,8 @@ namespace callui { using namespace ucl; - IncomingCall::IncomingCall(CallManager &cm, cm_call_data_h callData, SimSlot slot): - BaseCall(callData), - m_cm(cm), - m_simSlot(slot) + IncomingCall::IncomingCall(CallManager &cm, cm_call_data_h callData): + m_cm(cm) { } @@ -40,20 +38,20 @@ namespace callui { { } - IncomingCallSRef IncomingCall::newInstance(CallManager &cm, cm_call_data_h callData, SimSlot slot) + IncomingCallSRef IncomingCall::newInstance(CallManager &cm, cm_call_data_h callData) { if (!callData) { LOG_RETURN_VALUE(RES_FAIL, {}, "callData is NULL"); } - auto result = makeShared(cm, callData, slot); - FAIL_RETURN_VALUE(result->prepare(), {}, "result->prepare() failed!"); + auto result = makeShared(cm, callData); + FAIL_RETURN_VALUE(result->prepare(callData), {}, "result->prepare() failed!"); return result; } - Result IncomingCall::prepare() + Result IncomingCall::prepare(cm_call_data_h callData) { - m_callInfo = CallInfo::newInstance(*m_cm.getCallClient(), m_callData); + m_callInfo = CallInfo::newInstance(*m_cm.getCallClient(), callData); if (!m_callInfo) { LOG_RETURN_VALUE(RES_FAIL, RES_FAIL, "CallInfo::newInstance() failed!"); } @@ -89,7 +87,8 @@ namespace callui { if (!msg) { LOG_RETURN(RES_FAIL, "message is not RejectMsg type!"); } - return msg->send(m_callInfo->getPhoneNumber(), m_simSlot); + return msg->send(m_callInfo->getPhoneNumber(), m_cm.getSimSlot()); + } Result IncomingCall::stopAlert() diff --git a/src/model/IncomingCall.h b/src/model/IncomingCall.h index f64f73e..cfa3742 100644 --- a/src/model/IncomingCall.h +++ b/src/model/IncomingCall.h @@ -19,20 +19,15 @@ #include -#include "BaseCall.h" #include "model/IIncomingCall.h" #include "implTypes.h" namespace callui { - class IncomingCall final : - public BaseCall, - public IIncomingCall { + class IncomingCall final : public IIncomingCall { public: - static IncomingCallSRef newInstance(CallManager &cm, - cm_call_data_h callData, - SimSlot slot = SimSlot::DEFAULT); + static IncomingCallSRef newInstance(CallManager &cm, cm_call_data_h callData); virtual ~IncomingCall(); @@ -47,14 +42,13 @@ namespace callui { private: friend class ucl::RefCountObj; - IncomingCall(CallManager &cm, cm_call_data_h callData, SimSlot slot); + IncomingCall(CallManager &cm, cm_call_data_h callData); - ucl::Result prepare(); + ucl::Result prepare(cm_call_data_h callData); private: CallManager &m_cm; CallInfoSRef m_callInfo; - SimSlot m_simSlot; }; } diff --git a/src/model/helpers.h b/src/model/helpers.h index d1014e2..66f5a53 100644 --- a/src/model/helpers.h +++ b/src/model/helpers.h @@ -28,7 +28,7 @@ namespace callui { AudioStateType convertCMAudioState(cm_audio_state_type_e state); - DialStatus convertCMDialStatus(cm_dial_status_e status); + CallManagerErr convertCMDialStatusIntoErr(cm_dial_status_e status); cm_multi_sim_slot_type_e convertCUISimSlot(SimSlot slot); diff --git a/src/model/helpers.hpp b/src/model/helpers.hpp index d645901..d80b800 100644 --- a/src/model/helpers.hpp +++ b/src/model/helpers.hpp @@ -47,17 +47,17 @@ namespace callui { } } - inline DialStatus convertCMDialStatus(cm_dial_status_e status) + inline CallManagerErr convertCMDialStatusIntoErr(cm_dial_status_e status) { switch (status) { - case CM_DIAL_SUCCESS: return DialStatus::SUCCESS; - case CM_DIAL_CANCEL: return DialStatus::CANCEL; - case CM_DIAL_FAIL: return DialStatus::FAIL; - case CM_DIAL_FAIL_SS: return DialStatus::FAIL_SS; - case CM_DIAL_FAIL_FDN: return DialStatus::FAIL_FDN; - case CM_DIAL_FAIL_FLIGHT_MODE: return DialStatus::FLIGHT_MODE; + case CM_DIAL_SUCCESS: return CallManagerErr::NONE; + case CM_DIAL_CANCEL: return CallManagerErr::DIAL_CANCEL; + case CM_DIAL_FAIL: return CallManagerErr::DIAL_FAIL; + case CM_DIAL_FAIL_SS: return CallManagerErr::DIAL_FAIL_SS; + case CM_DIAL_FAIL_FDN: return CallManagerErr::DIAL_FAIL_FDN; + case CM_DIAL_FAIL_FLIGHT_MODE: return CallManagerErr::DIAL_FLIGHT_MODE; default: - return DialStatus::FAIL; + return CallManagerErr::DIAL_FAIL; } } diff --git a/src/model/implTypes.h b/src/model/implTypes.h index 4db1188..e1e185c 100644 --- a/src/model/implTypes.h +++ b/src/model/implTypes.h @@ -33,7 +33,6 @@ namespace callui { UCL_DECLARE_REF_ALIASES(SoundManager); UCL_DECLARE_REF_ALIASES(CallManager); - UCL_DECLARE_REF_ALIASES(CallDialer); UCL_DECLARE_REF_ALIASES(IncomingCall); UCL_DECLARE_REF_ALIASES(ActiveCall); @@ -48,10 +47,8 @@ namespace callui { UCL_DECLARE_REF_ALIASES(RejectMsgProvider); UCL_DECLARE_REF_ALIASES(RejectMsg); - using CallStateEvent = ucl::Event; using AudioStateEvent = ucl::Event; using MuteStateEvent = ucl::Event; - using DialStatusEvent = ucl::Event; } #endif // __CALLUI_MODEL_IMPL_TYPES_H__ diff --git a/tizen-manifest.xml b/tizen-manifest.xml index c3ee103..27ffd04 100644 --- a/tizen-manifest.xml +++ b/tizen-manifest.xml @@ -4,6 +4,12 @@ call-ui.png + + + + + + http://tizen.org/privilege/keygrab