~ubuntu-branches/ubuntu/raring/openwalnut/raring

« back to all changes in this revision

Viewing changes to src/core/kernel/combiner/WModuleProjectFileCombiner.cpp

  • Committer: Package Import Robot
  • Author(s): Sebastian Eichelbaum
  • Date: 2012-12-12 11:26:32 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20121212112632-xhiuwkxuz5h0idkh
Tags: 1.3.1+hg5849-1
* Minor changes compared to 1.3.0 but included several bug fixes.
* See http://www.openwalnut.org/versions/4

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <utility>
31
31
 
32
32
#include <boost/regex.hpp>
33
 
#include <boost/lexical_cast.hpp>
34
33
 
35
34
#include "../WKernel.h"
36
35
#include "../WModuleCombiner.h"
43
42
#include "../exceptions/WModuleConnectorNotFound.h"
44
43
 
45
44
#include "../../common/exceptions/WFileNotFound.h"
 
45
#include "../../common/WStringUtils.h"
46
46
#include "../../common/WProperties.h"
47
47
#include "../../common/WPropertyBase.h"
48
48
#include "../../common/WPropertyVariable.h"
73
73
{
74
74
    // this is the proper regular expression for modules
75
75
    static const boost::regex modRe( "^ *MODULE:([0-9]*):(.*)$" );
76
 
    static const boost::regex dataRe( "^ *DATA:([0-9]*):(.*)$" );
 
76
    static const boost::regex dataRe( "^ *DATA:([0-9]*):\"?([^\"]*)\"?$" );
77
77
    static const boost::regex conRe( "^ *CONNECTION:\\(([0-9]*),(.*)\\)->\\(([0-9]*),(.*)\\)$" );
78
78
    static const boost::regex propRe( "^ *PROPERTY:\\(([0-9]*),(.*)\\)=(.*)$" );
79
79
 
92
92
        // data modules are not allowed here
93
93
        if( !proto )
94
94
        {
95
 
            wlog::error( "Project Loader" ) << "There is no prototype available for module \"" << matches[2] << "\". Skipping.";
 
95
            addError( "There is no prototype available for module \"" + matches[2] + "\". Skipping." );
96
96
        }
97
97
        else if( proto->getType() == MODULE_DATA )
98
98
        {
99
 
            wlog::error( "Project Loader" ) << "Data modules are not allowed to be specified in a \"MODULE\" Statement." <<
100
 
                                               " Use the \"DATA\" statement instead. Skipping.";
 
99
            addError( "Data modules are not allowed to be specified in a \"MODULE\" Statement. Use the \"DATA\" statement instead. Skipping." );
101
100
        }
102
101
        else
103
102
        {
104
103
            boost::shared_ptr< WModule > module = WModuleFactory::getModuleFactory()->create( proto );
105
 
            m_modules.insert( ModuleID( boost::lexical_cast< unsigned int >( matches[1] ), module ) );
 
104
            m_modules.insert( ModuleID( string_utils::fromString< unsigned int >( matches[1] ), module ) );
106
105
        }
107
106
    }
108
107
    else if( boost::regex_match( line, matches, dataRe ) )
116
115
        boost::shared_ptr< WModule > proto = WModuleFactory::getModuleFactory()-> isPrototypeAvailable( "Data Module" );
117
116
        if( !proto )
118
117
        {
119
 
            wlog::error( "Project Loader" ) << "There is no prototype available for module \"" << "Data Module" << "\"."
120
 
                                            << " This should not happen!. Skipping.";
 
118
            addError( "There is no prototype available for module \"Data Module\". This should not happen!. Skipping." );
121
119
        }
122
120
        else
123
121
        {
125
123
            boost::shared_ptr< WModule > module = WModuleFactory::getModuleFactory()->create( proto );
126
124
            if( parameter.empty() )
127
125
            {
128
 
                wlog::error( "Project Loader" ) << "Data modules need an additional filename parameter. Skipping.";
 
126
                addError( "Data modules need an additional filename parameter. Skipping." );
129
127
            }
130
128
            else
131
129
            {
132
130
                boost::shared_static_cast< WDataModule >( module )->setFilename( parameter );
133
 
                m_modules.insert( ModuleID( boost::lexical_cast< unsigned int >( matches[1] ), module ) );
 
131
                m_modules.insert( ModuleID( string_utils::fromString< unsigned int >( matches[1] ), module ) );
134
132
            }
135
133
        }
