/home/tetron/hack/vos/apps/tutorials/vostut4.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <vos/vos/vos.hh>
00018
00019 using namespace VUtil;
00020 using namespace VOS;
00021
00022 #ifdef WIN32
00023 #define sleep _sleep
00024 #endif
00025
00026 void listChildren(Vobject* vobject);
00027 void listParents(Vobject* vobject);
00028
00029
00030
00031
00032 int main(int argc, char** argv)
00033 {
00034 std::cout << "VOS Tutorial 4\n\n";
00035
00036 Site localsite;
00037 localsite.addSiteExtension(new LocalVipSiteExtension());
00038 localsite.setDefaultPolicy("core:accept-all");
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 vRef<Vobject> sphere = localsite.createVobjectA("sphere");
00057 vRef<Vobject> tertius = localsite.createVobjectA("tertius");
00058 vRef<Vobject> quartus = localsite.createVobjectA("quartus");
00059 vRef<Vobject> quintus = localsite.createVobjectA("quintus");
00060 vRef<Vobject> sextus = localsite.createVobjectA("sextus");
00061 vRef<Vobject> septimus = localsite.createVobjectA("septimus");
00062
00063
00064 sphere->setDefaultPolicy("core:accept-all");
00065 tertius->setDefaultPolicy("core:accept-all");
00066 quartus->setDefaultPolicy("core:accept-all");
00067 quintus->setDefaultPolicy("core:accept-all");
00068 sextus->setDefaultPolicy("core:accept-all");
00069 septimus->setDefaultPolicy("core:accept-all");
00070
00071 listChildren(&localsite);
00072 std::cout << "\n";
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 std::cout << "Appending tertius as \"position\"\n";
00088 sphere->insertChild(-1, "position", tertius);
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 listChildren(sphere);
00101 listParents(tertius);
00102 std::cout << "\n";
00103
00104
00105
00106
00107
00108
00109
00110 std::cout << "Appending quartus as \"orientation\"\n";
00111 sphere->insertChild(-1, "orientation", quartus);
00112
00113 std::cout << "Appending quintus as \"radius\"\n";
00114 sphere->insertChild(-1, "radius", quintus);
00115
00116 std::cout << "Appending quartus as \"position\"\n";
00117 sphere->insertChild(-1, "position", quartus);
00118
00119 listChildren(sphere);
00120 listParents(quartus);
00121 std::cout << "\n";
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 std::cout << "Inserting sextus as \"color\" into position 2\n";
00132 sphere->insertChild(2, "color", sextus);
00133
00134 listChildren(sphere);
00135 std::cout << "\n";
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 std::cout << "Replacing quartus in position 4 with septimus as \"mass\"\n";
00147 sphere->setChild(4, "mass", septimus);
00148
00149 listChildren(sphere);
00150 std::cout << "\n";
00151
00152
00153
00154
00155
00156
00157
00158 std::cout << "Removing quintus (\"orientation\") from position 1\n";
00159 sphere->removeChild(sphere->findChild(1));
00160
00161 listChildren(sphere);
00162 std::cout << "\n";
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 std::cout << "Removing septimus (\"mass\") from the last position\n";
00174 sphere->removeChild(sphere->findChild(-1));
00175
00176 listChildren(sphere);
00177 std::cout << "\n";
00178
00179 try {
00180
00181
00182
00183
00184
00185
00186 vRef<Vobject> primus = Vobject::findObjectFromRoot("vip://localhost:4231/primus");
00187
00188 std::cout << "Adding local vobject septimus to remote vobject primus\n";
00189 primus->insertChild(-1, "septimus", septimus);
00190
00191 listChildren(primus);
00192 listParents(septimus);
00193 std::cout << "\n";
00194
00195
00196 std::cout << "Adding remote vobject primus to local vobject quartus\n";
00197 quartus->insertChild(-1, "primus", primus);
00198
00199 listChildren(quartus);
00200 listParents(primus);
00201 std::cout << "\n";
00202 } catch(std::runtime_error& e) {
00203 std::cerr << "An exception occured: " << e.what() << "\n";
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 vRef<ParentChildRelation> pcr = sphere->findChild("color");
00220 std::cout << "Results of findChild():\n";
00221 std::cout << " Parent: " << pcr->getParent()->getURLstr() << "\n";
00222 std::cout << " Position: " << pcr->getPosition() << "\n";
00223 std::cout << " Contextual name: " << pcr->getContextualName() << "\n";
00224 std::cout << " Child: " << pcr->getChild()->getURLstr() << "\n";
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 vRef<Vobject> color = localsite.findObject("sphere/color");
00236
00237 listParents(color);
00238
00239
00240
00241
00242
00243 vRef<ParentChildRelation> pcr2 = color->findParent(sphere);
00244 std::cout << "Results of findParent():\n";
00245 std::cout << " Parent: " << pcr2->getParent()->getURLstr() << "\n";
00246 std::cout << " Position: " << pcr2->getPosition() << "\n";
00247 std::cout << " Contextual name: " << pcr2->getContextualName() << "\n";
00248 std::cout << " Child: " << pcr2->getChild()->getURLstr() << "\n";
00249
00250
00251 std::cout << "Going into runloop now. Try connecting to " << localsite.getURLstr() << " using \"mesh\"\n";
00252 std::cout << "to inspect the current vobject structure.\n";
00253
00254 while(true) sleep(1000);
00255 }
00256
00257 void listChildren(Vobject* vobject)
00258 {
00259 std::cout << "Children of " << vobject->getURL().getString() << ":\n";
00260
00261 for(ChildListIterator childlist = vobject->getChildren();
00262 childlist.hasMore();
00263 childlist++)
00264 {
00265 vRef<ParentChildRelation> pcr = *childlist;
00266 std::cout << " #" << pcr->getPosition() << " " << pcr->getContextualName() << " -> "
00267 << pcr->getChild()->getURLstr() << "\n";
00268 }
00269 }
00270
00271 void listParents(Vobject* vobject)
00272 {
00273 std::cout << "Parents of " << vobject->getURLstr() << ":\n";
00274
00275 for(ParentSetIterator parentset = vobject->getParents();
00276 parentset.hasMore();
00277 parentset++)
00278 {
00279 vRef<ParentChildRelation> pcr = *parentset;
00280 std::cout << " " << pcr->getParent()->getURLstr() << " linked as #"
00281 << pcr->getPosition() << " " << pcr->getContextualName() << "\n";
00282 }
00283 }