Skip to content
Permalink
Browse files

WIP: Add utility functions for snapshot entity

Add Tcl-C interface functions for registry::snapshot entity
  • Loading branch information
umeshksingla authored and neverpanic committed Aug 10, 2017
1 parent c342d9b commit a0478d2a83f429e0edbf0df0b252d8e17900d7e5
Showing with 66 additions and 4 deletions.
  1. +11 −3 src/cregistry/entry.c
  2. +1 −0 src/cregistry/entry.h
  3. +1 −1 src/registry2.0/entry.c
  4. +47 −0 src/registry2.0/util.c
  5. +6 −0 src/registry2.0/util.h
@@ -1710,9 +1710,17 @@ int reg_snapshot_get(reg_registry* reg, char* id, reg_snapshot* snapshot, reg_er

if (r == SQLITE_DONE) {

(*snapshot)->id = NULL;
(*snapshot)->note = NULL;
(*snapshot)->ports = result;
reg_snapshot* s = malloc(sizeof(reg_snapshot*));

if (!s) {
return -1;
}

s->id = NULL;
s->note = NULL;
s->proc = NULL;
s->ports = result;
*snapshot = s;

return result_count;

@@ -58,6 +58,7 @@ typedef struct {
char* id;
char* note;
port* ports;
char* proc; /* name of Tcl proc, if using Tcl */
} reg_snapshot;

reg_entry* reg_entry_create(reg_registry* reg, char* name, char* version,
@@ -559,7 +559,7 @@ static int get_snapshot(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
reg_error error;
reg_snapshot* snapshot;
int port_count = reg_snapshot_get(reg, id, &snapshot, &error);
if (snapshot != NULL) {
if (snapshot != NULL && port_count >= 0) {
Tcl_Obj* resultObj;
if (entry_to_obj(interp, &resultObj, snapshot, NULL, &error)) {
Tcl_SetObjResult(interp, resultObj);
@@ -190,6 +190,29 @@ int set_entry(Tcl_Interp* interp, char* name, reg_entry* entry,
return 0;
}

/**
* Sets a given name to be an snapshot object.
*
* @param [in] interp Tcl interpreter to create the snapshot within
* @param [in] name name to associate the given snapshot with
* @param [in] snapshot snapshot to associate with the given name
* @param [out] errPtr description of error if it couldn't be set
* @return true if success; false if failure
* @see set_object
*/
int set_snapshot(Tcl_Interp* interp, char* name, reg_snapshot* snapshot,
reg_error* errPtr) {
if (set_object(interp, name, snapshot, "snapshot", snapshot_obj_cmd, NULL,
errPtr)) {
snapshot->proc = strdup(name);
if (!snapshot->proc) {
return 0;
}
return 1;
}
return 0;
}

/**
* Sets a given name to be a file object.
*
@@ -303,6 +326,23 @@ int entry_to_obj(Tcl_Interp* interp, Tcl_Obj** obj, reg_entry* entry,
return 1;
}

int snapshot_to_obj(Tcl_Interp* interp, Tcl_Obj** obj, reg_snapshot* snapshot,
int* lower_bound, reg_error* errPtr) {
if (snapshot->proc == NULL) {
char* name = unique_name(interp, "::registry::snapshot", lower_bound);
if (!name) {
return 0;
}
if (!set_snapshot(interp, name, entry, errPtr)) {
free(name);
return 0;
}
free(name);
}
*obj = Tcl_NewStringObj(snapshot->proc, -1);
return 1;
}

int file_to_obj(Tcl_Interp* interp, Tcl_Obj** obj, reg_file* file,
int* lower_bound, reg_error* errPtr) {
if (file->proc == NULL) {
@@ -344,6 +384,13 @@ int list_entry_to_obj(Tcl_Interp* interp, Tcl_Obj*** objs,
(void***)objs, (void**)entries, entry_count, errPtr);
}

int list_snapshot_to_obj(Tcl_Interp* interp, Tcl_Obj*** objs,
reg_snapshot** snapshots, int snapshot_count, reg_error* errPtr) {
int lower_bound = 0;
return recast(interp, (cast_function*)snapshot_to_obj, &lower_bound, NULL,
(void***)objs, (void**)snapshots, snapshot_count, errPtr);
}

int list_file_to_obj(Tcl_Interp* interp, Tcl_Obj*** objs,
reg_file** files, int file_count, reg_error* errPtr) {
int lower_bound = 0;
@@ -58,6 +58,8 @@ int set_object(Tcl_Interp* interp, char* name, void* value, char* type,
Tcl_ObjCmdProc* proc, Tcl_CmdDeleteProc* deleteProc, reg_error* errPtr);
int set_entry(Tcl_Interp* interp, char* name, reg_entry* entry,
reg_error* errPtr);
int set_snapshot(Tcl_Interp* interp, char* name, reg_snapshot* snapshot,
reg_error* errPtr);
int set_file(Tcl_Interp* interp, char* name, reg_file* file,
reg_error* errPtr);
int set_portgroup(Tcl_Interp* interp, char* name, reg_portgroup* portgroup,
@@ -75,6 +77,10 @@ int entry_to_obj(Tcl_Interp* interp, Tcl_Obj** obj, reg_entry* entry,
int* lower_bound, reg_error* errPtr);
int list_entry_to_obj(Tcl_Interp* interp, Tcl_Obj*** objs,
reg_entry** entries, int entry_count, reg_error* errPtr);
int snapshot_to_obj(Tcl_Interp* interp, Tcl_Obj** obj, reg_snapshot* snapshot,
int* lower_bound, reg_error* errPtr);
int list_snapshot_to_obj(Tcl_Interp* interp, Tcl_Obj*** objs,
reg_snapshot** snapshots, int snapshot_count, reg_error* errPtr);
int file_to_obj(Tcl_Interp* interp, Tcl_Obj** ibj, reg_file* file,
int* lower_bound, reg_error* errPtr);
int list_file_to_obj(Tcl_Interp* interp, Tcl_Obj*** objs,

0 comments on commit a0478d2

Please sign in to comment.
You can’t perform that action at this time.