136
134
    }
144
142
                                                 << matches[1] << " and \"" << matches[4] << "\" of module " << matches[3] << ".";
145
143
 
146
144
        // now we search in modules[ matches[1] ] for an output connector named matches[2]
147
 
        m_connections.push_back( Connection( Connector( boost::lexical_cast< unsigned int >( matches[1] ), matches[2] ),
148
 
                                           Connector( boost::lexical_cast< unsigned int >( matches[3] ), matches[4] ) ) );
 
145
        m_connections.push_back( Connection( Connector( string_utils::fromString< unsigned int >( matches[1] ), matches[2] ),
 
146
                                           Connector( string_utils::fromString< unsigned int >( matches[3] ), matches[4] ) ) );
149
147
    }
150
148
    else if( boost::regex_match( line, matches, propRe ) )
151
149
    {
157
155
        wlog::debug( "Project Loader [Parser]" ) << "Line " << lineNumber << ": Property \"" << matches[2] << "\" of module " << matches[1]
158
156
                                                 << " set to " << matches[3];
159
157
 
160
 
        m_properties.push_back( PropertyValue( Property( boost::lexical_cast< unsigned int >( matches[1] ), matches[2] ), matches[3] ) );
 
158
        m_properties.push_back( PropertyValue( Property( string_utils::fromString< unsigned int >( matches[1] ), matches[2] ), matches[3] ) );
161
159
    }
162
160
    else
163
161
    {
184
182
        // if isReady now is false, the module has crashed before it got ready -> remove the module from the list
185
183
        if( ( *iter ).second->isCrashed()() )
186
184
        {
187
 
            wlog::warn( "Project Loader" ) << "In the module with ID "
188
 
                                           << ( *iter ).first
189
 
                                           << " a problem occurred. Connections and properties relating to this"
190
 
                                           << " module will fail.";
 
185
            addError( "In the module with ID " + ( *iter ).first +
 
186
                      std::string( " a problem occurred. Connections and properties relating to this module will fail." ) );
191
187
            m_modules.erase( iter );
192
188
        }
193
189
    }
198
194
        // grab corresponding module
199
195
        if( !m_modules.count( ( *iter ).first.first ) )
200
196
        {
201
 
            wlog::error( "Project Loader" ) << "There is no module with ID \"" << ( *iter ).first.first <<  "\" to set the property \"" <<
202
 
                                               ( *iter ).first.second << "\" for. Skipping.";
 
197
            addError( "There is no module with ID \"" + string_utils::toString( ( *iter ).first.first ) + "\" to set the property \"" +
 
198
                                                        ( *iter ).first.second + std::string( "\" for. Skipping." ) );
203
199
            continue;
204
200
        }
205
201
        boost::shared_ptr< WModule > m = m_modules[ ( *iter ).first.first ];
208
204
        boost::shared_ptr< WPropertyBase > prop = m->getProperties()->findProperty( ( *iter ).first.second );
209
205
        if( !prop )
210
206
        {
211
 
            wlog::error( "Project Loader" ) << "The module \"" << m->getName() << "\" has no property named \"" <<
212
 
                         ( *iter ).first.second << "\". Skipping.";
 
207
            addError( "The module \"" + m->getName() + std::string( "\" has no property named \"" ) + ( *iter ).first.second +
 
208
                      std::string( "\". Skipping." ) );
213
209
            continue;
214
210
        }
215
211
        else
220
216
                bool result = prop->setAsString( ( *iter ).second );
221
217
                if( !result )
222
218
                {
223
 
                    wlog::error( "Project Loader" ) << "Failed to set property " << ( *iter ).first.second << " in module \"" <<
224
 
                                                       m->getName() << "\".";
 
219
                    addError( "Failed to set property " + ( *iter ).first.second + " in module \"" + m->getName() + "\"." );
225
220
                }
226
221
            }
227
222
            else
228
223
            {
229
 
                wlog::error( "Project Loader" ) << "The module \"" << m->getName() << "\" has a property named \"" <<
230
 
                         ( *iter ).first.second << "\" which is an INFORMATION property. Skipping.";
 
224
                addError( "The module \"" + m->getName() + "\" has a property named \"" +
 
225
                         ( *iter ).first.second + "\" which is an INFORMATION property. Skipping." );
231
226
            }
