|
Urbi SDK Remote for C++
2.7.3
|
00001 /* 00002 * Copyright (C) 2009-2011, Gostai S.A.S. 00003 * 00004 * This software is provided "as is" without warranty of any kind, 00005 * either expressed or implied, including but not limited to the 00006 * implied warranties of fitness for a particular purpose. 00007 * 00008 * See the LICENSE file for more information. 00009 */ 00010 00011 #include "umachine.hh" 00012 00013 // Register the UMachine UObject in the Urbi world. 00014 UStart(UMachine); 00015 00016 // Bouncing the name to the UObject constructor is mandatory. 00017 UMachine::UMachine(const std::string& name) 00018 : urbi::UObject(name) 00019 , machine(0) 00020 { 00021 // Register the Urbi constructor. This is the only mandatory 00022 // part of the C++ constructor. 00023 UBindFunction(UMachine, init); 00024 } 00025 00026 int 00027 UMachine::init(ufloat d) 00028 { 00029 // Failure on invalid arguments. 00030 if (d < 0) 00031 return 1; 00032 00033 // Bind the functions, i.e., declare them to the Urbi world. 00034 UBindFunction(UMachine, assemble); 00035 UBindThreadedFunctionRename 00036 (UMachine, assemble, "threadedAssemble", urbi::LOCK_FUNCTION); 00037 // Bind the UVars before using them. 00038 UBindVar(UMachine, duration); 00039 00040 // Set the duration. 00041 duration = d; 00042 // Build the machine. 00043 machine = new Machine(d); 00044 00045 // Request that duration_set be invoked each time duration is 00046 // changed. Declared after the above "duration = d" since we don't 00047 // want it to be triggered for this first assignment. 00048 UNotifyChange(duration, &UMachine::duration_set); 00049 00050 // Success. 00051 return 0; 00052 } 00053 00054 int 00055 UMachine::duration_set(urbi::UVar& v) 00056 { 00057 assert(machine); 00058 ufloat d = static_cast<ufloat>(v); 00059 if (0 <= d) 00060 { 00061 // Valid value. 00062 machine->duration = d; 00063 return 0; 00064 } 00065 else 00066 // Report failure. 00067 return 1; 00068 } 00069 00070 00071 std::string 00072 UMachine::assemble(std::list<std::string> components) 00073 { 00074 assert(machine); 00075 00076 // Bounce to Machine::operator(). 00077 return (*machine)(components); 00078 }