2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FMedia_ImageUriDataEvent.cpp
20 * @brief This file contains the implementation of _ImageUriDataEvent class,
21 * required internally by Image::DecodeUrl.
24 #include <unique_ptr.h>
25 #include <FMediaImage.h>
26 #include <FMediaIImageEventListener.h>
28 #include <FBaseSysLog.h>
29 #include <FMedia_ImageImpl.h>
31 #include "FMedia_ImageUriDataFactory.h"
32 #include "FMedia_ImageUriDataEvent.h"
33 #include "FMedia_ImageUriDataEventArg.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
39 namespace Tizen{ namespace Media{
42 _ImageUriDataEvent::_ImageUriDataEvent(void):__cntListener(0)
47 _ImageUriDataEvent::~_ImageUriDataEvent(void)
53 _ImageUriDataEvent::Construct(void)
56 r = _Event::Initialize();
61 _ImageUriDataEvent::FireImpl(Runtime::IEventListener& listener, const Runtime::IEventArg& arg)
65 Runtime::IEventArg* pTempArg = const_cast <Runtime::IEventArg*>(&arg);
66 SysTryReturn(NID_MEDIA, pTempArg != null, ,E_INVALID_ARG,
67 "[E_INVALID_ARG] Received invalid EventArg.");
68 _ImageUriDataEventTypeArg* pEventTypeArg = dynamic_cast<_ImageUriDataEventTypeArg*>(pTempArg);
69 SysTryReturn(NID_MEDIA, pEventTypeArg != null, ,E_INVALID_ARG,
70 "[E_INVALID_ARG] Received invalid EventArg.");
72 SysLog(NID_MEDIA, "Event Type(): %d", pEventTypeArg->GetEventType());
73 reqId = pEventTypeArg->GetRequestId();
75 switch (pEventTypeArg->GetEventType())
77 case IMAGE_URI_DATA_EVENT_ERROR:
79 _ImageUriDataErrorArg* pArg = dynamic_cast<_ImageUriDataErrorArg*>(pEventTypeArg);
80 SysTryReturn(NID_MEDIA, pArg != null, ,E_INVALID_ARG,
81 "[E_INVALID_ARG] Received invalid EventTypeArg.");
82 IImageDecodeUrlEventListener* pEventListener = dynamic_cast<IImageDecodeUrlEventListener*>(&listener);
83 SysTryReturn(NID_MEDIA, pEventListener != null, ,E_INVALID_ARG,
84 "[E_INVALID_ARG] Received invalid ImageDecodeUrlEventListener.");
86 pEventListener->OnImageDecodeUrlReceived(reqId, null,
87 pArg->GetError(), pArg->GetErrorCode(), pArg->GetErrorMessage());
91 case IMAGE_URI_DATA_EVENT_SUCCESS:
93 _ImageUriDataEventArg* pArg = dynamic_cast<_ImageUriDataEventArg*>(pEventTypeArg);
94 SysTryReturn(NID_MEDIA, pArg != null, ,E_INVALID_ARG,
95 "[E_INVALID_ARG] Received invalid EventTypeArg.");
96 IImageDecodeUrlEventListener* pEventListener = dynamic_cast<IImageDecodeUrlEventListener*>(&listener);
97 SysTryReturn(NID_MEDIA, pEventListener != null, ,E_INVALID_ARG,
98 "[E_INVALID_ARG] Received invalid ImageDecodeUrlEventListener.");
100 if (pArg->GetData() != null) // if the network sends only file data.
102 // decode data to bitmap & call the listener.
103 std::unique_ptr<Bitmap> pBitmap(_ImageImpl::DecodeToBitmapN(*((pArg)->GetData()),
104 pArg->GetColorFormat(),
105 pArg->GetDestDimension(),
106 BUFFER_SCALING_AUTO));
108 if (pBitmap.get() != null)
110 pEventListener->OnImageDecodeUrlReceived(
111 reqId, pBitmap.get(), E_SUCCESS, L"E_SUCCESS", L"E_SUCCESS");
115 pEventListener->OnImageDecodeUrlReceived(
116 reqId, null, E_DECODING_FAILED, L"E_DECODING_FAILED", L"E_DECODING_FAILED");
119 else // if E_SUCCESS but the data is null
121 pEventListener->OnImageDecodeUrlReceived(
122 reqId, null, E_SYSTEM, L"E_SYSTEM", L"E_SYSTEM");
127 case IMAGE_URI_DATA_EVENT_CANCEL:
129 IImageDecodeUrlEventListener* pEventListener = dynamic_cast<IImageDecodeUrlEventListener*>(&listener);
130 SysTryReturn(NID_MEDIA, pEventListener != null, ,E_INVALID_ARG,
131 "[E_INVALID_ARG] Received invalid ImageDecodeUrlEventListener.");
132 _ImageUriDataEventArg* pArg = dynamic_cast<_ImageUriDataEventArg*>(pEventTypeArg);
133 SysTryReturn(NID_MEDIA, pArg != null, ,E_INVALID_ARG,
134 "[E_INVALID_ARG] Received invalid EventTypeArg.");
135 pEventListener->OnImageDecodeUrlReceived(reqId, null, pArg->GetResult(),
136 GetErrorMessage(pArg->GetResult()), GetErrorMessage(pArg->GetResult()));
140 case IMAGE_URI_DATA_EVENT_DESTROY:
142 _ImageUriDataFactory* pFactory = _ImageUriDataFactory::GetInstance();
144 if (pFactory != null)
146 pFactory->OnMediaSessionEnded(reqId);