gphoto4ruby 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +5 -0
- data/ext/gphoto4ruby.c +158 -3
- data/ext/gphoto4ruby.h +12 -0
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
data/ext/gphoto4ruby.c
CHANGED
@@ -185,6 +185,13 @@ static VALUE camera_allocate(VALUE klass) {
|
|
185
185
|
return Data_Wrap_Struct(klass, camera_mark, camera_free, c);
|
186
186
|
}
|
187
187
|
|
188
|
+
static void camera_event_mark(GPhoto2CameraEvent *ce) {
|
189
|
+
}
|
190
|
+
|
191
|
+
static void camera_event_free(GPhoto2CameraEvent *ce) {
|
192
|
+
free(ce);
|
193
|
+
}
|
194
|
+
|
188
195
|
/*
|
189
196
|
* call-seq:
|
190
197
|
* GPhoto2::Camera.new(port=nil)
|
@@ -918,29 +925,173 @@ static VALUE camera_folder_down(VALUE self, VALUE folder) {
|
|
918
925
|
return self;
|
919
926
|
}
|
920
927
|
|
928
|
+
/*
|
929
|
+
* call-seq:
|
930
|
+
* wait(timeout=2000) => camera event
|
931
|
+
*
|
932
|
+
* Waits for an event from camera for specified amount of milliseconds.
|
933
|
+
* Returns an instance of GPhoto2::CameraEvent. When capturing image manually
|
934
|
+
* with camera connected through USB, images are not saved on memory card
|
935
|
+
* until you call this method. During tests EVENT_TYPE_FILE_ADDED event
|
936
|
+
* was always followed by EVENT_TYPE_UNKNOWN. So in the case of
|
937
|
+
* EVENT_TYPE_FILE_ADDED or EVENT_TYPE_FOLDER_ADDED, an extra call is made
|
938
|
+
* with 100ms timeout which result is ignored.
|
939
|
+
*
|
940
|
+
* When image is captured manually and then event is caught, camera virtual
|
941
|
+
* folder is changed to the one where files are saved.
|
942
|
+
*
|
943
|
+
* Examples:
|
944
|
+
*
|
945
|
+
* c = GPhoto2::Camera.new
|
946
|
+
* # capture the image manually
|
947
|
+
* evt = c.wait
|
948
|
+
* evt.type #=> "file added"
|
949
|
+
* evt.type == GPhoto2::CameraEvent::EVENT_TYPE_FILE_ADDED
|
950
|
+
* #=> true
|
951
|
+
* evt.file #=> "DSC_0384.JPG"
|
952
|
+
*
|
953
|
+
* # do nothing
|
954
|
+
* c.wait(1).type #=> "timeout"
|
955
|
+
*/
|
956
|
+
static VALUE camera_wait(int argc, VALUE *argv, VALUE self) {
|
957
|
+
GPhoto2Camera *c;
|
958
|
+
GPhoto2CameraEvent *ce;
|
959
|
+
CameraEventType fakeType;
|
960
|
+
void *evtData, *fakeData;
|
961
|
+
int to;
|
962
|
+
|
963
|
+
switch (argc) {
|
964
|
+
case 0:
|
965
|
+
to = 2000;
|
966
|
+
break;
|
967
|
+
case 1:
|
968
|
+
to = FIX2INT(rb_funcall(argv[0], rb_intern("to_i"), 0));
|
969
|
+
break;
|
970
|
+
default:
|
971
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for 0 or 1)", argc);
|
972
|
+
return Qnil;
|
973
|
+
}
|
974
|
+
|
975
|
+
Data_Get_Struct(self, GPhoto2Camera, c);
|
976
|
+
ce = (GPhoto2CameraEvent*) malloc(sizeof(GPhoto2CameraEvent));
|
977
|
+
|
978
|
+
gp_result_check(gp_camera_wait_for_event(c->camera, to, &(ce->type), &evtData, c->context));
|
979
|
+
|
980
|
+
switch (ce->type) {
|
981
|
+
case GP_EVENT_FILE_ADDED:
|
982
|
+
case GP_EVENT_FOLDER_ADDED:
|
983
|
+
ce->path = (CameraFilePath*)evtData;
|
984
|
+
strcpy(c->virtFolder, ce->path->folder);
|
985
|
+
gp_result_check(gp_camera_wait_for_event(c->camera, 100, &fakeType, &fakeData, c->context));
|
986
|
+
break;
|
987
|
+
}
|
988
|
+
return Data_Wrap_Struct(rb_cGPhoto2CameraEvent, camera_event_mark, camera_event_free, ce);
|
989
|
+
}
|
990
|
+
|
991
|
+
/*
|
992
|
+
* call-seq:
|
993
|
+
* type => string
|
994
|
+
*
|
995
|
+
* Returns type of event. Can be compared to EVENT_TYPE class constants
|
996
|
+
*
|
997
|
+
* Examples:
|
998
|
+
*
|
999
|
+
* c = GPhoto2::Camera.new
|
1000
|
+
* # capture the image manually
|
1001
|
+
* evt = c.wait
|
1002
|
+
* evt.type #=> "file added"
|
1003
|
+
* evt.type == GPhoto2::CameraEvent::EVENT_TYPE_FILE_ADDED
|
1004
|
+
* #=> true
|
1005
|
+
* evt.file #=> "DSC_0384.JPG"
|
1006
|
+
*
|
1007
|
+
* # do nothing
|
1008
|
+
* c.wait(1).type #=> "timeout"
|
1009
|
+
*/
|
1010
|
+
static VALUE camera_event_type(VALUE self) {
|
1011
|
+
GPhoto2CameraEvent *ce;
|
1012
|
+
|
1013
|
+
Data_Get_Struct(self, GPhoto2CameraEvent, ce);
|
1014
|
+
|
1015
|
+
switch (ce->type) {
|
1016
|
+
case GP_EVENT_FILE_ADDED:
|
1017
|
+
return EVENT_FILE_ADDED;
|
1018
|
+
case GP_EVENT_FOLDER_ADDED:
|
1019
|
+
return EVENT_FOLDER_ADDED;
|
1020
|
+
case GP_EVENT_TIMEOUT:
|
1021
|
+
return EVENT_TIMEOUT;
|
1022
|
+
case GP_EVENT_UNKNOWN:
|
1023
|
+
return EVENT_UNKNOWN;
|
1024
|
+
default:
|
1025
|
+
return Qnil;
|
1026
|
+
}
|
1027
|
+
}
|
1028
|
+
|
1029
|
+
/*
|
1030
|
+
* call-seq:
|
1031
|
+
* file => string or nil
|
1032
|
+
*
|
1033
|
+
* Returns file name of manually captured image. Only applies to
|
1034
|
+
* EVENT_TYPE_FILE_ADDED event.
|
1035
|
+
*
|
1036
|
+
* Examples:
|
1037
|
+
*
|
1038
|
+
* c = GPhoto2::Camera.new
|
1039
|
+
* # capture the image manually
|
1040
|
+
* evt = c.wait
|
1041
|
+
* evt.type #=> "file added"
|
1042
|
+
* evt.type == GPhoto2::CameraEvent::EVENT_TYPE_FILE_ADDED
|
1043
|
+
* #=> true
|
1044
|
+
* evt.file #=> "DSC_0384.JPG"
|
1045
|
+
*
|
1046
|
+
* # do nothing
|
1047
|
+
* c.wait(1).type #=> "timeout"
|
1048
|
+
*/
|
1049
|
+
static VALUE camera_event_file(VALUE self) {
|
1050
|
+
GPhoto2CameraEvent *ce;
|
1051
|
+
|
1052
|
+
Data_Get_Struct(self, GPhoto2CameraEvent, ce);
|
1053
|
+
|
1054
|
+
if (ce->type == GP_EVENT_FILE_ADDED) {
|
1055
|
+
return rb_str_new2(ce->path->name);
|
1056
|
+
} else {
|
1057
|
+
return Qnil;
|
1058
|
+
}
|
1059
|
+
}
|
1060
|
+
|
921
1061
|
void Init_gphoto4ruby() {
|
922
1062
|
/*
|
923
|
-
* Module contains camera class definition and some exceptions
|
1063
|
+
* Module contains camera class definition and some exceptions.
|
924
1064
|
*/
|
925
1065
|
rb_mGPhoto2 = rb_define_module("GPhoto2");
|
926
1066
|
/*
|
927
1067
|
* GPhoto2::Camera object is a Ruby wrapping aroung gphoto2 C library.
|
928
1068
|
*/
|
929
1069
|
rb_cGPhoto2Camera = rb_define_class_under(rb_mGPhoto2, "Camera", rb_cObject);
|
1070
|
+
/*
|
1071
|
+
* GPhoto2::CameraEvent is returned by camera.wait function. Probable usage
|
1072
|
+
* is waiting for camera to save files if you capture them manually and not
|
1073
|
+
* with camera.capture method. This class has no constructor.
|
1074
|
+
*/
|
1075
|
+
rb_cGPhoto2CameraEvent = rb_define_class_under(rb_mGPhoto2, "CameraEvent", rb_cObject);
|
930
1076
|
/*
|
931
1077
|
* GPhoto2::Exception is raised when libgphoto2 functions from C core
|
932
|
-
* return any error code
|
1078
|
+
* return any error code.
|
933
1079
|
*/
|
934
1080
|
rb_cGPhoto2Exception = rb_define_class_under(rb_mGPhoto2, "Exception", rb_eStandardError);
|
935
1081
|
/*
|
936
1082
|
* GPhoto2::ConfigurationError is raised when trying to set configuration
|
937
1083
|
* values that are not allowed or trying to access properties that are not
|
938
|
-
* supported
|
1084
|
+
* supported.
|
939
1085
|
*/
|
940
1086
|
rb_cGPhoto2ConfigurationError = rb_define_class_under(rb_mGPhoto2, "ConfigurationError", rb_eStandardError);
|
941
1087
|
|
942
1088
|
rb_define_const(rb_cGPhoto2Camera, "CONFIG_TYPE_RADIO", INT2FIX(GP_WIDGET_RADIO));
|
943
1089
|
rb_define_const(rb_cGPhoto2Camera, "CONFIG_TYPE_RANGE", INT2FIX(GP_WIDGET_RANGE));
|
1090
|
+
|
1091
|
+
rb_define_const(rb_cGPhoto2CameraEvent, "EVENT_TYPE_UNKNOWN", EVENT_UNKNOWN);
|
1092
|
+
rb_define_const(rb_cGPhoto2CameraEvent, "EVENT_TYPE_TIMEOUT", EVENT_TIMEOUT);
|
1093
|
+
rb_define_const(rb_cGPhoto2CameraEvent, "EVENT_TYPE_FILE_ADDED", EVENT_FILE_ADDED);
|
1094
|
+
rb_define_const(rb_cGPhoto2CameraEvent, "EVENT_TYPE_FOLDER_ADDED", EVENT_FOLDER_ADDED);
|
944
1095
|
|
945
1096
|
rb_define_alloc_func(rb_cGPhoto2Camera, camera_allocate);
|
946
1097
|
rb_define_module_function(rb_cGPhoto2Camera, "ports", camera_class_ports, 0);
|
@@ -957,5 +1108,9 @@ void Init_gphoto4ruby() {
|
|
957
1108
|
rb_define_method(rb_cGPhoto2Camera, "files", camera_files, 0);
|
958
1109
|
rb_define_method(rb_cGPhoto2Camera, "folder_up", camera_folder_up, 0);
|
959
1110
|
rb_define_method(rb_cGPhoto2Camera, "folder_down", camera_folder_down, 1);
|
1111
|
+
rb_define_method(rb_cGPhoto2Camera, "wait", camera_wait, -1);
|
1112
|
+
|
1113
|
+
rb_define_method(rb_cGPhoto2CameraEvent, "type", camera_event_type, 0);
|
1114
|
+
rb_define_method(rb_cGPhoto2CameraEvent, "file", camera_event_file, 0);
|
960
1115
|
}
|
961
1116
|
|
data/ext/gphoto4ruby.h
CHANGED
@@ -32,8 +32,20 @@ typedef struct {
|
|
32
32
|
char *virtFolder;
|
33
33
|
} GPhoto2Camera;
|
34
34
|
|
35
|
+
typedef struct {
|
36
|
+
CameraEventType type;
|
37
|
+
CameraFilePath *path;
|
38
|
+
} GPhoto2CameraEvent;
|
39
|
+
|
40
|
+
#define EVENT_UNKNOWN rb_str_new2("unknown")
|
41
|
+
#define EVENT_TIMEOUT rb_str_new2("timeout")
|
42
|
+
#define EVENT_FILE_ADDED rb_str_new2("file added")
|
43
|
+
#define EVENT_FOLDER_ADDED rb_str_new2("folder added")
|
44
|
+
|
35
45
|
static VALUE rb_mGPhoto2;
|
36
46
|
static VALUE rb_cGPhoto2Camera;
|
47
|
+
static VALUE rb_cGPhoto2CameraEvent;
|
48
|
+
|
37
49
|
static VALUE rb_cGPhoto2Exception;
|
38
50
|
static VALUE rb_cGPhoto2ConfigurationError;
|
39
51
|
|