Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sds
bake
Commits
ce62da3f
Commit
ce62da3f
authored
Jan 19, 2021
by
Philip Carns
Browse files
json sub-object for file backend
parent
72a714b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/bake-file-backend.c
View file @
ce62da3f
...
...
@@ -19,6 +19,7 @@
#include "bake-server.h"
#include "bake-provider.h"
#include "bake-backend.h"
#include "bake-macros.h"
/* bake-file-backend
*
...
...
@@ -164,9 +165,11 @@ static int bake_file_backend_initialize(bake_provider_t provider,
bake_file_entry_t
*
new_entry
=
calloc
(
1
,
sizeof
(
*
new_entry
));
new_entry
->
provider
=
provider
;
new_entry
->
log_fd
=
-
1
;
const
char
*
tmp
;
ptrdiff_t
d
;
struct
stat
statbuf
;
const
char
*
tmp
;
ptrdiff_t
d
;
struct
stat
statbuf
;
struct
json_object
*
file_backend_json
=
NULL
;
struct
json_object
*
target_array
=
NULL
;
if
(
!
json_object_get_boolean
(
json_object_object_get
(
provider
->
json_cfg
,
"pipeline_enable"
)))
{
...
...
@@ -180,6 +183,15 @@ static int bake_file_backend_initialize(bake_provider_t provider,
return
(
BAKE_ERR_INVALID_ARG
);
}
CONFIG_HAS_OR_CREATE_OBJECT
(
provider
->
json_cfg
,
"file_backend"
,
"file_backend"
,
file_backend_json
);
CONFIG_HAS_OR_CREATE_ARRAY
(
file_backend_json
,
"targets"
,
"file_backend.targets"
,
target_array
);
/* TODO: populate tuning parameters specific to this backend; for now
* that's probably alignment and abt-io thread count?
*/
tmp
=
strrchr
(
path
,
'/'
);
if
(
!
tmp
)
tmp
=
path
;
new_entry
->
filename
=
strdup
(
tmp
);
...
...
@@ -236,6 +248,11 @@ static int bake_file_backend_initialize(bake_provider_t provider,
goto
error_cleanup
;
}
/* target successfully added; inject it into the json in array of
* targets for this backend
*/
json_object_array_add
(
target_array
,
json_object_new_string
(
path
));
fprintf
(
stderr
,
"WARNING: Bake file backend does not yet support the following:
\n
"
);
fprintf
(
stderr
,
" * writes to non-zero region offsets
\n
"
);
...
...
src/bake-macros.h
View file @
ce62da3f
...
...
@@ -31,4 +31,40 @@ static const int json_type_int64 = json_type_int;
} \
} while (0)
// Checks if a JSON object has a particular key and its value is of type object.
// If the field does not exist, creates it with an empty object.
// If the field exists but is not of type object, prints an error and return -1.
// After a call to this macro, __out is set to the ceated/found field.
#define CONFIG_HAS_OR_CREATE_OBJECT(__config, __key, __fullname, __out) \
do { \
__out = json_object_object_get(__config, __key); \
if (__out && !json_object_is_type(__out, json_type_object)) { \
fprintf(stderr, "\"%s\" is in configuration but is not an object", \
__fullname); \
return -1; \
} \
if (!__out) { \
__out = json_object_new_object(); \
json_object_object_add(__config, __key, __out); \
} \
} while (0)
// Checks if a JSON object has a particular key and its value is of type array.
// If the field does not exist, creates it with an empty array.
// If the field exists but is not of type object, prints an error and return -1.
// After a call to this macro, __out is set to the ceated/found field.
#define CONFIG_HAS_OR_CREATE_ARRAY(__config, __key, __fullname, __out) \
do { \
__out = json_object_object_get(__config, __key); \
if (__out && !json_object_is_type(__out, json_type_array)) { \
fprintf(stderr, "\"%s\" is in configuration but is not an array", \
__fullname); \
return -1; \
} \
if (!__out) { \
__out = json_object_new_array(); \
json_object_object_add(__config, __key, __out); \
} \
} while (0)
#endif
/* __BAKE_MACROS */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment