(AutomatedTests) Fix for 14.04
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-platform-abstraction / resource-collector.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "resource-collector.h"
19 #include "tizen-platform-abstraction.h"
20 #include <dali/integration-api/debug.h>
21 #include <unistd.h>
22
23 namespace Dali
24 {
25 namespace Internal
26 {
27 namespace Platform
28 {
29 using namespace Dali::Integration;
30
31 ResourceCollector::ResourceCollector() :
32   mGrandTotalCompletions(0),
33   mGrandTotalNotifications(0)
34 {
35 }
36
37 ResourceCollector::~ResourceCollector() {}
38
39 void ResourceCollector::LoadResponse( Dali::Integration::ResourceId id, Dali::Integration::ResourceTypeId type, Dali::Integration::ResourcePointer resource, Dali::Integration::LoadStatus status )
40 {
41   ++mGrandTotalNotifications;
42   if( status == RESOURCE_COMPLETELY_LOADED )
43   {
44     DALI_ASSERT_DEBUG( mCompletionCounts.find(id) == mCompletionCounts.end() && "A resource can only complete once." );
45     mCompletionStatuses[id] = true;
46     ++mCompletionCounts[id];
47     ++mSuccessCounts[id];
48     mCompletionSequence.push_back( id );
49     ++mGrandTotalCompletions;
50   }
51 }
52
53 void ResourceCollector::LoadFailed( Dali::Integration::ResourceId id, Dali::Integration::ResourceFailure failure )
54 {
55   mCompletionStatuses[id] = false;
56   ++mFailureCounts[id];
57   mCompletionSequence.push_back( id );
58   ++mGrandTotalCompletions;
59   ++mGrandTotalNotifications;
60 }
61
62 void PollForNotification( ResourceCollector& collector, Integration::PlatformAbstraction&  abstraction, const unsigned maxPolls )
63 {
64   // Poll for at least one completed or partially completed load:
65   const unsigned outstandingNotifications = collector.mGrandTotalNotifications;
66   for( unsigned poll = 0; poll < maxPolls; ++poll )
67   {
68     abstraction.GetResources( collector );
69     if( collector.mGrandTotalNotifications > outstandingNotifications )
70     {
71       break;
72     }
73     usleep( 3 ); //< Wait 3 microseconds each time around.
74   }
75 }
76
77 } /* namespace Platform */
78 } /* namespace Internal */
79 } /* namespace Dali */