On 06/29/2014 09:01 PM, Nathan Scott wrote:
Thought of another possible approach over the weekend. If we expect this
interface to need further change (given this is the second version of the
interface now, with more development being planned in discovery, we should
plan for it) we could use a versioned interface like pmGetOptions(3) and
his little friend, pmdaGetOptions(3).
That might look something like...
typedef struct {
int version;
int interrupted; /* could become a flags bitfield? */
const char *globalOptions; /* and this could be more explicit, */
/* instead of every possibly option being */
/* coerced into one comma-separated string? */
} pmDiscoveryOptions;
int
pmDiscoverServicesWithOptions(
const char *service,
const char *mechanism,
pmDiscoveryOptions *options,
char ***urls);
That API looks fairly neat to me and is a bit more future proof than
what we currently have. As new extensions/requirements for the API
come along, using the version field & addition-to-end-of-struct-only
gives backwards compatibility almost for free (the libpcp code gets
to be simpler to extend internally too).
I ended up going with this approach. See the commit below. I ended up
leaving 'interrupted' as an int because, currently, the interrupting
signal number is stored there. The code does not examine it at this
point, but I can see potential for this possibility down the road. I
also anticipate this field being used to implement the upcoming global
timeout and it might be useful to invent a code for that as well.
As suggested, 'globalOptions' is now broken into individual fields for
individual options. Currently, only the 'resolve' option is represented
and, since it is a boolean option, it is a single bit in a bitfield.
Dave
------------------------------
Author: Dave Brolley <brolley@xxxxxxxxxx>
Date: Mon Jul 7 14:51:47 2014 -0400
Replace pmDiscoverServicesAdvanced(1) with
pmDiscoverServicesWithOptions(1)
New API takes a pointer pmServiceDiscoveryOptions which is a
versioned struct describing the service discovery options.
|