| Get_String of (unit -> string)
| Get_ObjectPath of (unit -> string)
+ (* setters are tuples of predicates and the real_setters; the
+ real setters are only called if the predicate is satisfied on
+ the input value *)
type setter =
- | Set_Byte of (char -> unit)
- | Set_Bool of (bool -> unit)
- | Set_Int16 of (int -> unit)
- | Set_UInt16 of (int -> unit)
- | Set_Int32 of (int32 -> unit)
- | Set_UInt32 of (int32 -> unit)
- | Set_Int64 of (int64 -> unit)
- | Set_UInt64 of (int64 -> unit)
- | Set_Double of (float -> unit)
- | Set_String of (string -> unit)
- | Set_ObjectPath of (string -> unit)
+ | Set_Byte of (char -> bool) * (char -> unit)
+ | Set_Bool of (bool -> bool) * (bool -> unit)
+ | Set_Int16 of (int -> bool) * (int -> unit)
+ | Set_UInt16 of (int -> bool) * (int -> unit)
+ | Set_Int32 of (int32 -> bool) * (int32 -> unit)
+ | Set_UInt32 of (int32 -> bool) * (int32 -> unit)
+ | Set_Int64 of (int64 -> bool) * (int64 -> unit)
+ | Set_UInt64 of (int64 -> bool) * (int64 -> unit)
+ | Set_Double of (float -> bool) * (float -> unit)
+ | Set_String of (string -> bool) * (string -> unit)
+ | Set_ObjectPath of (string -> bool) * (string -> unit)
+
+ (* common utility predicate *)
+ let true_predicate _ = true
+ let bool_string_predicate = function
+ | "true" | "false" -> true
+ | _ -> false
+ let int_string_predicate s =
+ try ignore (int_of_string s); true with _ -> false
+ let uint_string_predicate s =
+ try (int_of_string s) >= 0 with _ -> false
let getter_argtype_str = function
| Get_Byte _ -> "byte"
let dispatch_set properties pname dbus_ty =
let opt_setter = (try Some (snd (List.assoc pname properties))
- with Not_found -> None)
+ with Not_found -> None) in
+ let invalid_error = Left (DBus.ERR_INVALID_ARGS, "invalid value", [])
in match opt_setter, dbus_ty with
- | Some (Set_Byte f), DBus.Byte v -> f v; Right []
- | Some (Set_Bool f), DBus.Bool v -> f v; Right []
- | Some (Set_Int16 f), DBus.Int16 v -> f v; Right []
- | Some (Set_UInt16 f), DBus.UInt16 v -> f v; Right []
- | Some (Set_Int32 f), DBus.Int32 v -> f v; Right []
- | Some (Set_UInt32 f), DBus.UInt32 v -> f v; Right []
- | Some (Set_Int64 f), DBus.Int64 v -> f v; Right []
- | Some (Set_UInt64 f), DBus.UInt64 v -> f v; Right []
- | Some (Set_Double f), DBus.Double v -> f v; Right []
- | Some (Set_String f), DBus.String v -> f v; Right []
- | Some (Set_ObjectPath f), DBus.ObjectPath v -> f v; Right []
+ | Some (Set_Byte (p, f)), DBus.Byte v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
+ | Some (Set_Bool (p, f)), DBus.Bool v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
+ | Some (Set_Int16 (p, f)), DBus.Int16 v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
+ | Some (Set_UInt16 (p, f)), DBus.UInt16 v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
+ | Some (Set_Int32 (p, f)), DBus.Int32 v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
+ | Some (Set_UInt32 (p, f)), DBus.UInt32 v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
+ | Some (Set_Int64 (p, f)), DBus.Int64 v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
+ | Some (Set_UInt64 (p, f)), DBus.UInt64 v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
+ | Some (Set_Double (p, f)), DBus.Double v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
+ | Some (Set_String (p, f)), DBus.String v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
+ | Some (Set_ObjectPath (p, f)), DBus.ObjectPath v ->
+ if p v then begin f v; Right [] end
+ else invalid_error
| Some g, _ ->
Left (DBus.ERR_INVALID_ARGS, "invalid arg(s)",
[ DBus.String (