1
#include "artsbuilder.h"
2
#include "weakreference.h"
3
#include "sequenceutils.h"
4
#include "moduleinfo.h"
5
#include "compatibility.h"
12
typedef WeakReference<PortDesc> PortDesc_wref;
13
typedef WeakReference<ModuleDesc> ModuleDesc_wref;
14
typedef WeakReference<StructureDesc> StructureDesc_wref;
16
class PortDesc_impl :virtual public Arts::PortDesc_skel {
20
vector<PortDesc_wref> _connections;
21
ModuleDesc_wref _parent;
27
list<long> oldConnections;
29
void removeNullConnections();
34
inline PortDesc self() { return PortDesc::_from_base(_copy()); }
35
void constructor(ModuleDesc parent, const string& name, const PortType& type);
44
void hasValue(bool newvalue);
45
vector<PortDesc> *connections();
47
void floatValue( float _new_value );
50
void stringValue( const string& _new_value );
53
void value( const Any& _new_value );
55
bool connectTo( PortDesc port );
56
void internalConnectInput( PortDesc port );
57
void disconnectFrom( PortDesc port );
59
void loadFromList(const vector<string>& list);
60
vector<string> *saveToList();
62
void internalReConnect( const vector<PortDesc>& allports );
66
class ModuleDesc_impl : virtual public ModuleDesc_skel {
69
StructureDesc_wref _parent;
72
vector<PortDesc> _ports;
73
long collectPorts( const Arts::ModuleInfo& info );
75
bool _isInterface, _isStructure;
77
inline ModuleDesc self() { return ModuleDesc::_from_base(_copy()); }
81
StructureDesc parent();
83
vector<PortDesc> *ports();
88
bool moveTo( long x, long y );
89
void constructor( StructureDesc parent, const ModuleInfo& info );
91
void loadFromList(const vector<string>& list);
92
vector<string> *saveToList();
98
Arts::PortDesc findPort(const string& name);
101
class StructureDesc_impl : virtual public Arts::StructureDesc_skel {
104
vector<ModuleDesc> _modules;
105
vector<StructurePortDesc> _ports; /* only structure ports which are part of the interface */
107
ModuleInfo _externalInterface;
109
inline StructureDesc self() { return StructureDesc::_from_base(_copy()); }
112
void name(const string& newName);
114
vector<string> *saveToList();
115
void loadFromList(const vector<string>& list);
116
vector<ModuleDesc> *modules();
117
vector<StructurePortDesc> *ports();
125
ModuleDesc createModuleDesc( const ModuleInfo& info );
126
ModuleDesc createModuleDesc( const string& name );
127
void freeModuleDesc(ModuleDesc moduledesc);
129
// external interface
130
StructurePortDesc createStructurePortDesc(const PortType& type, const string& name);
131
void freeStructurePortDesc(StructurePortDesc portdesc);
132
void moveStructurePortDesc(StructurePortDesc portdesc, long newposition);
134
ModuleInfo externalInterface();
136
StructureDesc_impl();
137
~StructureDesc_impl();
140
class StructurePortDesc_impl :
141
virtual public PortDesc_impl,
142
virtual public StructurePortDesc_skel
145
StructureDesc_wref _parentStructure;
146
long _x, _y, _position;
148
inline StructurePortDesc self() {
149
return StructurePortDesc::_from_base(_copy());
152
void constructor(StructureDesc parent, const string& name,
153
const PortType& type);
154
~StructurePortDesc_impl();
159
void lowerPosition();
160
void raisePosition();
161
void rename(const string& newname);
163
void internalSetPosition(long position);
164
StructureDesc parentStructure();
165
bool moveTo( long X, long Y );
167
void loadFromList(const vector<string>& list);
168
vector<string> *saveToList();
171
REGISTER_IMPLEMENTATION(PortDesc_impl);
172
REGISTER_IMPLEMENTATION(ModuleDesc_impl);
173
REGISTER_IMPLEMENTATION(StructureDesc_impl);
174
REGISTER_IMPLEMENTATION(StructurePortDesc_impl);
177
#include "structures.h"
178
#include "sequenceutils.h"
184
#define dname(dir) ((dir)==Arts::input?"input":"output")
186
printf("port name %s, direction %s, id %d\n",_Name.c_str(),dname(_Type.direction),_ID);
188
void PortDesc_impl::constructor(ModuleDesc parent, const string& name,
189
const PortType& type)
194
char * pname = parent->Name();
195
describe("PortDesc."+string(pname)+string(".")+name);
199
describe("PortDesc.Structure."+name);
205
_isConnected = false;
207
_value.type = _type.dataType;
211
StructureDesc sd = parent.parent();
214
// else: assume that some smart object which derives from us will set the ID accordingly
215
// -> for instance StructurePortDesc_impl does so
219
void PortDesc_impl::cleanUp()
227
* This is new and related to weak references, it purges all null references from _connections
229
void PortDesc_impl::removeNullConnections()
231
vector<PortDesc_wref>::iterator i = _connections.begin();
233
while(i != _connections.end())
238
_connections.erase(i);
239
i = _connections.begin();
240
printf("removeNullConnections() removed something (shouldn't happen)\n");
245
_isConnected = !_connections.empty();
248
void PortDesc_impl::disconnectAll()
250
// disconnect all connected ports
251
while(!_connections.empty())
253
PortDesc pd = _connections.front();
255
if(pd.isNull()) // weak references can automatically disappear
256
_connections.erase(_connections.begin());
258
pd.disconnectFrom(self());
262
PortDesc_impl::~PortDesc_impl()
266
// Implementation for interface PortDesc
267
long PortDesc_impl::ID()
272
ModuleDesc PortDesc_impl::parent()
277
string PortDesc_impl::name()
282
PortType PortDesc_impl::type()
287
bool PortDesc_impl::isConnected()
289
if(_isConnected) removeNullConnections();
293
bool PortDesc_impl::hasValue()
298
void PortDesc_impl::hasValue(bool newvalue)
300
if(_hasValue != newvalue)
302
assert(newvalue == false);
303
_hasValue = newvalue;
307
vector<PortDesc> *PortDesc_impl::connections()
309
vector<PortDesc_wref>::iterator i;
310
vector<PortDesc> *result = new vector<PortDesc>;
312
for(i = _connections.begin(); i != _connections.end(); i++)
315
if(!pd.isNull()) result->push_back(pd);
320
float PortDesc_impl::floatValue()
323
assert(_type.dataType == "float");
326
b.write(_value.value);
327
return b.readFloat();
330
void PortDesc_impl::floatValue( float _new_value )
332
assert(!_isConnected);
333
assert(_type.direction == Arts::input);
334
assert(_type.dataType == "float");
335
assert(_value.type == "float");
338
b.writeFloat(_new_value);
339
b.read(_value.value, b.size());
343
string PortDesc_impl::stringValue()
346
assert(_type.dataType == "string");
347
assert(_value.type == "string");
351
b.write(_value.value);
352
b.readString(result);
356
void PortDesc_impl::stringValue( const string& _new_value )
358
assert(!_isConnected); // shouldn't happen, but check anyway
359
assert(_type.direction == Arts::input);
360
assert(_type.dataType == "string");
363
b.writeString(_new_value);
364
b.read(_value.value, b.size());
368
Any PortDesc_impl::value()
374
void PortDesc_impl::value( const Any& _new_value )
380
bool PortDesc_impl::connectTo( PortDesc port )
382
removeNullConnections();
384
// check if we are already connected to that port:
387
for(i=0;i<_connections.size();i++)
389
PortDesc pd = _connections[i];
390
if(pd.ID() == port.ID()) return true;
393
const PortType& rType = port.type();
395
// only stream or event channels may be connected
396
if( _type.connType != rType.connType )
399
// TODO: eventually check conditions when it is legal to connect property
400
// ports, and when it is insane (_Type.connType == Arts::property)
402
// for incoming structure ports, for instance, it is perfectly allright
404
// only same data type connections allowed
405
if( _type.dataType != rType.dataType )
408
// only opposite directions
409
if( _type.direction == rType.direction )
412
// always first connect the input port to the output port and
413
// then the other direction
415
if( _type.direction == Arts::input )
417
if(!_isConnected || _type.isMultiPort)
419
assert(_connections.empty() || _type.isMultiPort);
420
_connections.push_back(port);
422
port.internalConnectInput(self());
429
if( _type.direction == Arts::output )
430
return port.connectTo(self());
435
void PortDesc_impl::internalConnectInput( PortDesc port )
437
_connections.push_back(port);
441
void PortDesc_impl::disconnectFrom( PortDesc port )
443
removeNullConnections();
445
unsigned long found = 0;
447
artsdebug("port %ld disconnecting from port %ld\n",ID(),port.ID());
449
vector<PortDesc_wref>::iterator i = _connections.begin();
450
while(!found && i != _connections.end())
452
Arts::PortDesc other = *i;
453
if(!other.isNull() && other.ID() == port.ID())
455
_connections.erase(i);
456
i = _connections.begin();
462
_isConnected = !_connections.empty();
464
ModuleDesc parent = _parent;
466
artsdebug("_Parent = <some structure>, isConnected = %d\n",_isConnected);
468
artsdebug("_Parent = %s, isConnected = %d\n",parent.name().c_str(),_isConnected);
471
port.disconnectFrom(self());
474
// Implementation for interface ModuleDesc
475
long ModuleDesc_impl::ID()
480
StructureDesc ModuleDesc_impl::parent()
485
string ModuleDesc_impl::name()
490
vector<PortDesc> *ModuleDesc_impl::ports()
492
return new vector<PortDesc>(_ports);
495
long ModuleDesc_impl::x()
500
long ModuleDesc_impl::y()
505
long ModuleDesc_impl::width()
511
long ModuleDesc_impl::height()
518
bool ModuleDesc_impl::moveTo( long x, long y )
520
// FIXME: collision checking!
528
// Implementation for interface StructureDesc
529
long StructureDesc_impl::width()
535
long StructureDesc_impl::height()
542
* Query the module for it's paramenters
545
void ModuleDesc_impl::constructor( StructureDesc parent,
546
const Arts::ModuleInfo& info )
549
_x = -1; // no position assigned
551
_ID = parent.obtainID();
553
_isInterface = info.isInterface;
554
_isStructure = info.isStructure;
559
ModuleDesc_impl::~ModuleDesc_impl()
563
bool ModuleDesc_impl::isInterface()
568
bool ModuleDesc_impl::isStructure()
574
PortDesc ModuleDesc_impl::findPort(const string& name)
576
vector<PortDesc>::iterator p;
578
for(p = _ports.begin(); p != _ports.end(); p++)
580
if(name == p->name()) return *p;
583
return PortDesc::null();
586
long ModuleDesc_impl::collectPorts( const Arts::ModuleInfo& info )
588
vector<PortType>::const_iterator i;
589
vector<string>::const_iterator ni = info.portnames.begin();
592
for(i=info.ports.begin(); i != info.ports.end(); i++)
594
const PortType& porttype = *i;
595
const string& portname = *ni++;
597
artsdebug("#%d: %s\n",portcount,portname.c_str());
599
PortDesc pd(self(),portname,porttype);
600
_ports.push_back(pd);
606
ModuleDesc StructureDesc_impl::createModuleDesc( const ModuleInfo& info )
608
Arts::ModuleDesc result = createModuleDesc(info.name);
610
assert(!result.isNull());
614
ModuleDesc StructureDesc_impl::createModuleDesc( const string& name )
616
/* FIXME: need new comment
617
* to create a representation of a specified synth module, we
619
* - create an instance of this synth module by contacting the
620
* module server and telling him to do so (result is a C++ class)
622
* - create an instance of a ModuleDesc, and tell it to query the
623
* module for it's parameters (result is a CORBA object)
625
* - destroy the synth module (C++ class) again and return a reference
626
* to the CORBA object
629
ModuleServer<SynthModule> *MS_SynthModule;
630
MS_SynthModule = (ModuleServer<SynthModule> *)SynthModule::get_MS();
632
SynthModule *m = (SynthModule *)MS_SynthModule->getModule(name);
635
Arts::ModuleInfo_var info = ModuleBroker->lookupModule(name);
638
const Arts::ModuleInfo& info = makeModuleInfo(name);
639
Arts::ModuleDesc moduledesc = ModuleDesc(self(),info);
640
_modules.push_back(moduledesc);
644
void StructureDesc_impl::freeModuleDesc(ModuleDesc moduledesc)
646
vector<ModuleDesc>::iterator i;
648
for(i=_modules.begin();i != _modules.end(); i++)
650
Arts::ModuleDesc current = *i;
652
if(current.ID() == moduledesc.ID())
654
_modules.erase(i); // will get freed automagically
660
vector<ModuleDesc> *StructureDesc_impl::modules()
662
vector<ModuleDesc> *retval = new vector<ModuleDesc>(_modules);
666
StructureDesc_impl::StructureDesc_impl()
668
arts_debug("PORT: created structuredesc_impl");
671
_externalInterface.name = "unknown"; // FIXME
672
_externalInterface.isStructure = true;
673
_externalInterface.isInterface = false;
676
StructureDesc_impl::~StructureDesc_impl()
678
artsdebug("StructureDesc released...\n");
681
long StructureDesc_impl::obtainID()
686
bool StructureDesc_impl::valid()
691
void StructureDesc_impl::clear()
700
vector<string> *PortDesc_impl::saveToList()
702
vector<string> *list = new vector<string>;
704
sqprintf(list,"id=%ld",_ID);
707
if(_type.dataType == "string")
709
sqprintf(list,"string_data=%s",stringValue().c_str());
711
else if(_type.dataType == "float")
713
sqprintf(list,"audio_data=%2.5f",floatValue());
719
sqprintf(list,"any_data=%s",b.toString("value").c_str());
725
vector<PortDesc_wref>::iterator i;
727
for(i=_connections.begin();i != _connections.end(); i++)
729
Arts::PortDesc port = *i;
730
if(!port.isNull()) sqprintf(list,"connect_to=%ld",port.ID());
736
vector<string> *ModuleDesc_impl::saveToList()
738
vector<string> *list = new vector<string>;
739
vector<PortDesc>::iterator i;
741
sqprintf(list,"id=%ld",_ID);
742
sqprintf(list,"x=%ld",_x);
743
sqprintf(list,"y=%ld",_y);
744
for(i=_ports.begin();i != _ports.end();i++)
747
sqprintf(list,"port=%s",pd.name().c_str());
749
vector<string> *portlist = pd.saveToList();
750
addSubStringSeq(list,portlist);
756
vector<string> *StructureDesc_impl::saveToList()
758
vector<string> *list = new vector<string>;
759
vector<ModuleDesc>::iterator mi;
760
vector<StructurePortDesc>::iterator pi;
762
sqprintf(list,"name=%s",_externalInterface.name.c_str());
763
for(mi=_modules.begin();mi != _modules.end();mi++)
766
sqprintf(list,"module=%s",md.name().c_str());
768
vector<string> *modulelist = md.saveToList();
769
addSubStringSeq(list,modulelist);
772
for(pi=_ports.begin(); pi!=_ports.end(); pi++)
774
Arts::StructurePortDesc spd = *pi;
775
sqprintf(list,"structureport");
777
vector<string> *portlist= spd.saveToList();
778
addSubStringSeq(list,portlist);
784
void PortDesc_impl::internalReConnect( const vector<PortDesc>& allports )
786
vector<PortDesc>::const_iterator i;
788
for(i=allports.begin(); i != allports.end(); i++)
791
long oid = pd.internalOldID();
793
if(find(oldConnections.begin(),oldConnections.end(),oid)
794
!= oldConnections.end())
801
long PortDesc_impl::internalOldID()
806
void PortDesc_impl::loadFromList(const vector<string>& list)
810
for(i=0;i<list.size();i++)
812
if(parse_line(list[i],cmd,param)) // otherwise: empty or comment
814
if(cmd == "audio_data") {
815
floatValue(atof(param.c_str()));
816
} else if(cmd == "string_data") {
818
} else if(cmd == "any_data") {
820
if(b.fromString(param,"value"))
824
if(!b.readError() && !b.remaining())
827
} else if(cmd == "id") {
828
_oldID = atol(param.c_str());
829
} else if(cmd == "connect_to") {
830
oldConnections.push_back(atol(param.c_str()));
836
void ModuleDesc_impl::loadFromList(const vector<string>& list)
838
artsdebug("mlist-----------\n");
841
for(i=0;i<list.size();i++)
843
if(parse_line(list[i],cmd,param)) // otherwise: empty or comment
845
artsdebug("MD: load-> cmd was %s\n",cmd.c_str());
849
OldFormatTranslator::newPortName(_name,param);
850
PortDesc pd = PortDesc::null();
851
vector<PortDesc>::iterator pi;
853
for(pi=_ports.begin(); pi != _ports.end(); pi++)
855
artsdebug("pdi = %s, portName = %s\n",pi->name().c_str(),
857
if(pi->name() == portName) pd = *pi;
859
assert(!pd.isNull());
861
vector<string> *plist = getSubStringSeq(&list,i);
862
pd.loadFromList(*plist);
864
} else if(cmd == "x") {
865
_x = atol(param.c_str());
866
artsdebug("X set to %ld (param was %s)\n",_x,param.c_str());
867
} else if(cmd == "y") {
868
_y = atol(param.c_str());
869
artsdebug("Y set to %ld (param was %s)\n",_y,param.c_str());
873
artsdebug("-----------mlist\n");
876
void StructureDesc_impl::loadFromList(const vector<string>& list)
880
vector<PortDesc> allports;
883
_externalInterface.name = (const char *)"unknown";
885
artsdebug("loadFromList; listlen = %ld\n",list.size());
886
for(i=0;i<list.size();i++)
888
if(parse_line(list[i],cmd,param)) // otherwise: empty or comment
890
artsdebug("SD: load-> cmd was %s\n",cmd.c_str());
893
string newName = OldFormatTranslator::newModuleName(param);
894
ModuleDesc md = createModuleDesc(newName);
896
vector<string> *mlist = getSubStringSeq(&list,i);
900
md.loadFromList(*mlist);
902
// PORT: order changed
903
vector<PortDesc> *pd = md.ports();
904
vector<PortDesc>::iterator pi;
905
for(pi = pd->begin(); pi != pd->end();pi++)
906
allports.push_back(*pi);
912
// module couldn't be found
917
else if(cmd == "name")
919
_externalInterface.name = param;
921
else if(cmd == "structureport")
923
// just to have valid values to pass to the new (to be loaded)
926
type.direction = Arts::input;
927
type.dataType = "float";
928
type.connType = Arts::conn_stream;
930
StructurePortDesc spd =
931
createStructurePortDesc(type,"unknown");
933
vector<string> *splist = getSubStringSeq(&list,i);
934
spd.loadFromList(*splist);
937
// yes; this is a port as well
938
allports.push_back(spd);
943
for(i=0;i<allports.size();i++)
944
allports[i].internalReConnect(allports);
947
void StructureDesc_impl::name(const string& name)
949
_externalInterface.name = name;
952
string StructureDesc_impl::name()
954
return _externalInterface.name;
957
long extint_pscore(StructurePortDesc p)
959
long result = p.position(); //p->X()*1000+p->Y();
960
if(p.type().direction == Arts::input) result += 5000000;
965
bool extint_port_compare(StructurePortDesc p1, StructurePortDesc p2)
967
long p1s = extint_pscore(p1);
968
long p2s = extint_pscore(p2);
970
artsdebug("compare; [%s] = %d ; [%s] = %d\n", p1.name().c_str(),p1s,
971
p2.name().c_str(),p2s);
974
//if(p1s == p2s) return 0;
978
ModuleInfo StructureDesc_impl::externalInterface()
980
ModuleInfo result = _externalInterface;
981
vector<StructurePortDesc> sorted_ports = _ports;
982
vector<StructurePortDesc>::iterator p;
985
for(l=0;l<_Ports->length();l++) sorted_ports.push_back((*_Ports)[l]);
987
sort(sorted_ports.begin(),sorted_ports.end(),extint_port_compare);
990
for(p=sorted_ports.begin();p != sorted_ports.end();p++)
992
string pname = p->name();
993
PortType ptype = p->type();
995
if(ptype.direction == Arts::input)
996
ptype.direction = Arts::output;
998
ptype.direction = Arts::input;
1000
artsdebug("externalInterface; sorted ports: %d => %s\n",l,pname.c_str());
1001
result.ports.push_back(ptype);
1002
result.portnames.push_back(pname);
1008
vector<StructurePortDesc> *StructureDesc_impl::ports()
1010
return new vector<StructurePortDesc>(_ports);
1013
StructurePortDesc StructureDesc_impl::createStructurePortDesc(
1014
const Arts::PortType& type, const string& name)
1016
artsdebug("creating new port %s\n",name.c_str());
1017
StructurePortDesc port(self(), name, type);
1018
_ports.push_back(port);
1020
// set the Position (put it at the end of the ports)
1021
unsigned long i, count = 0;
1022
for(i=0;i<_ports.size();i++)
1024
if(_ports[i].type().direction == type.direction) count++;
1026
assert(count > 0); // we just inserted one ;)
1027
port.internalSetPosition(count-1);
1031
void StructureDesc_impl::freeStructurePortDesc(StructurePortDesc portdesc)
1033
vector<StructurePortDesc>::iterator i;
1035
for(i=_ports.begin(); i != _ports.end(); i++)
1037
if(i->ID() == portdesc.ID())
1045
void StructureDesc_impl::moveStructurePortDesc(StructurePortDesc
1046
portdesc, long newposition)
1048
const Arts::PortType& type = portdesc.type();
1052
for(i=0;i<_ports.size();i++)
1054
if(_ports[i].type().direction == type.direction) count++;
1057
if(newposition < 0) newposition = 0;
1058
if(newposition > count-1) newposition = count-1;
1060
if(newposition == portdesc.position()) return;
1062
int delta, lower, upper;
1064
if(newposition > portdesc.position())
1066
// if the port gets a higher position, move all ports that
1067
// are between it's current position and its new position down one
1068
lower = portdesc.position();
1069
upper = newposition;
1074
// if the port gets a lower position, move all ports that
1075
// are between it's current position and its new position up one
1076
lower = newposition;
1077
upper = portdesc.position();
1081
for(i=0;i<_ports.size();i++)
1083
StructurePortDesc pd = _ports[i];
1085
if(pd.type().direction == type.direction)
1087
if(pd.ID() != portdesc.ID() &&
1088
pd.position() >= lower && pd.position() <= upper)
1090
pd.internalSetPosition(pd.position()+delta);
1095
portdesc.internalSetPosition(newposition);
1098
void StructurePortDesc_impl::constructor(StructureDesc parent,
1099
const string& name, const PortType& type)
1101
PortDesc_impl::constructor(ModuleDesc::null(),name,type);
1102
_parentStructure = parent;
1103
_ID = parent.obtainID();
1109
StructurePortDesc_impl::~StructurePortDesc_impl()
1111
// this destructor is required to make some compilers (egcs-1.1.2) compile
1114
long StructurePortDesc_impl::x()
1119
long StructurePortDesc_impl::y()
1124
long StructurePortDesc_impl::position()
1129
void StructurePortDesc_impl::lowerPosition()
1131
StructureDesc parent = _parentStructure; // weak reference
1133
if(!parent.isNull())
1134
parent.moveStructurePortDesc(self(), _position-1);
1137
void StructurePortDesc_impl::raisePosition()
1139
StructureDesc parent = _parentStructure; // weak reference
1141
if(!parent.isNull())
1142
parent.moveStructurePortDesc(self(), _position+1);
1145
void StructurePortDesc_impl::rename(const string& newname)
1150
// only used by the structure to reorder the ports
1151
void StructurePortDesc_impl::internalSetPosition(long position)
1153
_position = position;
1156
StructureDesc StructurePortDesc_impl::parentStructure()
1158
return _parentStructure;
1161
bool StructurePortDesc_impl::moveTo( long X, long Y )
1163
// FIXME: check space
1171
override load & save behaviour this kind of port requires that we save the type
1172
of the port as well, that means all of the porttype:
1174
enum PortDirection {input, output};
1175
enum PortDataType {audio_data, string_data};
1176
enum PortConnType {stream, event, property};
1178
PortDirection direction;
1179
PortDataType dataType;
1180
PortConnType connType;
1183
so when saved, it will look like that:
1191
direction=input/output
1192
datatype=audio/string
1193
conntype=stream/event/property
1197
[original port saves here]
1202
PortType loadTypeFromList(const vector<string>& list)
1204
unsigned long i,loadstate = 0;
1206
Arts::PortType result;
1208
for(i=0;i<list.size();i++)
1210
if(parse_line(list[i],cmd,param)) // otherwise: empty or comment
1212
artsdebug("PortType: load-> cmd was %s\n",cmd.c_str());
1213
if(cmd == "direction")
1215
if(param == "input") {
1216
result.direction = Arts::input;
1218
else if(param == "output") {
1219
result.direction = Arts::output;
1224
} else if(cmd == "datatype") {
1225
if(param == "audio") {
1226
result.dataType = "float";
1228
else if(param == "string") {
1229
result.dataType = "string";
1234
} else if(cmd == "conntype") {
1235
if(param == "stream") {
1236
result.connType = Arts::conn_stream;
1238
else if(param == "event") {
1239
result.connType = Arts::conn_event;
1241
else if(param == "property") {
1242
result.connType = Arts::conn_property;
1243
artsdebug("got property stuff\n");
1251
assert(loadstate == 10101); // should see every member exactly once
1255
void StructurePortDesc_impl::loadFromList(const vector<string>& list)
1257
artsdebug("structureportlist-----------\n");
1260
vector<string> *typelist = 0, *datalist = 0;
1261
bool haveType = false, haveData = false;
1262
// need both to do restore, type first
1264
for(i=0;i<list.size();i++)
1266
if(parse_line(list[i],cmd,param)) // otherwise: empty or comment
1268
artsdebug("StructurePortDesc: load-> cmd was %s\n",cmd.c_str());
1271
assert(!haveType); // only allowed once
1273
typelist = getSubStringSeq(&list,i);
1274
} else if(cmd == "data") {
1275
assert(!haveData); // only allowed once
1277
datalist = getSubStringSeq(&list,i);
1278
} else if(cmd == "x") {
1279
_x = atol(param.c_str());
1280
artsdebug("X set to %ld (param was %s)\n",_x,param.c_str());
1281
} else if(cmd == "y") {
1282
_y = atol(param.c_str());
1283
artsdebug("Y set to %ld (param was %s)\n",_y,param.c_str());
1284
} else if(cmd == "position") {
1285
_position = atol(param.c_str());
1286
artsdebug("Position set to %ld (param was %s)\n",_position,
1288
} else if(cmd == "name") {
1290
artsdebug("Name set to %s\n",_name.c_str());
1294
assert(haveType && haveData);
1296
_type = loadTypeFromList(*typelist);
1298
if(_type.connType == Arts::conn_property) artsdebug("have property here\n");
1299
PortDesc_impl::loadFromList(*datalist);
1303
artsdebug("-----------structureportlist\n");
1306
vector<string> *saveTypeToList(const PortType& type)
1308
vector<string> *list = new vector<string>;
1310
switch(type.direction)
1312
case Arts::input: sqprintf(list,"direction=input");
1314
case Arts::output: sqprintf(list,"direction=output");
1316
default: assert(false); // should never happen!
1318
if(type.dataType == "float")
1320
sqprintf(list,"datatype=audio");
1322
else if(type.dataType == "string")
1324
sqprintf(list,"datatype=string");
1328
assert(false); // should never happen!
1330
switch(type.connType)
1332
case Arts::conn_stream: sqprintf(list,"conntype=stream");
1334
case Arts::conn_event: sqprintf(list,"conntype=event");
1336
case Arts::conn_property: sqprintf(list,"conntype=property");
1338
default: assert(false); // should never happen!
1344
vector<string> *StructurePortDesc_impl::saveToList()
1346
vector<string> *list = new vector<string>;
1347
sqprintf(list,"name=%s",_name.c_str());
1348
sqprintf(list,"x=%ld",_x);
1349
sqprintf(list,"y=%ld",_y);
1350
sqprintf(list,"position=%ld",_position);
1351
sqprintf(list,"type");
1353
vector<string> *typelist = saveTypeToList(_type);
1354
addSubStringSeq(list,typelist);
1357
sqprintf(list,"data");
1359
vector<string> *portlist = PortDesc_impl::saveToList();
1360
addSubStringSeq(list,portlist);