由於大多的程式都具有 UI 介面,不管是網頁程式,又或是作業系統,都是透過使用者的操作來決定程式的執行順序,使得程式與使用者的互動越來越重要。這種互動性高的程式在設計上往往透過事件驅動的方式來完成。 事件驅動的程式設計是一種現在常見的電腦程式設計模型,程式執行的流程相較以往由程式設計師來決定,事件驅動的程式則是由與使用者或是與其他程式的互動(像是訊息的接收)來做決定。事件驅動的程式在撰寫難易度上,因使用的語言而有所不同。常見的語言像是 C#、JAVA、PYTHON 等,這些語言在基礎上就有支援事件的語法,因此使用上較為輕鬆。而當今廣泛運用的一種語言:C 語言,因為缺乏語言基礎上的支援,大多只能靠使用者的經驗去設計。 本文將提出一套工具 C Event Dispatcher,協助程式設計者在 C 語言上事件驅動程式的撰寫。此工具的特色在於他的事件觸發條件不局限於以往使用的 timeout 與 signal,而是採用較為靈活的條件判斷式,讓程式設計者可以使用變數、邏輯運算等方式作事件的觸發。這樣的彈性讓我們在使用事件驅動的架構設計程式的控制表或有限狀態機時更加便利,可以依據不同的狀態設置不同的轉換條件。尤其是運用在嵌入式系統上,更可以達到動態的管理程式系統模型。不僅在使用上更加靈活,也增加程式碼的可維護性。 ;Now a day, most of programs having UI interfaces. Whether it is a website program or an operating system, the process of the programs is determined by the user′s operating. So that, the interaction between the program and the user is more and more important. The design of such programs is often using event-driven design. Event-driven programming is a common programming paradigm in which the flow of program is determined by the event such as user motions or messages from other programs. How difficult it is to design the event-driven programs is also depending on the programming language. Programming languages like C#, JAVA, PYTHON, etc., are easier to design event-driven programs because of the supporting of language itself. However, one of widely using language: C language, because of the lack of language-based support, can only design event-driven programs by the experience from designers. This research will present a tool which is called “C Event Dispatcher”(CED) to assist programmers in writing event-driven programs in C language. The feature of CED tool is that it use different way to trigger the event handler. Without using timeout and signal, it use conditional expression to trigger the handler, giving user more flexibility to design event-driven program. User can use the mechanism of conditional expression to monitor a event variable, calling the event handler depending on the condition of the event variable. The CED tool also support the publish–subscribe pattern, increasing the flexibility of event-driven architecture and the maintainability of the code. The finite-state machine built by CED tool can dynamically decrease and increase the states in the finite-state machine. This advantage is suitable for using on the embedded system. It can make the embedded system more flexible and maintainable.