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>
22 #include <Win32WindowSystem.h>
25 #include <dali/integration-api/debug.h>
29 #include <dali/internal/system/common/file-descriptor-monitor.h>
31 #define MESSAGE_TYPE_OFFSET 10000
41 TriggerEvent* triggerEventArray[10000] = { 0 };
43 int SetTriggerEvent(TriggerEvent *event)
45 for (size_t i = 0; i < 10000; i++)
47 if (NULL == triggerEventArray[i])
49 triggerEventArray[i] = event;
57 TriggerEvent::TriggerEvent( CallbackBase* callback, TriggerEventInterface::Options options )
58 : mCallback( callback ),
59 mFileDescriptor( -1 ),
62 // Create accompanying file descriptor.
63 mFileDescriptor = SetTriggerEvent( this );
64 Win32WindowSystem::AddListener( mFileDescriptor + MESSAGE_TYPE_OFFSET, mCallback );
66 if (mFileDescriptor >= 0)
68 // Now Monitor the created event file descriptor
72 DALI_LOG_ERROR("Unable to create TriggerEvent File descriptor\n");
76 TriggerEvent::~TriggerEvent()
80 if (mFileDescriptor >= 0)
86 void TriggerEvent::Trigger()
88 if (mFileDescriptor >= 0)
90 // Increment event counter by 1.
91 // Writing to the file descriptor triggers the Dispatch() method in the other thread
92 // (if in multi-threaded environment).
94 Win32WindowSystem::PostWinMessage( mFileDescriptor + MESSAGE_TYPE_OFFSET, 0, 0 );
98 DALI_LOG_WARNING("Attempting to write to an invalid file descriptor\n");
102 void TriggerEvent::Triggered( FileDescriptorMonitor::EventType eventBitMask )
104 if( !( eventBitMask & FileDescriptorMonitor::FD_READABLE ) )
106 DALI_ASSERT_ALWAYS( 0 && "Trigger event file descriptor error");
110 // Reading from the file descriptor resets the event counter, we can ignore the count.
111 uint64_t receivedData;
113 size = read(mFileDescriptor, &receivedData, sizeof(uint64_t));
114 if (size != sizeof(uint64_t))
116 DALI_LOG_WARNING("Unable to read to UpdateEvent File descriptor\n");
119 // Call the connected callback
120 CallbackBase::Execute( *mCallback );
122 //check if we should delete ourselves after the trigger
123 if( mOptions == TriggerEventInterface::DELETE_AFTER_TRIGGER )
129 } // namespace Adaptor
131 } // namespace Internal