232
227
        }
233
228
    }
244
239
        boost::shared_ptr< WModule > m1;
245
240
        if( !m_modules.count( c1.first ) )
246
241
        {
247
 
            wlog::error( "Project Loader" ) << "There is no module with ID \"" << c1.first <<  "\" for the connection "
248
 
                                            << "(" << c1.first << "," << c1.second << ")->(" << c2.first << "," << c2.second << "). Skipping.";
249
 
 
 
242
            addError( "There is no module with ID \"" + string_utils::toString( c1.first ) + "\" for the connection "
 
243
                      + "(" + string_utils::toString( c1.first ) + "," + c1.second + ")->(" +  string_utils::toString( c2.first ) + "," +
 
244
                      c2.second + "). Skipping." );
250
245
            continue;
251
246
        }
252
247
        m1 = m_modules[ c1.first ];
254
249
        boost::shared_ptr< WModule > m2;
255
250
        if( !m_modules.count( c2.first ) )
256
251
        {
257
 
            wlog::error( "Project Loader" ) << "There is no module with ID \"" << c2.first <<  "\" for the connection "
258
 
                                            << "(" << c1.first << "," << c1.second << ")->(" << c2.first << "," << c2.second << "). Skipping.";
 
252
            addError( "There is no module with ID \"" + string_utils::toString( c2.first ) +  "\" for the connection "
 
253
                      + "(" + string_utils::toString( c1.first ) + "," + c1.second + ")->(" + string_utils::toString( c2.first ) +
 
254
                      "," + c2.second + "). Skipping." );
259
255
 
260
256
            continue;
261
257
        }
271
267
        }
272
268
        catch( const WModuleConnectorNotFound& e )
273
269
        {
274
 
            wlog::error( "Project Loader" ) << "There is no output connector \"" << c1.second << "\" in module \"" << m1->getName() << "\"";
 
270
            addError( "There is no output connector \"" + c1.second + "\" in module \"" + m1->getName() + "\"" );
275
271
            continue;
276
272
        }
277
273
        boost::shared_ptr< WModuleInputConnector > con2;
281
277
        }
282
278
        catch( const WModuleConnectorNotFound& e )
283
279
        {
284
 
            wlog::error( "Project Loader" ) << "There is no input connector \"" << c2.second << "\" in module \"" << m2->getName() << "\"";
 
280
            addError( "There is no input connector \"" + c2.second + "\" in module \"" + m2->getName() + "\"" );
285
281
            continue;
286
282
        }
287
283
 
292
288
        }
293
289
        catch( const WException& e )
294
290
        {
295
 
            wlog::error( "Project Loader" ) << "Connection " << "(" << c1.first << "," << c1.second << ")->(" << c2.first << "," << c2.second <<
296
 
                                                ") could not be created. Incompatible connectors?. Skipping.";
 
291
            addError( "Connection (" + string_utils::toString( c1.first ) + "," + c1.second + ")->(" +
 
292
                      string_utils::toString( c2.first ) + "," + c2.second +
 
293
                      ") could not be created. Incompatible connectors?. Skipping." );
297
294
            continue;
298
295
        }
299
296
    }
369
366
        // handle data modules separately
370
367
        if( ( *iter )->getType() == MODULE_DATA )
371
368
        {
372
 
            output << "DATA:" << i << ":" <<  boost::shared_static_cast< WDataModule >( ( *iter ) )->getFilename() << std::endl;
 
369
            output << "DATA:" << i << ":" <<  boost::shared_static_cast< WDataModule >( ( *iter ) )->getFilename().string() << std::endl;
373
370
        }
374
371
        else
375
372
        {
399
396
        for( WModule::OutputConnectorList::const_iterator citer = outs.begin(); citer != outs.end(); ++citer )
400
397
        {
401
398
            // iterate over all connections:
402
 
            // TODO(ebaum): iterating over a protected member variable? Thats ugly. This should be adopted to WSharedObject
403
399
            boost::unique_lock<boost::shared_mutex> lock( ( *citer )->m_connectionListLock );
404
400
            for( std::set<boost::shared_ptr<WModuleConnector> >::const_iterator iciter = ( *citer )->m_connected.begin();
405
401
                  iciter != ( *citer )->m_connected.end(); ++iciter )