22 #ifndef PROPERTYSET_IMPL_H 23 #define PROPERTYSET_IMPL_H 30 #include <boost/bind.hpp> 32 #include "ossie/debug.h" 33 #include "ossie/PropertyInterface.h" 34 #include "ossie/ProcessThread.h" 35 #include "ossie/Autocomplete.h" 40 #ifdef BEGIN_AUTOCOMPLETE_IGNORE
41 :
public virtual POA_CF::PropertyEmitter
58 throw (CF::PropertyEmitter::AlreadyInitialized, CF::PropertySet::PartialConfiguration,
59 CF::PropertySet::InvalidConfiguration, CORBA::SystemException);
63 configure (
const CF::Properties& configProperties)
64 throw (CF::PropertySet::PartialConfiguration,
65 CF::PropertySet::InvalidConfiguration, CORBA::SystemException);
69 query (CF::Properties& configProperties)
70 throw (CF::UnknownProperties, CORBA::SystemException);
82 throw(CF::UnknownProperties, CF::InvalidObjectReference);
84 throw(CF::InvalidIdentifier);
99 validate (CF::Properties property, CF::Properties& validProps,
100 CF::Properties& invalidProps);
105 template <
typename T>
107 const std::string&
id,
108 const std::string& name,
109 const std::string& mode,
110 const std::string& units,
111 const std::string& action,
112 const std::string& kinds)
114 PropertyInterface* wrapper = PropertyWrapperFactory::Create(value);
115 wrapper->configure(
id, name, mode, units, action, kinds);
116 wrapper->isNil(
true);
119 _propMonitors[wrapper->id] = PropertyChange::MonitorFactory::Create(value);
126 template <
typename T,
typename T2>
128 const T2& initial_value,
129 const std::string&
id,
130 const std::string& name,
131 const std::string& mode,
132 const std::string& units,
133 const std::string& action,
134 const std::string& kinds)
136 PropertyInterface* wrapper =
addProperty(value,
id, name, mode, units, action, kinds);
137 value = initial_value;
138 wrapper->isNil(
false);
142 template <
class C,
typename T>
146 PropertyWrapper<T>* wrapper = getPropertyWrapperById<T>(id);
147 wrapper->addChangeListener(target, func);
148 }
catch (
const std::invalid_argument& error) {
153 template <
typename T>
157 PropertyWrapper<T>* wrapper = getPropertyWrapperById<T>(id);
158 wrapper->addChangeListener(func);
159 }
catch (
const std::invalid_argument& error) {
164 template <
typename Func>
170 template <
typename Target,
typename Func>
179 template <
typename T,
typename Target,
typename Func>
184 }
catch (
const std::invalid_argument& error) {
192 template <
typename T,
typename Func>
197 }
catch (
const std::invalid_argument& error) {
206 template <
typename T,
typename Target,
typename Func>
211 }
catch (
const std::exception& error) {
212 LOG_WARN(
PropertySet_impl,
"Cannot set query implementation: " << error.what());
219 template <
typename T,
typename Func>
224 }
catch (
const std::exception& error) {
225 LOG_WARN(
PropertySet_impl,
"Cannot set query implementation: " << error.what());
233 template <
typename T,
typename Target,
typename Func>
238 }
catch (
const std::exception& error) {
239 LOG_WARN(
PropertySet_impl,
"Cannot set configure implementation: " << error.what());
246 template <
typename T,
typename Func>
251 }
catch (
const std::exception& error) {
252 LOG_WARN(
PropertySet_impl,
"Cannot set configure implementation: " << error.what());
265 cb = boost::bind(func, &target, _1);
266 setPropertyCallback(
id, cb);
273 cb = boost::bind(func, target, _1);
274 setPropertyCallback(
id, cb);
282 throw std::invalid_argument(
"No property '" +
id +
"'");
284 return castProperty<T>(property);
292 throw std::invalid_argument(
"No property associated with value");
294 return castProperty<T>(property);
324 template <
typename T>
325 PropertyWrapper<T>* castProperty(PropertyInterface* property)
327 PropertyWrapper<T>* wrapper =
dynamic_cast<PropertyWrapper<T>*
>(property);
329 std::ostringstream message;
330 message <<
"Property '" <<
property->id <<
"' is of type '" <<
property->getNativeType() <<
"'" 331 <<
" (not '" << ossie::traits<T>::name() <<
"')";
332 throw std::invalid_argument(message.str());
337 typedef boost::function<void (const std::string&)> PropertyCallback;
338 void setPropertyCallback (
const std::string&
id, PropertyCallback callback);
340 typedef std::map<std::string, PropertyCallback> PropertyCallbackMap;
341 PropertyCallbackMap propCallbacks;
346 struct PCL_Callback {
350 PCL_Callback() : isChanged_(false), isRecorded_(false) {};
351 void recordChanged(
void) {
352 if ( !isRecorded_ ) {
357 void reset() { isChanged_ =
false; isRecorded_=
false;};
358 bool isChanged() {
return isChanged_; };
359 bool isSet() {
return isRecorded_; };
363 typedef boost::shared_ptr<PCL_Callback> PCL_CallbackPtr;
366 typedef std::map< std::string, PCL_CallbackPtr > PropertyReportTable;
369 class PropertyChangeListener;
370 class EC_PropertyChangeListener;
371 class INF_PropertyChangeListener;
372 typedef boost::shared_ptr< PropertyChangeListener > PCL_ListenerPtr;
376 struct PropertyChangeRec {
377 static std::string RSC_ID;
380 CORBA::Object_ptr listener;
381 boost::posix_time::time_duration reportInterval;
382 boost::posix_time::ptime expiration;
384 PropertyReportTable props;
389 class PropertyChangeListener {
391 virtual ~PropertyChangeListener() {};
392 virtual int notify( PropertyChangeRec *rec, CF::Properties &changes ) = 0;
398 typedef std::map< std::string, PropertyChangeRec > PropertyChangeRegistry;
402 typedef std::map<std::string, PropertyChange::Monitor *> PropertyMonitorTable;
403 PropertyMonitorTable _propMonitors;
406 PropertyChangeRegistry _propChangeRegistry;
409 ossie::ProcessThread _propChangeThread;
412 int _propertyChangeServiceFunction();
414 bool _propertiesInitialized;
void validate(CF::Properties property, CF::Properties &validProps, CF::Properties &invalidProps)
PropertyInterface * getPropertyFromId(const std::string &)
void(* PropertyCallbackFn)(const std::string &)
Definition: PropertySet_impl.h:304
void addPropertyListener(T &value, Func func)
Definition: PropertySet_impl.h:193
void registerPropertyChangePort(PropertyEventSupplier *_propertyChangePort)
Definition: PropertySet_impl.h:77
void initializeProperties(const CF::Properties &initialProperties)
void startPropertyChangeMonitor(const std::string &rsc_id)
void setPropertyChangeListener(const std::string &id, T &target, void(T::*func)(const std::string &))
Definition: PropertySet_impl.h:262
void addPropertyChangeListener(const char *id, Target target, Func func)
Definition: PropertySet_impl.h:171
void setPropertyChangeListener(const std::string &id, T *target, void(T::*func)(const std::string &))
Definition: PropertySet_impl.h:270
PropertyInterface * getPropertyFromName(const std::string &)
void addPropertyListener(T &value, Target target, Func func)
Definition: PropertySet_impl.h:180
boost::mutex propertySetAccess
Definition: PropertySet_impl.h:313
PropertyInterface * getPropertyFromAddress(const void *address)
void unregisterPropertyListener(const char *reg_id)
friend class PropertyChangeThread
Definition: PropertySet_impl.h:400
void executePropertyCallback(const std::string &id)
PropertyMap propTable
Definition: PropertySet_impl.h:321
PropertyInterface * addProperty(T &value, const T2 &initial_value, const std::string &id, const std::string &name, const std::string &mode, const std::string &units, const std::string &action, const std::string &kinds)
Definition: PropertySet_impl.h:127
PropertyInterface * addProperty(T &value, const std::string &id, const std::string &name, const std::string &mode, const std::string &units, const std::string &action, const std::string &kinds)
Definition: PropertySet_impl.h:106
PropertyWrapper< T > * getPropertyWrapperById(const std::string &id)
Definition: PropertySet_impl.h:278
CF::DataType getProperty(CORBA::String_var id)
void setExecparamProperties(std::map< std::string, char * > &)
void query(CF::Properties &configProperties)
void addPropertyChangeListener(const char *id, Func func)
Definition: PropertySet_impl.h:165
void setPropertyQueryImpl(T &value, Func func)
Definition: PropertySet_impl.h:220
float Float
Definition: bulkio_base.h:155
void setPropertyConfigureImpl(T &value, Func func)
Definition: PropertySet_impl.h:247
void configure(const CF::Properties &configProperties)
Definition: PropertySet_impl.h:39
std::vector< PropertyInterface * > ownedWrappers
Definition: PropertySet_impl.h:317
void addPropertyChangeListener(const std::string &id, C *target, void(C::*func)(const T *, const T *))
Definition: PropertySet_impl.h:143
std::map< std::string, PropertyInterface * > PropertyMap
Definition: PropertySet_impl.h:320
PropertyWrapper< T > * getPropertyWrapper(T &value)
Definition: PropertySet_impl.h:288
void setPropertyConfigureImpl(T &value, Target target, Func func)
Definition: PropertySet_impl.h:234
void setPropertyQueryImpl(T &value, Target target, Func func)
Definition: PropertySet_impl.h:207
PropertyEventSupplier * propertyChangePort
Definition: PropertySet_impl.h:315
void addPropertyChangeListener(const std::string &id, void(*func)(const T *, const T *))
Definition: PropertySet_impl.h:154
char * registerPropertyListener(CORBA::Object_ptr listener, const CF::StringSequence &prop_ids, const CORBA::Float interval)
void stopPropertyChangeMonitor()