00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _PROPERTY_HH_
00025 #define _PROPERTY_HH_
00026
00027 #include <typeinfo>
00028 #include <set>
00029 #include <assert.h>
00030
00031 #include <vos/vos/vos.hh>
00032
00033 namespace VOS {
00034 class PropertyAccessControl;
00035 class PropertyListener;
00036 class PropertyEvent;
00037
00038
00039
00040
00041
00042
00043 class VOS_API Property : public MetaObject
00044 {
00045 private:
00046 Message::Priority priority;
00047
00048 protected:
00049 Property(VobjectBase* superobject);
00050
00051 public:
00052
00053
00054 virtual int getLength() = 0;
00055
00056
00057
00058
00059 virtual void read(std::string& target) = 0;
00060
00061
00062
00063
00064
00065
00066
00067 virtual void read(std::string& target, int start, int length) = 0;
00068
00069
00070
00071
00072 virtual std::string read() = 0;
00073
00074
00075
00076
00077 virtual std::string read(int start, int length) = 0;
00078
00079
00080 virtual void write(int start, const std::string& newdata) = 0;
00081
00082
00083
00084
00085
00086
00087
00088 virtual void replace(const std::string& newdata, const std::string& newtype = "?") = 0;
00089
00090
00091 virtual const std::string getDataType() = 0;
00092
00093
00094
00095
00096
00097
00098 void replace(const char* format, size_t maxlen, ...);
00099 void replace(const char* format, const char* type, size_t maxlen, ...);
00100 void replace(const char* str);
00101 void read(const char* format, ...);
00102 void replace(bool b);
00103 void replace(int i);
00104 void replace(float x);
00105 void replace(float x, float y);
00106 void replace(float x, float y, float z);
00107 void replace(float x, float y, float z, float r);
00108 void replace(double x);
00109 void replace(double x, double y);
00110 void replace(double x, double y, double z);
00111 void replace(double x, double y, double z, double r);
00112 void read(int& i);
00113 void read(bool& i);
00114 void read(double& x);
00115 void read(double& x, double& y);
00116 void read(double& x, double& y, double& z);
00117 void read(double& x, double& y, double& z, double& r);
00118 void read(float& x);
00119 void read(float& x, float& y);
00120 void read(float& x, float& y, float& z);
00121 void read(float& x, float& y, float& z, float& r);
00122 void read(std::vector<float>& vec);
00123 void read(std::vector<int>& vec);
00124 void replace(std::vector<float>& vec);
00125 void replace(std::vector<int>& vec);
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 static VUtil::vRef<ParentChildRelation> setProperty(Vobject& on,
00141 const std::string& propname, const std::string& type,
00142 const char* fmt, size_t maxlen, ...);
00143 static VUtil::vRef<ParentChildRelation> setProperty(Vobject& on,
00144 const std::string& propname, const std::string& type,
00145 const std::string& pac, const char* fmt, size_t maxlen, ...);
00146 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& on,
00147 const std::string& propname, const char* fmt, ...);
00148
00149 static VUtil::vRef<ParentChildRelation> setProperty(Vobject& on,
00150 const std::string& propname,
00151 const std::string& propval,
00152 const std::string& valtype,
00153 const std::string& pac = "",
00154 bool letErrorThrough = false);
00155
00156 static VUtil::vRef<ParentChildRelation> setProperty(Vobject& base,
00157 const std::string& propname,
00158 bool b,
00159 const std::string& pac = "");
00160
00161 static VUtil::vRef<ParentChildRelation> setProperty(Vobject& base,
00162 const std::string& propname,
00163 int i,
00164 const std::string& pac = "");
00165
00166 static VUtil::vRef<ParentChildRelation> setProperty(Vobject& base,
00167 const std::string& propname,
00168 double x,
00169 const std::string& pac = "");
00170
00171 static VUtil::vRef<ParentChildRelation> setProperty(Vobject& base,
00172 const std::string& propname,
00173 double x, double y,
00174 const std::string& pac = "");
00175
00176 static VUtil::vRef<ParentChildRelation> setProperty(Vobject& base,
00177 const std::string& name,
00178 int x, int y,
00179 const std::string& pac = "");
00180
00181 static VUtil::vRef<ParentChildRelation> setProperty(Vobject& base,
00182 const std::string& propname,
00183 double x, double y, double z,
00184 const std::string& pac = "");
00185
00186 static VUtil::vRef<ParentChildRelation> setProperty(Vobject& base,
00187 const std::string& propname,
00188 double x, double y, double z, double r,
00189 const std::string& pac = "");
00190
00191 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00192 const std::string& propname,
00193 std::string& data,
00194 std::string& datatype);
00195
00196 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00197 const std::string& propname,
00198 int& i);
00199
00200 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00201 const std::string& propname,
00202 bool& i);
00203
00204 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00205 const std::string& propname,
00206 double& x);
00207
00208 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00209 const std::string& propname,
00210 double& x, double& y);
00211
00212 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00213 const std::string& propname,
00214 double& x, double& y, double& z);
00215
00216 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00217 const std::string& propname,
00218 double& x, double& y, double& z, double& r);
00219
00220 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00221 const std::string& propname,
00222 float& x);
00223
00224 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00225 const std::string& propname,
00226 float& x, float& y);
00227
00228 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00229 const std::string& name,
00230 int& x, int& y);
00231
00232 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00233 const std::string& propname,
00234 float& x, float& y, float& z);
00235
00236 static VUtil::vRef<ParentChildRelation> getProperty(Vobject& base,
00237 const std::string& propname,
00238 float& x, float& y, float& z, float& r);
00239
00240
00241
00242 virtual void setPriority(Message::Priority p) { priority = p; };
00243 virtual Message::Priority getPriority() { return priority; }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 virtual void addPropertyListener(PropertyListener* pl, bool refresh = true) = 0;
00254
00255
00256
00257
00258
00259 virtual void removePropertyListener(PropertyListener* pl) = 0;
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 void writeToFile(const std::string& filename, int offset = 0, int length = -1);
00272
00273
00274
00275
00276
00277
00278
00279 void readFromFile(const std::string& filename, const std::string& type = "");
00280
00281
00282 virtual const std::string getVOSType() = 0;
00283
00284 virtual void doSaveState(MessageBlock& output, std::set<std::string>& types, bool portable);
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 virtual void cacheProperty(bool b);
00295 };
00296
00297
00298
00299
00300
00301
00302 class VOS_API PropertyAccessControl
00303 {
00304 public:
00305 virtual ~PropertyAccessControl() { }
00306
00307
00308
00309
00310
00311
00312 virtual bool checkReadPermission(PropertyEvent& event, std::string& message) = 0;
00313
00314
00315
00316
00317
00318
00319 virtual bool checkChangePermission(PropertyEvent& event, std::string& message) = 0;
00320
00321
00322 virtual const std::string getPolicyName() = 0;
00323 };
00324
00325 extern VOS_API PolicyDomain<PropertyAccessControl> PropertyAccessControlPolicies;
00326
00327
00328
00329
00330 class VOS_API AcceptAllPropertyAccessControl : public PropertyAccessControl
00331 {
00332 public:
00333 static AcceptAllPropertyAccessControl static_;
00334
00335 virtual ~AcceptAllPropertyAccessControl() { }
00336
00337 virtual const std::string getPolicyName()
00338 { return "property:accept-all"; }
00339
00340 virtual bool checkReadPermission(PropertyEvent& event, std::string& message)
00341 { return true; };
00342 virtual bool checkChangePermission(PropertyEvent& event, std::string& message)
00343 { return true; };
00344 };
00345
00346
00347
00348
00349
00350
00351
00352 class VOS_API ReadOnlyPropertyAccessControl : public PropertyAccessControl
00353 {
00354 public:
00355 static ReadOnlyPropertyAccessControl static_;
00356
00357 virtual ~ReadOnlyPropertyAccessControl() { }
00358
00359 virtual const std::string getPolicyName()
00360 { return "property:read-only"; }
00361
00362 virtual bool checkReadPermission(PropertyEvent& event, std::string& message)
00363 { return true; };
00364 virtual bool checkChangePermission(PropertyEvent& event, std::string& message)
00365 { message = "This property is read-only."; return false; };
00366 };
00367
00368
00369
00370
00371
00372
00373 class VOS_API DenyAllPropertyAccessControl : public PropertyAccessControl
00374 {
00375 public:
00376 static DenyAllPropertyAccessControl static_;
00377
00378 virtual ~DenyAllPropertyAccessControl() { }
00379
00380 virtual const std::string getPolicyName()
00381 { return "property:deny-all"; }
00382
00383 virtual bool checkReadPermission(PropertyEvent& event, std::string& message)
00384 { return false; };
00385 virtual bool checkChangePermission(PropertyEvent& event, std::string& message)
00386 { return false; };
00387 };
00388
00389 }
00390
00391 #ifndef VOS_EXPORTS
00392 IMPORT_METAOBJECT_FACTORIES(DefaultPropertyACs)
00393 IMPORT_METAOBJECT_FACTORIES(BasicLocalProperty)
00394 IMPORT_METAOBJECT_FACTORIES(RemoteProperty)
00395 #endif
00396
00397
00398 #endif