summaryrefslogtreecommitdiffstats
path: root/src/corelib/statemachine/qstatemachine_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* QStateMachine: replace a QPair with a small structMarc Mutz2016-01-051-1/+13
| | | | | | | | | | | | | | | | | | | | | The use of QPair made the return type of initializeAnimation() so complicated, that the original author opted to declare the pair on one line, then assign to it in the next, to keep below the line length limit. She also copied a member of the pair just so as to give it a descriptive name. Fix both by introducing a small result struct. It has a nicer name, compared to the pair, but still port callers to use 'auto'. The member names are descriptive enough now. Saves more than 0.5KiB in text size on optimized GCC 4.9 Linux AMD64 builds, too. Change-Id: I7ed007ffa0fb16e182e38cd405cfd54da4e363fb Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
* QStateMachine: make enterStates/exitStates virtual.Erik Verbruggen2015-09-251-6/+6
| | | | | | | | This allows handling of state specific code when entering/exiting states during a micro-step. Change-Id: If2fa8dde9a1e209345950a93dee59414063d863e Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Add a method to detect when the state-machine can exit.Erik Verbruggen2015-09-151-0/+1
| | | | | | | | | | | According to the SCXML specification, the state-machine can exit the interpreter loop when a final state has been reached. This happens after finishing a macro-step or when it ends up in a final state right after startup (e.g. when the only state is a final state). This patch adds a virtual method which can be used to detect this reliably. Change-Id: I594e952a4972dd70d4089a2c4ce1c86880568eb9 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* QStateMachine: remove left-over method.Erik Verbruggen2015-07-231-3/+0
| | | | | | | | | | This method was probably there in older versions of the specification, but it is no longer used now. The only caller was in QStateMachinePrivate::setError, which has been changed to use the newer methods. Change-Id: Ic4961990d8d2c902676e63193d3f30ef427e6f0c Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
* QStateMachinePrivate: replace an inefficient QList with QVectorMarc Mutz2015-07-131-6/+6
| | | | | | | | | | | QPropertyAssignment is larger as a void*, and wasn't marked as movable, so QList<QPropertyAssignment> is horribly inefficient. Fix by marking it movable and using a QVector. Change-Id: I34e21e3f28f64dd8b187c144fb5bee022414216b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* StateMachine: Move Q...Private::get to _p.h file.Erik Verbruggen2015-07-081-1/+2
| | | | | | | Micro optimization, because it's called a lot. Change-Id: I50f775b39393f1f450e09ae9dc59a77d584f3c10 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* QStateMachine: fix RestorableId exception specificationMarc Mutz2015-05-191-1/+2
| | | | | | | | We're interested in whether qHash(QByteArray) throws, not declval<QByteArray>, of course. Change-Id: If3ba6e90aba69d0d4d12ac289e817f0d9705a601 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QStateMachine: allow posting of events when starting.Erik Verbruggen2015-05-071-0/+1
| | | | | | | | | | | This allows subclasses to submit any queued events that have to be handled before normal operation starts. For example, if an error event got generated during initialization which has to be handled by the state machine, the startup hook in the private class can be used to post those events and have the state machine handle them appropriately. Change-Id: I62249a31d8840f47bc19920870ad5da9647e61f9 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
* qstatemachine: add methods detect when a machine has processed an eventFawzi Mohamed2015-05-041-0/+4
| | | | | | | | | | | | | currently when adding an event it is not possible to know when processing it has finished. In particular if the event is ignored no method is called. Adding virtual methods to the private implementation (binary compatibility). These methods allow for extended automatic testing of the state machines. (cherry picked from commit e7feb956280105113b3e58f12e5f32f54199a95a) Change-Id: Iaa48fb9d7f6a6cde1a8a7a2bece7b4df55c147e8 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
* QStateMachine: cache expensive calculations.Erik Verbruggen2015-05-041-7/+10
| | | | | | | | | | | | | | | | | | As nothing changes in the state machine when selecting transitions for events and then calculating the exit- and entry-sets, some calculations can be cached. The exit set for a transition was calculated multiple times. First in removeConflictingTransitions, where the two loops would each calculate them multiple times. Then secondly in microstep(), which would calculate the exit set for all transitions. Transition selection, exit set calculation, and entry set calculation all calculate the transition domain and effective target states for transitions. Change-Id: I217328a73db2f71e371eb5f60a0c7b222303f0ca Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
* QStateMachine: remove conflicting transitions after selection.Erik Verbruggen2015-04-101-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After selecting all (enabled) transitions for a microstep, filter out any conflicting transition. The actual conflict resulution is done by ordering the transitions in order of the states that selected them. For example: if an event would trigger two transitions in a parallel state where one would exit that state and the other would not, this filtering prevents the state machine from selecting both states (as this case is an invalid state of the whole machine). This also fixes the exit set calculation for parallel states when one of its substates is exited and subsequently re-entered in the same transition. Previously, the parallel state was not exited, and subsequent re-entry was ignored (because it was still active). Now it is correctly exited and re-entered. A side-effect of the transition ordering mentioned above is it also fixes the non-deterministic behavior of which of the conflicting transitions is taken. [ChangeLog][QtCore] Fixed an issue where the state machine could end up in an invalid state when transitions from a parallel state were not checked for conflicts. [ChangeLog][QtCore] Fixed a case where a parallel state was not exited and re-entered when one of its substates was exited and subsequently re-entered. [ChangeLog][QtCore] Fixed the non-deterministic behavior of picking a transition from a set of conflicting transitions. Task-number: QTBUG-44783 Change-Id: I2ee72b6a2f552077bfa7aa4d369474ab62f4c2f0 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com> Reviewed-by: Kevin Funk <kevin.funk@kdab.com>
* QStateMachine: fix history state restoration.Erik Verbruggen2015-04-101-4/+10
| | | | | | | | | | | | | | | | | | | | | | | When a history state is entered that has an actual saved history (so not the initial state), the entry set was calculated wrongly in some cases. See the bug report for the specific case. The fix is to fully implement the standard, so method names in the private class are updated to reflect the names as used in the standard. Note that, as mentioned in the bug report, the algorithm as described in http://www.w3.org/TR/2014/WD-scxml-20140529/ has a bug. What is implemented is the fixed algorithm as described in the current working draft as of Friday March 13, 2015. This draft can be found at: http://www.w3.org/Voice/2013/scxml-irp/SCXML.htm [ChangeLog][QtCore] Fixed an issue where a history state restore would activate too many states, possibly putting the state machine in an invalid state. Change-Id: Ibb5491b2fdcf3a167c223fa8c9c4aad302dbb795 Task-number: QTBUG-44963 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
* QStateMachine: move methods out of Private class.Erik Verbruggen2015-04-101-2/+0
| | | | | | | | Also rename them to match the names in the scxml standard, and add the relevant description from the standard to the methods. Change-Id: I495832358f5836ed6ea04bf43061d42e29f4f743 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
* QStateMachine: move QState::finished() emision into method.Erik Verbruggen2015-04-091-0/+2
| | | | | | | | | By moving the code for QState::finished() emission into a virtual method which also receives the QFinalState that caused the emission, subclasses can hook in and do some extra processing. Change-Id: Id19947c09e196a0df4edb87d71b74b0600c78867 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* QStateMachine: replace a QHash key involving a QPointerMarc Mutz2015-01-091-1/+18
| | | | | | | | | | | | | | | | Using QPointers (or any type that makes a QPointer part of its identity) as a key in any associative container is wrong. They get externally set to nullptr, violating the associative container's class invariants, which could lead to data corruption, even though bucket-based hash implementations are less susceptible than binary trees. To fix, write a new class that acts much like the old QPair<QPointer<>,QByteArray>, but uses the QPointer only as a guard, not as part of its identity. To preseve identity, also saves the naked pointer originally passed and uses that for op== and qHash(). Change-Id: I4fa5a6bf86bad8fe7f5abe53d7c7f3ad3754d8d6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Whitespace cleanup: remove trailing whitespaceAxel Waggershauser2013-03-161-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | Remove all trailing whitespace from the following list of files: *.cpp *.h *.conf *.qdoc *.pro *.pri *.mm *.rc *.pl *.qps *.xpm *.txt *README excluding 3rdparty, test-data and auto generated code. Note A): the only non 3rdparty c++-files that still have trailing whitespace after this change are: * src/corelib/codecs/cp949codetbl_p.h * src/corelib/codecs/qjpunicode.cpp * src/corelib/codecs/qbig5codec.cpp * src/corelib/xml/qxmlstream_p.h * src/tools/qdoc/qmlparser/qqmljsgrammar.cpp * src/tools/uic/ui4.cpp * tests/auto/other/qtokenautomaton/tokenizers/* * tests/benchmarks/corelib/tools/qstring/data.cpp * util/lexgen/tokenizer.cpp Note B): in about 30 files some overlapping 'leading tab' and 'TAB character in non-leading whitespace' issues have been fixed to make the sanity bot happy. Plus some general ws-fixes here and there as asked for during review. Change-Id: Ia713113c34d82442d6ce4d93d8b1cf545075d11d Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* statemachine: Really fix signal transition handling in multi-threaded setupKent Hansen2012-08-081-0/+1
| | | | | | | | | | | | | | | | | | | | | Commit f9a17d7f0f02f7af849afdf653a763ffdaf78a1b fixed it for the case where the sender object is in a different thread at transition setup time. However, it still didn't work if either the sender object or the state machine was moved to a different thread at some later time, before the machine was started. Therefore: Bite the sour grape and traverse all the machine's transitions when the machine is being started, registering those signal transitions whose sender objects are in other threads. This will increase the machine's startup time (proportional to the number of transitions), but at least it works in all known scenarios, meaning we don't have to document weird restrictions regarding the order in which the user's operations have to be done. Task-number: QTBUG-19789 Change-Id: I5f1dd1321994e49635f52be65cf56d2678ed1253 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Move RestorePolicy enum to QState classKent Hansen2012-07-161-1/+1
| | | | | | | | | | This makes it possible to add API for setting the restore policy per state, or even per property assignment (QTBUG-17861). This change is fully source compatible with Qt4. Change-Id: I53628546b070f6fc84891f86e7ad7bd8ef5ba285 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Make signal transition registration thread-safeKent Hansen2012-07-131-0/+1
| | | | | | | | Since Qt's connections are thread-safe, QStateMachine's plumbing around them should be thread-safe too. Change-Id: I8ae91c2edc2d32ca4ed4258b71e5da22de30ed91 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Small refactoring of transition registrationKent Hansen2012-07-131-0/+4
| | | | | | | | | | | | | | Split the guts of registerTransitions() into a registerTransition() function. This allows a particular transition to be registered, instead of walking the source state's whole list of transitions every time. Move the logic for determining whether a transition should be registered to the state machine, since that's also where the actual registration takes place. Change-Id: I0496dee9454cd77b62cf2768942a82a96b320744 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Fix state entry bug for parallel state groupsKent Hansen2012-07-121-0/+3
| | | | | | | | | | | | | | | | | | The SCXML spec had a bug that would cause the initial state of a compound state within a parallel state group to be entered even if the transition specified another (non-initial) state of the compound state as its target. This only happened if the transition had multiple target states. The bug has been fixed in recent revisions of the SCXML spec. This commit implements the fix, which is to walk the ancestors of the transition's target states only after all the target states themselves have been added, so that the default initial states are correctly overridden/ignored. Task-number: QTBUG-25958 Change-Id: Iac532047678c483a4a3996e24dacf30e00f6bbe0 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Small refactoring of initial transition codeKent Hansen2012-07-111-0/+1
| | | | | | | | In preparation of supporting parallel root states, which will make the initial transition creation slightly more involved. Change-Id: Iad996eb4db248842c1a2088430c13bd5c953c374 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Get rid of hidden start stateKent Hansen2012-07-111-4/+0
| | | | | | | | | | | The hidden start state was used as a mechanism for performing the initial transition (to the real initial state, QStateMachine::setInitialState()), but it mutated the state machine in a way that causes problems when the root state is a parallel state group (see future commit). Change-Id: I41ac4f6bcabf3bec0a412e46282a1373928105a3 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Revamp property assignments implementationKent Hansen2012-07-111-12/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the old implementation, property assignments (QState::assignProperty()) were "second-class citizens". Assignments were not really integrated into the state machine algorithm, but rather done as a separate step (QStateMachinePrivate::applyProperties()). While that was convenient for SCXML spec transcription purposes, it resulted in some pretty poor semantics on the user side: * Properties were not assigned until _after_ both the QAbstractState::onEntry() function had been called and the QState::entered() signal had been emitted. * Automatic property restoration (QStateMachine::RestoreProperties) did not play nice with nested states (and parallel states, in particular). The proper fix is to refactor the implementation to make property assignments first-class in the core state machine algorithm (QStateMachinePrivate::microstep()). In practice, this meant splitting some steps. Instead of calling exitStates() straight away, we now first only compute the states to exit (without actually exiting them), and use the resulting set to compute which properties are candidates for restoration. Similarly, instead of calling enterStates(), we first only compute the states to enter (without actually entering them), and use the resulting set to compute which properties are assigned by the entered states. With that in place, the rest was a matter of moving the various chunks of the old applyProperties() logic to the place where they belong in the per-state entry/exit. All existing autotests pass. Added several tests that verify the desired semantics in more detail. Task-number: QTBUG-20362 Change-Id: I7d8c7253b66cae87bb0d09aa504303218e230c65 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Refactor {enter,exit}States() functionsKent Hansen2012-07-111-2/+6
| | | | | | | | | | | | Move the computation of the sets of entered/exited states to separate functions. This separation is done in order to facilitate the integration of property assignments (QState::assignProperty()) into the core state machine algorithm. Change-Id: I5b7084e0e37037eb64909d217856746d81bf1878 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Add some missing QT_NO_PROPERTIES guardsKent Hansen2012-07-101-4/+4
| | | | | | | ... and move the applyProperties() declaration to the right place. Change-Id: Iff4f468f2e7bc0350866b737a0db02c0f74bdd4f Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Small refactoring of animation selection codeKent Hansen2012-07-101-0/+1
| | | | | | | | | QStateMachinePrivate::applyProperties() is an epically long function. Move the code for selecting animations to a separate function, in preparation of a larger refactoring. Change-Id: Ic5846db97dd0cb0d6ad01740f413b233d2a66975 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Don't crash if property assignment target is deletedKent Hansen2012-07-101-1/+2
| | | | | | | | Do like QPropertyAnimation and store the QObject in a QPointer. Purge the assignments list upon state entry and property restore. Change-Id: I54a56885a2905178ab6aa5cf292b3d25c86b7a97 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Make delayed event posting work from secondary threadKent Hansen2012-06-061-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | postDelayedEvent() and cancelDelayedEvent() are marked as thread-safe in the documentation. Unfortunately, they didn't actually work when called from another thread; they just produced some warnings: QObject::startTimer: timers cannot be started from another thread QObject::killTimer: timers cannot be stopped from another thread As the warnings indicate, the issue was that postDelayedEvent() (cancelDelayedEvent()) unconditionally called QObject::startTimer() (stopTimer()), i.e. without considering which thread the function was called from. If the function is called from a different thread, the actual starting/stopping of the associated timer is now done from the correct thread, by asynchronously calling a private slot on the state machine. This also means that the raw timer id can no longer be used as the id of the delayed event, since a valid event id must be returned before the timer has started. The state machine now manages those ids itself (using a QFreeList, just like startTimer() and killTimer() do), and also keeps a mapping from timer id to event id once the timer has been started. This is inherently more complex than before, but at least the API should work as advertised/intended now. Task-number: QTBUG-17975 Change-Id: I3a866d01dca23174c8841112af50b87141df0943 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* Remove "All rights reserved" line from license headers.Jason McDonald2012-01-301-1/+1
| | | | | | | | | | As in the past, to avoid rewriting various autotests that contain line-number information, an extra blank line has been inserted at the end of the license text to ensure that this commit does not change the total number of lines in the license header. Change-Id: I311e001373776812699d6efc045b5f742890c689 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update contact information in license headers.Jason McDonald2012-01-231-1/+1
| | | | | | | Replace Nokia contact email address with Qt Project website. Change-Id: I431bbbf76d7c27d8b502f87947675c116994c415 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update copyright year in license headers.Jason McDonald2012-01-051-1/+1
| | | | | Change-Id: I02f2c620296fcd91d4967d58767ea33fc4e1e7dc Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update licenseheader text in source files for qtbase Qt moduleJyri Tahtela2011-05-241-17/+17
| | | | | | | Updated version of LGPL and FDL licenseheaders. Apply release phase licenseheaders for all source files. Reviewed-by: Trust Me
* Initial import from the monolithic Qt.Qt by Nokia2011-04-271-0/+250
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12