From 15850cf44da3d14db0370b2144a294f42eb8345d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 30 Nov 2014 17:44:35 +0000 Subject: Support returning/fetching a single item via ice --- project2/ice/iceRows.cpp | 20 +++++++++++++------- project2/ice/iceViewSerializer.cpp | 10 ++++++++-- project2/ice/slice2Daemon.cpp | 4 ++-- project2/ice/slice2Rows.cpp | 2 +- project2/ice/unittests/expected/clientPresenter.log | 8 ++++++++ project2/ice/unittests/lib/testrows.xml | 6 ++++++ project2/ice/unittests/testClient.cpp | 7 +++++++ project2/ice/unittests/testClient.xml | 2 ++ project2/ice/unittests/testDaemon.cpp | 6 ++++++ project2/ice/unittests/unittest.ice | 2 ++ .../views/UnitTest/SimpleInterface/SingleRow.xml | 5 +++++ 11 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 project2/ice/unittests/views/UnitTest/SimpleInterface/SingleRow.xml diff --git a/project2/ice/iceRows.cpp b/project2/ice/iceRows.cpp index 77519cd..be079dd 100644 --- a/project2/ice/iceRows.cpp +++ b/project2/ice/iceRows.cpp @@ -68,19 +68,25 @@ RowProcSerializer::Serialize(ModelPartPtr mp) case mpt_Null: return; case mpt_Simple: - case mpt_Complex: case mpt_Dictionary: throw std::runtime_error("Not a sequence of things"); + case mpt_Complex: + { + IceRowState irs(mp); + irs.IterateOver(mp, rpc); + break; + } case mpt_Sequence: - IceRowState * irs = NULL; - mp->OnEachChild(boost::bind(&RowProcSerializer::SerializeRow, this, boost::ref(irs), _2)); - if (irs) { - delete irs; + { + IceRowState * irs = NULL; + mp->OnEachChild(boost::bind(&RowProcSerializer::SerializeRow, this, boost::ref(irs), _2)); + if (irs) { + delete irs; + } + break; } - break; } } - } void diff --git a/project2/ice/iceViewSerializer.cpp b/project2/ice/iceViewSerializer.cpp index b690224..7651fc1 100644 --- a/project2/ice/iceViewSerializer.cpp +++ b/project2/ice/iceViewSerializer.cpp @@ -50,10 +50,16 @@ IceViewSerializer::addNamedValue(const Glib::ustring & name, const VariableType void IceViewSerializer::addNewRow(const Glib::ustring & name) const { - rowmpp = mpp->GetChild(name); - if (rowmpp) { + if (mpp->GetType() == Slicer::mpt_Complex) { + rowmpp = mpp; rowmpp->Create(); } + else { + rowmpp = mpp->GetChild(name); + if (rowmpp) { + rowmpp->Create(); + } + } } void diff --git a/project2/ice/slice2Daemon.cpp b/project2/ice/slice2Daemon.cpp index 3e66339..4cd879f 100644 --- a/project2/ice/slice2Daemon.cpp +++ b/project2/ice/slice2Daemon.cpp @@ -43,8 +43,8 @@ Slice2Daemon::visitOperation(const Slice::OperationPtr & o) fprintf(code, "const ::Ice::Current &) {\n"); visitParameterMap(o); if (o->returnType()) { - fprintf(code, "\t\t\t\t%s rtn;\n", o->returnType()->typeId().c_str()); - fprintf(code, "\t\t\t\tSlicer::ModelPartPtr mpp = new Slicer::ModelPartForSequence< %s >(rtn);\n", o->returnType()->typeId().c_str()); + fprintf(code, "\t\t\t\t%s rtn;\n", returnTypeToString(o->returnType(), o->returnIsOptional()).c_str()); + fprintf(code, "\t\t\t\tSlicer::ModelPartPtr mpp = Slicer::ModelPartFor(rtn);\n"); fprintf(code, "\t\t\t\texecuteView(\"%s/%s/%s\", mpp, params);\n", module.c_str(), interface.c_str(), o->name().c_str()); fprintf(code, "\t\t\t\treturn rtn;\n"); } diff --git a/project2/ice/slice2Rows.cpp b/project2/ice/slice2Rows.cpp index 3534aff..cea2d6b 100644 --- a/project2/ice/slice2Rows.cpp +++ b/project2/ice/slice2Rows.cpp @@ -47,7 +47,7 @@ Slice2Rows::visitOperation(const Slice::OperationPtr & o) fprintf(code, "\t\t\t\t\t\tauto result = "); CallOperation(o); fprintf(code, ";\n"); - fprintf(code, "\t\t\t\t\t\tSlicer::ModelPartPtr mp = new Slicer::ModelPartForSequence(&result);\n"); + fprintf(code, "\t\t\t\t\t\tSlicer::ModelPartPtr mp = Slicer::ModelPartFor(result);\n"); fprintf(code, "\t\t\t\t\t\ttoRpc->Serialize(mp);\n"); fprintf(code, "\t\t\t\t\t}\n\n"); ParameterVariables(o); diff --git a/project2/ice/unittests/expected/clientPresenter.log b/project2/ice/unittests/expected/clientPresenter.log index cda61fc..cebd0bf 100644 --- a/project2/ice/unittests/expected/clientPresenter.log +++ b/project2/ice/unittests/expected/clientPresenter.log @@ -1,4 +1,12 @@ init +addNewRowSet: row +addNewArray: rec(1) +addNewRow: rec +addNamedValue: a=3 +addNamedValue: b=single +finishRow +finishArray: (1) +finishRowSet addNewRowSet: somerows addNewArray: rec(1) addNewRow: rec diff --git a/project2/ice/unittests/lib/testrows.xml b/project2/ice/unittests/lib/testrows.xml index 876e311..75578d6 100644 --- a/project2/ice/unittests/lib/testrows.xml +++ b/project2/ice/unittests/lib/testrows.xml @@ -2,6 +2,12 @@ /unittest-data.xml + + + + + + diff --git a/project2/ice/unittests/testClient.cpp b/project2/ice/unittests/testClient.cpp index e5d45b7..4040b60 100644 --- a/project2/ice/unittests/testClient.cpp +++ b/project2/ice/unittests/testClient.cpp @@ -24,6 +24,11 @@ class Dummy : public UnitTest::SimpleInterface { { } + UnitTest::SimplePtr SingleRow(const Ice::Current&) + { + return new UnitTest::Simple { 3, "single" }; + } + UnitTest::Simples SomeRows(const Ice::Current&) { UnitTest::Simples rtn { @@ -66,6 +71,7 @@ commonTests() BOOST_TEST_CHECKPOINT("Verify loaded"); BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTask")); BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTaskParams")); + BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SingleRow")); BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRows")); BOOST_REQUIRE(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams")); @@ -96,6 +102,7 @@ unloadTests() BOOST_TEST_CHECKPOINT("Verify unloaded"); BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTask"), NotSupported); BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeTaskParams"), NotSupported); + BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SingleRow"), NotSupported); BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRows"), NotSupported); BOOST_REQUIRE_THROW(ElementLoader::getFor("UnitTest-SimpleInterface-SomeRowsParams"), NotSupported); } diff --git a/project2/ice/unittests/testClient.xml b/project2/ice/unittests/testClient.xml index 4ae33b1..c8fb208 100644 --- a/project2/ice/unittests/testClient.xml +++ b/project2/ice/unittests/testClient.xml @@ -3,8 +3,10 @@ xmlns:p2="http://project2.randomdan.homeip.net"> + + diff --git a/project2/ice/unittests/testDaemon.cpp b/project2/ice/unittests/testDaemon.cpp index 9e86a03..fe0b0f5 100644 --- a/project2/ice/unittests/testDaemon.cpp +++ b/project2/ice/unittests/testDaemon.cpp @@ -74,6 +74,12 @@ commonTests() BOOST_REQUIRE(si); si->ice_ping(); + BOOST_TEST_CHECKPOINT("Call view (single)"); + auto single = si->SingleRow(); + BOOST_REQUIRE(single); + BOOST_REQUIRE_EQUAL(1, single->a); + BOOST_REQUIRE_EQUAL("third", single->b); + BOOST_TEST_CHECKPOINT("Call view (no parameters)"); auto rows = si->SomeRows(); BOOST_REQUIRE_EQUAL(4, rows.size()); diff --git a/project2/ice/unittests/unittest.ice b/project2/ice/unittests/unittest.ice index 60e44bb..f7305d3 100644 --- a/project2/ice/unittests/unittest.ice +++ b/project2/ice/unittests/unittest.ice @@ -9,6 +9,8 @@ module UnitTest { interface SimpleInterface { + ["project2:rows"] + Simple SingleRow(); ["project2:rows"] Simples SomeRows(); ["project2:rows"] diff --git a/project2/ice/unittests/views/UnitTest/SimpleInterface/SingleRow.xml b/project2/ice/unittests/views/UnitTest/SimpleInterface/SingleRow.xml new file mode 100644 index 0000000..2b54b96 --- /dev/null +++ b/project2/ice/unittests/views/UnitTest/SimpleInterface/SingleRow.xml @@ -0,0 +1,5 @@ + + + + + -- cgit v1.2.3