2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/system/common/trigger-event.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali/internal/system/common/file-descriptor-monitor.h>
28 #include <dali/internal/window-system/windows/platform-implement-win.h>
30 #define MESSAGE_TYPE_OFFSET 10000
40 TriggerEvent* triggerEventArray[10000] = { 0 };
42 int SetTriggerEvent(TriggerEvent *event)
44 for (size_t i = 0; i < 10000; i++)
46 if (NULL == triggerEventArray[i])
48 triggerEventArray[i] = event;
56 TriggerEvent::TriggerEvent( CallbackBase* callback, TriggerEventInterface::Options options )
57 : mCallback( callback ),
58 mFileDescriptor( -1 ),
61 // Create accompanying file descriptor.
62 mFileDescriptor = SetTriggerEvent( this );
63 WindowsPlatformImplement::AddListener( mFileDescriptor + MESSAGE_TYPE_OFFSET, mCallback );
65 if (mFileDescriptor >= 0)
67 // Now Monitor the created event file descriptor
71 DALI_LOG_ERROR("Unable to create TriggerEvent File descriptor\n");
75 TriggerEvent::~TriggerEvent()
79 if (mFileDescriptor >= 0)
85 void TriggerEvent::Trigger()
87 if (mFileDescriptor >= 0)
89 // Increment event counter by 1.
90 // Writing to the file descriptor triggers the Dispatch() method in the other thread
91 // (if in multi-threaded environment).
93 WindowsPlatformImplement::PostWinMessage( mFileDescriptor + MESSAGE_TYPE_OFFSET, 0, 0 );
97 DALI_LOG_WARNING("Attempting to write to an invalid file descriptor\n");
101 void TriggerEvent::Triggered( FileDescriptorMonitor::EventType eventBitMask )
103 if( !( eventBitMask & FileDescriptorMonitor::FD_READABLE ) )
105 DALI_ASSERT_ALWAYS( 0 && "Trigger event file descriptor error");
109 // Reading from the file descriptor resets the event counter, we can ignore the count.
110 uint64_t receivedData;
112 size = read(mFileDescriptor, &receivedData, sizeof(uint64_t));
113 if (size != sizeof(uint64_t))
115 DALI_LOG_WARNING("Unable to read to UpdateEvent File descriptor\n");
118 // Call the connected callback
119 CallbackBase::Execute( *mCallback );
121 //check if we should delete ourselves after the trigger
122 if( mOptions == TriggerEventInterface::DELETE_AFTER_TRIGGER )
128 } // namespace Adaptor
130 } // namespace Internal