1 /* === S I N F G =========================================================== */
5 ** $Id: main.cpp,v 1.3 2005/01/10 07:40:26 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
24 //#define SINFG_NO_ANGLE
41 #include <ETL/stringf>
42 #include "listimporter.h"
47 #include "valuenode.h"
50 #include "loadcanvas.h"
68 using namespace sinfg;
70 /* === M A C R O S ========================================================= */
72 #define MODULE_LIST_FILENAME "sinfg_modules.cfg"
74 /* === S T A T I C S ======================================================= */
76 static etl::reference_counter sinfg_ref_count_(0);
78 /* === P R O C E D U R E S ================================================= */
80 /* === M E T H O D S ======================================================= */
100 sinfg::get_build_date()
106 sinfg::get_build_time()
111 extern const char *get_build_time();
114 sinfg::check_version_(int version,int vec_size, int color_size,int canvas_size,int layer_size)
120 if(version!=SINFG_LIBRARY_VERSION)
122 sinfg::error(_("API Version mismatch (LIB:%d, PROG:%d)"),SINFG_LIBRARY_VERSION,version);
125 if(vec_size!=sizeof(Vector))
127 sinfg::error(_("Size of Vector mismatch (app:%d, lib:%d)"),vec_size,sizeof(Vector));
130 if(color_size!=sizeof(Color))
132 sinfg::error(_("Size of Color mismatch (app:%d, lib:%d)"),color_size,sizeof(Color));
135 if(canvas_size!=sizeof(Canvas))
137 sinfg::error(_("Size of Canvas mismatch (app:%d, lib:%d)"),canvas_size,sizeof(Canvas));
140 if(layer_size!=sizeof(Layer))
142 sinfg::error(_("Size of Layer mismatch (app:%d, lib:%d)"),layer_size,sizeof(Layer));
149 static void broken_pipe_signal (int sig) {
150 sinfg::warning("Broken Pipe...");
153 bool retrieve_modules_to_load(String filename,std::list<String> &modules_to_load)
155 if(filename=="standard")
159 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_bmp")==modules_to_load.end())
160 modules_to_load.push_back("trgt_bmp");
161 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_gif")==modules_to_load.end())
162 modules_to_load.push_back("trgt_gif");
163 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_dv")==modules_to_load.end())
164 modules_to_load.push_back("trgt_dv");
165 if(find(modules_to_load.begin(),modules_to_load.end(),"mod_ffmpeg")==modules_to_load.end())
166 modules_to_load.push_back("mod_ffmpeg");
167 if(find(modules_to_load.begin(),modules_to_load.end(),"mod_imagemagick")==modules_to_load.end())
168 modules_to_load.push_back("mod_imagemagick");
169 if(find(modules_to_load.begin(),modules_to_load.end(),"lyr_std")==modules_to_load.end())
170 modules_to_load.push_back("lyr_std");
171 if(find(modules_to_load.begin(),modules_to_load.end(),"lyr_freetype")==modules_to_load.end())
172 modules_to_load.push_back("lyr_freetype");
174 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_png")==modules_to_load.end())
175 modules_to_load.push_back("trgt_png");
178 if(find(modules_to_load.begin(),modules_to_load.end(),"mod_openexr")==modules_to_load.end())
179 modules_to_load.push_back("mod_openexr");
185 std::ifstream file(filename.c_str());
188 // warning("Cannot open "+filename);
194 getline(file,modulename);
195 if(!modulename.empty() && find(modules_to_load.begin(),modules_to_load.end(),modulename)==modules_to_load.end())
196 modules_to_load.push_back(modulename);
209 sinfg::Main::Main(const sinfg::String& basepath,ProgressCallback *cb):
210 ref_count_(sinfg_ref_count_)
212 if(ref_count_.count())
215 sinfg_ref_count_.reset();
216 ref_count_=sinfg_ref_count_;
218 // Add initialization after this point
223 String prefix=basepath+"/..";
226 std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
229 #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
230 signal(SIGPIPE, broken_pipe_signal);
233 //_config_search_path=new vector"string.h"();
235 // Init the subsystems
236 if(cb)cb->amount_complete(0, 100);
237 if(cb)cb->task(_("Starting Subsystem \"Modules\""));
238 if(!Module::subsys_init(prefix))
239 throw std::runtime_error(_("Unable to initialize subsystem \"Module\""));
241 if(cb)cb->task(_("Starting Subsystem \"Layers\""));
242 if(!Layer::subsys_init())
244 Module::subsys_stop();
245 throw std::runtime_error(_("Unable to initialize subsystem \"Layers\""));
248 if(cb)cb->task(_("Starting Subsystem \"Targets\""));
249 if(!Target::subsys_init())
251 Layer::subsys_stop();
252 Module::subsys_stop();
253 throw std::runtime_error(_("Unable to initialize subsystem \"Targets\""));
256 if(cb)cb->task(_("Starting Subsystem \"Importers\""));
257 if(!Importer::subsys_init())
259 Target::subsys_stop();
260 Layer::subsys_stop();
261 Module::subsys_stop();
262 throw std::runtime_error(_("Unable to initialize subsystem \"Importers\""));
265 if(cb)cb->task(_("Starting Subsystem \"ValueNodes\""));
266 if(!ValueNode::subsys_init())
268 Importer::subsys_stop();
269 Target::subsys_stop();
270 Layer::subsys_stop();
271 Module::subsys_stop();
272 throw std::runtime_error(_("Unable to initialize subsystem \"ValueNodes\""));
275 // Load up the list importer
276 Importer::book()[String("lst")]=ListImporter::create;
280 // Load up the modules
281 std::list<String> modules_to_load;
282 std::vector<String> locations;
284 if(!getenv("SYNFIG_MODULE_LIST"))
286 locations.push_back("standard");
287 locations.push_back("./"MODULE_LIST_FILENAME); //1
288 locations.push_back("../etc/"MODULE_LIST_FILENAME); //1
289 locations.push_back("~/.sinfg/"MODULE_LIST_FILENAME); //2
290 locations.push_back(prefix+"/etc/"+MODULE_LIST_FILENAME); //3
291 locations.push_back("/usr/local/etc/"MODULE_LIST_FILENAME);
293 locations.push_back(SYSCONFDIR"/"MODULE_LIST_FILENAME);
296 locations.push_back("/Library/Frameworks/synfig.framework/Resources/"MODULE_LIST_FILENAME);
297 locations.push_back("/Library/Synfig/"MODULE_LIST_FILENAME);
298 locations.push_back("~/Library/Synfig/"MODULE_LIST_FILENAME);
301 locations.push_back("C:\\Program Files\\Synfig\\etc\\"MODULE_LIST_FILENAME);
306 locations.push_back(getenv("SYNFIG_MODULE_LIST"));
309 const char *locations[]=
312 "./"MODULE_LIST_FILENAME, //1
313 "../etc/"MODULE_LIST_FILENAME, //1
314 "~/.sinfg/"MODULE_LIST_FILENAME, //2
315 "/usr/local/lib/sinfg/modules/"MODULE_LIST_FILENAME, //3
316 "/usr/local/etc/"MODULE_LIST_FILENAME,
318 SYSCONFDIR"/"MODULE_LIST_FILENAME,
321 "/Library/Frameworks/sinfg.framework/Resources/"MODULE_LIST_FILENAME,
322 "/Library/SINFG/"MODULE_LIST_FILENAME,
323 "~/Library/SINFG/"MODULE_LIST_FILENAME,
326 "C:\\Program Files\\SINFG\\etc\\"MODULE_LIST_FILENAME,
331 for(i=0;i<locations.size();i++)
332 if(retrieve_modules_to_load(locations[i],modules_to_load))
333 if(cb)cb->task(strprintf(_("Loading modules from %s"),locations[i].c_str()));
335 std::list<String>::iterator iter;
337 for(i=0,iter=modules_to_load.begin();iter!=modules_to_load.end();++iter,i++)
339 Module::Register(*iter,cb);
340 if(cb)cb->amount_complete((i+1)*100,modules_to_load.size()*100);
348 if(cb)cb->amount_complete(100, 100);
349 if(cb)cb->task(_("DONE"));
355 if(!sinfg_ref_count_.unique())
357 sinfg_ref_count_.detach();
359 // Add deinitialization after this point
361 if(get_open_canvas_map().size())
363 sinfg::warning("Canvases still open!");
364 std::map<sinfg::String, etl::loose_handle<Canvas> >::iterator iter;
365 for(iter=get_open_canvas_map().begin();iter!=get_open_canvas_map().end();++iter)
367 sinfg::warning("%s: count()=%d",iter->first.c_str(), iter->second.count());
371 ValueNode::subsys_stop();
372 Importer::subsys_stop();
373 Target::subsys_stop();
374 Layer::subsys_stop();
376 /*! \fixme For some reason, uncommenting the next
377 ** line will cause things to crash. This needs to be
378 ** looked into at some point. */
379 //Module::subsys_stop();
381 #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
382 signal(SIGPIPE, SIG_DFL);
395 sinfg::error(const char *format,...)
398 va_start(args,format);
399 error(vstrprintf(format,args));
403 sinfg::error(const String &str)
405 static Mutex mutex; Mutex::Lock lock(mutex);
406 cerr<<"sinfg("<<getpid()<<"): "<<_("error")<<": "+str<<endl;
410 sinfg::warning(const char *format,...)
413 va_start(args,format);
414 warning(vstrprintf(format,args));
418 sinfg::warning(const String &str)
420 static Mutex mutex; Mutex::Lock lock(mutex);
421 cerr<<"sinfg("<<getpid()<<"): "<<_("warning")<<": "+str<<endl;
425 sinfg::info(const char *format,...)
428 va_start(args,format);
429 info(vstrprintf(format,args));
433 sinfg::info(const String &str)
435 static Mutex mutex; Mutex::Lock lock(mutex);
436 cerr<<"sinfg("<<getpid()<<"): "<<_("info")<<": "+str<<endl;