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 const char *locations[]=
285 "./"MODULE_LIST_FILENAME, //1
286 "../etc/"MODULE_LIST_FILENAME, //1
287 "~/.sinfg/"MODULE_LIST_FILENAME, //2
288 "/usr/local/lib/sinfg/modules/"MODULE_LIST_FILENAME, //3
289 "/usr/local/etc/"MODULE_LIST_FILENAME,
291 SYSCONFDIR"/"MODULE_LIST_FILENAME,
294 "/Library/Frameworks/sinfg.framework/Resources/"MODULE_LIST_FILENAME,
295 "/Library/SINFG/"MODULE_LIST_FILENAME,
296 "~/Library/SINFG/"MODULE_LIST_FILENAME,
299 "C:\\Program Files\\SINFG\\etc\\"MODULE_LIST_FILENAME,
302 String module_path=prefix+"/etc/"+MODULE_LIST_FILENAME;
303 locations[3]=module_path.c_str();
305 for(i=0;i<(signed)(sizeof(locations)/sizeof(char*));i++)
306 if(retrieve_modules_to_load(locations[i],modules_to_load))
307 if(cb)cb->task(strprintf(_("Loading modules from %s"),locations[i]));
309 std::list<String>::iterator iter;
311 for(i=0,iter=modules_to_load.begin();iter!=modules_to_load.end();++iter,i++)
313 Module::Register(*iter,cb);
314 if(cb)cb->amount_complete((i+1)*100,modules_to_load.size()*100);
322 if(cb)cb->amount_complete(100, 100);
323 if(cb)cb->task(_("DONE"));
329 if(!sinfg_ref_count_.unique())
331 sinfg_ref_count_.detach();
333 // Add deinitialization after this point
335 if(get_open_canvas_map().size())
337 sinfg::warning("Canvases still open!");
338 std::map<sinfg::String, etl::loose_handle<Canvas> >::iterator iter;
339 for(iter=get_open_canvas_map().begin();iter!=get_open_canvas_map().end();++iter)
341 sinfg::warning("%s: count()=%d",iter->first.c_str(), iter->second.count());
345 ValueNode::subsys_stop();
346 Importer::subsys_stop();
347 Target::subsys_stop();
348 Layer::subsys_stop();
350 /*! \fixme For some reason, uncommenting the next
351 ** line will cause things to crash. This needs to be
352 ** looked into at some point. */
353 //Module::subsys_stop();
355 #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
356 signal(SIGPIPE, SIG_DFL);
369 sinfg::error(const char *format,...)
372 va_start(args,format);
373 error(vstrprintf(format,args));
377 sinfg::error(const String &str)
379 static Mutex mutex; Mutex::Lock lock(mutex);
380 cerr<<"sinfg("<<getpid()<<"): "<<_("error")<<": "+str<<endl;
384 sinfg::warning(const char *format,...)
387 va_start(args,format);
388 warning(vstrprintf(format,args));
392 sinfg::warning(const String &str)
394 static Mutex mutex; Mutex::Lock lock(mutex);
395 cerr<<"sinfg("<<getpid()<<"): "<<_("warning")<<": "+str<<endl;
399 sinfg::info(const char *format,...)
402 va_start(args,format);
403 info(vstrprintf(format,args));
407 sinfg::info(const String &str)
409 static Mutex mutex; Mutex::Lock lock(mutex);
410 cerr<<"sinfg("<<getpid()<<"): "<<_("info")<<": "+str<<endl;