Commit c96effe6 authored by Jim Nelson's avatar Jim Nelson

Created Library unit which represents Shotwell in library mode. This and the...

Created Library unit which represents Shotwell in library mode.  This and the Direct unit greatly simplifies unit initialization, as initializing the respective unit will initialize all their dependencies automatically.
parent 8783510f
......@@ -320,7 +320,7 @@ UNIT_MKS := $(foreach unit,$(UNITS),src/$(unit)/mk/$(notdir $(unit)).mk)
include $(UNIT_MKS)
UNITIZE_DIR := src/.unitize
UNITIZE_ENTRIES := $(foreach group,$(APP_GROUPS),$(UNITIZE_DIR)/_$(group)_unitize_entry.vala)
UNITIZE_ENTRIES := $(foreach unit,$(APP_UNITS),$(UNITIZE_DIR)/_$(unit)_unitize_entry.vala)
UNITIZE_INITS := $(foreach nm,$(UNIT_NAMESPACES),$(UNITIZE_DIR)/_$(nm)Internals.vala)
UNITIZE_STAMP := $(UNITIZE_DIR)/.unitized
......@@ -561,8 +561,8 @@ $(PC_FILE): $(PC_INPUT) $(MAKE_FILES)
$(UNITIZE_STAMP): $(MAKE_FILES) src/unit/rc/UnitInternals.m4 src/unit/rc/unitize_entry.m4
@mkdir -p $(UNITIZE_DIR)
@$(foreach group,$(APP_GROUPS),\
`m4 '--define=_APP_GROUP_=$(group)' '--define=_UNIT_ENTRY_POINTS_=$(foreach nm,$($(group)_UNITS),$(nm).init_entry,)' '--define=_UNIT_TERMINATE_POINTS_=$(foreach nm,$($(group)_UNITS),$(nm).terminate_entry,)' src/unit/rc/unitize_entry.m4 > $(UNITIZE_DIR)/_$(group)_unitize_entry.vala`)
@$(foreach unit,$(APP_UNITS),\
`m4 '--define=_APP_UNIT_=$(unit)' src/unit/rc/unitize_entry.m4 > $(UNITIZE_DIR)/_$(unit)_unitize_entry.vala`)
@$(foreach nm,$(UNIT_NAMESPACES),\
`m4 '--define=_UNIT_NAME_=$(nm)' '--define=_UNIT_USES_INITS_=$($(nm)_USES_INITS)' '--define=_UNIT_USES_TERMINATORS_=$($(nm)_USES_TERMINATORS)' src/unit/rc/UnitInternals.m4 > $(UNITIZE_DIR)/_$(nm)Internals.vala`)
@touch $@
......
......@@ -305,6 +305,12 @@ public class Video : VideoSource, Flaggable, Monitorable {
}
public static void init(ProgressMonitor? monitor = null) {
// initialize GStreamer, but don't pass it our actual command line arguments -- we don't
// want our end users to be able to parameterize the GStreamer configuration
string[] fake_args = new string[0];
unowned string[] fake_unowned_args = fake_args;
Gst.init(ref fake_unowned_args);
global = new VideoSourceCollection();
Gee.ArrayList<VideoRow?> all = VideoTable.get_instance().get_all();
......
......@@ -11,20 +11,21 @@ UNIT_DIR := direct
#
# NOTE: Do *not* include the unit's master file, i.e. UNIT_NAME.vala.
UNIT_FILES := \
DirectWindow.vala \
DirectPhoto.vala \
DirectPhotoPage.vala \
DirectView.vala
DirectWindow.vala \
DirectPhoto.vala \
DirectPhotoPage.vala \
DirectView.vala
# Any unit this unit relies upon (and should be initialized before it's initialized) should
# be listed here using its Vala namespace.
#
# NOTE: All units are assumed to rely upon the unit-unit. Do not include that here.
UNIT_USES := \
Db \
Util \
Photos \
Slideshow
Db \
Util \
Photos \
Slideshow \
Core
# List any additional files that are used in the build process as a part of this unit that should
# be packaged in the tarball. File names should be relative to the unit's home directory.
......
/* Copyright 2011 Yorba Foundation
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
*/
namespace Library {
public void init() throws Error {
}
public void terminate() {
}
}
# UNIT_NAME is the Vala namespace. A file named UNIT_NAME.vala must be in this directory with
# a init() and terminate() function declared in the namespace.
UNIT_NAME := Library
# UNIT_DIR should match the subdirectory the files are located in. Generally UNIT_NAME in all
# lowercase. The name of this file should be UNIT_DIR.mk.
UNIT_DIR := library
# All Vala files in the unit should be listed here with no subdirectory prefix.
#
# NOTE: Do *not* include the unit's master file, i.e. UNIT_NAME.vala.
UNIT_FILES :=
# Any unit this unit relies upon (and should be initialized before it's initialized) should
# be listed here using its Vala namespace.
#
# NOTE: All units are assumed to rely upon the unit-unit. Do not include that here.
UNIT_USES := \
Util \
Threads \
Db \
Plugins \
Slideshow \
Photos \
Publishing \
AlienDb \
AlienDb.FSpot \
Core
# List any additional files that are used in the build process as a part of this unit that should
# be packaged in the tarball. File names should be relative to the unit's home directory.
UNIT_RC :=
# unitize.mk must be called at the end of each UNIT_DIR.mk file.
include unitize.mk
......@@ -38,7 +38,7 @@ void library_exec(string[] mounts) {
Unique.App shotwell = new Unique.App("org.yorba.shotwell", null);
shotwell.add_command("MOUNTED_CAMERA", (int) ShotwellCommand.MOUNTED_CAMERA);
shotwell.message_received.connect(on_shotwell_message);
if (shotwell.is_running) {
// send attached cameras & activate the window
foreach (string mount in mounts) {
......@@ -59,7 +59,7 @@ void library_exec(string[] mounts) {
// initialize units
try {
Library.unitize_init();
Library.app_init();
} catch (Error err) {
AppWindow.panic(err.message);
......@@ -112,11 +112,7 @@ void library_exec(string[] mounts) {
return;
}
// initialize GStreamer, but don't pass it our actual command line arguments -- we don't
// want our end users to be able to parameterize the GStreamer configuration
string[] fake_args = new string[0];
unowned string[] fake_unowned_args = fake_args;
Gst.init(ref fake_unowned_args);
Video.init();
ProgressDialog progress_dialog = null;
AggregateProgressMonitor aggregate_monitor = null;
......@@ -221,7 +217,7 @@ void library_exec(string[] mounts) {
ThumbnailCache.terminate();
Video.terminate();
Library.unitize_terminate();
Library.app_terminate();
}
private bool do_system_pictures_import = false;
......@@ -272,7 +268,7 @@ void editing_exec(string filename) {
// initialize units for direct-edit mode
try {
Direct.unitize_init();
Direct.app_init();
} catch (Error err) {
AppWindow.panic(err.message);
......@@ -296,7 +292,7 @@ void editing_exec(string filename) {
DesktopIntegration.terminate();
// terminate units for direct-edit mode
Direct.unitize_terminate();
Direct.app_terminate();
}
namespace CommandlineOptions {
......
......@@ -5,12 +5,6 @@
*/
namespace Unit {
[CCode (has_target = false)]
public delegate void Initializer() throws Error;
[CCode (has_target = false)]
public delegate void Terminator();
public void init() throws Error {
}
......
......@@ -6,64 +6,14 @@
* Auto-generated file. Do not modify!
*/
namespace _APP_GROUP_ {
namespace _APP_UNIT_ {
// Initialize all units, unwinding the inits if an error occurs. The caller should *not* call
// _APP_GROUP_.unitize_terminate() if an error is thrown.
public void unitize_init() throws Error {
Unit.Initializer[] entry_points = Unitize.get_entry_points();
int ctr = 0;
while (ctr < entry_points.length) {
try {
entry_points[ctr]();
} catch (Error err) {
Unit.Terminator[] terminate_points = Unitize.get_terminate_points();
while (ctr >= 0)
terminate_points[ctr--]();
throw err;
}
ctr++;
}
public void app_init() throws Error {
_APP_UNIT_.init_entry();
}
public void unitize_terminate() {
Unit.Terminator[] terminate_points = Unitize.get_terminate_points();
for (int ctr = 0; ctr < terminate_points.length; ctr++)
terminate_points[ctr]();
public void app_terminate() {
_APP_UNIT_.terminate_entry();
}
namespace Unitize {
private Unit.Initializer[]? unitize_entry_points = null;
private Unit.Terminator[]? unitize_terminate_points = null;
// non-const initializers not allowed in static variables and delegates may not be used as
// const initializers, hence the accessors
public Unit.Initializer[] get_entry_points() {
// dummy_init/dummy_terminate used to deal with dangling comma in macro lists
if (unitize_entry_points == null)
unitize_entry_points = { _UNIT_ENTRY_POINTS_ dummy_init };
return unitize_entry_points;
}
public Unit.Terminator[] get_terminate_points() {
if (unitize_terminate_points == null)
unitize_terminate_points = { _UNIT_TERMINATE_POINTS_ dummy_terminate };
return unitize_terminate_points;
}
private void dummy_init() throws Error {
}
private void dummy_terminate() {
}
}
}
......@@ -3,8 +3,9 @@
#
# This list is primarily used at compile time to build the executable.
#
# NOTE: In all unit listings, the unit-unit must be first. Units may follow in any order
# thereafter.
# NOTE: The unit-unit must be first. Units may follow in any order thereafter.
#
# NOTE: Be sure to add the unit to the appropriate APP_UNITS .mk file.
UNITS = \
unit \
util \
......@@ -16,39 +17,12 @@ UNITS = \
publishing \
alien_db \
alien_db/f_spot \
library \
direct \
core
# Names of variables (which follow) that represent unit groups for different uses of the
# application. The variables should be formed as Name_UNITS. Entry and terminate points in
# the code will be Name.unitize_init() and Name.unitize_terminate().
#
# These lists are used primarily at run-time to initialize the proper units depending on the mode
# the executable starts in.
#
# Note that these names can be the names of units as well. In that case, the init and terminate
# code will be placed in that unit's namespace.
APP_GROUPS = Library Direct
# List of units for library mode.
Library_UNITS = \
Unit \
Util \
Threads \
Db \
Plugins \
Slideshow \
Photos \
Publishing \
AlienDb \
AlienDb.FSpot \
Core
# List of units for direct-edit mode.
Direct_UNITS = \
Unit \
Util \
Db \
Direct \
Core
# Name(s) of units that represent application entry points. These units will have init and
# termination entry points generated: Name.unitize_init() and Name.unitize_terminate(). These
# methods should be called in main(). They will initialize the named unit and all is prerequisite
# units, thereby initializing the entire application.
APP_UNITS = Library Direct
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment