Index: TODO =================================================================== diff -u -r74b7a4066526ff5f5a8080ed907f71c9ed5c7700 -r25023d3c048b369645973fdfa125a3705c7f1898 --- TODO (.../TODO) (revision 74b7a4066526ff5f5a8080ed907f71c9ed5c7700) +++ TODO (.../TODO) (revision 25023d3c048b369645973fdfa125a3705c7f1898) @@ -4945,7 +4945,12 @@ use "package req nx::volatile" instead - don't define per method "volatile" per default; use "::nsf::method::require ::nx::Object volatile" instead +- get rid of -volatile in nx.tcl and serializer +- updated/extened regression test +nx-mongo: +- added command "::mongo::status /mongoConn/" +- extended regression test ======================================================================== TODO: Index: library/mongodb/mongoAPI.decls =================================================================== diff -u -ra77e97b5d2b703b7c60a850b1f20f6c75e5029ac -r25023d3c048b369645973fdfa125a3705c7f1898 --- library/mongodb/mongoAPI.decls (.../mongoAPI.decls) (revision a77e97b5d2b703b7c60a850b1f20f6c75e5029ac) +++ library/mongodb/mongoAPI.decls (.../mongoAPI.decls) (revision 25023d3c048b369645973fdfa125a3705c7f1898) @@ -22,13 +22,15 @@ cmd connect NsfMongoConnect { {-argName "-uri" -required 0 -nrargs 1} } - cmd run NsfMongoRunCmd { {-argName "-nocomplain" -required 0 -nrargs 0} {-argName "conn" -required 1 -type mongoc_client_t} {-argName "db" -required 1} {-argName "cmd" -required 1 -type tclobj} } +cmd status NsfMongoStatus { + {-argName "conn" -required 1 -type mongoc_client_t -withObj 1} +} # # collection Index: library/mongodb/mongoAPI.h =================================================================== diff -u -ra77e97b5d2b703b7c60a850b1f20f6c75e5029ac -r25023d3c048b369645973fdfa125a3705c7f1898 --- library/mongodb/mongoAPI.h (.../mongoAPI.h) (revision a77e97b5d2b703b7c60a850b1f20f6c75e5029ac) +++ library/mongodb/mongoAPI.h (.../mongoAPI.h) (revision 25023d3c048b369645973fdfa125a3705c7f1898) @@ -85,7 +85,7 @@ /* just to define the symbol */ -static Nsf_methodDefinition method_definitions[28]; +static Nsf_methodDefinition method_definitions[29]; static CONST char *method_command_namespace_names[] = { "::mongo" @@ -117,6 +117,7 @@ static int NsfMongoGridFileReadStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int NsfMongoGridFileSeekStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int NsfMongoRunCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); +static int NsfMongoStatusStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int NsfCollectionClose(Tcl_Interp *interp, mongoc_collection_t *collectionPtr, Tcl_Obj *collectionObj); static int NsfCollectionOpen(Tcl_Interp *interp, mongoc_client_t *connPtr, CONST char *dbname, CONST char *collectionname); @@ -145,6 +146,7 @@ static int NsfMongoGridFileRead(Tcl_Interp *interp, mongoc_gridfs_file_t *gridfilePtr, int size); static int NsfMongoGridFileSeek(Tcl_Interp *interp, mongoc_gridfs_file_t *gridfilePtr, int offset); static int NsfMongoRunCmd(Tcl_Interp *interp, int withNocomplain, mongoc_client_t *connPtr, CONST char *db, Tcl_Obj *cmd); +static int NsfMongoStatus(Tcl_Interp *interp, mongoc_client_t *connPtr, Tcl_Obj *connObj); enum { NsfCollectionCloseIdx, @@ -173,7 +175,8 @@ NsfMongoGridFileOpenIdx, NsfMongoGridFileReadIdx, NsfMongoGridFileSeekIdx, - NsfMongoRunCmdIdx + NsfMongoRunCmdIdx, + NsfMongoStatusIdx } NsfMethods; @@ -735,7 +738,26 @@ } } -static Nsf_methodDefinition method_definitions[28] = { +static int +NsfMongoStatusStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { + ParseContext pc; + (void)clientData; + + if (likely(ArgumentParse(interp, objc, objv, NULL, objv[0], + method_definitions[NsfMongoStatusIdx].paramDefs, + method_definitions[NsfMongoStatusIdx].nrParameters, 0, NSF_ARGPARSE_BUILTIN, + &pc) == TCL_OK)) { + mongoc_client_t *connPtr = (mongoc_client_t *)pc.clientData[0]; + + assert(pc.status == 0); + return NsfMongoStatus(interp, connPtr,pc.objv[0]); + + } else { + return TCL_ERROR; + } +} + +static Nsf_methodDefinition method_definitions[29] = { {"::mongo::collection::close", NsfCollectionCloseStub, 1, { {"collection", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Pointer, NULL,NULL,"mongoc_collection_t",NULL,NULL,NULL,NULL,NULL}} }, @@ -861,6 +883,9 @@ {"conn", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Pointer, NULL,NULL,"mongoc_client_t",NULL,NULL,NULL,NULL,NULL}, {"db", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_String, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, {"cmd", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Tclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} +}, +{"::mongo::status", NsfMongoStatusStub, 1, { + {"conn", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Pointer, NULL,NULL,"mongoc_client_t",NULL,NULL,NULL,NULL,NULL}} },{NULL} }; Index: library/mongodb/nsfmongo.c =================================================================== diff -u -ra77e97b5d2b703b7c60a850b1f20f6c75e5029ac -r25023d3c048b369645973fdfa125a3705c7f1898 --- library/mongodb/nsfmongo.c (.../nsfmongo.c) (revision a77e97b5d2b703b7c60a850b1f20f6c75e5029ac) +++ library/mongodb/nsfmongo.c (.../nsfmongo.c) (revision 25023d3c048b369645973fdfa125a3705c7f1898) @@ -530,7 +530,6 @@ return TCL_OK; } - /* cmd connect NsfMongoConnect { {-argName "-uri" -required 1 -nrargs 1} @@ -614,6 +613,29 @@ } /* +cmd status NsfMongoStatus { + {-argName "conn" -required 1 -type mongoc_client_t -withObj 1} +} +*/ +static int +NsfMongoStatus(Tcl_Interp *interp, mongoc_client_t *clientPtr, Tcl_Obj *clientObj) { + mongoc_read_prefs_t *readPrefs = NULL; /* TODO: not handled */ + bson_t reply, *replyPtr = &reply; + bson_error_t bsonError; + int result = TCL_OK; + + if (likely(mongoc_client_get_server_status(clientPtr, readPrefs, replyPtr, &bsonError)) !=0) { + Tcl_SetObjResult(interp, BsonToList(interp, replyPtr, 0)); + } else { + result = NsfPrintError(interp, "mongo::status: error: %s", bsonError.message); + } + + bson_destroy(replyPtr); + return result; +} + + +/* cmd collection::open NsfCollectionOpen { {-argName "conn" -required 1 -type mongoc_client_t} {-argName "dbname" -required 1} @@ -693,7 +715,6 @@ 0 /*skip */, 0 /*limit */, NULL /* read preferences */, &bsonError); - fprintf(stderr, "count returns %d \n", count); if (count == -1) { bson_destroy( queryPtr ); return NsfPrintError(interp, "mongo::collection::count: error: %s", bsonError.message); @@ -720,7 +741,7 @@ NsfMongoCollectionDelete(Tcl_Interp *interp, mongoc_collection_t *collectionPtr, Tcl_Obj *conditionObj) { - int objc, result, status; + int objc, result, success; Tcl_Obj **objv; bson_t query, *queryPtr = &query; bson_error_t bsonError; @@ -734,9 +755,9 @@ } BsonAppendObjv(interp, queryPtr, objc, objv); - status = mongoc_collection_delete(collectionPtr, deleteFlags, queryPtr, writeConcern, &bsonError); + success = mongoc_collection_delete(collectionPtr, deleteFlags, queryPtr, writeConcern, &bsonError); - if (status == 0) { + if (success == 0) { result = NsfPrintError(interp, "mongo::collection::delete: error: %s", bsonError.message); } bson_destroy(queryPtr); @@ -808,7 +829,7 @@ static int NsfMongoCollectionInsert(Tcl_Interp *interp, mongoc_collection_t *collectionPtr, Tcl_Obj *valuesObj) { - int i, objc, result; + int i, objc, result, success; Tcl_Obj **objv; bson_t bson, *bsonPtr = &bson; bson_oid_t oid; @@ -838,16 +859,16 @@ BsonAppend(interp, bsonPtr, name, tag, value); } - result = mongoc_collection_insert(collectionPtr, insertFlags, bsonPtr, writeConcern, &bsonError); + success = mongoc_collection_insert(collectionPtr, insertFlags, bsonPtr, writeConcern, &bsonError); - if (result == 0) { - bson_destroy(bsonPtr); - return NsfPrintError(interp, "mongo::collection::insert: error: %s", bsonError.message); + if (success == 0) { + result = NsfPrintError(interp, "mongo::collection::insert: error: %s", bsonError.message); } else { Tcl_SetObjResult(interp, BsonToList(interp, bsonPtr, 0)); - result = TCL_OK; - bson_destroy(bsonPtr); } + + bson_destroy(bsonPtr); + return result; } Index: library/mongodb/tests/nsf-mongo.test =================================================================== diff -u -ra6a6d9c14bfefba367b3147e05fbab4137f044ce -r25023d3c048b369645973fdfa125a3705c7f1898 --- library/mongodb/tests/nsf-mongo.test (.../nsf-mongo.test) (revision a6a6d9c14bfefba367b3147e05fbab4137f044ce) +++ library/mongodb/tests/nsf-mongo.test (.../nsf-mongo.test) (revision 25023d3c048b369645973fdfa125a3705c7f1898) @@ -163,7 +163,6 @@ [list \$query document {projects document {$in array {0 string nsf 1 string gtat}}}]]} 3 puts stderr "\nStatistics of $mongoColl" -puts stderr [::mongo::collection::stats $mongoColl] set stats [::mongo::collection::stats $mongoColl] ? {expr [llength $stats] % 3 == 0} 1 @@ -175,6 +174,13 @@ puts [C bson pp $stats] } +puts stderr "\nStatus" +set status [::mongo::status $mongoConn] +puts [C bson pp $status] + +? {expr [llength $status] % 3 == 0} 1 +? {expr [llength $status] > 0} 1 + puts stderr "\nClose connection $mongoConn" ::mongo::close $mongoConn