biji1016

来源:互联网 发布:vb与matlab混合编程 编辑:程序博客网 时间:2024/06/05 02:06

At run-time each EB GUIDE model is represented by one instance of class GtfCoreModel. This interface class provides access to otherassociated interfaces (for example datapool, external event system).section 7.2.5,“Software module structure of EBGUIDE GTF”describes how software moduleinterfaces (for example Gtf-CoreModel) are published at system start-up.

 

 

8.2.2.1.1. Event receipt

Theexternal event system creates a separated event queue for each subscribedcommunication context.

Whenevernew events arrive in a previously empty event queue, the external event systeminvokes the corresponding

communicationcontext by calling a registered callback method.

 

1.    To register an invoking callback method atsystem start-up, use method SetInvoker().

 

Newproperty values changed by one communication context are invisible to othercommunication contexts

untilthe writer explicitly commits the new values. If the writer explicitly commitsthe new values, a reading

communicationcontext can explicitly update these new property values to see them. Committingas well as

updating affects all manipulated properties at once. Both operations areatomic with respect to the commit and

update activities of other communication contexts.

Each datapool property is a directed communication channel betweenexactly one writing communication context

and one reading communication context; this is described in detail in section 6.3.5, “Datapool”. The writing

communication context has always an up-to-date view on the respectiveproperties. This means internal

properties do not require committing or updating, because they have oneand the same reader and writer

communication context.

 

 

8.2.2.2.1. Property access methods

The datapool provides the following three types of property accessmethods:

The first group of methods expectsparameters which are container objects (for example string objects).

These methods are only for EB GUIDE GTF internal usage.

The second group of methods expectsfunctor callback parameters. These callbacks must provide access

to a stream of plain old data (for example strings stored asnull-terminated byte stream). These methods

are intended for EB GUIDE GTF internal usage, but you can use them, too.

The third group of methods expectsparameters which are stored as plain old data structures in a buffer (for

example strings stored as null-terminated byte arrays). These methodsare recommended for application

developers

 

8.2.2.2.4. Property value updates

To retrieve the manipulated values, a reading communication context hasto call methodUpdate(). The

method Update() affects all datapool properties which have beenmanipulated and committed by other communication

contexts since the previous call.

Whenever manipulated values are available, the datapool invokes thecorresponding reader communication

context by calling a registered callback method. But this will onlyhappen if methodUpdate() was called at

least once since last invoking. Use method SetInvoker()toregister an invoking callback method at system

start-up.

 

 

8.2.2.2.5. Property value updatenotifications

Only the reader communication context of a datapool property canretrieve update notifications. Use the method

 

Fetch()to fetch and process the notifications.The modeler can select a notification policy for datapool properties

by setting the respective element attribute. For further informationabout element attributes, refer tosection

10.11, “Element attributes”.

 

8.2.4. Observer patterns andcallbacks

To trackthe value of widget properties or observe other elements of the EB GUIDE model,EB GUIDE GTF

uses theobserver pattern.There are implementations of the observer pattern with an observer interfaceclass and respective registration method, for example the GtfStateMachineObserver. Widget properties are

observedusing the functor template GtfFunctorX as shown in the following example:

pWidget->subscribe(pContext,propertyIndex, this,gtf_bind(&MyComp::propertyChanged, this, pWidget,propertyIndex) );

In this small example the method propertyChanged is called, whenever theproperty at index propertyIndex

changes. section 8.2.4.1, “Functors” explains the usage and behavior of GtfFunctorX.

 

 

8.2.4.1. Functors

A functor is a data type that stores a function or method invocation andprovides an interface to call the encapsulated function or method like anordinary function. In EB GUIDE GTF a set of functor type templates

and utility routines are provided to assemble function invocations. The GtfFunctorX templates are used to

store callbacks.

The signature of the function call is encoded in the functor template.There is a separate functor template type for every possible number ofparameters. In the documentation the number of parameters is denoted as asuffix X. The first template parameter of GtfFunctorX describes the type of the return value. All furthertemplate parameters define the expected parameter types of the call.

 

Functor利用某些类对象支持operator()的特性,来达到模拟函数调用效果的技术。

仿函数可以不带痕迹地传递上下文参数,而回调技术通常使用一个额外的void*参数传递。

Std::sort( vec.begin(), vec.end(), compare());

Func比较复杂而无法展开,此时回调函数作为一个函数指针传入,其代码亦无法展开,但func函数对functor的调用是编译器编译期间就可以确定并进行inline展开的。

这种性能优势有时是一种无可比拟的优势(对于std::sort就是如此,因为元素比较的次数非常巨大,是否可以进行内联展开导致了一种雪崩效应。

Functor并不能完全取代回调函数所有的应用场合。Std::AutoFreeAlloc中使用回调函数,因为AutoFreeAlloc要容纳异质的析构函数,而不是只支持某一种类的析构。这和模板不能处理在同一个容器中支持异质类型,是一个道理。

Acallback is a function that is passed as an argument to another function and isexecuted after its parent function has completed.

0 0