This class lets you define dynamic view servers. More...
#include <ilserver/mvserver.h>
Public Types | |
enum | ThreadMode { ILS_SINGLE_THREAD , ILS_THREADED_SEND, ILS_THREAD_SAFE_TRANS, ILS_THREADED_DEFAULT } |
possible execution modes of the server More... | |
Public Member Functions | |
virtual IlsBoolean | processRequest (IlsTime *t) |
Handles a request. More... | |
View Handling | |
virtual void | onOpenView (IlsMvView &) |
Called each time a new dynamic view is opened. More... | |
virtual void | onCloseView (IlsMvView &) |
Called each time a view is closed on the server. More... | |
Transaction Control | |
The way a dynamic view server processes a component transaction can be controlled both on the component side and on the server side.
| |
virtual IlsBoolean | beginTransaction (IlsMvComponentItf &comp, IlsTransactionId tId, IlsC2STransStatus tStat) |
This virtual member function is executed by Server at the beginning of a transaction that was opened by the component. More... | |
virtual IlsBoolean | endTransaction (IlsMvComponentItf &comp, IlsTransactionId tId, IlsC2STransStatus tStat, IlsBoolean res) |
This virtual member function is executed by Server at the end of a transaction that was opened by the component. More... | |
Static Public Member Functions | |
static IlsBoolean | AbortTransaction () |
Instructs the server to abort a component transaction handled by the server. More... | |
static void | CreateDefaultCompAtStartup (IlsBoolean b) |
Change creation of default component at startup. More... | |
static IlsMvUser * | GetDefaultUser () |
Returns the user associated with the default component that is linked to the server. More... | |
static IlsMvServer & | GetSingleton () |
Retrieves a reference of the unique instance of the dynamic view server that has been initialized in the application. More... | |
static void | Notify () |
Performs notification and/or re-evaluation during an interaction cycle. More... | |
static void | ReplyMessage (const IlsMvMessage::SvMsg &msg, IlsBoolean local=IlsFalse) |
Send a message of type IlsMvMessage::SvMsg to the component that sent the transaction currently processed by the server. More... | |
static void | SetCatchExceptionMode () |
Enable exception mode. More... | |
static void | UnsetCatchExceptionMode () |
Disable exception mode. More... | |
Initialization | |
static IlsBoolean | Initialize (int &argc, char **argv, int threadMode=ILS_THREADED_DEFAULT) |
Initialization of IlsMvServer . More... | |
Loading Dynamic View Types Specifications | |
static IlsBoolean | LoadResources (IlsString resourceFile) |
Loads a resource file that contains a list of dynamic view type specification files. More... | |
static IlsBoolean | LoadViewSpec (IlsString ilsFile, IlsBoolean useXmlParser=IlsFalse) |
Loads a dynamic-view type specification file on the server. More... | |
static IlsBoolean | InterpretViewSpec (IlsString viewSpec, IlsMvComponentItf *compItf=0, IlsBoolean useXmlParser=IlsFalse) |
Interprets the dynamic-view type specification passed by the viewSpec parameter. More... | |
Opening Views | |
Dynamic views are generally opened from an application component (see the function | |
static IlsMvView * | OpenView (const IlsString &objId, const IlsString &viewId, IlsMvComponentItf *compItf=0, const IlsMvValue *params=0, unsigned long paramsNb=0, IlsBoolean force=IlsFalse, IlsOpenViewStatus *status=0) |
Opens the dynamic view whose label is passed as its second parameter on the object whose label is provided as its first parameter. More... | |
static IlsMvView * | OpenView (IlsViewed *obj, const IlsString &viewId, IlsMvComponentItf *compItf=0, const IlsMvValue *params=0, unsigned long paramsNb=0, IlsBoolean force=IlsFalse, IlsOpenViewStatus *status=0) |
Similar to the previous one, except that it takes a pointer to a Server object, instead of an object identifier, as its first argument. More... | |
Trace Mode | |
static void | SetTrace (IlsBoolean status=IlsTrue) |
Activates the trace mode of the server. More... | |
static IlsBoolean | IsTraced () |
Returns IlsTrue if the server is operating in trace mode. | |
static void | SetTraceTime (IlsBoolean status=IlsTrue) |
Enable or disable time-tracing mode. More... | |
static IlsBoolean | IsTracedTime () |
Returns IlsTrue if time tracing-mode is enabled. | |
Identifying Objects | |
static IlsBoolean | DeclObjectLabel (IlsViewed &obj, IlsString label) |
Associates a label with a server object and stores the association in the server. More... | |
static IlsString | GetLabelOfObject (IlsViewed &object) |
Returns the label assigned to an object. More... | |
static IlsViewed * | GetObjectFromLabel (IlsString label) |
Returns the Server object with which the string label is associated. More... | |
static IlsBoolean | UndeclObjectLabel (IlsViewed &object) |
Breaks the association established between the Server object object and a label, if any. More... | |
static IlsBoolean | UndeclObjectLabel (IlsString label) |
Breaks any association established between label and a server object. More... | |
Protected Member Functions | |
IlsMvServer (int threadMode=0) | |
This protected constructor is implicitly called when the dynamic view server is initialized. More... | |
Friends | |
class | IlsMvComponentItf |
class | IlsMvServerFactory |
class | IlsMvView |
Component Connection | |
virtual void | onConnect (IlsMvComponentItf &compItf) |
Called each time a new component connects to the server. More... | |
virtual void | onDisconnect (IlsMvComponentItf &compItf) |
Called when a component disconnects from the server —that is, when the component interface compItf is deleted. More... | |
virtual IlsBoolean | acceptConnection (IlsMvComponentItf &compItf, IlsString &cause) |
alled before the method onConnect() but after the user has been created and bound (see IlsMvUsr::onBind() ). More... | |
static IlsMvComponentItf * | GetComponent (IlsMvComponentId id) |
Returns the component identified by id. More... | |
static IlsMvComponentItf *const * | GetComponents (int &dim) |
Returns an array of all the components that are currently connected to the server. More... | |
Execution Loop | |
virtual void | beginNotification () |
If you override this virtual member function, you must call the inherited function. | |
virtual void | endNotification () |
If you override this virtual member function, you must call the inherited function. | |
void | registerEndCycleTask (IlsCallbackFunc cb, IlsAny arg) |
Register a callback which will be executed at the end of the notification cycle. These callbacks are executed only once and are unregistered after execution. More... | |
static IlsBoolean | Run (int nb=0, IlsTime *t=0) |
Runs the execution loop of a dynamic view server. More... | |
static void | Stop () |
Interrupts the execution loop once the current interaction cycle is over. | |
Interactors | |
virtual IlsMvUser * | getInteractingUser () |
Returns the user associated with the interface of the component that issued the request handled during the current interaction cycle. More... | |
static IlsMvComponentItf * | GetDefaultComp () |
Returns a pointer to the interface of the default component that is implicitly created by Server when a view is opened with no associated component. More... | |
static IlsMvComponentItf * | GetInteractor () |
Returns a pointer to the interface of the component that issued the request handled during the current interaction cycle. More... | |
static IlsMvUser * | GetInteractingUser () |
Returns the current interacting user by calling the virtual function getInteractingUser() . | |
static IlsMvView * | GetInteractingView () |
Retrieves the interacting view while an update request from a component is processed by the server. More... | |
This class lets you define dynamic view servers.
<>:</>
In a dynamic view server, views are loaded at runtime from dynamic view type specifications.
IlsMvComponent
, IlsMvComponentItf
, IlsMvMessage
, IlsTransaction
. possible execution modes of the server
Enumerator | |
---|---|
ILS_SINGLE_THREAD | The server runs in a single thread and is not multithread safe |
ILS_THREADED_SEND | The server is multithread safe. A thread is started for each component to send representation updates to the component. This mode is interesting if the server interacts with remote components because the server does not have to wait for the communication layer to send updates. |
ILS_THREAD_SAFE_TRANS | This mode tells ILOG Server to create a Server transaction systematically each time a component transaction is processed, so as to allow concurrent transactions to be safely processed in other threads (see the member function |
ILS_THREADED_DEFAULT | When the threadMode parameter is set to this value, the mode |
|
protected |
This protected constructor is implicitly called when the dynamic view server is initialized.
The dynamic view server is actually created during this initialization phase by the current instance of IlsMvServerFactory
. Only one dynamic view server can exist at a given time. The threadMode parameter specifies the execution mode of the server.
IlsMvServerFactory::newInstance()
.threadMode | execution mode of the server |
|
static |
Instructs the server to abort a component transaction handled by the server.
This transaction will be rolled back both on the server side and on the component side. This function returns IlsTrue
, unless the server was not processing a component transaction.
IlsTrue
, unless the server was not processing a component transaction.
|
virtual |
alled before the method onConnect()
but after the user has been created and bound (see IlsMvUsr::onBind()
).
At this point, you can accept the connection by returning true
or reject it by returning false
. If you reject the connection, the component is disconnected and a connection error message is sent to the component (see IlsMvComponent::connectionDenied()
). In this case, you should set the cause parameter to explain why you rejected the connection. If you accept the connection, you can set the cause parameter that will be given back to the component (see IlsMvComponent::connectionAllowed()
).
Note that this method is not called for the default component. A default linked component is automatically created when a server starts handling linked views opened on the server.
compItf | componentItf |
cause | this value must be set to explain why you reject or accept the connection |
IlsTrue
if the connection is accepted. IlsFalse
otherwise.
|
virtual |
This virtual member function is executed by Server at the beginning of a transaction that was opened by the component.
When this function is not overridden, it implicitly creates a Server transaction, except if:
ILS_C2S_NO_ROLLBACK
is set in the parameter tStat, andIlsMvServer
constructor.)comp | identifies the component interface |
tId | the identifier of the transaction |
tStat | the status of the transaction as assigned by the component (see the member function IlsMvComponent::commitC2STransaction() ) |
IlsFalse
will roll back the transaction on the component side.
|
static |
Change creation of default component at startup.
By default, Server instantiates the default component used for linked views at startup. Use this function if you need to change the default behavior.
|
static |
Associates a label with a server object and stores the association in the server.
Using this association, an application component can open a view by using the object label as a parameter. The application component can also query the server to obtain a list of labels that match a given pattern. For details, see the functions IlsMvComponent::openView()
and IlsMvComponent::getObjectIds()
.
This member function returns IlsFalse
if the object has already an associated label or if the specified label already has been assigned to another object. If at least one view has subscribed to the object, the association is automatically broken when the server object is suppressed or cut. It is up to the user to undeclare and redeclare the association each time the label has to be changed.
obj | object to be associated with a label |
label | label associated to the object |
IlsFalse
if the object has already an associated label or if the specified label already has been assigned to another object
|
virtual |
This virtual member function is executed by Server at the end of a transaction that was opened by the component.
This function takes the following parameters:
comp
parameter .tId
parameter is .tStat
parameter is .When this function is not overridden, it executes the following instructions, depending on the values of the tStat and res parameters:
IlsTrue
or ILS_C2S_NO_ROLLBACK
is set in tStat parameter:beginTransaction()
, this transaction is committed.ILS_C2S_NO_NOTIFY
is not set in the tStat parameter, a notification cycle is executed.comp | identifies the component interface |
tId | the identifier of the transaction |
tStat | the status of the transaction as assigned by the component (See the member function IlsMvComponent::commitC2STransaction() ) |
res | specifies the results of the transaction execution |
IlsFalse
and the tStat parameter is not set to ILS_C2S_NO_ROLLBACK
, the transaction is rolled back on the component side.IlsTrue
and
the tStat
parameter is not set to ILS_C2S_NO_ACKNOWLEDGE
, the transaction is acknowledged on the component side.
|
static |
Returns the component identified by id.
id | id of the component |
null
if the component has already been disconnected
|
static |
Returns an array of all the components that are currently connected to the server.
dim | receive the size of the array |
null
entries) corresponding to components that have already been disconnected. This array is managed by Rogue Wave Server internally. You must not delete it.
|
static |
Returns a pointer to the interface of the default component that is implicitly created by Server when a view is opened with no associated component.
The default component is local to the server. See the member functions OpenView()
for more information.
By default this function returns a null pointer.
|
static |
Returns the user associated with the default component that is linked to the server.
This function return null
if the default component has not yet been initialized. See also the static member function GetDefaultComp()
.
|
virtual |
Returns the user associated with the interface of the component that issued the request handled during the current interaction cycle.
It returns a null pointer if no interaction cycle is in progress.
|
static |
Retrieves the interacting view while an update request from a component is processed by the server.
The interactive view is set if the update is initialized at representation-object level (see IlsRpObject::onUpdate()
or execCallback()
).
|
static |
Returns a pointer to the interface of the component that issued the request handled during the current interaction cycle.
It returns a null pointer if no interaction cycle is in progress.
Returns the label assigned to an object.
object | object for which you request the label |
Returns the Server object with which the string label is associated.
label | label of the object |
|
static |
Retrieves a reference of the unique instance of the dynamic view server that has been initialized in the application.
An error message is issued if this method is invoked before the server has been initialized.
|
static |
Initialization of IlsMvServer
.
A dynamic view server must be initialized before it can make use of other functions provided by the IlsMvServer
API. Initialization must take place after the static member function IlsMvProcess::Initialize()
, or that of a derived class, has been called. This static member function takes the arguments of the command line as its parameters. It extracts and parses the following arguments:
-ilsr
or -ilsres filename
These options load a resource file by executing the member function IlsMvServer::LoadResources()
, which takes the name of the resource file as its parameter.
-ilsd
or -ilsdef filename
These options load a dynamic view type specification file by executing the member function IlsMvServer::LoadViewSpec()
, which takes the name of the view specification file as its parameter.
The threadMode parameter specifies the execution mode of the server. Refer to the protected IlsMvServer
constructor for details about the various execution modes.
|
static |
Interprets the dynamic-view type specification passed by the viewSpec
parameter.
If the specification is valid, it is registered with the server. If another specification with the same name has already been registered, it is replaced by the new one.
The argument compItf is a pointer to a component interface. If this pointer is non-null, the error or information messages produced by the view interpreter are sent to the component (see the function IlsMvComponent::recvMessage()
).
The parameter useXmlParser specifies to use the XML parser.
This function returns IlsTrue
if the string viewSpec
contains a valid dynamic-view type specification. Otherwise, it returns IlsFalse
.
Dynamic views are generally opened from an application component (see the function IlsMvComponent::openView()
). The following static member functions let you open a view from the server.
viewSpec | IlsString that contains the view specification |
compItf | a pointer to a component interface |
useXmlParser | IlsTrue for XML description |
IlsTrue
if viewSpec contains a valid view specification
|
static |
Loads a resource file that contains a list of dynamic view type specification files.
For each one of these files, it executes the member function IlsMvServer::LoadViewSpec()
by passing the specification file name as a parameter. The resource file is located by means of the access paths specified by the environment variable ILSPATH
. This member function returns IlsTrue
if the file is found. Otherwise, it returns IlsFalse
.
resourceFile | resource file name |
IlsTrue
if the file is found. IlsFalse
otherwise.
|
static |
Loads a dynamic-view type specification file on the server.
If a dynamic-view type specification with the same name has already been loaded, it is replaced with the new one. The dynamic-view type specification file is located by means of the access paths specified by the environment variable ILSPATH
. This member function returns IlsTrue
if the file is found and the dynamic-view type specification is valid. Otherwise, it returns IlsFalse
. The parameter useXmlParser specifies to use the XML parser.
ilsFile | view specicication file name |
useXmlParser | IlsTrue if the file is in XML format |
IlsTrue
if the file is found. IlsFalse
otherwise.
|
static |
Performs notification and/or re-evaluation during an interaction cycle.
You can use it to start a notification cycle manually for a dynamic view server – for instance, when some actions are performed on the model outside any transaction, because in that case, notification is not automatic.
This function carries out the following steps sequentially:
|
virtual |
Called each time a view is closed on the server.
It does nothing, but can be overridden.
|
virtual |
Called each time a new component connects to the server.
If the server execution mode is set to ILS_THREADED_SEND
, this function creates a thread that sends the updates to the component.
This function can be overridden. See the IlsMvServer
constructor for details about the various execution modes.
compItf | the interface of the connected component |
|
virtual |
Called when a component disconnects from the server —that is, when the component interface compItf is deleted.
It does nothing but can be overridden.
compItf | deleted component interface |
|
virtual |
Called each time a new dynamic view is opened.
By default, this function has no effect. It can be overridden.
|
static |
Opens the dynamic view whose label is passed as its second parameter on the object whose label is provided as its first parameter.
objId | name of the object origin of the view |
viewId | name of the view to open |
compItf | A representation of the view is created in the component identified by the interface address compItf. If the address is null, the representation of the view is created in a default local component created by the server. |
params | an array of IlsMvValue . It can be null. The values, if any, contained in this array are assigned to the dynamic view parameters on a sequential basis. When a value is void, it is discarded. |
paramsNb | the number of parameters in the params value array. |
force | If set to IlsTrue , this argument forces the opening of the view, even if this view has already been opened by the component (and is still opened). The default value is IlsFalse , which means that the view is not duplicated. |
status | When the value pointed to by this parameter is a non-null pointer, that value is assigned the status of the view-opening action. See the type definition IlsOpenViewStatus for more information on the possible values. |
Otherwise, the function returns the null pointer.
|
static |
Similar to the previous one, except that it takes a pointer to a Server object, instead of an object identifier, as its first argument.
obj | pointer to the object origin of the view. If the pointer is null, the view is created with no origin. |
viewId | name of the view to open |
compItf | A representation of the view is created in the component identified by the interface address compItf. If the address is null, the representation of the view is created in a default local component created by the server. |
params | an array of IlsMvValue . It can be null. The values, if any, contained in this array are assigned to the dynamic view parameters on a sequential basis. When a value is void, it is discarded. |
paramsNb | the number of parameters in the params value array. |
force | If set to IlsTrue , this argument forces the opening of the view, even if this view has already been opened by the component (and is still opened). The default value is IlsFalse , which means that the view is not duplicated. |
status | When the value pointed to by this parameter is a non-null pointer, that value is assigned the status of the view-opening action. See the type definition IlsOpenViewStatus for more information on the possible values. |
Otherwise, the function returns the null pointer.
|
virtual |
Handles a request.
It calls the virtual function IlsMvProcess::processRequest()
.
void IlsMvServer::registerEndCycleTask | ( | IlsCallbackFunc | cb, |
IlsAny | arg | ||
) |
Register a callback which will be executed at the end of the notification cycle. These callbacks are executed only once and are unregistered after execution.
If such callbacks modify the server model, you should restart a new notification cycle by calling the static member function IlsMvServer::Notify()
.
cb | callback to call |
arg | user argument |
|
static |
Send a message of type IlsMvMessage::SvMsg
to the component that sent the transaction currently processed by the server.
See the GetInteractor()
function for details.
The virtual member function IlsMvComponent::recvMessage()
* will be executed on the component side.
|
static |
Runs the execution loop of a dynamic view server.
The execution loop is also interrupted if the member function processRequest()
executed during an interaction cycle returns IlsFalse
.
An interaction cycle executes the following phases sequentially:
IlsViewServer::beginInteractionCycle()
. If this member function returns IlsFalse
, the execution loop ends.processRequest()
is called to execute an action. Any viewed object or viewed list of objects modified by an action is marked as requiring notification. The reference counter of every viewed object that has been marked is incremented to prevent these objects from being deleted before the notification phase. If the function processRequest()
returns IlsFalse
, the interaction cycle is stopped before the notification phase is executed, and the execution loop terminates.Notify()
, provided automatic notification mode is selected.At the end of notification, the reference counter of each marked object is decremented, and the objects are unmarked. Every object with a null reference counter is destroyed. Viewed objects that are the target of relations owned by destroyed objects are thus modified. They are marked in turn as requiring notification. Consequently, the reevaluation/notification phase loops until all eager derived members are updated and no new viewed object requires notification.
IlsViewServer::endInteractionCycle()
terminates an interaction cycle. If this member function returns IlsFalse, the execution loop stops.Another technique is to execute an interaction cycle manually. To do so, you have to call the static member function Notify()
explicitly after any action performed on viewed objects and after creating or closing a view.
nb | number of interaction cycles to be performed as its first argument. If nb equals 0 , the loop will never stop. |
t | specifies how long the server will wait for a request to be issued by a component. If the pointer is null, the function loops indefinitely. If no request arrives during this lapse of time, the execution loop exits. Otherwise, the function stops once the specified number of interaction cycles has been executed if nb is a number strictly greater than 0. |
IlsFalse
if interrupted by timeout.
|
static |
Enable exception mode.
Each time a transaction is committed by a component (see the member function IlsMvComponent::commitC2STransaction()
), a transaction is executed at the server level (see the class IlsTransaction
).
By default, any instance of IlsException
raised by the Server when this transaction is executed is caught and results in the transaction being rolled back both at server and component levels. The static member function UnsetCatchExceptionMode()
disables exception-catching mode for subsequent transactions, while the SetCatchExceptionMode()
static member function enables the mode again.
|
static |
Activates the trace mode of the server.
Trace mode can also be activated by the ILS_TRACE_TIME environment variable.
|
static |
Enable or disable time-tracing mode.
In this mode, timing information are collected and displayed. The following durations are collected:
IlsMvServer::beginTransaction()
and the call to IlsMvServer::endTransaction()
.ILS_THREADED_SEND
mode is not active. However, if this mode is active, Send traces may be interlaced with Notification traces.See the ILS_TRACE_TIME
environment variable.
|
static |
Breaks any association established between label
and a server object.
As objects are maintained in the association table through smart pointers, this method may delete the object.
label | label for which you want to break the association |
IlsTrue
if an association was found. Otherwise, it returns IlsFalse
.
|
static |
Breaks the association established between the Server object object and a label, if any.
object | the object for which you want to break the association |
IlsTrue
if an association was found. Otherwise, it returns IlsFalse
|
static |
Disable exception mode.
Each time a transaction is committed by a component (see the member function IlsMvComponent::commitC2STransaction()
), a transaction is executed at the server level (see the class IlsTransaction
).
By default, any instance of IlsException
raised by the Server when this transaction is executed is caught and results in the transaction being rolled back both at server and component levels. The static member function UnsetCatchExceptionMode()
disables exception-catching mode for subsequent transactions, while the SetCatchExceptionMode()
static member function enables the mode again.