cisst-saw
Loading...
Searching...
No Matches
mtsMulticastCommandWrite.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5 Author(s): Ankur Kapoor, Peter Kazanzides, Anton Deguet
6 Created on: 2004-04-30
7
8 (C) Copyright 2004-2014 Johns Hopkins University (JHU), All Rights
9 Reserved.
10
11--- begin cisst license - do not edit ---
12
13This software is provided "as is" under an open source license, with
14no warranty. The complete license can be found in license.txt and
15http://www.cisst.org/cisst/license.txt.
16
17--- end cisst license ---
18*/
19
20
25
26
27#ifndef _mtsMulticastCommandWrite_h
28#define _mtsMulticastCommandWrite_h
29
30
33#include <vector>
34
35// Always include last
37
44template <class _argumentType>
46{
47public:
49 typedef _argumentType ArgumentType; // does not need to derive from mtsGenericObject
50 typedef typename mtsGenericTypes<ArgumentType>::FinalBaseType ArgumentFinalType; // derived from mtsGenericObject
51
52public:
54 mtsMulticastCommandWrite(const std::string & name, const ArgumentType & argumentPrototype):
55 BaseType(name)
56 {
57 //this->ArgumentPrototype = new ArgumentType(argumentPrototype);
59 }
60
63 if (this->ArgumentPrototype) {
64 delete this->ArgumentPrototype;
65 }
66 }
67
70 mtsBlockingType CMN_UNUSED(blocking)) {
71 // cast argument first
72 const ArgumentFinalType * data = dynamic_cast< const ArgumentFinalType * >(&argument);
73 if (data == 0) {
75 }
76 // if cast succeeded call using actual type
77 size_t index;
78 const size_t commandsSize = Commands.size();
79 for (index = 0; index < commandsSize; index++) {
80 Commands[index]->Execute(*data, MTS_NOT_BLOCKING);
81 }
83 }
84
86 mtsCommandWriteBase * CMN_UNUSED(finishedEventHandler)) {
87 return Execute(argument, blocking);
88 }
89};
90
91
92
94{
95public:
97
98public:
100 mtsMulticastCommandWriteGeneric(const std::string & name,
101 const mtsGenericObject & argumentPrototype):
102 BaseType(name)
103 {
104 this->ArgumentPrototype = dynamic_cast<mtsGenericObject*>(argumentPrototype.Services()->Create(argumentPrototype));
105 }
106
109 if (this->ArgumentPrototype) {
110 delete this->ArgumentPrototype;
111 }
112 }
113
116 mtsBlockingType CMN_UNUSED(blocking)) {
117 // cast argument first
118
119 if (typeid(argument) != typeid(*(this->ArgumentPrototype))) {
121 }
122 // if cast succeeded call using actual type
123 size_t index;
124 const size_t commandsSize = Commands.size();
125 for (index = 0; index < commandsSize; index++) {
126 Commands[index]->Execute(argument, MTS_NOT_BLOCKING);
127 }
129 }
130
132 mtsCommandWriteBase * CMN_UNUSED(finishedEventHandler)) {
133 return Execute(argument, blocking);
134 }
135
136};
137
138
139#endif // _mtsMulticastCommandWrite_h
140
virtual const cmnClassServicesBase * Services(void) const =0
mtsCommandWriteBase(void)
Definition mtsCommandWriteBase.h:49
const mtsGenericObject * ArgumentPrototype
Definition mtsCommandWriteBase.h:109
Definition mtsExecutionResult.h:34
@ INVALID_INPUT_TYPE
Definition mtsExecutionResult.h:44
@ COMMAND_SUCCEEDED
Definition mtsExecutionResult.h:44
Base class for data object in cisstMultiTask.
Definition mtsGenericObject.h:52
static mtsGenericObject * ConditionalCreate(const T &arg, const std::string &name)
Definition mtsGenericObjectProxy.h:691
mtsGenericTypesImpl< T, cmnIsDerivedFrom< T, mtsGenericObject >::IS_DERIVED >::FinalBaseType FinalBaseType
Definition mtsGenericObjectProxy.h:685
mtsMulticastCommandWriteBase(const std::string &name)
Definition mtsMulticastCommandWriteBase.h:54
VectorType Commands
Definition mtsMulticastCommandWriteBase.h:50
mtsMulticastCommandWriteGeneric(const std::string &name, const mtsGenericObject &argumentPrototype)
Definition mtsMulticastCommandWrite.h:100
~mtsMulticastCommandWriteGeneric()
Definition mtsMulticastCommandWrite.h:108
mtsExecutionResult Execute(const mtsGenericObject &argument, mtsBlockingType blocking, mtsCommandWriteBase *CMN_UNUSED(finishedEventHandler))
Definition mtsMulticastCommandWrite.h:131
mtsMulticastCommandWriteBase BaseType
Definition mtsMulticastCommandWrite.h:96
virtual mtsExecutionResult Execute(const mtsGenericObject &argument, mtsBlockingType CMN_UNUSED(blocking))
Definition mtsMulticastCommandWrite.h:115
_argumentType ArgumentType
Definition mtsMulticastCommandWrite.h:49
mtsGenericTypes< ArgumentType >::FinalBaseType ArgumentFinalType
Definition mtsMulticastCommandWrite.h:50
virtual mtsExecutionResult Execute(const mtsGenericObject &argument, mtsBlockingType CMN_UNUSED(blocking))
Definition mtsMulticastCommandWrite.h:69
mtsMulticastCommandWriteBase BaseType
Definition mtsMulticastCommandWrite.h:48
mtsExecutionResult Execute(const mtsGenericObject &argument, mtsBlockingType blocking, mtsCommandWriteBase *CMN_UNUSED(finishedEventHandler))
Definition mtsMulticastCommandWrite.h:85
~mtsMulticastCommandWrite()
Definition mtsMulticastCommandWrite.h:62
mtsMulticastCommandWrite(const std::string &name, const ArgumentType &argumentPrototype)
Definition mtsMulticastCommandWrite.h:54
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
Rules of exporting.
mtsBlockingType
Definition mtsForwardDeclarations.h:54
@ MTS_NOT_BLOCKING
Definition mtsForwardDeclarations.h:54
Defines a command with one argument sent to multiple interfaces.